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

📄 page_field.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// $Id: Page_Field.java,v 1.13 2003/07/14 16:37:58 shuber Exp $//////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//package org.jahia.engines.shared;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaUpdateLockException;import org.jahia.utils.*;                       // JahiaConsoleimport org.jahia.data.*;                        // JahiaData, ConnectionTypesimport org.jahia.params.*;                      // ParamBeanimport org.jahia.engines.*;                     // JahiaEngine interfaceimport org.jahia.engines.copytree.*;            // CopyTree_Engineimport org.jahia.engines.shared.*;              // TreeUtilsimport org.jahia.data.fields.*;                 // JahiaField, FieldTypesimport org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.PageLoadFlags;import org.jahia.services.pages.*;import org.jahia.registries.*;                  // ServicesRegistryimport org.jahia.services.usermanager.JahiaUser;import org.jahia.services.acl.*;import org.jahia.data.containers.*;public class Page_Field{    private static final String CLASS_NAME = Page_Field.class.getName();    private static          Page_Field      theObject   = null;    private static final    String          JSP_FILE    = "/jsp/jahia/engines/shared/page_field.jsp";    public  static final    String  READONLY_JSP  		= "/jsp/jahia/engines/shared/readonly_page_field.jsp";    private static          int             staticUndefined = 0;    /***        * gets a single instance of the object        *        */    public static synchronized Page_Field getInstance()    {        if (theObject == null) {            theObject = new Page_Field();        }        return theObject;    } // end getInstance    /***        * handles the field actions        *        * @param        jParams             a ParamBean object        * @param        mode                the mode, according to JahiaEngine        * @return       true if everything went okay, false if not        * @see          org.jahia.engines.JahiaEngine        *        */    public boolean handleField( ParamBean jParams, Integer modeInt, HashMap engineMap )        throws  JahiaException,                JahiaUpdateLockException    {        int mode = modeInt.intValue();        JahiaField theField = (JahiaField) engineMap.get ("theField");        ///////////////////////////////////////////////////////////////////////////////////////////        // FIXME -Fulco-        //        //  Has been disabled until full implementation of the objectlocking.        //        ////////////////////////////////////////////////////////////////////////////////////////////*        // get the page object. If the page is not null, we are coming from        // the update page engine, otherwise we are coming from the add page        // engine. If the page is not null, check if the page is not already        // locked by another user.        JahiaPage thePage = (JahiaPage)theField.getObject();        if (thePage != null) {            if (!thePage.getUpdateLock (jParams.getUser())) {                // the lock could not be obtained!                throw new JahiaUpdateLockException (thePage);            }        }*/        ///////////////////////////////////////////////////////////////////////////////////////////        switch (mode)        {            case (JahiaEngine.LOAD_MODE) :                JahiaConsole.println(CLASS_NAME + ".handleField", "Loading pagefield");                return composeEngineMap( jParams, engineMap, theField );            case (JahiaEngine.UPDATE_MODE) :                JahiaConsole.println(CLASS_NAME + ".handleField", "Updating pagefield");                return getFormData( jParams, engineMap, theField );            case (JahiaEngine.SAVE_MODE) :                JahiaConsole.println(CLASS_NAME + ".handleField", "Saving pagefield");                return saveData( jParams, engineMap, theField );        }        return false;    } // end handleField    /***        * composes engine hash map        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine hashmap        * @param        theField            the field we are working on        * @return       true if everything went okay, false if not        *        */    private boolean composeEngineMap( ParamBean jParams, HashMap engineMap, JahiaField theField )    throws JahiaException    {        JahiaConsole.println(CLASS_NAME+".composeEngineMap","Started");        JahiaPageEngineTempBean thePage = composePage( jParams, engineMap, theField );        JahiaUser               theUser = null;        if (jParams != null)            theUser = jParams.getUser();        boolean editable = false;        JahiaContainer theContainer = (JahiaContainer)engineMap.get("theContainer");        if ( theContainer == null ){            // in case of a field , not a field in a container            editable = true;        } else if ( theContainer.getListID()!=0 ){            JahiaBaseACL acl = JahiaEngineTools.getCtnListFieldACL((HashMap)engineMap.get("ctnListFieldAcls"), theField.getID());            if ( acl != null ){                editable = acl.getPermission(jParams.getUser(),JahiaBaseACL.WRITE_RIGHTS, jParams.getSiteID());            }        } else {            editable = true;        }        String output = "";        if ( editable ) {            // warns that page is being created            // cannot use the field id to create a unique enginemap name,            // because can field id can change (in addcontainer mode, for example)            // so we use the field definition's name to create a unique enginemap name...            engineMap.put( "createPage_" + theField.getDefinition().getName(), Boolean.TRUE );            //flag to warns the field is being updated, then keep current pageBean            if ( (jParams.getSession().getAttribute("UpdateContainer") != null) && (jParams.getSession().getAttribute("UpdateContainer").equals("true")) )            {                engineMap.put("updateField" + theField.getDefinition().getName(), "true");            }            // templates            Enumeration templateList = ServicesRegistry.getInstance().getJahiaPageTemplateService().                    getPageTemplates (thePage.getSiteID(), true); // show only visible templates            engineMap.put( "templateList", templateList );            // remote url            String remoteUrl = (String) engineMap.get( "remoteUrl" );            if ((remoteUrl == null) || (remoteUrl.trim().equals(""))) {                engineMap.put( "remoteUrl", "http://www" );            }            String pageTitle = JahiaTools.html2text(thePage.getTitle());            if ((pageTitle != null) || (!pageTitle.equals(""))) {                engineMap.put( "pageTitle"+ theField.getDefinition().getName(), FormDataManager.getInstance().formDecode(pageTitle) );            }            int pageTemplateID = thePage.getPageTemplateID();            if (pageTemplateID > 0) {                engineMap.put( "templateID", new Integer(pageTemplateID) );            } else {                // use default value if any was here.                try {                    if (!"".equals(theField.getValue())) { // we have a 'default' value                        JahiaPageDefinition p =                            ServicesRegistry.getInstance().                            getJahiaPageTemplateService().                            lookupPageTemplateByName(theField.getValue(),                            thePage.getSiteID());                        engineMap.put("templateID", new                                      Integer(p.getID()));                    }                } catch (JahiaException ignore) {}            }            String manageTreeURL = CopyTree_Engine.getInstance().renderLink( jParams, jParams.getPage() );            engineMap.put( "manageTreeURL", manageTreeURL );            thePage.setTitle( FormDataManager.getInstance().formDecode(thePage.getTitle()) );            output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, JSP_FILE );            thePage.setTitle( FormDataManager.getInstance().decode(thePage.getTitle()) );        } else {            output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, READONLY_JSP );        }        engineMap.put( "fieldForm", output );        return true;    } // end composeEngineMap    /***        * gets POST data from the form and saves it in session        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine hashmap        * @param        theField            the field we are working on        * @return       true if everything went okay, false if not        *        */    private boolean getFormData (ParamBean jParams, HashMap engineMap, JahiaField theField)        throws JahiaException    {        JahiaConsole.println(CLASS_NAME + ".getFormData",                        "Gets POST data from the form and saves it in session");        // ----------------------------------------------------------------------------------------        // STEP 1 : Init vars, compose Page object  -----------------------------------------------        // ----------------------------------------------------------------------------------------        boolean     changed      =  false;        boolean     out          =  true;        Integer     sourcePageID =  null;        Integer     pageLinkID   =  null;        String      operation    =  "";        String      pageTitle    =  "";        String      remoteUrl    =  "";        int         templateID   =  -1;        int         remotePageID =  0;        int         choiceID     =  0;        int         movedPageID  =  0;        JahiaPageEngineTempBean thePage     = null;        HashMap     subEngineMap = (HashMap) jParams.getRequest().getSession()                                             .getAttribute("org.jahia.engines.CopyTree_Engine.engineMap");        if(subEngineMap != null) {            sourcePageID =  (Integer)subEngineMap.get(CopyTree_Engine.SOURCEPAGE_ID);            operation    =  (String )subEngineMap.get("operation");            if( (operation.equals("link")) && (sourcePageID != null) ) {                remotePageID = sourcePageID.intValue();                changed = true;            }        }        // compose page object        thePage = composePage( jParams, engineMap, theField );        // ----------------------------------------------------------------------------------------        // STEP 2 : Get form & pop-up data --------------------------------------------------------        // ----------------------------------------------------------------------------------------        String submitted =  jParams.getRequest().getParameter( "page_field_submitted" );        String reload    =  jParams.getRequest().getParameter( "reload" );        // checks if we are getting POST data and we are not reloading from the tree pop-up        if ((submitted != null)&&(reload == null)) {            changed = true;            // if yes, gets all the form field values in string format            pageTitle               =  jParams.getRequest().getParameter( "page_title" );            String choiceIDStr      =  jParams.getRequest().getParameter( "choice" );            JahiaConsole.println(CLASS_NAME + ".getFormData", "Choice: " + choiceIDStr);            String templateIDStr    =  jParams.getRequest().getParameter( "template_id" );            //toDebug("################ page field :: template: "+templateIDStr);            String pageLinkIDStr    =  jParams.getRequest().getParameter( "pagelinkid" );            remoteUrl               =  jParams.getRequest().getParameter( "remote_url" );            //if ( (remoteUrl == null) || (remoteUrl.trim().equals("")) || (remoteUrl.trim().equals("http://")) )            //{             //   remoteUrl = "http://www";            //}            // transform string vars in int            if( (choiceIDStr != null) && (templateIDStr != null) && (!choiceIDStr.equals("")) && (!templateIDStr.equals("")) ) {                try {                    choiceID            =  Integer.parseInt( choiceIDStr );                    templateID          =  Integer.parseInt( templateIDStr );                } catch (NumberFormatException nfe) {                    ;                }            } else {            // no value in choiceID or templateID...                changed = false;            }            if(pageLinkIDStr != null) {                try {                    pageLinkID      =  new Integer( pageLinkIDStr );                } catch (NumberFormatException nfe) {                    ;                }            }            if( (pageTitle != null) && (!pageTitle.trim().equals("")) ) {                thePage.setTitle( pageTitle );                engineMap.put("pageTitle"+ theField.getDefinition().getName(), pageTitle);                //System.out.println("##### pageTitle1: "+pageTitle);            }            engineMap.put("operation", operation);        } else if (reload != null) {            // if no form data is received, check if the pop-up launched for target page id            // has been launched            subEngineMap = (HashMap) jParams.getRequest().getSession()                                             .getAttribute("org.jahia.engines.CopyTree_Engine.engineMap");            if (subEngineMap != null) {                if(subEngineMap.get(CopyTree_Engine.SOURCEPAGE_ID) != null) {                    remotePageID         =  ((Integer)subEngineMap.get(CopyTree_Engine.SOURCEPAGE_ID)).intValue();                    JahiaPage remotePage =  ServicesRegistry.getInstance().getJahiaPageService().lookupPage(remotePageID);                    pageTitle            =  remotePage.getTitle();

⌨️ 快捷键说明

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