📄 jahiapage.java
字号:
// $Id: JahiaPage.java,v 1.2 2002/11/27 15:37:38 knguyen Exp $//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//package org.jahia.services.pages;import java.util.*; // Enumerationimport org.jahia.data.FormDataManager;import org.jahia.params.ParamBean;import org.jahia.utils.JahiaConsole;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaTemplateNotFoundException;import org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.registries.ServicesRegistry;import org.jahia.registries.locks.JahiaLocksRegistry;import org.jahia.services.usermanager.*;import org.jahia.services.acl.JahiaBaseACL;import org.jahia.services.acl.ACLResourceInterface;import org.jahia.services.acl.JahiaACLException;import org.jahia.services.sites.JahiaSite;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.services.pages.JahiaPagesDB;import org.jahia.services.pages.JahiaPageBaseService;import org.jahia.services.pages.JahiaPageInfo;import org.jahia.services.pages.PageInfoInterface;import org.jahia.utils.*;import org.jahia.content.PageXRefManager;public class JahiaPage implements PageInfoInterface, ACLResourceInterface, Comparator{ private static final String CLASS_NAME = JahiaPage.class.getName(); // lock parameter names constants private static final String LOCK_USER_PARAMETER = "user"; private static final String LOCK_PAGE_PARAMETER = "page"; private static final String LOCK_ENGINE_NAME_PARAMETER = "engineName"; private JahiaPageService mPageService = null; private JahiaPageInfo mPageInfo; private JahiaPageDefinition mPageTemplate; private JahiaBaseACL mACL; private ParamBean mParams = null; private JahiaPageDefinition mTempPageTemplate; private JahiaLocksRegistry mLocksRegistry; private boolean declared = false; //------------------------------------------------------------------------- protected JahiaPage (JahiaPageInfo pageInfo, JahiaPageDefinition pageTemplate, JahiaBaseACL acl, ParamBean jParam) throws JahiaException { mPageInfo = pageInfo; mPageTemplate = pageTemplate; mACL = acl; mParams = jParam; mTempPageTemplate = pageTemplate; mPageService = ServicesRegistry.getInstance().getJahiaPageService(); if (mPageService == null) { throw new JahiaException ("Page error", "Could not get the page templates service instance.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } mLocksRegistry = JahiaLocksRegistry.getInstance(); if (mPageService == null) { throw new JahiaException ("Page instanciation error", "Could not get the JahiaLocksRegistry instance.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } } //------------------------------------------------------------------------- private boolean checkAccess (JahiaUser user, int permission) { if (user == null) { return false; } // Test the access rights boolean result = false; try { result = mACL.getPermission (user, permission, this.getJahiaID()); } catch (JahiaACLException ex) { // if an error occured, just return false; } //if (!result) { // JahiaConsole.println ("JahiaPage", "Permission denied for user ["+user.getUsername()+"::"+ // user.getName()+"] to page ["+getID ()+ // "] for access permission ["+permission+"]"); //} else { // JahiaConsole.println ("JahiaPage", "Permission granted for user ["+user.getUsername()+"::"+ // user.getName()+"] to page ["+getID()+ // "] for access permission ["+permission+"]"); //} return result; } //------------------------------------------------------------------------- /** * Check if the user has administration access on the specified page. Admin * access means having the ability to add pages, containers and fields, but * also giving rights to users to the different objects/applications in the * specified page. * * @param user Reference to the user. * @param pageID Page identification number. * * @return Return true if the user has read access for the specified page, * or false in any other case. */ public final boolean checkAdminAccess (JahiaUser user) { return checkAccess (user, JahiaBaseACL.ADMIN_RIGHTS); } //------------------------------------------------------------------------- /** * Check if the user has read access on the specified page. Read access means * having the rights to display and read the page. * * @param user Reference to the user. * @param pageID Page identification number. * * @return Return true if the user has read access for the specified page, * or false in any other case. */ public final boolean checkReadAccess (JahiaUser user) { return checkAccess (user, JahiaBaseACL.READ_RIGHTS); } //------------------------------------------------------------------------- /** * Check if the user has Write access on the specified page. Write access means * adding new pages, containers and fields in the specified page. * * @param user Reference to the user. * @param pageID Page identification number. * * @return Return true if the user has read access for the specified page, * or false in any other case. */ public final boolean checkWriteAccess (JahiaUser user) { return checkAccess (user, JahiaBaseACL.WRITE_RIGHTS); } //------------------------------------------------------------------------- /** * Check if the Guest user of a site has read access. * * @param int siteID the site id. * * @return Return true if the site's guest user has read access for this page, * or false in any other case. */ public final boolean checkGuestAccess (int siteID) { // get the User Manager service instance. JahiaUserManagerService userMgr = ServicesRegistry.getInstance(). getJahiaUserManagerService(); if ( userMgr == null ) return false; JahiaUser theUser = userMgr.lookupUser (siteID, userMgr.GUEST_USERNAME); if ( theUser == null ) return false; return checkAccess (theUser, JahiaBaseACL.READ_RIGHTS); } //------------------------------------------------------------------------- /** @todo this is called even for a page counter update, can we avoid that * in the future ? */ public void commitChanges (boolean flushCaches) throws JahiaException { JahiaConsole.println("JahiaPage.commitChanges", "called."); if (flushCaches) { // let's flush the cache of all the pages referencing this one. int siteID = getJahiaID(); JahiaSite site = ServicesRegistry.getInstance().getJahiaSitesService().getSite(siteID); if (site == null) { JahiaConsole.println("JahiaPage.commitChanges", "Invalid site for page, cannot flush cache."); } else { Set refPages = PageXRefManager.getInstance().getPageIDs(site.getSiteKey(), getID()); Iterator refPagesIter = refPages.iterator(); while (refPagesIter.hasNext()) { Integer curPageID = (Integer) refPagesIter.next(); ServicesRegistry.getInstance().getCacheServerService().removeEntry(curPageID.toString()); } // let's flush this page's cache... ServicesRegistry.getInstance().getCacheServerService().removeEntry(Integer.toString(getID())); } } mPageInfo.commitChanges (); mPageTemplate = mTempPageTemplate; } //------------------------------------------------------------------------- /** Return the page's ACL object. * * @return Return the page's ACL. */ public final JahiaBaseACL getACL () { return mACL; } //------------------------------------------------------------------------- /** Return the ACL unique identification number. * * @return Return the ACL ID. */ public final int getAclID () { int id = -1; try { id = mACL.getID (); } catch (JahiaACLException ex) { // This exception should not happen ... :) } return id; } //------------------------------------------------------------------------- /** Return the page's hit counter. * * @return Return the page counter. */ public final int getCounter () { return mPageInfo.getCounter (); } //------------------------------------------------------------------------- /** Return the user nickname who created the page. This nickname is the * user name used internally by Jahia. * * @return Return the creator nickname. */ public final String getCreator () { return mPageInfo.getCreator (); } //------------------------------------------------------------------------- /** Return the page's date of creation in ms from 1975. * * @return Return the date of creation. */ public final String getDoc () { return mPageInfo.getDoc (); } //------------------------------------------------------------------------- /** Return the page's unique identification number. * * @return Return the page ID. */ public final int getID () { return mPageInfo.getID (); } //------------------------------------------------------------------------- /** Return the site ID in which the page is located. * * @return Return the page site ID. */ public final int getJahiaID () { return mPageInfo.getJahiaID (); } //------------------------------------------------------------------------- /** Return the reference on the page definition object. * * @return Return the page definition object. */ public final JahiaPageDefinition getPageTemplate () { return mPageTemplate; } //------------------------------------------------------------------------- /** Return the page definition ID. * * @return Return the page definition ID. */ public final int getPageTemplateID () { return mPageInfo.getPageTemplateID (); } //------------------------------------------------------------------------- /** Return the internal representation of the page information. * * @return Return the JahiaPageInfo object. */ protected final JahiaPageInfo getPageInfo () { return mPageInfo; } //------------------------------------------------------------------------- /** Return the internal jahia page ID in case the page is an internal * jahia link. * * @return Return the page link ID. */ public final int getPageLinkID () { return mPageInfo.getPageLinkID (); } //------------------------------------------------------------------------- /** Return the page type * * @return Return the page type */ public final int getPageType () { return mPageInfo.getPageType (); } //------------------------------------------------------------------------- /** Return the parent page unique identification number. * * @return Return the parent page ID. */ public final int getParentID () { return mPageInfo.getParentID (); } //------------------------------------------------------------------------- /** Return the remote URL in case the page is an external reference (a non * Jahia page. If the page is not an external URL, "<no url>" is returned. * * @return Return the remote URL. */ public final String getRemoteURL () { return mPageInfo.getRemoteURL (); } //------------------------------------------------------------------------- /** Return the page title. * * @return Return the page title. */ public final String getTitle () { return JahiaTools.text2html(mPageInfo.getTitle ()); } //-------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -