📄 jahiapagebaseservice.java
字号:
// $Id: JahiaPageBaseService.java,v 1.4 2002/06/07 13:46:35 pmartin Exp $////// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//package org.jahia.services.pages;import java.util.Enumeration;import java.util.Vector;import org.jahia.data.fields.JahiaField;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaPageNotFoundException;import org.jahia.exceptions.JahiaTemplateNotFoundException;import org.jahia.exceptions.JahiaOperationNotAllowedException;import org.jahia.params.ParamBean;import org.jahia.registries.ServicesRegistry;import org.jahia.services.pages.JahiaPageService;import org.jahia.services.pages.JahiaPageTemplateService;import org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.services.pages.JahiaPageInfo;import org.jahia.services.pages.JahiaPageCache;import org.jahia.services.pages.JahiaPagesDB;import org.jahia.services.pages.JahiaPageUtilsDB;import org.jahia.services.acl.ACLNotFoundException;import org.jahia.services.acl.JahiaBaseACL;import org.jahia.services.usermanager.JahiaUser;import org.jahia.data.files.*;import org.jahia.data.events.*; // JahiaEventimport org.jahia.utils.JahiaConsole;import org.jahia.data.JahiaDOMObject;/** * Class JahiaPageBaseService * * @author Eric Vassalli, Khue, Fulco Houkes * @version 1.0 */public class JahiaPageBaseService extends JahiaPageService{ private static final String CLASS_NAME ="JahiaPageBaseService"; private static JahiaPageBaseService mObject = null; private static int undefined_counter = 0; private JahiaPageCache mPageCache = null; private JahiaPagesDB mPageDB = null; private JahiaPageUtilsDB mUtilsDB = null; private JahiaPageTemplateService mTemplateService = null; //------------------------------------------------------------------------- /** * constructor */ protected JahiaPageBaseService () throws JahiaException { JahiaConsole.println ("JahiaPageService", "***** Starting up the Jahia Page Service *****"); setServiceName ("JahiaPageBaseService"); ////////////////////////////////////////////////////////////////////////////////////// // 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. // // remove also the exception throwing when removing the init method. ////////////////////////////////////////////////////////////////////////////////////// init(); } //------------------------------------------------------------------------- private boolean authorizePageLoad (JahiaPage page, int loadFlag, ParamBean jParams) { boolean out = false; if ((jParams != null) && (page != null)) { JahiaUser user = jParams.getUser(); if (!page.checkReadAccess(user)) { return out; } switch (page.getPageType()) { case (JahiaPageInfo.TYPE_DIRECT) : if ((loadFlag & PageLoadFlags.DIRECT) != 0) { out = true; } break; case (JahiaPageInfo.TYPE_LINK) : if ((loadFlag & PageLoadFlags.INTERNAL) != 0) { out = true; } break; case (JahiaPageInfo.TYPE_URL) : if ((loadFlag & PageLoadFlags.URL) != 0) { out = true; } break; } } return out; } //------------------------------------------------------------------------- private boolean authorizePageLoad (JahiaPage page, int loadFlag, JahiaUser user) { boolean out = false; if ((user != null) && (page != null)) { if (!page.checkReadAccess(user)) { return out; } switch (page.getPageType()) { case (JahiaPageInfo.TYPE_DIRECT) : if ((loadFlag & PageLoadFlags.DIRECT) != 0) { out = true; } break; case (JahiaPageInfo.TYPE_LINK) : if ((loadFlag & PageLoadFlags.INTERNAL) != 0) { out = true; } break; case (JahiaPageInfo.TYPE_URL) : if ((loadFlag & PageLoadFlags.URL) != 0) { out = true; } break; } } return out; } //------------------------------------------------------------------------- public synchronized JahiaPage createPage (int siteID, int parentID, int pageType, String title, int pageTemplateID, String remoteURL, int pageLinkID, String creator, int parentAclID, ParamBean jParam) throws JahiaException { JahiaConsole.println(CLASS_NAME + ".createPage", "Page " + title); // Check if the service is running checkService (); JahiaConsole.println(CLASS_NAME + ".", "Create page started"); // Verify if the specified parent page does exist // // khatmandu-------------- // MULTISITE ISSUE: if parent id equal zero, don't check parent page info... // if (parentID > 0) { JahiaPageInfo parentPageInfo= lookupPageInfo (parentID); if (parentPageInfo == null) { throw new JahiaException ("Could not create page.", "Could not create a new page : parent page ["+parentID+"] not found.", JahiaException.PAGE_ERROR, JahiaException.ERROR); } parentPageInfo = null; } // Get the next available counter. int pageID = mPageDB.getNextID (); // No page hits until now ;) int counter = 0; // Get the current date. String dateOfCreation = new Long((new java.util.Date()).getTime()).toString(); JahiaPage linkedPage = null; JahiaBaseACL acl = null; // An new ACL is created and associated automaticaly to the new page // only if the page is a DIRECT page or an URL link. // In case of a LINK typed page, the ACL of the linked page will be // used. switch (pageType) { case JahiaPage.TYPE_DIRECT : case JahiaPage.TYPE_URL : // Create a new ACL for the page/URL. acl = new JahiaBaseACL (); if (acl != null) { try { acl.create (parentAclID); } catch (ACLNotFoundException ex) { throw new JahiaException ("Could not create page.", "The parent ACL ID ["+parentAclID+"] could not be found,"+ " while trying to create a new page.", JahiaException.PAGE_ERROR, JahiaException.ERROR); } } else { throw new JahiaException ("Could not create page.", "Could not instanciate a new ACL object while trying to create a new page.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } break; case JahiaPage.TYPE_LINK : linkedPage = lookupPage (pageLinkID); acl = linkedPage.getACL(); break; } JahiaPageDefinition pageTemplate = null; switch (pageType) { case JahiaPageInfo.TYPE_DIRECT : pageTemplate = mTemplateService.lookupPageTemplate (pageTemplateID); break; case JahiaPageInfo.TYPE_LINK : pageTemplate = linkedPage.getPageTemplate(); pageTemplateID = pageTemplate.getID(); break; } linkedPage = null; // checks if page title is not null if ((title == null) || ("".equals (title))) { undefined_counter++; title = "Undefined Page " + undefined_counter; } // At this point, the page definition exist and has been instanciate, // as well as the ACL object could be created. // Now create the raw page info object JahiaPageInfo pageInfo = new JahiaPageInfo (pageID, siteID, parentID, pageType, title, pageTemplateID, remoteURL, pageLinkID, creator, dateOfCreation, counter, acl.getID()); dateOfCreation = null; if (pageInfo == null) { throw new JahiaException ("Could not create page.", "Could not instanciate a new JahiaPageInfo object.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } // insert the page info into the database. if (!mPageDB.insertPageInfo (pageInfo)) { throw new JahiaException ("Could not create page.", "Could not insert the page info into the database", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } // Let's create the page!! JahiaPage page = new JahiaPage (pageInfo, pageTemplate, acl, jParam); acl = null; if (page == null) { throw new JahiaException ("Could not create page.", "Could not instanciate a new JahiaPage object.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } // add the page into the cache mPageCache.add (pageInfo); pageInfo = null; // log the page creation Event JahiaEvent theEvent = new JahiaEvent( this, jParam, page ); ServicesRegistry.getInstance().getJahiaEventService(). fireAddPage (theEvent); theEvent = null; return page; } //------------------------------------------------------------------------- // deletes all container lists in page private void deleteAllPageContainerLists (JahiaPage thePage, ParamBean jParam) throws JahiaException { Vector cListIDs = ServicesRegistry.getInstance() .getJahiaContainersService() .getContainerListIDsInPage( thePage ); for (int i=0; i < cListIDs.size(); i++) { int cListID = ((Integer)cListIDs.elementAt(i)).intValue(); JahiaConsole.println("JahiaPageBaseService.deleteAllPageContainerLists", "Deleting container list ID " + cListID); ServicesRegistry.getInstance().getJahiaContainersService().deleteContainerList( cListID ); } cListIDs = null; } //------------------------------------------------------------------------- // deletes all fields in page private void deleteAllPageFields (JahiaPage thePage, ParamBean jParam) throws JahiaException { Vector fieldIDs = ServicesRegistry.getInstance().getJahiaFieldService( ).getFieldIDsInPage (thePage.getID()); for (int i=0; i < fieldIDs.size(); i++) { int fieldID = ((Integer)fieldIDs.elementAt (i)).intValue (); ServicesRegistry.getInstance ().getJahiaFieldService ().deleteField (fieldID, jParam); } fieldIDs = null; } //------------------------------------------------------------------------- // deletes all fields/containers pointing on this page private void deleteLinksOnPage (JahiaPage thePage, ParamBean jParam) throws JahiaException { Vector links = getPagesPointingOnPage (thePage.getID(), null); for (int i=0; i < links.size(); i++) { JahiaPage theLink = (JahiaPage) links.elementAt(i); JahiaField theField = mUtilsDB.getPageField (theLink.getID()); if (theField != null) { ServicesRegistry.getInstance().getJahiaFieldService().deleteField (theField.getID(), jParam); } } links = null; } //------------------------------------------------------------------------- public synchronized void deletePage (JahiaPage theVictim, ParamBean jParam) throws JahiaException, JahiaOperationNotAllowedException { // Check if the service is running checkService (); // Just be sure the victim did run away meanwhile ... if (theVictim == null) { return; } int currentPageID = -1; if ( jParam != null ){ currentPageID = jParam.getPageID(); } // avoid to delete the current page if (theVictim.getID() != currentPageID) { // First remove it from the cache mPageCache.remove (theVictim.getID()); // only direct pages do have content. if (theVictim.getPageType() == JahiaPage.TYPE_DIRECT) { // delete all the fields associated to the page. deleteAllPageFields (theVictim, jParam); // delete all the container list associated to the page. deleteAllPageContainerLists (theVictim, jParam); // delete all links pointing on this page. deleteLinksOnPage (theVictim, jParam); } // If the victim is a link, the ACL must not be deleted, because the // page and the link share the same ACL object. if (theVictim.getPageType() != JahiaPage.TYPE_LINK) { // delete the page's ACL JahiaBaseACL acl = theVictim.getACL (); acl.delete (); acl = null; } // kill the files which belongs to the page Vector files = ServicesRegistry.getInstance().getJahiaFilemanagerService().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -