I'm developing a program for users from a VBulletin's forum. This forum has a lot of people interested in write good articles but some of them don't know how to use the formatting bar in his favor. Sometimes, the others members don't read this threads/articles because it doesn't have a interesting formatting (crazy world, huh?). So here's my idea:
Idea
The user don't need to worry about formatting the thread, so he can be focused just on the writing and the content. The formatting part (the boring part) will be generated by the program, the user just need choose colors for titles and text content.
Code
I've created a class named Markup
where all models for formatting will be set.
public class Markup {}
Inside this class I created a private enum
to define Which BBcodes are accepted by VBulletin, something like:
enum BBcode {
BOLD("B"),
ITALIC("I"),
IMAGE("IMG"),
UNDERLINE("U"),
VIDEO("VIDEO");
/* many others... */
final String code;
private BBcode(String code) {
this.code = code;
}
public String code(){
return this.code;
}
}
Still inside Markup
class I've created a private class
named Syntax
to define how the BBcode syntax will created., like this:
class Syntax {
public String in(BBcode bbcode){
return "[" + bbcode.code() + "]"; // will return "[BOLD]" for example.
}
public String inValued(BBcode bbcode, String value){
return "[" + bbcode.code() + "=" + value + "]"; // will return "[COLOR=#333]" for example.
}
public String out(BBcode bbcode){
return "[/" + bbcode.code() + "]"; // will return "[/BOLD]" for example.
}
}
So I can handle it like:
public String setContents(BBcode bbcode, String contents){
return syntax.in(bbcode) + contents + syntax.out(bbcode); // will return "[BOLD]foo[/BOLD]
}
My questions:
- The names for class and methods are ok? Other peoples can be part of the project and I want them to know what the class does.
- All this stuff are inside the
Markup
class (because theBBcode
and theSyntax
will be util just for theMarkup
). It's a good practice group similar things inside a unique class?