Kawai Wiki

Rev

Rev 195 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.kawai.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.mentawai.util.HttpUtils;

/**
 * Model class Page.
 *
 * @author Sergio Oliveira
 *
 */

public class Page {

    /** 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;
   
    private String prettyURLFormattedTitle;

    /**
     * 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;
        if (title != null) {
                this.prettyURLFormattedTitle = HttpUtils.getPrettyURLFormatted(title);
        } else {
                this.prettyURLFormattedTitle = null;
        }
    }
   
    public String getPrettyURLFormattedTitle() {
        return prettyURLFormattedTitle;
    }

    /**
     * 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() + "]";
    }

}