Kawai Wiki

Compare Revisions

Ignore whitespace Rev 193 → Rev 194

/trunk/src/main/java/org/kawai/model/Preview.java
2,126 → 2,146
 
import java.util.Date;
 
/**
* Model class Preview.
*
* @author Sergio Oliveira
*
*/
public class Preview {
private int id;
private int userId;
private User user;
private String name;
private int languageId;
private String title;
private String body;
private Date createdOn;
private boolean isNew;
private boolean isSystemPage;
private String comment;
public Preview() { }
 
public int getId() {
return id;
/** Attribute id of Preview. */
private int id;
/** Attribute userId of Preview. */
private int userId;
/** Attribute user of Preview. */
private User user;
/** Attribute name of Preview. */
private String name;
/** Attribute languageId of Preview. */
private int languageId;
/** Attribute title of Preview. */
private String title;
/** Attribute body of Preview. */
private String body;
/** Attribute createdOn of Preview. */
private Date createdOn;
/** Attribute isNew of Preview. */
private boolean isNew;
/** Attribute isSystemPage of Preview. */
private boolean isSystemPage;
/** Attribute comment of Preview. */
private String comment;
 
/**
* Default constructor.
*/
public Preview() { }
 
public int getId() {
return id;
}
 
public void setId(int id) {
this.id = id;
public void setId(int id) {
this.id = id;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getComment() {
return comment;
}
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
 
public int getUserId() {
return userId;
public void setComment(String comment) {
this.comment = comment;
}
 
public void setUserId(int userId) {
this.userId = userId;
public String getComment() {
return comment;
}
 
public Date getCreatedOn() {
return createdOn;
public void setUser(User user) {
this.user = user;
}
 
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
public User getUser() {
return user;
}
 
public String getTitle() {
return title;
public int getUserId() {
return userId;
}
 
public void setTitle(String title) {
this.title = title;
public void setUserId(int userId) {
this.userId = userId;
}
 
public String getBody() {
return body;
public Date getCreatedOn() {
return createdOn;
}
 
public void setBody(String body) {
this.body = body;
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
 
public String getName() {
return name;
public String getTitle() {
return title;
}
 
public void setName(String name) {
this.name = name;
public void setTitle(String title) {
this.title = title;
}
 
public int getLanguageId() {
return languageId;
public String getBody() {
return body;
}
 
public void setLanguageId(int languageId) {
this.languageId = languageId;
public void setBody(String body) {
this.body = body;
}
public void setNew(boolean b) {
this.isNew = b;
}
public boolean isNew() {
return isNew;
}
public void setSystemPage(boolean b) {
this.isSystemPage = b;
}
public boolean isSystemPage() {
return isSystemPage;
}
public Page getPage() {
Page p = new Page();
p.setId(-1);
p.setName(name);
p.setLanguageId(languageId);
p.setTitle(title);
p.setBody(body);
p.setDeleted(false);
p.setCreatedById(userId);
p.setCreatedBy(user);
p.setCreatedOn(createdOn);
p.setPreview(true);
p.setNew(isNew);
p.setSystemPage(isSystemPage);
p.setComment(comment);
return p;
}
}
 
public String getName() {
return name;
}
 
public void setName(String name) {
this.name = name;
}
 
public int getLanguageId() {
return languageId;
}
 
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
 
public void setNew(boolean b) {
this.isNew = b;
}
 
public boolean isNew() {
return isNew;
}
 
public void setSystemPage(boolean b) {
this.isSystemPage = b;
}
 
public boolean isSystemPage() {
return isSystemPage;
}
 
public Page getPage() {
Page p = new Page();
p.setId(-1);
p.setName(name);
p.setLanguageId(languageId);
p.setTitle(title);
p.setBody(body);
p.setDeleted(false);
p.setCreatedById(userId);
p.setCreatedBy(user);
p.setCreatedOn(createdOn);
p.setPreview(true);
p.setNew(isNew);
p.setSystemPage(isSystemPage);
p.setComment(comment);
 
return p;
}
}
/trunk/src/main/java/org/kawai/model/Language.java
7,100 → 7,111
import org.mentawai.list.ListData;
import org.mentawai.list.SimpleListData;
 
/**
* Model class Language.
*
* @author Sergio Oliveira
*
*/
public class Language {
 
private static final List<Language> LANGUAGES = new ArrayList<Language>(16);
private final int id;
private final String name;
private final Locale loc;
private final String imageFile;
/** Attribute LANGUAGES of Language. */
private static final List<Language> LANGUAGES = new ArrayList<Language>(16);
 
/** Attribute id of Language. */
private final int id;
/** Attribute name of Language. */
private final String name;
/** Attribute loc of Language. */
private final Locale loc;
/** Attribute imageFile of Language. */
private final String imageFile;
 
public Language(int code, String name, String locale, String imageFile) {
this.id = code;
this.name = name;
this.loc = getLocaleFromString(locale);
this.imageFile = imageFile;
this.id = code;
this.name = name;
this.loc = getLocaleFromString(locale);
this.imageFile = imageFile;
}
 
public Language(int code, String name, String locale) {
this(code, name, locale, null);
this(code, name, locale, null);
}
 
public static void add(Language language) {
LANGUAGES.add(language);
LANGUAGES.add(language);
}
 
public static Language getDefault() {
if (LANGUAGES.isEmpty()) throw new IllegalStateException("No languages were defined!");
return LANGUAGES.get(0);
if (LANGUAGES.isEmpty()) throw new IllegalStateException("No languages were defined!");
return LANGUAGES.get(0);
}
 
public int getId() {
return id;
return id;
}
 
public String getName() {
return name;
return name;
}
 
public Locale getLocale() {
return loc;
return loc;
}
 
public String getImageFile() {
return imageFile;
return imageFile;
}
 
@Override
public String toString() {
return name;
return name;
}
 
public static ListData getListData() {
SimpleListData list = new SimpleListData("languages");
for(Language l : LANGUAGES) {
list.add(l.getId(), l.getName());
}
return list;
SimpleListData list = new SimpleListData("languages");
for(Language l : LANGUAGES) {
list.add(l.getId(), l.getName());
}
return list;
}
 
public static Language fromId(int id) {
for(Language l : LANGUAGES) {
if (l.getId() == id) return l;
}
return null;
for(Language l : LANGUAGES) {
if (l.getId() == id) return l;
}
return null;
}
 
public static Language fromLocale(Locale loc) {
if (loc == null) return null;
for(Language l : LANGUAGES) {
if (l.getLocale().equals(loc)) return l;
}
for(Language l : LANGUAGES) {
if (l.getLocale().getLanguage().equals(loc.getLanguage())) {
return l;
}
}
return null;
if (loc == null) return null;
for(Language l : LANGUAGES) {
if (l.getLocale().equals(loc)) return l;
}
for(Language l : LANGUAGES) {
if (l.getLocale().getLanguage().equals(loc.getLanguage())) {
return l;
}
}
return null;
}
 
public static Language fromLocale(String s) {
if (s == null) return null;
Locale loc = getLocaleFromString(s);
return fromLocale(loc);
if (s == null) return null;
Locale loc = getLocaleFromString(s);
return fromLocale(loc);
}
 
public static Language fromName(String name) {
if (name == null) return null;
for(Language l : LANGUAGES) {
if (l.getName().equalsIgnoreCase(name)) return l;
}
return null;
if (name == null) return null;
for(Language l : LANGUAGES) {
if (l.getName().equalsIgnoreCase(name)) return l;
}
return null;
}
 
public static Locale getLocaleFromString(String s) {
if (s == null) return null;
if (s == null) return null;
String[] temp = s.split("_");
if (temp.length == 1) {
return new Locale(temp[0]);
111,12 → 122,12
}
return null;
}
 
public static List<Language> all() {
return LANGUAGES;
return LANGUAGES;
}
 
public static void clear() {
LANGUAGES.clear();
LANGUAGES.clear();
}
}
/trunk/src/main/java/org/kawai/model/Group.java
3,40 → 3,48
import org.mentawai.list.ListData;
import org.mentawai.list.SimpleListData;
 
/**
* Enum Group.
*
* @author Sergio Oliveira
*
*/
public enum Group {
 
ADMIN(1, "Admin"), EDITOR(2, "Editor");
private int id;
private String name;
ADMIN(1, "Admin"), EDITOR(2, "Editor");
 
/** Attribute id of Group. */
private int id;
/** Attribute name of Group. */
private String name;
 
private Group(int code, String name) {
this.id = code;
this.name = name;
this.id = code;
this.name = name;
}
 
public int getId() {
return id;
return id;
}
 
public String getName() {
return name;
return name;
}
 
public static Group fromId(int id) {
for(Group g : Group.values()) {
if (g.getId() == id) {
return g;
}
}
return null;
for(Group g : Group.values()) {
if (g.getId() == id) {
return g;
}
}
return null;
}
 
public static ListData getListData() {
SimpleListData list = new SimpleListData("groups");
for(Group g : Group.values()) {
list.add(g.getId(), g.getName());
}
return list;
SimpleListData list = new SimpleListData("groups");
for(Group g : Group.values()) {
list.add(g.getId(), g.getName());
}
return list;
}
}
/trunk/src/main/java/org/kawai/model/Page.java
4,231 → 4,262
import java.util.Date;
import java.util.Locale;
 
/**
* Model class Page.
*
* @author Sergio Oliveira
*
*/
public class Page {
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
public static final String LEFT_COLUMN = "LeftColumn";
public static final String CSS = "CSS";
public static final String PRINT_CSS = "PrintCSS";
public static final String LOGO = "logo";
public static final String JAVASCRIPT = "JavaScript";
private int id;
private String name;
private String title;
private String body;
private boolean isSystemPage;
private int languageId;
private int modifiedById;
private User modifiedBy;
private Date modifiedOn;
private int createdById;
private User createdBy;
private Date createdOn;
private boolean isFrontPage;
private Boolean isDeleted;
private boolean isPreview;
private boolean isNew;
private boolean isRevision;
private int revisionNumber;
private String comment;
public Page() { }
public void setPreview(Preview preview) {
this.isPreview = true;
this.title = preview.getTitle();
this.body = preview.getBody();
}
public void setComment(String s) {
this.comment = s;
}
public String getComment() {
return comment;
}
 
public boolean isRevision() {
return isRevision;
/** Attribute FORMATTER of Page. */
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
 
/** Attribute LEFT_COLUMN of Page. */
public static final String LEFT_COLUMN = "LeftColumn";
/** Attribute CSS of Page. */
public static final String CSS = "CSS";
/** Attribute PRINT_CSS of Page. */
public static final String PRINT_CSS = "PrintCSS";
/** Attribute LOGO of Page. */
public static final String LOGO = "logo";
/** Attribute JAVASCRIPT of Page. */
public static final String JAVASCRIPT = "JavaScript";
 
/** Attribute id of Page. */
private int id;
/** Attribute name of Page. */
private String name;
/** Attribute title of Page. */
private String title;
/** Attribute body of Page. */
private String body;
/** Attribute isSystemPage of Page. */
private boolean isSystemPage;
/** Attribute languageId of Page. */
private int languageId;
/** Attribute modifiedById of Page. */
private int modifiedById;
/** Attribute modifiedBy of Page. */
private User modifiedBy;
/** Attribute modifiedOn of Page. */
private Date modifiedOn;
/** Attribute createdById of Page. */
private int createdById;
/** Attribute createdBy of Page. */
private User createdBy;
/** Attribute createdOn of Page. */
private Date createdOn;
/** Attribute isFrontPage of Page. */
private boolean isFrontPage;
/** Attribute isDeleted of Page. */
private Boolean isDeleted;
/** Attribute isPreview of Page. */
private boolean isPreview;
/** Attribute isNew of Page. */
private boolean isNew;
/** Attribute isRevision of Page. */
private boolean isRevision;
/** Attribute revisionNumber of Page. */
private int revisionNumber;
/** Attribute comment of Page. */
private String comment;
 
public Page() { }
 
public void setPreview(Preview preview) {
this.isPreview = true;
this.title = preview.getTitle();
this.body = preview.getBody();
}
 
public void setRevision(boolean isRevision) {
this.isRevision = isRevision;
public void setComment(String s) {
this.comment = s;
}
 
public int getRevisionNumber() {
return revisionNumber;
public String getComment() {
return comment;
}
 
public void setRevisionNumber(int revisionNumber) {
this.revisionNumber = revisionNumber;
public boolean isRevision() {
return isRevision;
}
 
public int getId() {
return id;
public void setRevision(boolean isRevision) {
this.isRevision = isRevision;
}
 
public void setId(int id) {
this.id = id;
public int getRevisionNumber() {
return revisionNumber;
}
 
public String getName() {
return name;
public void setRevisionNumber(int revisionNumber) {
this.revisionNumber = revisionNumber;
}
 
public void setName(String name) {
this.name = name;
public int getId() {
return id;
}
 
public String getTitle() {
return title;
public void setId(int id) {
this.id = id;
}
 
public void setTitle(String title) {
this.title = title;
public String getName() {
return name;
}
 
public String getBody() {
return body;
public void setName(String name) {
this.name = name;
}
 
public void setBody(String body) {
this.body = body;
public String getTitle() {
return title;
}
 
public boolean isSystemPage() {
return isSystemPage;
public void setTitle(String title) {
this.title = title;
}
 
public void setSystemPage(boolean isSystemPage) {
this.isSystemPage = isSystemPage;
public String getBody() {
return body;
}
 
public int getLanguageId() {
return languageId;
public void setBody(String body) {
this.body = body;
}
 
public void setLanguageId(int languageId) {
this.languageId = languageId;
public boolean isSystemPage() {
return isSystemPage;
}
public Language getLanguage() {
return Language.fromId(languageId);
}
public Locale getLocale() {
return getLanguage() != null ? getLanguage().getLocale() : null;
}
public String getLang() {
return getLocale() != null ? getLocale().toString() : null;
}
 
public int getModifiedById() {
return modifiedById;
public void setSystemPage(boolean isSystemPage) {
this.isSystemPage = isSystemPage;
}
public boolean isModified() {
return modifiedById > 0;
}
 
public void setModifiedById(int modifiedById) {
this.modifiedById = modifiedById;
public int getLanguageId() {
return languageId;
}
 
public Date getModifiedOn() {
return modifiedOn;
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
public String getFormattedModifiedOn() {
return modifiedOn != null ? FORMATTER.format(modifiedOn) : null;
}
 
public void setModifiedOn(Date modifiedOn) {
this.modifiedOn = modifiedOn;
public Language getLanguage() {
return Language.fromId(languageId);
}
 
public int getCreatedById() {
return createdById;
public Locale getLocale() {
return getLanguage() != null ? getLanguage().getLocale() : null;
}
 
public void setCreatedById(int createdById) {
this.createdById = createdById;
public String getLang() {
return getLocale() != null ? getLocale().toString() : null;
}
 
public Date getCreatedOn() {
return createdOn;
public int getModifiedById() {
return modifiedById;
}
public String getFormattedCreatedOn() {
return createdOn != null ? FORMATTER.format(createdOn) : null;
}
 
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
public boolean isModified() {
return modifiedById > 0;
}
public void setFrontPage(boolean isFrontPage) {
this.isFrontPage = isFrontPage;
}
public boolean isFrontPage() {
return isFrontPage;
}
public User getModifiedBy() {
return modifiedBy;
 
public void setModifiedById(int modifiedById) {
this.modifiedById = modifiedById;
}
 
public void setModifiedBy(User modifiedBy) {
this.modifiedBy = modifiedBy;
public Date getModifiedOn() {
return modifiedOn;
}
 
public User getCreatedBy() {
return createdBy;
public String getFormattedModifiedOn() {
return modifiedOn != null ? FORMATTER.format(modifiedOn) : null;
}
 
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
public void setModifiedOn(Date modifiedOn) {
this.modifiedOn = modifiedOn;
}
public boolean isCSS() {
return name.equals(CSS) || name.equals(PRINT_CSS);
}
public Boolean isDeleted() {
return isDeleted;
}
public boolean getDeleted() {
return isDeleted != null ? isDeleted : false;
}
public void setDeleted(Boolean b) {
this.isDeleted = b;
}
public void setPreview(boolean b) {
this.isPreview = b;
}
public boolean isPreview() {
return isPreview;
}
public boolean isNew() {
return isNew;
}
public void setNew(boolean b) {
this.isNew = b;
}
 
@Override
public int getCreatedById() {
return createdById;
}
 
public void setCreatedById(int createdById) {
this.createdById = createdById;
}
 
public Date getCreatedOn() {
return createdOn;
}
 
public String getFormattedCreatedOn() {
return createdOn != null ? FORMATTER.format(createdOn) : null;
}
 
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
 
public void setFrontPage(boolean isFrontPage) {
this.isFrontPage = isFrontPage;
}
 
public boolean isFrontPage() {
return isFrontPage;
}
 
public User getModifiedBy() {
return modifiedBy;
}
 
public void setModifiedBy(User modifiedBy) {
this.modifiedBy = modifiedBy;
}
 
public User getCreatedBy() {
return createdBy;
}
 
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
 
public boolean isCSS() {
return name.equals(CSS) || name.equals(PRINT_CSS);
}
 
public Boolean isDeleted() {
return isDeleted;
}
 
public boolean getDeleted() {
return isDeleted != null ? isDeleted : false;
}
 
public void setDeleted(Boolean b) {
this.isDeleted = b;
}
 
public void setPreview(boolean b) {
this.isPreview = b;
}
 
public boolean isPreview() {
return isPreview;
}
 
public boolean isNew() {
return isNew;
}
 
public void setNew(boolean b) {
this.isNew = b;
}
 
@Override
public String toString() {
return "Page:[name=" + name + ";language=" + getLanguage() + "]";
return "Page:[name=" + name + ";language=" + getLanguage() + "]";
}
}
 
}
/trunk/src/main/java/org/kawai/model/Revision.java
4,162 → 4,323
import java.util.Date;
import java.util.Locale;
 
/**
* Model class Revision.
*
* @author Sergio Oliveira
*
*/
public class Revision {
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
private int id;
private Integer revision;
private String name;
private int languageId;
private int userId;
private User user;
private String currTitle;
private String oldTitle;
private String newTitle;
private String oldBody;
private String newBody;
private Date createdOn;
private String comment;
private boolean isSystemPage;
private boolean isFrontPage;
public Revision() { }
 
public int getId() {
return id;
/**Attribute constant FORMATTER of Revision. */
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
 
/** Attribute id of Revision. */
private int id;
/** Attribute revision of Revision. */
private Integer revision;
/** Attribute name of Revision. */
private String name;
/** Attribute languageId of Revision. */
private int languageId;
/** Attribute userId of Revision. */
private int userId;
/** Attribute user of Revision. */
private User user;
/** Attribute currTitle of Revision. */
private String currTitle;
/** Attribute oldTitle of Revision. */
private String oldTitle;
/** Attribute newTitle of Revision. */
private String newTitle;
/** Attribute oldBody of Revision. */
private String oldBody;
/** Attribute newBody of Revision. */
private String newBody;
/** Attribute createdOn of Revision. */
private Date createdOn;
/** Attribute comment of Revision. */
private String comment;
/** Attribute isSystemPage of Revision. */
private boolean isSystemPage;
/** Attribute isFrontPage of Revision. */
private boolean isFrontPage;
 
/**
* Default constructor.
*/
public Revision() { }
 
/**
* Gets the id of Revision.
* @return int
*/
public int getId() {
return id;
}
public void setTitle(String s) {
this.currTitle = s;
}
public String getTitle() {
return currTitle;
}
public void setFrontPage(boolean b) {
this.isFrontPage = b;
}
public boolean isFrontPage() {
return isFrontPage;
}
public void setSystemPage(boolean b) {
this.isSystemPage = b;
}
public boolean isSystemPage() {
return isSystemPage;
}
public String getComment() {
return comment;
}
public void setComment(String s) {
this.comment = s;
}
 
public void setId(int id) {
this.id = id;
/**
* Sets the id of Revision.
* @param s String
*/
public void setTitle(String s) {
this.currTitle = s;
}
 
public Integer getRevision() {
return revision;
/**
* Gets the currTitle of Revision.
* @return String
*/
public String getTitle() {
return currTitle;
}
 
public void setRevision(int revision) {
this.revision = revision;
/**
* Sets if isFrontPage of Revision.
* @param b boolean
*/
public void setFrontPage(boolean b) {
this.isFrontPage = b;
}
 
public String getName() {
return name;
/**
* Check if isFrontPage of Revision.
* @return boolean
*/
public boolean isFrontPage() {
return isFrontPage;
}
 
public void setName(String name) {
this.name = name;
/**
* Set if isSystemPage of Revision.
* @param b boolean
*/
public void setSystemPage(boolean b) {
this.isSystemPage = b;
}
 
public int getLanguageId() {
return languageId;
/**
* Checks if isSystemPage of Revision.
* @return boolean
*/
public boolean isSystemPage() {
return isSystemPage;
}
 
public void setLanguageId(int languageId) {
this.languageId = languageId;
/**
* Gets the comment of Revision.
* @return String
*/
public String getComment() {
return comment;
}
 
public int getUserId() {
return userId;
/**
* Sets the comment of Revision.
* @param s String
*/
public void setComment(String s) {
this.comment = s;
}
 
public void setUserId(int userId) {
this.userId = userId;
/**
* Sets the id of Revision.
* @param id int
*/
public void setId(int id) {
this.id = id;
}
 
public User getUser() {
return user;
/**
* Gets the revision of Revision.
* @return Integer
*/
public Integer getRevision() {
return revision;
}
 
public void setUser(User user) {
this.user = user;
/**
* Sets the revision of Revision.
* @param revision int
*/
public void setRevision(int revision) {
this.revision = revision;
}
 
public String getOldTitle() {
return oldTitle;
/**
* Gets the name of Revision.
* @return String
*/
public String getName() {
return name;
}
 
public void setOldTitle(String oldTitle) {
this.oldTitle = oldTitle;
/**
* Sets the name of Revision.
* @param name String
*/
public void setName(String name) {
this.name = name;
}
 
public String getNewTitle() {
return newTitle;
/**
* Gets the languageId of Revision.
* @return int
*/
public int getLanguageId() {
return languageId;
}
 
public void setNewTitle(String newTitle) {
this.newTitle = newTitle;
/**
* Sets the languageId of Revision.
* @param languageId int
*/
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
public Language getLanguage() {
return Language.fromId(languageId);
}
public Locale getLocale() {
return getLanguage() != null ? getLanguage().getLocale() : null;
}
public String getLang() {
return getLocale() != null ? getLocale().toString() : null;
}
 
public String getOldBody() {
return oldBody;
/**
* Gets the userId of Revision.
* @return int
*/
public int getUserId() {
return userId;
}
 
public void setOldBody(String oldBody) {
this.oldBody = oldBody;
/**
* Sets the userId of Revision.
* @param userId int
*/
public void setUserId(int userId) {
this.userId = userId;
}
 
public String getNewBody() {
return newBody;
/**
* Gets the user of Revision.
* @return user
*/
public User getUser() {
return user;
}
 
public void setNewBody(String newBody) {
this.newBody = newBody;
/**
* Sets the user of Revision.
* @param user User
*/
public void setUser(User user) {
this.user = user;
}
 
public Date getCreatedOn() {
return createdOn;
/**
* Gets the oldTitle of Revision.
* @return String
*/
public String getOldTitle() {
return oldTitle;
}
public String getFormattedCreatedOn() {
return FORMATTER.format(createdOn);
}
 
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
/**
* Sets the oldTitle of Revision.
* @param oldTitle String
*/
public void setOldTitle(String oldTitle) {
this.oldTitle = oldTitle;
}
}
 
/**
* Gets the newTitle of Revision.
* @return String
*/
public String getNewTitle() {
return newTitle;
}
 
/**
* Sets the newTitle of Revision.
* @param newTitle String
*/
public void setNewTitle(String newTitle) {
this.newTitle = newTitle;
}
 
/**
* Gets the language of Revision.
* @return Language
*/
public Language getLanguage() {
return Language.fromId(languageId);
}
 
/**
* Gets the locale of Revision.
* @return Locale
*/
public Locale getLocale() {
return getLanguage() != null ? getLanguage().getLocale() : null;
}
 
/**
* Gets the lang of Revision.
* @return String
*/
public String getLang() {
return getLocale() != null ? getLocale().toString() : null;
}
 
/**
* Gets the oldBody of Revision.
* @return String
*/
public String getOldBody() {
return oldBody;
}
 
/**
* Sets the oldBody of Revision.
* @param oldBody String
*/
public void setOldBody(String oldBody) {
this.oldBody = oldBody;
}
 
/**
* Gets the newBody of Revision.
* @return String
*/
public String getNewBody() {
return newBody;
}
 
/**
* Sets the newBody of Revision.
* @param newBody String
*/
public void setNewBody(String newBody) {
this.newBody = newBody;
}
 
/**
* Gets the createdOn date of Revision.
* @return Date
*/
public Date getCreatedOn() {
return createdOn;
}
 
/**
* Gets the formatted createdOn date of Revision.
* @return String
*/
public String getFormattedCreatedOn() {
return FORMATTER.format(createdOn);
}
 
/**
* Sets the createdOn date of Revision.
* @param createdOn Date
*/
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
 
}
/trunk/src/main/java/org/kawai/AppManager.java
37,255 → 37,287
import org.mentawai.i18n.LocaleManager;
import org.mentawai.transaction.JdbcTransaction;
 
/**
* Mentawai ApplicationManager class AppManager.
*
* @author Sergio Oliveira
*
*/
public class AppManager extends ApplicationManager {
 
private Props props;
private ConnectionHandler connHandler;
public ConnectionHandler getConnHandler() {
return connHandler;
}
@Override
public void init(Context application) {
ApplicationManager.DEFAULT_ENVIRONMENT = Environment.PROD;
this.props = getProps();
///////////////////////////////////////////////////
// TURN ON/OFF APP MANAGER AUTO-REDEPLOY FEATURE
/** Attribute props of AppManager. */
private Props props;
 
/** Attribute connHandler of AppManager. */
private ConnectionHandler connHandler;
 
public ConnectionHandler getConnHandler() {
 
return connHandler;
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void init(Context application) {
 
ApplicationManager.DEFAULT_ENVIRONMENT = Environment.PROD;
 
this.props = getProps();
 
///////////////////////////////////////////////////
// TURN ON/OFF APP MANAGER AUTO-REDEPLOY FEATURE
// OBS: Requires http://www.javarebel.com to work
///////////////////////////////////////////////////
setReloadable(props.getBoolean("auto_reload"));
////////////////////////////////////////////////
// Setting up supported kCodes tags
////////////////////////////////////////////////
List<String> kCodeTags = props.getList("kcodes");
for(String tag : kCodeTags) {
KCodeHandler.add(tag);
}
}
///////////////////////////////////////////////////
setReloadable(props.getBoolean("auto_reload"));
 
@Override
public void setupDB() {
String driver = props.getString("jdbc.driver");
String url = props.getString("jdbc.url");
String user = props.getString("jdbc.user");
String pass = props.getString("jdbc.pass");
this.connHandler = new BoneCPConnectionHandler(driver, url, user, pass, "select username from Users limit 1");
}
@Override
public void loadBeans() {
bean(User.class, "Users")
.pk("id", DBTypes.AUTOINCREMENT)
.field("username", DBTypes.STRING)
.field("password", DBTypes.STRING)
.field("groupId", "group_id", DBTypes.INTEGER);
bean(Page.class, "Pages")
.pk("id", DBTypes.AUTOINCREMENT)
.field("name", DBTypes.STRING)
.field("title", DBTypes.STRING)
.field("body", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER)
.field("systemPage", "system_page", DBTypes.BOOLEANSTRING)
.field("frontPage", "front_page", DBTypes.BOOLEANSTRING)
.field("modifiedById", "modified_by", DBTypes.INTEGER)
.field("modifiedOn", "modified_on", DBTypes.NOW_ON_UPDATE_TIMESTAMP)
.field("createdById", "created_by", DBTypes.INTEGER)
.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP)
.field("deleted", DBTypes.BOOLEANSTRING);
bean(Preview.class, "Previews")
.pk("id", DBTypes.AUTOINCREMENT)
.field("userId", "user_id", DBTypes.INTEGER)
.field("title", DBTypes.STRING)
.field("body", DBTypes.STRING)
.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP)
.field("name", DBTypes.STRING)
.field("comment", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER);
bean(Revision.class, "Revisions")
.pk("id", DBTypes.AUTOINCREMENT)
.field("userId", "user_id", DBTypes.INTEGER)
.field("newTitle", "new_title", DBTypes.STRING)
.field("newBody", "new_body", DBTypes.STRING)
.field("oldTitle", "old_title", DBTypes.STRING)
.field("oldBody", "old_body", DBTypes.STRING)
.field("createdOn", "created_on", DBTypes.AUTOTIMESTAMP)
.field("name", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER)
.field("comment", DBTypes.STRING)
.field("revision", DBTypes.INTEGER);
////////////////////////////////////////////////
// Setting up supported kCodes tags
////////////////////////////////////////////////
 
}
List<String> kCodeTags = props.getList("kcodes");
for(String tag : kCodeTags) {
KCodeHandler.add(tag);
}
}
 
@Override
public void loadLocales() {
Language.clear();
if (!props.has("languages")) {
Language l = new Language(1, "English", "en");
Language.add(l);
addLocale(l.getLocale());
} else {
List<String[]> languages = props.getArrays("languages");
for(int i = 0; i < languages.size(); i++) {
String[] array = languages.get(i);
Language l = new Language(i + 1, array[0], array[1], array.length >= 3 ? array[2] : null);
Language.add(l);
addLocale(l.getLocale());
}
}
LocaleManager.stopLocaleScan();
}
/**
* ${@inheritDoc}.
*/
@Override
public void setupDB() {
 
String driver = props.getString("jdbc.driver");
String url = props.getString("jdbc.url");
String user = props.getString("jdbc.user");
String pass = props.getString("jdbc.pass");
 
this.connHandler = new BoneCPConnectionHandler(driver, url, user, pass, "select username from Users limit 1");
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void loadBeans() {
 
bean(User.class, "Users")
.pk("id", DBTypes.AUTOINCREMENT)
.field("username", DBTypes.STRING)
.field("password", DBTypes.STRING)
.field("groupId", "group_id", DBTypes.INTEGER);
 
bean(Page.class, "Pages")
.pk("id", DBTypes.AUTOINCREMENT)
.field("name", DBTypes.STRING)
.field("title", DBTypes.STRING)
.field("body", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER)
.field("systemPage", "system_page", DBTypes.BOOLEANSTRING)
.field("frontPage", "front_page", DBTypes.BOOLEANSTRING)
.field("modifiedById", "modified_by", DBTypes.INTEGER)
.field("modifiedOn", "modified_on", DBTypes.NOW_ON_UPDATE_TIMESTAMP)
.field("createdById", "created_by", DBTypes.INTEGER)
.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP)
.field("deleted", DBTypes.BOOLEANSTRING);
 
bean(Preview.class, "Previews")
.pk("id", DBTypes.AUTOINCREMENT)
.field("userId", "user_id", DBTypes.INTEGER)
.field("title", DBTypes.STRING)
.field("body", DBTypes.STRING)
.field("createdOn", "created_on", DBTypes.NOW_ON_INSERT_TIMESTAMP)
.field("name", DBTypes.STRING)
.field("comment", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER);
 
bean(Revision.class, "Revisions")
.pk("id", DBTypes.AUTOINCREMENT)
.field("userId", "user_id", DBTypes.INTEGER)
.field("newTitle", "new_title", DBTypes.STRING)
.field("newBody", "new_body", DBTypes.STRING)
.field("oldTitle", "old_title", DBTypes.STRING)
.field("oldBody", "old_body", DBTypes.STRING)
.field("createdOn", "created_on", DBTypes.AUTOTIMESTAMP)
.field("name", DBTypes.STRING)
.field("languageId", "language_id", DBTypes.INTEGER)
.field("comment", DBTypes.STRING)
.field("revision", DBTypes.INTEGER);
 
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void loadLocales() {
 
Language.clear();
 
if (!props.has("languages")) {
 
Language l = new Language(1, "English", "en");
Language.add(l);
addLocale(l.getLocale());
 
} else {
 
List<String[]> languages = props.getArrays("languages");
 
for(int i = 0; i < languages.size(); i++) {
String[] array = languages.get(i);
 
Language l = new Language(i + 1, array[0], array[1], array.length >= 3 ? array[2] : null);
Language.add(l);
addLocale(l.getLocale());
}
}
 
LocaleManager.stopLocaleScan();
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void loadLists() {
addList(Group.getListData());
addList(Language.getListData());
}
@Override
public void loadFilters() {
/////////////////////////////////////////////
// GLOBAL FILTERS
/////////////////////////////////////////////
filter(new ExceptionFilter());
on(EXCEPTION, fwd("/error.jsp"));
filter(new MentaContainerFilter());
filter(new FlashScopeFilter());
//////////////////////////////////////////////////////////
// AUTHENTICATION: ALL ACTIONS THAT DO NOT IMPLEMENT
// THE AuthenticationFree INTERFACE WILL REQUIRE
// AUTHENTICATION
//////////////////////////////////////////////////////////
filter(new AuthenticationFilter());
on(LOGIN, redir("/"));
filter(new ValidationFilter());
filter(new TransactionFilter("transaction"));
}
@Override
public void setupIoC() {
addList(Group.getListData());
addList(Language.getListData());
}
 
////////////////////////////////////////////////////////
// INVERSION OF CONTROL: SET UP YOUR REPOSITORIES OR
// ANY OTHER OBJECT IMPLEMENTATION YOU WANT TO MAKE
// AVAILABLE THROUGH IOC (INVERSION OF CONTROL)
////////////////////////////////////////////////////////
ioc("conn", connHandler);
ioc("beanManager", getBeanManager()); // always return the same instance...
ioc("userDAO", JdbcUserDAO.class);
ioc("pageDAO", JdbcPageDAO.class);
ioc("beanSession", props.getClass("mentabean.dialect"));
ioc("transaction", JdbcTransaction.class);
}
@Override
public void loadActions() {
on(AJAX, ajax(new JsonRenderer()));
ActionConfig mainAction = action("/Page", PageAction.class)
.on(SUCCESS, fwd("/show_page.jsp"));
on(INDEX, redir(mainAction));
on(UPDATED, redir(mainAction, true));
Filter adminFilter = new AuthorizationFilter("admin");
Filter editorFilter = new AuthorizationFilter("admin", "editor");
on(ACCESSDENIED, redir(mainAction));
action("/User", UserAction.class, "add")
.filter(adminFilter)
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction));
action("/User", UserAction.class, "check")
.filter(adminFilter)
.all(ajax(new ResultRenderer()));
action("/Login", LoginAction.class)
.on(ERROR, chain(mainAction))
.on(SUCCESS, redir(mainAction, true));
action("/Logout", LogoutAction.class)
.on(SUCCESS, redir(mainAction));
action("/Page", PageAction.class, "get")
.filter(editorFilter);
action("/Page", PageAction.class, "getPreview")
.filter(editorFilter);
action("/Page", PageAction.class, "getRevisions")
.filter(editorFilter);
action("/Page", PageAction.class, "add")
.filter(editorFilter)
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction, true));
action("/Page", PageAction.class, "setFrontPage")
.filter(adminFilter);
action("/Page", PageAction.class, "delete")
.filter(adminFilter);
action("/Page", PageAction.class, "edit")
.filter(editorFilter);
/**
* ${@inheritDoc}.
*/
@Override
public void loadFilters() {
 
action("/Page", PageAction.class, "list")
.filter(editorFilter);
action("/Page", PageAction.class, "discardPreview")
.filter(editorFilter)
.on(REMOVED, redir(mainAction, true));
action("/Page", PageAction.class, "savePreview")
.filter(editorFilter)
.on(SUCCESS, redir(mainAction, true));
action("/Page", PageAction.class, "getCSS")
.on(SUCCESS, fwd("/generate_css.jsp"));
action("/Page", PageAction.class, "getPrintCSS")
.on(SUCCESS, fwd("/generate_css.jsp"));
action("/File", FileAction.class, "upload")
.filter(editorFilter)
.filter(new FileUploadFilter())
.on(SUCCESS, redir(mainAction, true));
action("/File", FileAction.class, "listFiles")
.filter(editorFilter);
}
}
/////////////////////////////////////////////
// GLOBAL FILTERS
/////////////////////////////////////////////
 
filter(new ExceptionFilter());
on(EXCEPTION, fwd("/error.jsp"));
 
filter(new MentaContainerFilter());
 
filter(new FlashScopeFilter());
 
//////////////////////////////////////////////////////////
// AUTHENTICATION: ALL ACTIONS THAT DO NOT IMPLEMENT
// THE AuthenticationFree INTERFACE WILL REQUIRE
// AUTHENTICATION
//////////////////////////////////////////////////////////
filter(new AuthenticationFilter());
on(LOGIN, redir("/"));
 
filter(new ValidationFilter());
 
filter(new TransactionFilter("transaction"));
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void setupIoC() {
 
////////////////////////////////////////////////////////
// INVERSION OF CONTROL: SET UP YOUR REPOSITORIES OR
// ANY OTHER OBJECT IMPLEMENTATION YOU WANT TO MAKE
// AVAILABLE THROUGH IOC (INVERSION OF CONTROL)
////////////////////////////////////////////////////////
 
ioc("conn", connHandler);
ioc("beanManager", getBeanManager()); // always return the same instance...
ioc("userDAO", JdbcUserDAO.class);
ioc("pageDAO", JdbcPageDAO.class);
ioc("beanSession", props.getClass("mentabean.dialect"));
ioc("transaction", JdbcTransaction.class);
}
 
/**
* ${@inheritDoc}.
*/
@Override
public void loadActions() {
 
on(AJAX, ajax(new JsonRenderer()));
 
ActionConfig mainAction = action("/Page", PageAction.class)
.on(SUCCESS, fwd("/show_page.jsp"));
 
on(INDEX, redir(mainAction));
on(UPDATED, redir(mainAction, true));
 
Filter adminFilter = new AuthorizationFilter("admin");
Filter editorFilter = new AuthorizationFilter("admin", "editor");
on(ACCESSDENIED, redir(mainAction));
 
action("/User", UserAction.class, "add")
.filter(adminFilter)
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction));
 
action("/User", UserAction.class, "check")
.filter(adminFilter)
.all(ajax(new ResultRenderer()));
 
action("/Login", LoginAction.class)
.on(ERROR, chain(mainAction))
.on(SUCCESS, redir(mainAction, true));
 
action("/Logout", LogoutAction.class)
.on(SUCCESS, redir(mainAction));
 
action("/Page", PageAction.class, "get")
.filter(editorFilter);
 
 
action("/Page", PageAction.class, "getPreview")
.filter(editorFilter);
 
action("/Page", PageAction.class, "getRevisions")
.filter(editorFilter);
 
action("/Page", PageAction.class, "add")
.filter(editorFilter)
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction, true));
 
action("/Page", PageAction.class, "setFrontPage")
.filter(adminFilter);
 
action("/Page", PageAction.class, "delete")
.filter(adminFilter);
 
action("/Page", PageAction.class, "edit")
.filter(editorFilter);
 
action("/Page", PageAction.class, "list")
.filter(editorFilter);
 
action("/Page", PageAction.class, "discardPreview")
.filter(editorFilter)
.on(REMOVED, redir(mainAction, true));
 
action("/Page", PageAction.class, "savePreview")
.filter(editorFilter)
.on(SUCCESS, redir(mainAction, true));
 
action("/Page", PageAction.class, "getCSS")
.on(SUCCESS, fwd("/generate_css.jsp"));
 
action("/Page", PageAction.class, "getPrintCSS")
.on(SUCCESS, fwd("/generate_css.jsp"));
 
action("/File", FileAction.class, "upload")
.filter(editorFilter)
.filter(new FileUploadFilter())
.on(SUCCESS, redir(mainAction, true));
 
action("/File", FileAction.class, "listFiles")
.filter(editorFilter);
 
}
}
/trunk/src/main/java/org/kawai/tag/EditTooltip.java
10,33 → 10,43
import org.mentawai.i18n.LocaleManager;
import org.mentawai.tag.util.PrintTag;
 
/**
* PrintTag class EditTooltip.
*
* @author Sergio Oliveira
*
*/
public class EditTooltip extends PrintTag {
private String name;
public void setName(String name) {
this.name = name;
}
@Override
public String getStringToPrint() throws JspException {
Locale loc = Language.getDefault().getLocale();
Page page = (Page) pageContext.findAttribute(name);
if (page == null) {
throw new JspException("Cannot find page with name: " + name);
}
User modifier = page.getModifiedBy();
if (modifier != null) {
return "Last modified by " + modifier.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getModifiedOn());
} else {
User creator = page.getCreatedBy();
if (creator == null) {
throw new IllegalStateException("Page without creator: " + page);
} else {
return "Created by " + creator.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getCreatedOn());
}
}
}
}
 
/** Attribute name of EditTooltip. */
private String name;
 
public void setName(String name) {
this.name = name;
}
 
/**
* {@inheritDoc}.
*/
@Override
public String getStringToPrint() throws JspException {
 
Locale loc = Language.getDefault().getLocale();
 
Page page = (Page) pageContext.findAttribute(name);
if (page == null) {
throw new JspException("Cannot find page with name: " + name);
}
User modifier = page.getModifiedBy();
if (modifier != null) {
return "Last modified by " + modifier.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getModifiedOn());
} else {
User creator = page.getCreatedBy();
if (creator == null) {
throw new IllegalStateException("Page without creator: " + page);
} else {
return "Created by " + creator.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getCreatedOn());
}
}
}
}
/trunk/src/main/java/org/kawai/tag/kcode/ContextPath.java
2,26 → 2,42
 
import java.util.Map;
 
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
 
/**
* KCode class ContextPath.
*
* @author Sergio Oliveira
*
*/
public class ContextPath implements KCode {
@Override
public String getTag() {
return "contextPath";
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
if (body != null) throw new JspException("contextPath tag cannot have a body!");
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
return req.getContextPath();
}
}
 
/**
* {@inheritDoc}.
*/
@Override
public String getTag() {
return "contextPath";
}
 
/**
* {@inheritDoc}.
*/
@Override
public boolean hasBody() {
return false;
}
 
/**
* {@inheritDoc}.
*/
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
if (body != null) throw new JspException("contextPath tag cannot have a body!");
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
return req.getContextPath();
}
}
/trunk/src/main/java/org/kawai/tag/kcode/Image.java
6,29 → 6,44
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
 
/**
* KCode class Image.
*
* @author Sergio Oliveira
*
*/
public class Image implements KCode {
@Override
public String getTag() {
return "img";
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
if (body != null) throw new JspException("contextPath tag cannot have a body!");
String filename = attributes.get("file");
if (filename == null) throw new JspException("file attribute is mandatory!");
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String cp = req.getContextPath();
return "<img src=\"" + cp + "/uploads/images/" + filename + "\" border=\"0\" />";
}
}
 
/**
* {@inheritDoc}.
*/
@Override
public String getTag() {
return "img";
}
 
/**
* {@inheritDoc}.
*/
@Override
public boolean hasBody() {
return false;
}
 
/**
* {@inheritDoc}.
*/
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
if (body != null) throw new JspException("contextPath tag cannot have a body!");
 
String filename = attributes.get("file");
 
if (filename == null) throw new JspException("file attribute is mandatory!");
 
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String cp = req.getContextPath();
 
return "<img src=\"" + cp + "/uploads/images/" + filename + "\" border=\"0\" />";
}
}
/trunk/src/main/java/org/kawai/tag/kcode/Download.java
6,30 → 6,45
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
 
/**
* KCode class Download.
*
* @author Sergio Oliveira
*
*/
public class Download implements KCode {
@Override
public String getTag() {
return "download";
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
if (body != null) throw new JspException("contextPath tag cannot have a body!");
String filename = attributes.get("file");
if (filename == null) throw new JspException("file attribute is mandatory!");
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String cp = req.getContextPath();
return "<a href=\"" + cp + "/uploads/archive/" + filename + "\">" + filename + "</a>";
}
}
 
/**
* {@inheritDoc}.
*/
@Override
public String getTag() {
return "download";
}
 
/**
* {@inheritDoc}.
*/
@Override
public boolean hasBody() {
return false;
}
 
/**
* {@inheritDoc}.
*/
@Override
public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
 
if (body != null) throw new JspException("contextPath tag cannot have a body!");
 
String filename = attributes.get("file");
 
if (filename == null) throw new JspException("file attribute is mandatory!");
 
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String cp = req.getContextPath();
 
return "<a href=\"" + cp + "/uploads/archive/" + filename + "\">" + filename + "</a>";
}
}
/trunk/src/main/java/org/kawai/tag/kcode/Code.java
7,65 → 7,80
 
import org.mentaregex.Regex;
 
/**
* KCode class Code.
*
* @author Sergio Oliveira
*
*/
public class Code implements KCode {
@Override
public boolean hasBody() {
return true;
}
@Override
public String getTag() {
return "code";
}
@Override
public String process(PageContext context, Map<String, String> attrs, String html) {
StringBuilder sb = new StringBuilder(1024 * 10);
boolean indent = true;
if (attrs.containsKey("ul")) {
indent = attrs.get("ul").equals("true");
}
 
if (indent) sb.append("<ul>");
sb.append(buildOpenShTag(attrs));
sb.append(escapeAngleBrackets(html));
sb.append("</pre>");
if (indent) sb.append("</ul>");
sb.append("<br/>");
return sb.toString();
}
private String escapeAngleBrackets(String html) {
String s = Regex.sub(html, "s/\\</\\&lt\\;/g");
s = Regex.sub(s, "s/\\>/\\&gt\\;/g");
return s;
}
private static String buildOpenShTag(Map<String, String> map) {
StringBuilder sb = new StringBuilder(256);
sb.append("<pre class=\"");
if (map.containsKey("brush")) {
sb.append("brush: ").append(map.get("brush")).append(";");
} else {
sb.append("brush: java;");
}
map.remove("brush");
if (map.containsKey("highlight")) {
sb.append(" highlight: [").append(map.get("highlight")).append("];");
}
map.remove("highlight");
Iterator<String> iter = map.keySet().iterator();
while(iter.hasNext()) {
String name = iter.next();
if (name.equals("ul")) continue;
String value = map.get(name);
sb.append(" ").append(name).append(": ").append(value).append(";");
}
sb.append("\">");
return sb.toString();
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasBody() {
return true;
}
 
/**
* {@inheritDoc}
*/
@Override
public String getTag() {
return "code";
}
 
/**
* {@inheritDoc}
*/
@Override
public String process(PageContext context, Map<String, String> attrs, String html) {
 
StringBuilder sb = new StringBuilder(1024 * 10);
 
boolean indent = true;
 
if (attrs.containsKey("ul")) {
indent = attrs.get("ul").equals("true");
}
 
if (indent) sb.append("<ul>");
sb.append(buildOpenShTag(attrs));
sb.append(escapeAngleBrackets(html));
sb.append("</pre>");
if (indent) sb.append("</ul>");
sb.append("<br/>");
return sb.toString();
}
 
private String escapeAngleBrackets(String html) {
String s = Regex.sub(html, "s/\\</\\&lt\\;/g");
s = Regex.sub(s, "s/\\>/\\&gt\\;/g");
return s;
}
 
private static String buildOpenShTag(Map<String, String> map) {
StringBuilder sb = new StringBuilder(256);
sb.append("<pre class=\"");
if (map.containsKey("brush")) {
sb.append("brush: ").append(map.get("brush")).append(";");
} else {
sb.append("brush: java;");
}
map.remove("brush");
if (map.containsKey("highlight")) {
sb.append(" highlight: [").append(map.get("highlight")).append("];");
}
map.remove("highlight");
Iterator<String> iter = map.keySet().iterator();
while(iter.hasNext()) {
String name = iter.next();
if (name.equals("ul")) continue;
String value = map.get(name);
sb.append(" ").append(name).append(": ").append(value).append(";");
}
sb.append("\">");
return sb.toString();
}
}
/trunk/src/main/java/org/kawai/tag/ListFlags.java
9,48 → 9,57
import org.mentawai.tag.i18n.RewriteWithLoc;
import org.mentawai.tag.util.PrintTag;
 
/**
* PrintTag class EditTooltip.
*
* @author Sergio Oliveira
*
*/
public class ListFlags extends PrintTag {
@Override
public String getStringToPrint() throws JspException {
/*
<mtw:isLocale value="pt">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #ccc;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #fff;" /></a>
</mtw:isLocale>
<mtw:isLocale value="en">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #fff;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #ccc;" /></a>
</mtw:isLocale>
*/
if (Language.all().size() == 1) return "";
LocaleManager.decideLocale(req, res); // force the locale to be chosen from param or cookie...
Locale selectedLocale = LocaleManager.getLocale(req, false);
String cp = req.getContextPath();
StringBuilder sb = new StringBuilder(1024);
 
for(Language lang : Language.all()) {
Locale loc = lang.getLocale();
boolean selected = lang.getLocale().equals(selectedLocale);
/**
* {@inheritDoc}.
*/
@Override
public String getStringToPrint() throws JspException {
 
RewriteWithLoc tag = new RewriteWithLoc();
tag.setPageContext(pageContext);
tag.setLoc(loc.toString());
tag.setTagsToExclude("revision");
tag.doStartTag();
String href = tag.getStringToPrint();
sb.append("<a href=\"").append(href).append("\">");
sb.append("<img src=\"").append(cp).append("/uploads/images/").append(lang.getImageFile()).append("\" border=\"0\" width=\"20\" height=\"13\" style=\"border: 3px solid ");
if (selected) sb.append("#ccc");
else sb.append("#fff");
sb.append("; \" /></a>\n");
}
return sb.toString();
}
}
/*
<mtw:isLocale value="pt">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #ccc;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #fff;" /></a>
</mtw:isLocale>
<mtw:isLocale value="en">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #fff;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #ccc;" /></a>
</mtw:isLocale>
*/
 
if (Language.all().size() == 1) return "";
 
LocaleManager.decideLocale(req, res); // force the locale to be chosen from param or cookie...
Locale selectedLocale = LocaleManager.getLocale(req, false);
 
String cp = req.getContextPath();
 
StringBuilder sb = new StringBuilder(1024);
 
for(Language lang : Language.all()) {
Locale loc = lang.getLocale();
boolean selected = lang.getLocale().equals(selectedLocale);
 
RewriteWithLoc tag = new RewriteWithLoc();
tag.setPageContext(pageContext);
tag.setLoc(loc.toString());
tag.setTagsToExclude("revision");
tag.doStartTag();
String href = tag.getStringToPrint();
 
sb.append("<a href=\"").append(href).append("\">");
sb.append("<img src=\"").append(cp).append("/uploads/images/").append(lang.getImageFile()).append("\" border=\"0\" width=\"20\" height=\"13\" style=\"border: 3px solid ");
if (selected) sb.append("#ccc");
else sb.append("#fff");
sb.append("; \" /></a>\n");
}
return sb.toString();
}
}