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

📄 jahiapagetemplatebaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//package org.jahia.services.pages;import java.util.Vector;import java.util.Enumeration;import java.util.Hashtable;import java.util.TreeMap;import org.jahia.utils.JahiaConsole;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaTemplateNotFoundException;import org.jahia.services.pages.JahiaPageTemplateService;import org.jahia.services.pages.JahiaPageTemplateCache;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.services.pages.JahiaPageTemplateDB;import org.jahia.services.acl.*;import org.jahia.services.usermanager.*;import org.jahia.services.sites.*;import org.jahia.registries.*;import org.jahia.data.JahiaDOMObject;/**  * Class JahiaPageBaseService  */public class JahiaPageTemplateBaseService extends JahiaPageTemplateService{        private static final String CLASS_NAME = JahiaPageTemplateBaseService.class.getName();        private static JahiaPageTemplateBaseService mObject = null;    private static JahiaPageTemplateCache  mTemplateCache  = null;    private JahiaPageTemplateDB     mTemplateDB     = null;    //-------------------------------------------------------------------------    /**     * constructor     */    protected JahiaPageTemplateBaseService ()        throws JahiaException    {        JahiaConsole.println ("JahiaPageService",            "***** Starting up the Jahia Page Template Service *****");        setServiceName ("JahiaPageTemplateBaseService");        //////////////////////////////////////////////////////////////////////////////////////        // FIXME -Fulco-        //        //      This init() call should be done by the Jahia main initialization process.        //      it has been added here until this main initialization process is well        //      implemented.        //////////////////////////////////////////////////////////////////////////////////////        init();        loadAllPageTemplates ();    }    //-------------------------------------------------------------------------    /** Create a new page template.     *     * @param   int 	siteID     	The jahia site ID.     * @param   String 	name        The page template name.     * @param   String	sourcePath  The page template source path.     * @param   boolean	isAvailable True is the page template is Available in edition     *                      		mode or false if it should be hidden.     * @param   String	image       Image path.     * @param	int	parentAclID		The parent acl id     *     * @return  Return a new page template instanciation.     *     * @exception   JahiaException  Throws this exception when any error occured     *              in the page template creation process.     */    public JahiaPageDefinition createPageTemplate (            int      siteID,            String   name,            String   sourcePath,            boolean  isAvailable,            String   image,            int parentAclID ) throws JahiaException {                // check if the service is running        checkService ();        // get the next available page template ID        int newID = mTemplateDB.getNextID();		// Create a new ACL.		JahiaBaseACL acl = new JahiaBaseACL ();		if (acl != null) {			try {		    	acl.create (parentAclID);		  	}		  	catch (ACLNotFoundException ex) {		    	throw new JahiaException ("Could not create the page def.",		        	"The parent ACL ID ["+parentAclID+"] could not be found,"+		          	" while trying to create a new page def.",		          	JahiaException.TEMPLATE_ERROR, JahiaException.ERROR);		  	}		} else {			throw new JahiaException ("Could not create page def.",		    	"Could not instanciate a new ACL object while trying to create a new page def.",		      	JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL);		}        // instanciate the new page template        JahiaPageDefinition template = new JahiaPageDefinition (newID, siteID,                name, sourcePath, isAvailable, image);		        if (template == null) {            throw new JahiaException ("Could not create page template",                "Could not instanciate a new JahiaPageDefinition object.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }				template.setACL(acl.getID());		        // Add the page template in the database.        if (!mTemplateDB.insertPageTemplate (template)) {            throw new JahiaException ("Could not create page template",                "Could not insert the page template into the database.",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL);        }		// set the template default permissions		// enable guest users to view the template		JahiaACLEntry aclEntry = new JahiaACLEntry(1,0);		JahiaGroup guestGroup = ServicesRegistry.getInstance().getJahiaGroupManagerService().getGuestGroup(siteID);		acl.setGroupEntry(guestGroup,aclEntry);		        // Finally add it into the cache        mTemplateCache.add (template);        return template;    }    //-------------------------------------------------------------------------    public synchronized void deletePageTemplate (int defID)        throws JahiaException    {        // check if the service is running        checkService ();        mTemplateDB.deletePageTemplate (defID);        // Finally remove it from the cache        mTemplateCache.remove (defID);    }    //-------------------------------------------------------------------------    public Vector getAllPageTemplateIDs ()        throws JahiaException    {        checkService();        return mTemplateDB.getAllPageTemplateIDs ();    }    //-------------------------------------------------------------------------    /** Returns an instance of the page service */    public static synchronized JahiaPageTemplateBaseService getInstance()        throws JahiaException    {        if (mObject == null) {            mObject = new JahiaPageTemplateBaseService();        }        return mObject;    }    //-------------------------------------------------------------------------    public JahiaPageDefinition getPageTemplateBySourcePath (int siteID, String path)        throws  JahiaException,                JahiaTemplateNotFoundException    {        // check if the service is running        checkService ();        JahiaPageDefinition template = null;        int templateID = mTemplateDB.getPageTemplateIDMatchingSourcePath (siteID, path);        if (templateID != -1) {            template = lookupPageTemplate (templateID);        }        return template;    }    //-------------------------------------------------------------------------    public Enumeration getPageTemplates (int siteID, boolean availableOnly)        throws JahiaException	{        // check if the service is running        checkService ();				TreeMap tm = new TreeMap();        Enumeration templates = mTemplateCache.getTemplates();        while (templates.hasMoreElements()) {            JahiaPageDefinition template = (JahiaPageDefinition)templates.nextElement();           	if ( template.getJahiaID() == siteID ){	 			if ( !availableOnly || template.isAvailable() ){	 				tm.put(template.getName(),template);            	}			}    	}        Vector theList = new Vector(tm.values());            return theList.elements();            }    //-------------------------------------------------------------------------    public synchronized void init ()        throws JahiaException    {        JahiaConsole.println ("JahiaPageService", "   ** Initializing the Page Template Service ...");        // do not allow initialization when the service is still running        if (!isInitialized ()) {            // Initialize the page template cache            JahiaConsole.println ("JahiaPageService", "    - Instanciate the page template cache ...");

⌨️ 快捷键说明

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