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

📄 jahiapagetemplatebaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            mTemplateCache = JahiaPageTemplateCache.getInstance ();            // get the page template DB access instance            JahiaConsole.println ("JahiaPageService", "    - Instanciate the database page template tools ...");            mTemplateDB = JahiaPageTemplateDB.getInstance ();            // Verify if the needed classes could be successfully instanciated.            if ((mTemplateCache != null) && (mTemplateDB != null)) {                mIsServiceInitialized = true;                JahiaConsole.println ("JahiaPageService", "   ** Page Template Service successfully initialized!");            } else {                // invalidate the previous initializations                mTemplateDB     = null;                mTemplateCache  = null;                // and raise an exception :(                throw new JahiaException ("Page Template Service initialization error.",                        "Page Template Service could not be initialized successfully.",                        JahiaException.SERVICE_ERROR, JahiaException.KISS_YOUR_ASS_GOODBYE);            }        }    }    //-------------------------------------------------------------------------    private synchronized void loadAllPageTemplates ()        throws JahiaException	{        Vector templateIDs = mTemplateDB.getAllPageTemplateIDs ();        for (int i=0; i < templateIDs.size(); i++) {            int templateID = ((Integer)templateIDs.elementAt(i)).intValue();            // the template which could not be found in the database are not            // loaded.            try {                JahiaPageDefinition template = lookupPageTemplate (templateID);                if (template != null) {                	                    mTemplateCache.add (template);                }            }            catch (JahiaTemplateNotFoundException ex) {                // the page template could not be found, don't add it into the                // database.                // This exception should theoreticaly not happen.            }        }    }    //-------------------------------------------------------------------------    public JahiaPageDefinition lookupPageTemplate (int templateID)        throws  JahiaException,                JahiaTemplateNotFoundException    {        // check if the service is running        checkService ();        // Try to read the page template out of the cache        JahiaPageDefinition template = mTemplateCache.get (templateID);        // if the template is not present in the cache, read it        // from the database.        if (template == null) {            template = mTemplateDB.loadPageTemplate (templateID);            // if the page template is not in the database, raise an            // exception            if (template != null) {                mTemplateCache.add (template);            } else {                throw new JahiaTemplateNotFoundException (templateID);            }        }        return template;    }    //-------------------------------------------------------------------------    public JahiaPageDefinition lookupPageTemplateByName (String name, int siteID)        throws  JahiaException,                JahiaTemplateNotFoundException	{        // check if the service is running        checkService ();        Enumeration templates = mTemplateCache.getTemplates();        while (templates.hasMoreElements()) {            JahiaPageDefinition template =                    (JahiaPageDefinition)templates.nextElement();            if ((template.getName().equals (name)) &&                (template.getJahiaID() == siteID))            {                return template;            }        }        throw new JahiaTemplateNotFoundException (name);    }    //-------------------------------------------------------------------------    public synchronized void shutdown ()    {        //////////////////////////////////////////////////////////////////////////////////////        // FIXME -Fulco- :        //   before shutting down the service, a check should be done to know        //   if a page has an update-lock active. If any active update-lock is        //   active, the system can not be shutdown !        //   If the shutdown process can be forced, a message should indicate the editing        //   user the service is in shutdown process, as soon as he does an action.        //////////////////////////////////////////////////////////////////////////////////////        if (isInitialized()) {            mTemplateCache.reset ();            // the service is not down!            mIsServiceInitialized = false;        }    }    //-------------------------------------------------------------------------    // FH   2 May 2001    // javadocs automaticaly imported.    //    public int getNbPageTemplates ()        throws  JahiaException    {        return mTemplateDB.getNbPageTemplates (-1);    }    //-------------------------------------------------------------------------    // NK   17 May 2001    // javadocs automaticaly imported.    //    public int getNbPageTemplates (int siteID)        throws  JahiaException    {        return mTemplateDB.getNbPageTemplates (siteID);    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of all page def of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getPageDefsAsDOM( int siteID ) throws JahiaException{		return JahiaPageTemplateDB.getInstance().getPageDefsAsDOM (siteID);  	}    //--------------------------------------------------------------------------    /**     * returns a DOM representation of all page def props of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getPageDefPropsAsDOM( int siteID ) throws JahiaException{		return JahiaPageDefinitionPropDB.getPageDefPropsAsDOM (siteID);  	}    //--------------------------------------------------------------------------    /**     * Returns a vector of all page templates' Acl ID of this site     * Need this for site extraction     *     * @param int siteID     */    public Vector getAclIDs( int siteID )    throws JahiaException{        return JahiaPageDefinitionPropDB.db_get_all_acl_id(siteID);    } 	// Patch --------------------------------------------------- 	// 30.01.2002 : NK patch for old databases containing templates without ACL 	// 				Do create ACL for them.	public final void patchTemplateWithoutACL() throws JahiaException {		JahiaSite site = null;    	JahiaPageDefinition template = null;    	    	Enumeration ids = mTemplateCache.getTemplateIDs();    	Integer I = null;    	while ( ids.hasMoreElements() ){    		I = (Integer)ids.nextElement();    		template = mTemplateCache.get(I.intValue());    			    	if ( template.getAclID()== -1 ){							site = ServicesRegistry.getInstance().getJahiaSitesService().getSite( template.getJahiaID() );				if ( site != null ){					// Create a new ACL.					JahiaBaseACL acl = new JahiaBaseACL ();					if (acl != null) {						try {					    	acl.create (site.getAclID());									template.setACL(acl.getID());												// set the template default permissions							// enable guest users to view the template							JahiaACLEntry aclEntry = new JahiaACLEntry(1,0);							JahiaGroup guestGroup = ServicesRegistry.getInstance().getJahiaGroupManagerService().getGuestGroup(site.getID());							acl.setGroupEntry(guestGroup,aclEntry);														template.commitChanges();							JahiaConsole.println(CLASS_NAME+".patchTemplateWithoutACL()","Patch : ACL [" + template.getAclID() + "] has been created for the template :" + template.getName());							    						  	}					  	catch (ACLNotFoundException ex) {					    	throw new JahiaException ("Could not patch ACL for the page def.",					        	"The parent ACL ID ["+site.getAclID()+"] could not be found,"+					          	" while trying to patch ACL ( create a new one ) for page def [" + template.getID() + "]",					          	JahiaException.TEMPLATE_ERROR, JahiaException.ERROR);					  	}					} else {						JahiaConsole.println(CLASS_NAME+".patchTemplateWithoutACL()","Could not patch ACL for page def.");					}				}         				}    	}	}	// End Patch -----------------------------------------------}

⌨️ 快捷键说明

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