Kawai Wiki

Compare Revisions

Ignore whitespace Rev 194 → Rev 195

/trunk/src/main/java/org/kawai/model/Preview.java
38,94 → 38,186
*/
public Preview() { }
 
/**
* Gets the id of Preview.
* @return int
*/
public int getId() {
return id;
}
 
/**
* Sets the id of Preview.
* @param id int
*/
public void setId(int id) {
this.id = id;
}
 
/**
* Sets the comment of Preview.
* @param comment String
*/
public void setComment(String comment) {
this.comment = comment;
}
 
/**
* Gets the comment of Preview.
* @return String
*/
public String getComment() {
return comment;
}
 
/**
* Sets the user of Preview.
* @param user User
*/
public void setUser(User user) {
this.user = user;
}
 
/**
* Gets the user of Preview.
* @return User
*/
public User getUser() {
return user;
}
 
/**
* Gets the userId of Preview.
* @return int
*/
public int getUserId() {
return userId;
}
 
/**
* Sets the userId of Preview.
* @param userId int
*/
public void setUserId(int userId) {
this.userId = userId;
}
 
/**
* Gets the createdOn date of Preview.
* @return Date
*/
public Date getCreatedOn() {
return createdOn;
}
 
/**
* Sets the createdOn date of Preview.
* @param createdOn Date
*/
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
 
/**
* Gets the title of Preview.
* @return String
*/
public String getTitle() {
return title;
}
 
/**
* Sets the title of Preview.
* @param title String
*/
public void setTitle(String title) {
this.title = title;
}
 
/**
* Gets the body of Preview.
* @return String
*/
public String getBody() {
return body;
}
 
/**
* Sets the body of Preview.
* @param body String
*/
public void setBody(String body) {
this.body = body;
}
 
/**
* Gets the name of Preview.
* @return String
*/
public String getName() {
return name;
}
 
/**
* Sets the name of Preview.
* @param name String
*/
public void setName(String name) {
this.name = name;
}
 
/**
* Gets the languageId of Preview.
* @return int
*/
public int getLanguageId() {
return languageId;
}
 
/**
* Sets the languageId of Preview.
* @param languageId int
*/
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
 
/**
* Sets the new attribute of Preview.
* @param b boolean
*/
public void setNew(boolean b) {
this.isNew = b;
}
 
/**
* Return if isNew Preview.
* @return boolean
*/
public boolean isNew() {
return isNew;
}
 
/**
* Sets if isSystemPage of Preview.
* @param b boolean
*/
public void setSystemPage(boolean b) {
this.isSystemPage = b;
}
 
/**
* Returns true if isSystemPage.
* @return boolean
*/
public boolean isSystemPage() {
return isSystemPage;
}
 
/**
* Gets the populated page object of Preview.
* @return Page
*/
public Page getPage() {
Page p = new Page();
p.setId(-1);
/trunk/src/main/java/org/kawai/model/Page.java
65,198 → 65,392
/** Attribute comment of Page. */
private String comment;
 
/**
* Default constructor.
*/
public Page() { }
 
/**
* Sets the preview object of Page.
* @param preview Preview
*/
public void setPreview(Preview preview) {
this.isPreview = true;
this.title = preview.getTitle();
this.body = preview.getBody();
}
 
/**
* Sets the comment of Page.
* @param s String
*/
public void setComment(String s) {
this.comment = s;
}
 
/**
* Gets the comment of Page.
* @return String
*/
public String getComment() {
return comment;
}
 
/**
* Return true if isRevision of Page.
* @return boolean
*/
public boolean isRevision() {
return isRevision;
}
 
/**
* Sets isRevision of Page.
* @param isRevision boolean
*/
public void setRevision(boolean isRevision) {
this.isRevision = isRevision;
}
 
/**
* Gets the revisionNumber of Page.
* @return int
*/
public int getRevisionNumber() {
return revisionNumber;
}
 
/**
* Sets the revisionNumber of Page.
* @param revisionNumber int
*/
public void setRevisionNumber(int revisionNumber) {
this.revisionNumber = revisionNumber;
}
 
/**
* Gets the id of Page.
* @return int
*/
public int getId() {
return id;
}
 
/**
* Sets the id of Page.
* @param id int
*/
public void setId(int id) {
this.id = id;
}
 
/**
* Gets the name of Page.
* @return String
*/
public String getName() {
return name;
}
 
/**
* Sets the name of Page.
* @param name String
*/
public void setName(String name) {
this.name = name;
}
 
/**
* Gets the title of Page.
* @return String
*/
public String getTitle() {
return title;
}
 
/**
* Sets the title of Page.
* @param title String
*/
public void setTitle(String title) {
this.title = title;
}
 
/**
* Gets the body of Page.
* @return String
*/
public String getBody() {
return body;
}
 
/**
* Sets the body of Page.
* @param body String
*/
public void setBody(String body) {
this.body = body;
}
 
/**
* Return true if isSystemPage of Page.
* @return boolean
*/
public boolean isSystemPage() {
return isSystemPage;
}
 
/**
* Sets isSystemPage of Page.
* @param isSystemPage boolean
*/
public void setSystemPage(boolean isSystemPage) {
this.isSystemPage = isSystemPage;
}
 
/**
* Gets the languageId of Page.
* @return int
*/
public int getLanguageId() {
return languageId;
}
 
/**
* Sets the languageId of Page.
* @param languageId int
*/
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
 
/**
* Gets the language of Page.
* @return Language
*/
public Language getLanguage() {
return Language.fromId(languageId);
}
 
/**
* Gets the locale of Page.
* @return Locale
*/
public Locale getLocale() {
return getLanguage() != null ? getLanguage().getLocale() : null;
}
 
/**
* Gets the lang of Page.
* @return String
*/
public String getLang() {
return getLocale() != null ? getLocale().toString() : null;
}
 
/**
* Gets the modifiedById of Page.
* @return int
*/
public int getModifiedById() {
return modifiedById;
}
 
/**
* Return true if modifiedById is not negative or different from zero.
* @return boolean
*/
public boolean isModified() {
return modifiedById > 0;
}
 
/**
* Sets the modifiedById attribute of Page.
* @param modifiedById int
*/
public void setModifiedById(int modifiedById) {
this.modifiedById = modifiedById;
}
 
/**
* Gets the modifiedOn date of Page.
* @return Date
*/
public Date getModifiedOn() {
return modifiedOn;
}
 
/**
* Gets the formatted modifiedOn date of Page.
* @return String
*/
public String getFormattedModifiedOn() {
return modifiedOn != null ? FORMATTER.format(modifiedOn) : null;
}
 
/**
* Sets the modifiedOn date of Page.
* @param modifiedOn
*/
public void setModifiedOn(Date modifiedOn) {
this.modifiedOn = modifiedOn;
}
 
/**
* Gets the createdById attribute of Page.
* @return int
*/
public int getCreatedById() {
return createdById;
}
 
/**
* Sets the createdById attribute of Page.
* @param createdById int
*/
public void setCreatedById(int createdById) {
this.createdById = createdById;
}
 
/**
* Gets the createdOn date of Page.
* @return Date
*/
public Date getCreatedOn() {
return createdOn;
}
 
/**
* Gets the formatted createdOn date of Page.
* @return String
*/
public String getFormattedCreatedOn() {
return createdOn != null ? FORMATTER.format(createdOn) : null;
}
 
/**
* Sets the createdOn date of Page.
* @param createdOn Date
*/
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
 
/**
* Sets isFrontPage attribute of Page.
* @param isFrontPage boolean
*/
public void setFrontPage(boolean isFrontPage) {
this.isFrontPage = isFrontPage;
}
 
/**
* Returns true if isFrontPage.
* @return boolean
*/
public boolean isFrontPage() {
return isFrontPage;
}
 
/**
* Gets the modifiedBy user of Page.
* @return User
*/
public User getModifiedBy() {
return modifiedBy;
}
 
/**
* Sets the modifiedBy user of Page.
* @param modifiedBy User
*/
public void setModifiedBy(User modifiedBy) {
this.modifiedBy = modifiedBy;
}
 
/**
* Gets the createdBy user of Page.
* @return User
*/
public User getCreatedBy() {
return createdBy;
}
 
/**
* Sets the createdBy user of Page.
* @param createdBy User
*/
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
 
/**
* Return true if name is css.
* @return boolean
*/
public boolean isCSS() {
return name.equals(CSS) || name.equals(PRINT_CSS);
}
 
/**
* Return true if isDeleted Page.
* @return Boolean
*/
public Boolean isDeleted() {
return isDeleted;
}
 
/**
* Return true if isDeleted Page.
* @return Boolean
*/
public boolean getDeleted() {
return isDeleted != null ? isDeleted : false;
}
 
/**
* Sets the isDeleted attribute of Page.
* @param b Boolean
*/
public void setDeleted(Boolean b) {
this.isDeleted = b;
}
 
/**
* Sets the isPreview of Page.
* @param b boolean
*/
public void setPreview(boolean b) {
this.isPreview = b;
}
 
/**
* Returns true if isPreview Page.
* @return boolean
*/
public boolean isPreview() {
return isPreview;
}
 
/**
* Return true if isNew Page.
* @return boolean
*/
public boolean isNew() {
return isNew;
}
 
/**
* Sets isNew of Page.
* @param b boolean
*/
public void setNew(boolean b) {
this.isNew = b;
}
 
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "Page:[name=" + name + ";language=" + getLanguage() + "]";
/trunk/src/main/java/org/kawai/dao/PageDAO.java
7,45 → 7,163
import org.kawai.model.Preview;
import org.kawai.model.Revision;
 
/**
* Interace DAO PageDAO.
*
* @author Sergio Oliveira
*
*/
public interface PageDAO {
public Page load(int id);
public void update(Page p);
public Page loadByName(String name, Language lang);
public Page loadByName(String name, Language lang, int revision);
public Page loadByNameWithPreview(int userId, String name, Language lang);
public Page loadFrontPage(Language lang);
public void insert(Page p);
public boolean exists(String name, Language lang);
public boolean isSystemPage(String name);
public List<Page> loadAll(boolean includeSystemPages);
public boolean setNewFrontPage(Page p);
public boolean delete(Page p);
public String getFrontPage(Language lang);
public Preview loadPreview(int userId, String name, Language lang);
public Preview insertPreview(int userId, Page p, String comment);
public void deletePreview(int userId, String name, Language lang);
public Revision loadRevision(int revision, String name, Language lang);
public void insertRevision(Revision r);
public List<Revision> loadRevisions(String name, Language lang);
public List<Revision> loadLastRevisions(Language lang, boolean includeSystemPages);
}
 
/**
* Loads the page by id.
* @param id int
* @return Page
*/
public Page load(int id);
 
/**
* Updates the page.
* @param p Page
*/
public void update(Page p);
 
/**
* Loads the page by name and language.
* @param name String
* @param lang Language
* @return Page
*/
public Page loadByName(String name, Language lang);
 
/**
* Loads the page by name, language and revision.
* @param name String
* @param lang Language
* @param revision int
* @return Page
*/
public Page loadByName(String name, Language lang, int revision);
 
/**
* Loads the page by userId, name and language.
* @param userId int
* @param name String
* @param lang Language
* @return Page
*/
public Page loadByNameWithPreview(int userId, String name, Language lang);
 
/**
* Loads the front page by language.
* @param lang Language
* @return Page
*/
public Page loadFrontPage(Language lang);
 
/**
* Inserts the page.
* @param p Page
*/
public void insert(Page p);
 
/**
* Checks if page exists by name and language.
* @param name String
* @param lang Language
* @return boolean
*/
public boolean exists(String name, Language lang);
 
/**
* Checks if isSystemPage.
* @param name String
* @return boolean
*/
public boolean isSystemPage(String name);
 
/**
* Loads all pages including the system pages or not.
* @param includeSystemPages boolean
* @return List<Page>
*/
public List<Page> loadAll(boolean includeSystemPages);
 
/**
* Sets the new front page.
* @param p Page
* @return boolean
*/
public boolean setNewFrontPage(Page p);
 
/**
* Delete page.
* @param p Page
* @return boolean
*/
public boolean delete(Page p);
 
/**
* Gets the front page by language.
* @param lang Language
* @return String
*/
public String getFrontPage(Language lang);
 
/**
* Loads the preview by userid, name and language.
* @param userId int
* @param name String
* @param lang Language
* @return Preview
*/
public Preview loadPreview(int userId, String name, Language lang);
 
/**
* Insert the preview with userId, page and comment.
* @param userId int
* @param p Page
* @param comment String
* @return Preview
*/
public Preview insertPreview(int userId, Page p, String comment);
 
/**
* Delete the preview with userId, name and language.
* @param userId int
* @param name String
* @param lang Language
*/
public void deletePreview(int userId, String name, Language lang);
 
/**
* Loads the revision by revision id, name and language.
* @param revision int
* @param name String
* @param lang Language
* @return Revision
*/
public Revision loadRevision(int revision, String name, Language lang);
 
/**
* Insert the revision.
* @param r Revision
*/
public void insertRevision(Revision r);
 
/**
* Load revisions by name and language.
* @param name String
* @param lang Language
* @return List < Revision >
*/
public List<Revision> loadRevisions(String name, Language lang);
 
/**
* Load the last revisions by language and including or not system pages.
* @param lang Language
* @param includeSystemPages boolean
* @return List < Revision >
*/
public List<Revision> loadLastRevisions(Language lang, boolean includeSystemPages);
}
/trunk/src/main/java/org/kawai/dao/UserDAO.java
2,15 → 2,44
 
import org.kawai.model.User;
 
/**
* Interace DAO UserDAO.
*
* @author Sergio Oliveira
*
*/
public interface UserDAO {
public User findByUsername(String username);
public void insert(User u);
public void update(User u);
public boolean insertOrUpdate(User u);
public User load(int id);
}
 
/**
* Find the user by name.
* @param username String
* @return User
*/
public User findByUsername(String username);
 
/**
* Insert the user.
* @param u User
*/
public void insert(User u);
 
/**
* Updates the user.
* @param u User
*/
public void update(User u);
 
/**
* Insert or update the user.
* @param u User
* @return boolean
*/
public boolean insertOrUpdate(User u);
 
/**
* Loads the user by id.
* @param id int
* @return User
*/
public User load(int id);
}
/trunk/src/main/java/org/kawai/dao/jdbc/AbstractJdbcDAO.java
6,23 → 6,44
 
import org.mentabean.BeanSession;
 
/**
* Abstract DAO class AbstractJdbcDAO.
*
* @author Sergio Oliveira
*
*/
public abstract class AbstractJdbcDAO {
protected BeanSession session;
protected Connection conn;
public AbstractJdbcDAO(BeanSession session) {
this.session = session;
this.conn = session.getConnection();
}
public final static void close(PreparedStatement stmt, ResultSet rset) {
if (rset != null) try { rset.close(); } catch(Exception e) { e.printStackTrace(); }
if (stmt != null) try { stmt.close(); } catch(Exception e) { e.printStackTrace(); }
}
public final static void close(PreparedStatement stmt) {
close(stmt, null);
}
}
 
/** Attribute session of AbstractJdbcDAO. */
protected BeanSession session;
/** Attribute conn of AbstractJdbcDAO. */
protected Connection conn;
 
/**
* Parametric constructor.
* @param session BeanSession
*/
public AbstractJdbcDAO(BeanSession session) {
this.session = session;
this.conn = session.getConnection();
}
 
/**
* Close connection resources.
* @param stmt PreparedStatement
* @param rset ResultSet
*/
public final static void close(PreparedStatement stmt, ResultSet rset) {
 
if (rset != null) try { rset.close(); } catch(Exception e) { e.printStackTrace(); }
if (stmt != null) try { stmt.close(); } catch(Exception e) { e.printStackTrace(); }
}
 
/**
* Close prepatedStatement.
* @param stmt PreparedStatement
*/
public final static void close(PreparedStatement stmt) {
close(stmt, null);
}
}
/trunk/src/main/java/org/kawai/tag/EditTooltip.java
21,6 → 21,10
/** Attribute name of EditTooltip. */
private String name;
 
/**
* Sets the name attribute of EditTooltip.
* @param name String
*/
public void setName(String name) {
this.name = name;
}
/trunk/src/main/java/org/kawai/tag/kcode/Code.java
15,8 → 15,8
*/
public class Code implements KCode {
 
/**
* {@inheritDoc}
/**
* {@inheritDoc}.
*/
@Override
public boolean hasBody() {
54,12 → 54,22
return sb.toString();
}
 
/**
* Escapes the angle brackets.
* @param html String
* @return String
*/
private String escapeAngleBrackets(String html) {
String s = Regex.sub(html, "s/\\</\\&lt\\;/g");
s = Regex.sub(s, "s/\\>/\\&gt\\;/g");
return s;
}
 
/**
* Builds the tag for syntax highlight.
* @param map Map<String, String>
* @return String
*/
private static String buildOpenShTag(Map<String, String> map) {
StringBuilder sb = new StringBuilder(256);
sb.append("<pre class=\"");
74,7 → 84,7
}
map.remove("highlight");
Iterator<String> iter = map.keySet().iterator();
while(iter.hasNext()) {
while (iter.hasNext()) {
String name = iter.next();
if (name.equals("ul")) continue;
String value = map.get(name);