⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiapagedefinition.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////// 08.05.2001 NK implements Comparator interface to be sortable// 22.01.2001 NK added page def ACL//package org.jahia.services.pages;import java.util.Hashtable;import java.util.Enumeration;import java.util.Comparator;import java.util.Properties;import org.jahia.data.JahiaEditableContent;import org.jahia.exceptions.JahiaException;import org.jahia.services.pages.JahiaPageTemplateDB;import org.jahia.services.acl.*;import org.jahia.registries.*;import org.jahia.utils.JahiaConsole;/** * This class is used to keep the page definitions information stored * in the database. Each time a page definition is loaded it's information * are stored into the cache using this class. <br/> * <br/> * This class knows how to save it's content, but it's not an automatic process * to avoid one database access for each little change made to the page data. * Therefore a call to the {@link #commitChanges() commitChanges()} method is * needed to save the update information to the database. * * @author  Eric Vassalli, Fulco Houkes, Khue Nguyen * @version 2.0 */public class JahiaPageDefinition extends JahiaEditableContent implements Comparator, ACLResourceInterface {        private static final String CLASS_NAME = JahiaPageDefinition.class.getName();        // Properties names    protected static final String ACLID_PROP = "acl_id";        private int     mID;    private int     mSiteID;    private String  mName;    private String  mSourcePath;         // JSP source path    private boolean mAvailable;            // Available or not for a user in the administration manager    private String  mImage;    private int     mTempSiteID;    private String  mTempName;    private String  mTempSourcePath;    private boolean mTempAvailable;    private String  mTempImage;	private Properties mProps = new Properties();	    private boolean mDataChanged;    //-------------------------------------------------------------------------    /** Default constructor.     *     * @param int 		ID          Unique identification number of the page definition.     * @param int 		jahiaID     Jahia site unique identification number     * @param String 	name        Name of the page definition.     * @param String 	sourcePath  Source path of the page definition     * @param boolean	isAvailable Not available to users if false     * @param String	image		A thumbnail     */    protected JahiaPageDefinition (	int ID, int siteID, String name,            						String sourcePath, boolean isAvailable,            						String image)    {        mID             = ID;        mSiteID         = siteID;        if (name == null) {            name = "Untitled-"+ID;        }        mName = name;        if (sourcePath == null) {            sourcePath = "<no source path>";        }        mSourcePath     = sourcePath;        mAvailable        = isAvailable;        if (image == null) {            image = "";        }        mImage          = image;        // temp variables.        mTempSiteID     = siteID;        mTempName       = name;        mTempSourcePath = sourcePath;        mTempAvailable  = isAvailable;        mTempImage      = image;		        mDataChanged = false;    }	     //-------------------------------------------------------------------------    /** Commit all the previous changes to the database.     *     * @exception   JahiaException Throws a JahiaException if the data could not     *              be saved successfully into the database.     */    public void commitChanges ()        throws JahiaException    {        // commit only if the data has really changed        if (mDataChanged) {            // get the needed database access class            JahiaPageTemplateDB mTemplateDB = JahiaPageTemplateDB.getInstance();            if (mTemplateDB == null) {                throw new JahiaException ("Page template error",                                          "Could not instanciate the specified page template.",                                          JahiaException.PAGE_ERROR,                                          JahiaException.CRITICAL);            }            mSiteID     = mTempSiteID;            mName       = mTempName;            mSourcePath = mTempSourcePath;            mAvailable  = mTempAvailable;            mImage      = mTempImage;            mTemplateDB.updatePageTemplate (this);            mDataChanged = false;        }    }    public void disableChanges ()    {        if (mDataChanged) {            mTempSiteID     = mSiteID;            mTempName       = mName;            mTempSourcePath = mSourcePath;            mTempAvailable  = mAvailable;            mTempImage      = mImage;        }    }    //-------------------------------------------------------------------------    /** Return the page definition unique identification number.     *     * @return  The identification number.     */    public final int getID () {        return mID;    }    //-------------------------------------------------------------------------    /** Get the image path     *     * @return String path to the image.     */    public String getImage() {        return mImage;    }    //-------------------------------------------------------------------------    /** Return the site unique identification number.     *     * @return  The site identification number.     */    public final int getJahiaID() {        return mSiteID;    }    //-------------------------------------------------------------------------    /** Return the page definition name.     *     * @return  The page definition name.     */    public final String getName() {        return mName;    }    //-------------------------------------------------------------------------    /** Return the JSP file associated with the page definition.     *     * @return  The source path.     */    public final String getSourcePath() {        return mSourcePath;    }    //-------------------------------------------------------------------------    /** Get the Available status     *     * @return  Return true if the page definition is available or false if     *          it's not.     */    public final boolean isAvailable () {        return mAvailable;    }    //-------------------------------------------------------------------------    /** Set the image's path     *     * @param   value   The new image path.     */    public void setImage (String value) {        mTempImage = value;        mDataChanged = true;    }    //-------------------------------------------------------------------------    /** Set the Jahia ID.     *     * @param   value   The new Jahia ID.     */    public void setJahiaID (int value) {        mTempSiteID = value;        mDataChanged = true;    }    //-------------------------------------------------------------------------    /** Set the page definition name.     *     * @param   value   The new page definition name.     */    public void setName (String value) {        mTempName = value;        mDataChanged = true;    }    //-------------------------------------------------------------------------    /** Set the source path.     *     * @param   value   The new source path.     */    public void setSourcePath (String value) {        mTempSourcePath = value;        mDataChanged = true;    }    //-------------------------------------------------------------------------    /** Set the available status.     *     * @param   value   Set the new available status. True the Definition page     *                  will be available, false it won't.     */    public void setAvailable (boolean value) {        mTempAvailable = value;        mDataChanged = true;    }    //-------------------------------------------------------------------------    /** Return the ACL object.     *     * @return  Return the ACL.     */    public final JahiaBaseACL getACL () { 		 		if ( mProps == null ) 			return null; 		 		String value = mProps.getProperty(ACLID_PROP); 		if ( value == null ) 			return null; 		 		JahiaBaseACL acl = null;        try {            acl = new JahiaBaseACL (Integer.parseInt(value));        }        catch (ACLNotFoundException ex) {            ex.printStackTrace();        }        catch (Throwable t) {        	t.printStackTrace();        }        return acl;	}    //-------------------------------------------------------------------------    /** Return the ACL id.     *     * @return  int the ACL id.     */    public final int getAclID () { 		 		if ( mProps == null ) 			return -1; 		 		String value = mProps.getProperty(ACLID_PROP); 		if ( value == null ) 			return -1; 		 		JahiaBaseACL acl = null;        try {            acl = new JahiaBaseACL (Integer.parseInt(value));            return acl.getID();        }        catch (ACLNotFoundException ex) {            ex.printStackTrace();        }        catch (Throwable t) {        	t.printStackTrace();        }        return -1;	}    //-------------------------------------------------------------------------    /** Set the acl id.     *     * @param int id, the acl id     */    protected final void setACL (int id ) {		if ( mProps == null ){			JahiaConsole.println(CLASS_NAME+".setACL","ACL cannot be set because properties is null");			return;		}					mProps.setProperty(ACLID_PROP,String.valueOf(id));        mDataChanged = true;    }    //-------------------------------------------------------------------------    /**      * Compare between two objects, sort by their name	 *     * @param Object     * @param Object     * @author NK     */	public int compare(Object c1, Object c2) throws ClassCastException {				return ((JahiaPageDefinition)c1)					.getName().toLowerCase()					.compareTo(((JahiaPageDefinition)c2).getName().toLowerCase());			}			//--------------------------------------------------------------------------	/**	 * Set the properties	 *	 * @param Properties properties	 */    public void setProperties(Properties props) {        mProps = props;    }	//--------------------------------------------------------------------------	/**	 * Return the properties	 *	 * @return Properties the properties	 */    public Properties getProperties() {        return mProps;    }		//--------------------------------------------------------------------------	/**	 * Return a property as String	 *	 * @param String , the property name, null if not found	 */    public String getProperty(String name) {        if (mProps != null) {            return mProps.getProperty(name);        } else {            return null;        }    }	//--------------------------------------------------------------------------	/**	 * Set a property	 *	 * @param String , the property name	 * @param String , the property value as String	 */    public void setProperty(String name, String value) {        if (mProps != null) {            mProps.setProperty(name, value);        }    }} // end JahiaPageDefinition

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -