📄 page_field.java
字号:
} thePage.commitChanges (true); break; case JahiaPage.TYPE_LINK : if (engineMap.get("createPage_" + theField.getDefinition().getName()) != null) { JahiaBaseACL fieldAcl3 = new JahiaBaseACL(theField.getAclID()); ServicesRegistry.getInstance().getJahiaFieldService().deleteField(theField.getID(), jParams); theField.setValue("<jahia_linkonly>"); theField.setAclID(0); theField.setObject("createFieldWithCurrentID"); ServicesRegistry.getInstance().getJahiaFieldService().saveField(theField,fieldAcl3.getParentID(),jParams); thePage = ServicesRegistry.getInstance().getJahiaPageService(). createPage (pageBean.getSiteID(), pageBean.getParentID(), pageBean.getPageType(), pageBean.getTitle(), pageBean.getPageTemplateID(), pageBean.getRemoteURL(), pageBean.getPageLinkID(), pageBean.getCreator(), theField.getAclID(), jParams); } else { thePage.setPageLinkID (pageBean.getPageLinkID()); } break; case JahiaPage.TYPE_URL : if (engineMap.get("createPage_" + theField.getDefinition().getName()) != null) { JahiaBaseACL fieldAcl3 = new JahiaBaseACL(theField.getAclID()); ServicesRegistry.getInstance().getJahiaFieldService().deleteField(theField.getID(), jParams); theField.setValue("<jahia_linkonly>"); theField.setAclID(0); theField.setObject("createFieldWithCurrentID"); ServicesRegistry.getInstance().getJahiaFieldService().saveField(theField,fieldAcl3.getParentID(),jParams); thePage = ServicesRegistry.getInstance().getJahiaPageService(). createPage (pageBean.getSiteID(), pageBean.getParentID(), pageBean.getPageType(), pageBean.getTitle(), pageBean.getPageTemplateID(), pageBean.getRemoteURL(), pageBean.getPageLinkID(), pageBean.getCreator(), theField.getAclID(), jParams); } else { thePage.setRemoteURL (pageBean.getRemoteURL()); } break; } //thePage.commitChanges (); } if (thePage != null) { if (engineMap.get("createPage_" + theField.getDefinition().getName()) != null) { //toDebug("########### title:#"+thePage.getTitle().trim()+"#length: "+thePage.getTitle().trim().length()); if (thePage.getTitle().trim().equals("") ) { thePage.setTitle( "Undefined Page " + nextUndefined() ); } theField.setValue( Integer.toString(thePage.getID()) ); //toDebug("####### save field "+theField.getDefinition().getName()+" - set fieldvalue to: "+thePage.getID()); // 0 for parentAclID in saveField, because field already exists // -> field already has an aclID // -> no need to create a new one ServicesRegistry.getInstance().getJahiaFieldService().saveField( theField, 0, jParams ); //System.out.println("%%%%%% fieldValue saved: "+theField.getValue()); //toDebug("############# Page_Field :: flagsave : "+ flagsave); if (!flagsave) { //toDebug("############# Page_Field :: delete field content : "); JahiaBaseACL fieldAcl = new JahiaBaseACL(theField.getAclID()); ServicesRegistry.getInstance().getJahiaFieldService().deleteField(theField.getID(), jParams); theField.setValue("<jahia_linkonly>"); theField.setAclID(0); theField.setObject("createFieldWithCurrentID"); ServicesRegistry.getInstance().getJahiaFieldService().saveField(theField,fieldAcl.getParentID(),jParams); } } return true; } else { return false; } } else { JahiaException je =new JahiaException( "Can't find edited page info", "Can't find edited page info", JahiaException.DATA_ERROR, JahiaException.ERROR ); return false; } } // end else } // end saveData /*** * composes page object * * @param jParams a ParamBean object * @param engineMap the engine hashmap * @param theField the field we are working on * @return the page object * */ private JahiaPageEngineTempBean composePage( ParamBean jParams, HashMap engineMap, JahiaField theField ) throws JahiaException { JahiaPageEngineTempBean thePage = null; // this is for creating a NEW page... boolean gotvalidbean = false; if (theField.getObject() instanceof String) { String testString = (String) theField.getObject(); if( testString.equals("new page") ) { gotvalidbean = true; } } //if the field has already been updated, keep the current PageBean if ( (engineMap.get("updateField" + theField.getDefinition().getName()) != null) && (engineMap.get("updateField" + theField.getDefinition().getName()).equals("true")) ) { gotvalidbean = true; } // We're NOT updating an existing Page, and we have NOT created a Bean yet... if(theField.getObject() == null) { JahiaConsole.println(CLASS_NAME + ".composePage", "NEW PageBean...(theField.getObject() was null)"); thePage = new JahiaPageEngineTempBean ( theField.getJahiaID(), theField.getPageID(), JahiaPage.TYPE_DIRECT, "", // no title 0, // page template 0 ..... THIS IS A BIG HACK ... A BUG !!!!!! null, // direct link ... so no remote URL needed. -1, // direct link ... so no link ID needed. jParams.getUser().getName(), theField.getID() ); // we should be creating a new field here, // so value should be -1 ... !!; engineMap.put( "isDirectLink", Boolean.FALSE ); engineMap.put( "isNewPage", Boolean.TRUE ); } // We've got something in theField.object ! it's either a REAL page, or an earmark else { // It's not an earmark... it's a REAL Page ! if(!gotvalidbean) { // CALL A REAL PAGE HERE.... thePage = loadPageBeanFromRealPage( theField ); //toDebug("########## Load page from DB"); } // It's an earmark... we should look for a Bean to load else { JahiaPageEngineTempBean theBean = (JahiaPageEngineTempBean)jParams.getRequest().getSession().getAttribute("PageBean"+ theField.getDefinition().getName()); try { // The Bean belongs to the Field... okay to load it ! if (theBean.getLinkFieldID() == theField.getID()) { JahiaConsole.println(CLASS_NAME + ".composePage", "Retrieving EXISTING Bean..."); // aleady loaded... thePage = theBean; StringBuffer pageAttribute = new StringBuffer(" siteID : ["+thePage.getSiteID()+"]\n"); pageAttribute.append(" parentID : ["+thePage.getParentID()+"]\n"); pageAttribute.append(" pageType : ["+thePage.getPageType()+"]\n"); pageAttribute.append(" title : ["+thePage.getTitle()+"]\n"); pageAttribute.append(" pageTemplateID: ["+thePage.getPageTemplateID()+"]\n"); pageAttribute.append(" remoteURL : ["+thePage.getRemoteURL()+"]\n"); pageAttribute.append(" pageLinkID : ["+thePage.getPageLinkID()+"]\n"); pageAttribute.append(" creator : ["+thePage.getCreator()+"]\n"); pageAttribute.append(" linkFieldID : ["+thePage.getLinkFieldID()+"]\n"); JahiaConsole.println(CLASS_NAME + ".composePage", pageAttribute.toString()); // The Bean does NOT belong to the Field... } else { // CALL A REAL PAGE HERE.... thePage = loadPageBeanFromRealPage( theField ); } } catch (Exception e) { // CALL A REAL PAGE HERE.... thePage = loadPageBeanFromRealPage( theField ); } } // now the bean has been populated with info from an existing page, // or retrieved with the result of some previous input. // set the flag for complete or partial JSP display if (engineMap.get("isDirectLink") == null) { if (thePage.getPageType() == JahiaPage.TYPE_DIRECT) { engineMap.put( "isDirectLink", Boolean.TRUE ); } else { engineMap.put( "isDirectLink", Boolean.FALSE ); } } if(gotvalidbean) { JahiaConsole.println(CLASS_NAME + ".composePage", "gotvalidbean is true"); if ( (engineMap.get("updateField" + theField.getDefinition().getName()) != null) && (engineMap.get("updateField" + theField.getDefinition().getName()).equals("true")) ) { toDebug(">> isNewPage set to false"); engineMap.put( "isNewPage", Boolean.FALSE ); } else { toDebug(">> isNewPage set to true"); engineMap.put( "isNewPage", Boolean.TRUE ); } } else { JahiaConsole.println(CLASS_NAME + ".composePage", "gotvalidbean is false"); engineMap.put( "isNewPage", Boolean.FALSE ); } } // check for page temporary changes JahiaConsole.println(CLASS_NAME+".composePage","Check page temporary changes"); HashMap subEngineMap = (HashMap) jParams.getRequest().getSession() .getAttribute("org.jahia.engines.CopyTree_Engine.engineMap"); if(subEngineMap != null) { JahiaConsole.println(CLASS_NAME+".composePage","CopyTree subengine found"); Integer sourcePageID = (Integer)subEngineMap.get(CopyTree_Engine.SOURCEPAGE_ID); int remotePageID = -1; String operation = (String)subEngineMap.get("operation"); if( (operation.equals("link")) && (sourcePageID != null) ) { remotePageID = sourcePageID.intValue(); } JahiaConsole.println(CLASS_NAME+".composePage","remotepageid " + remotePageID); if ( remotePageID != -1 && remotePageID != thePage.getPageLinkID() ) { JahiaPage linkPage = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(remotePageID); if ( linkPage != null ){ thePage.setTitle( linkPage.getTitle() ); } } } // for internal engine use jParams.getRequest().getSession().setAttribute( "PageBean"+ theField.getDefinition().getName(), thePage ); // for jsp jParams.getRequest().setAttribute( "PageBean"+ theField.getDefinition().getName(), thePage ); return thePage; } // end composePage /*** * loads the page cache bean with info from an existing JahiaPage * * @param theField the Field Object we're working on * @return a PageBean to use as cache for the page info * */ private JahiaPageEngineTempBean loadPageBeanFromRealPage( JahiaField theField ) { // not loaded yet... JahiaPage theRealPage = (JahiaPage)theField.getObject(); JahiaConsole.println(CLASS_NAME + ".loadPageBeanFromRealPage", "Making PageBean from REAL Page..."); StringBuffer pageAttribute = new StringBuffer(" jahiaID : ["+theRealPage.getJahiaID()+"]\n"); pageAttribute.append(" parentID : ["+theRealPage.getParentID()+"]\n"); pageAttribute.append(" pageType : ["+theRealPage.getPageType()+"]\n"); pageAttribute.append(" title : ["+theRealPage.getTitle()+"]\n"); pageAttribute.append(" pageTemplateID: ["+theRealPage.getPageTemplateID()+"]\n"); pageAttribute.append(" remoteURL : ["+theRealPage.getRemoteURL()+"]\n"); pageAttribute.append(" pageLinkID : ["+theRealPage.getPageLinkID()+"]\n"); pageAttribute.append(" creator : ["+theRealPage.getCreator()+"]\n"); pageAttribute.append(" linkFieldID : ["+theField.getID()+"]\n"); JahiaConsole.println(CLASS_NAME + ".loadPageBeanFromRealPage", pageAttribute.toString()); JahiaPageEngineTempBean thePage = new JahiaPageEngineTempBean ( theRealPage.getJahiaID(), theRealPage.getParentID(), theRealPage.getPageType(), theRealPage.getTitle(), theRealPage.getPageTemplateID(), theRealPage.getRemoteURL(), theRealPage.getPageLinkID(), theRealPage.getCreator(), theField.getID() ); return thePage; } // end loadPageBeanFromRealPage() /*** * returns next undefined page number * */ private static int nextUndefined() { staticUndefined++; return staticUndefined; } // end nextUndefined //------------------------------------------------------------------------- private synchronized void toDebug (String message) { if (true) { JahiaConsole.println ("Page_Field", message); } }} // end Page_Field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -