📄 guibean.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// GuiBean// EV 03.11.2000// DJ 02.02.2001 - added ACL check for link display// JB 16.05.2001//// html()// xml()// wap()//// drawHttpPath()// drawSwitchModeLink()//// drawPopupLoginUrl(), drawPopupLoginUrl( destinationPageID )// drawLoginUrl(), drawLoginUrl( destinationPageID )// drawPopupLogoutUrl([destionationPageID]), drawLogoutUrl([destinationPageID])// drawUpdateFieldUrl( JahiaField )// drawAddContainer( JahiaContainerList )// drawUpdateContainer( JahiaContainer )// drawDeleteContainer( JahiaContainer )// drawPagePropertiesUrl()// drawContainerListPropertiesUrl()// drawSearchUrl()//package org.jahia.gui;import java.util.*; // Vector / Calendarimport javax.servlet.*; // ServletContextimport javax.servlet.http.*; // HttpServletRequestimport org.jahia.bin.Jahia;import org.jahia.utils.*; // JahiaConsoleimport org.jahia.params.*; // ParamBeanimport org.jahia.data.*; // JahiaDataimport org.jahia.data.fields.*; // JahiaFieldsimport org.jahia.data.containers.*; // JahiaContainerimport org.jahia.registries.*; // EnginesRegistryimport org.jahia.engines.*; // JahiaEngineimport org.jahia.exceptions.JahiaException;import org.jahia.registries.*;import org.jahia.services.acl.*;import org.jahia.services.sites.JahiaSite;import org.jahia.services.pages.JahiaPageService;import org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.services.usermanager.JahiaUser;import org.jahia.engines.copytree.*;public class GuiBean { private static final String CLASS_NAME = GuiBean.class.getName(); private ParamBean jParams; private HTMLToolBox html; private JahiaUser currentUser; private JahiaPage thePage; /*** * constructor * EV 03.11.2000 * */ public GuiBean( ParamBean jParams ) { this.jParams = jParams; this.html = new HTMLToolBox( this, jParams ); this.currentUser = jParams.getUser(); this.thePage = jParams.getPage(); } // end constructor /*** * html * EV 15.12.2000 * */ public HTMLToolBox html() { return html; } // end constructor /*** * drawHttpPath * EV 21.11.2000 * */ public String drawHttpPath() throws JahiaException { if (jParams != null) { return jParams.settings().getJahiaTemplatesHttpPath(); } else { return ""; } } // end drawHttpPath /*** * drawHttpPath * JB 25.04.2001 * */ public String drawHttpPath(String theTemplateFolderName) throws JahiaException { if (jParams != null) { return jParams.settings().getJahiaTemplatesHttpPath() + theTemplateFolderName; } else { return ""; } } // end drawHttpPath //------------------------------------------------------------------------- /** */ public String drawHttpJspContext (HttpServletRequest req){ StringBuffer path = new StringBuffer(); path.append(req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf("/"))); return path.toString(); } /*** * drawPageLink * EV 21.11.2000 * */ public String drawPageLink(int thePageID) throws JahiaException { String result = ""; if (jParams != null) { // Get the current page JahiaPage currentPage = jParams.getPage(); if (currentPage != null) { result = jParams.composePageUrl(thePageID); } } return result; } // end drawPageLink /*** * drawSwitchModeLink * EV 21.11.2000 * */ public String drawSwitchModeLink() throws JahiaException { String result = ""; if (jParams != null) { // Get the current page JahiaPage currentPage = jParams.getPage(); if (currentPage != null) { // Check the write permission on the page if (currentPage.checkWriteAccess (jParams.getUser())) { if (jParams.getOperationMode().equals( jParams.NORMAL )) { result = jParams.composeOperationUrl( jParams.EDIT, "" ); } else { result = jParams.composeOperationUrl( jParams.NORMAL, "" ); } } } } return result; } // end drawSwitchModeLink public String drawPopupLoginUrl() throws JahiaException { return drawUrl( "login", "/pid/" + jParams.getPageID() ); } public String drawPopupLoginUrl( int destinationPageID ) throws JahiaException { return drawUrl( "login", "/pid/" + destinationPageID ); } public String drawLoginUrl() throws JahiaException { return drawUrl( "login", "/pid/" + jParams.getPageID() + "?screen=save" ); } public String drawLoginUrl( int destinationPageID ) throws JahiaException { return drawUrl( "login", "/pid/" + destinationPageID + "?screen=save" ); } // end drawLoginUrl // this draw logout is called by the other ones too public String drawPopupLogoutUrl( int destinationPageID ) throws JahiaException { String result = ""; if ( jParams.getUser().getUsername()!= "guest" ) { result = drawUrl( "logout", "/pid/" + destinationPageID ); } return result; } public String drawPopupLogoutUrl() throws JahiaException { return drawPopupLogoutUrl( jParams.getPageID() ); } public String drawLogoutUrl( int destinationPageID ) throws JahiaException { return drawPopupLogoutUrl( destinationPageID ); } // end drawLogoutUrl public String drawLogoutUrl() throws JahiaException { return drawPopupLogoutUrl( jParams.getPageID() ); } public String drawUpdateFieldUrl( JahiaField theField ) throws JahiaException { return drawUrlCheckWriteAccess( "updatefield", theField ); } public String drawAddContainerUrl( JahiaContainerList theContainerList ) throws JahiaException { if (theContainerList != null) { return drawUrlCheckWriteAccess( "addcontainer", theContainerList ); } else { JahiaException je = new JahiaException( "Accessing non-existing data", "GuiBean : Trying to access to non-existing containerlist (addContainerUrl)", JahiaException.DATA_ERROR, JahiaException.WARNING ); return new String(""); } } public String drawUpdateContainerUrl( JahiaContainer theContainer ) throws JahiaException { return drawUrlCheckWriteAccess( "updatecontainer", theContainer ); } public String drawDeleteContainerUrl( JahiaContainer theContainer ) throws JahiaException { return drawUrlCheckWriteAccess( "deletecontainer", theContainer ); } public String drawPagePropertiesUrl() throws JahiaException { return drawUrl( "pageproperties", jParams.getPage() ); } public String drawUpdateTemplateUrl( JahiaPageDefinition theTemplate ) throws JahiaException { return drawUrlCheckWriteAccess( "template", theTemplate ); } /** * operation if null, set to CopyTree_Engine.CHOOSE_OPERATION * * @param String operation * @param String unique name of the launcher of this engine * @param int initialSourcePage, the initial page to be selected. * @see CopyTree_Engine.COPY_OPERATION * @see CopyTree_Engine.MOVE_OPERATION * @see CopyTree_Engine.LINK_OPERATION * @see CopyTree_Engine.CHOOSE_OPERATION */ public String drawCopyTreeUrl(String operation,String engineLauncherName, int initialSourcePage) throws JahiaException { JahiaPage page = jParams.getPage(); if ( page == null && jParams.isInAdminMode() ) page = ServicesRegistry.getInstance() .getJahiaPageService().lookupPage(jParams.getSite().getHomePageID(),jParams); String url = drawUrlCheckWriteAccess( "copytree", page ); if ( operation == null ) operation = CopyTree_Engine.CHOOSE_OPERATION; if ( url != null ) url += "&operation=" + operation; if ( (engineLauncherName != null) && !engineLauncherName.trim().equals("") ) url += "&enginelauncher=" + engineLauncherName; url +="&sourcepageid=" + initialSourcePage; return url; } public String drawContainerListPropertiesUrl( JahiaContainerList theContainerList ) throws JahiaException { if (theContainerList.getID() != 0) { // WARNING : // Before, this line was set to drawUrlCheckWriteAccess // but had to replace with drawUrl because of a mysterious bug... // to correct ASAP ! // EV 14.03.2001 return drawUrl( "containerlistproperties", theContainerList ); } else { return new String(""); } } /** * Generates an URL for a NEXT WINDOW on a containerlist. * * @param theContainerList the containerList for which to generate the URL * @param pageStep the number of pages to skip through. * @param newWindowSize the size of the window (optional). -1 to keep * current window size. * @param boolean scrollingValueOnly if true, return only the scrolling * value , i.e. '5_10' , instead of the full url. * * @return the URL for the operation specified. * * @throws JahiaException on error accessing containerList definitions either * in memory or in the database. * @author Serge Huber */ public String drawContainerListNextWindowPageURL( JahiaContainerList theContainerList, int pageStep, int newWindowSize, boolean scrollingValueOnly ) throws JahiaException { return drawContainerListWindowPageURL( theContainerList, pageStep, newWindowSize, scrollingValueOnly); } /** * Generates an URL for a PREVIOUS WINDOW on a containerlist. * * @param theContainerList the containerList for which to generate the URL * @param pageStep the number of pages to skip through. * @param newWindowSize the size of the window (optional). -1 to keep * current window size. * @param boolean scrollingValueOnly if true, return only the scrolling * value , i.e. '5_10' , instead of the full url. * * @return the URL for the operation specified. * * @throws JahiaException on error accessing containerList definitions either * in memory or in the database. * @author Serge Huber */ public String drawContainerListPreviousWindowPageURL ( JahiaContainerList theContainerList, int pageStep, int newWindowSize, boolean scrollingValueOnly ) throws JahiaException { return drawContainerListWindowPageURL( theContainerList, -pageStep, newWindowSize, scrollingValueOnly); } /** * Generates an URL that allows navigation within a scrollable container * list. * * @param theContainerList the containerList for which to generate the URL * @param pageStep the number of pages to switch, this may be positive or * negative, going both ways. * @param windowSize the size of the window, optional (set to -1 if deactivated). * @param boolean scrollingValueOnly if true, return only the scrolling value, * i.e. '5_10' , instead of the full url. * * @return the URL generated for this operation. Size and offset are correct * to match containerList size. * * @throws JahiaException on error accessing containerList definitions either * in memory or in the database. * @author Serge Huber */ public String drawContainerListWindowPageURL ( JahiaContainerList theContainerList, int pageStep, int newWindowSize, boolean scrollingValueOnly ) throws JahiaException { if ( theContainerList == null ){ return null; } JahiaContainerListPagination cListPagination = theContainerList.getCtnListPagination(); if ( cListPagination == null || cListPagination.getWindowSize()!=newWindowSize ) { cListPagination = new JahiaContainerListPagination(theContainerList,jParams, newWindowSize); theContainerList.setCtnListPagination(cListPagination); } // For next & previous button check if ( !cListPagination.isValid() || (cListPagination.getNbPages()<2) ){ // feature is deactivated. return null; } // For previous button check if ( (cListPagination.getCurrentPageIndex()==1) && (pageStep<0) ){ // feature is deactivated. return null; } // For next button check int nextPage = cListPagination.getCurrentPageIndex()+1; if ( (nextPage>cListPagination.getNbPages()) && (pageStep>0) ){ // feature is deactivated. return null; } int windowSize = cListPagination.getWindowSize(); int windowOffset = cListPagination.getWindowOffset(); windowOffset += pageStep * windowSize; // we now have all the correct values, let's build the URL... String paramName = "ctnscroll_" + theContainerList.getDefinition().getName(); String paramValue = Integer.toString(windowSize) + "_" + Integer.toString(windowOffset); if ( scrollingValueOnly ){ return paramValue; } /** @todo this is really ugly... let's remember to clean it up... */ String cacheStatus = jParams.getCacheStatus(); jParams.setCacheStatus(ParamBean.CACHE_OFFONCE); String curPageURL = jParams.composePageUrl(jParams.getPageID()); jParams.setCacheStatus(cacheStatus); curPageURL += "/" + paramName + "/" + paramValue; return curPageURL; } /** * Generates an URL that allows navigation within a scrollable container * list. * * @param JahiaContainerList the container list with a valid JahiaContainerListPagination bean. * @param int pageStep must be bigger than 0. * @param boolean scrollingValueOnly if true, return only the scrolling value , i.e. '5_10' , instead of the full url. * * @return the URL generated for this operation. * * @throws JahiaException on error accessing containerList definitions either * in memory or in the database. * @author NK */ public String drawContainerListWindowPageURL ( JahiaContainerList containerList, int pageStep, boolean scrollingValueOnly ) throws JahiaException { if ( containerList == null || containerList.getCtnListPagination()== null || !containerList.getCtnListPagination().isValid() || (pageStep <= 0) ){ return null; } String paramName = "ctnscroll_" + containerList.getDefinition().getName(); String paramValue = Integer.toString(containerList.getCtnListPagination().getWindowSize()) + "_" + Integer.toString((pageStep-1)*containerList.getCtnListPagination().getWindowSize());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -