📄 jahiapagefield.java
字号:
// JahiaPageField// YG 17.07.2001package org.jahia.data.fields;import java.util.*; // Vector, Calendarimport org.jahia.utils.*;import org.jahia.data.*;import org.jahia.services.pages.*;import org.jahia.params.*; // ParamBeanimport org.jahia.registries.*; // Registriesimport org.jahia.exceptions.JahiaException;import org.jahia.registries.*; // Registriesimport org.jahia.content.PageXRefManager;public class JahiaPageField extends JahiaField{ /*** * constructor * YG 17.07.2001 * */ public JahiaPageField( Integer ID, Integer jahiaID, Integer pageID, Integer ctnid, Integer fieldDefID, Integer fieldType, Integer connectType, String fieldValue, Integer rank, Integer aclID ) { super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType, fieldValue, rank, aclID); } // end constructor public void load(int loadFlag, ParamBean jParams) throws JahiaException { if ((loadFlag & LoadFlags.PAGE) != 0) { int pageID = 0; if (!this.getValue().equals("<NoPage>")) { try { pageID = Integer.parseInt( this.getValue() ); } catch (NumberFormatException nfe) { pageID = 0; } if (pageID != 0) { JahiaPage thePage = null; try { thePage = ServicesRegistry.getInstance(). getJahiaPageService().lookupPage (pageID, jParams); } catch ( JahiaException je ){ // an unexpected error occured with requested page String msg = "An exception occured with requested pageid=" + pageID + "\n" + je.getMessage(); thePage = null; } this.setObject (thePage); if (thePage != null) { // now let's update the xref manager from this page field to // the actual page (actually the call uses the reverse order // for parameter call) if ( PageXRefManager.getInstance() != null ){ //JahiaConsole.println("PageXRefManager","PageXRefManager instance is not null "); if ( jParams != null ){ PageXRefManager.getInstance().setPageID(jParams.getSiteKey(), thePage.getID(), jParams.getPageID()); } } else { JahiaConsole.println("PageXRefManager","PageXRefManager instance is null "); } switch (thePage.getPageType ()) { case JahiaPage.TYPE_DIRECT : // MJ 01.04.2001 if (jParams == null) { //this.setObject( null ); //if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) //{ // this.setValue( ""); //} break; } if (thePage.checkReadAccess (jParams.getUser())) { // check if the page definition of this page is visible or not // if not deactivate the page ! JahiaPageDefinition def = thePage.getPageTemplate (); if (def != null) { //if ((def != null) && (def.isVisible())) { this.setValue (thePage.getUrl()); } else { this.setObject( null ); if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue( ""); } } } else { this.setObject( null ); if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue( ""); } } break; case JahiaPage.TYPE_LINK : JahiaPage tempPage = ServicesRegistry.getInstance(). getJahiaPageService().lookupPage (thePage. getPageLinkID(), jParams); if ((tempPage != null) && (jParams != null) && (jParams.getUser() != null)) { // no it's not, let's return null. if (!tempPage.checkReadAccess (jParams.getUser())) { this.setObject (null); if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue (""); } } } else { //this.setObject (null); //if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) //{ // this.setValue (""); //} } break; } } else { if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue (""); } } } else { if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue (""); } } } else { if (this.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { this.setValue (""); } } } //System.out.println("######## end loadField fieldValue: "+this.getValue()+"#########"); } public void save(ParamBean jParams) throws JahiaException { String tmpVal = this.getValue(); if (!tmpVal.equals("<empty>")) { int pageID = -1; try { pageID = Integer.parseInt( tmpVal ); } catch (NumberFormatException nfe) { pageID = -1; } if (pageID != -1) { // checks to see if the page already exists JahiaPage thePage = (JahiaPage) this.getObject(); if (thePage != null) { thePage.commitChanges(true); //ServicesRegistry.getInstance(). // getJahiaPageService().savePageInfo( thePage ); this.setValue( Integer.toString(thePage.getID()) ); tmpVal = Integer.toString( thePage.getID() ); // Very useful !??? } else { this.setValue( "" ); tmpVal = "<No Page>"; // Very useful !??? } } } else { tmpVal = "<No Page>"; // Very useful !??? } } public void delete(ParamBean jParams) throws JahiaException { try { int pageID = Integer.parseInt( this.getValue() ); JahiaPage thePage = ServicesRegistry.getInstance(). getJahiaPageService().lookupPage (pageID, null); if (thePage != null) { ServicesRegistry.getInstance().getJahiaPageService(). deletePage (thePage, jParams); } } catch (NumberFormatException nfe) { // do nothin' } } /** * Returns an hashtable of indexable attributes , pairs [attribute name/value]. * Returned pairs: * none * * @return Hashtable a map of indexable attributes , pairs [attribute name/value] */ public Hashtable getIndexableAttributes(){ Hashtable hash = new Hashtable(); return hash; } public String getEngineName() { return "org.jahia.engines.shared.Page_Field"; } public String getFieldContent4Ranking() { String fieldInfo = ""; JahiaPage page = (JahiaPage)this.getObject(); if (page != null) { fieldInfo = page.getTitle(); } else { fieldInfo = this.getValue(); } return fieldInfo; } public String getIconNameOff() { return "page"; } public String getIconNameOn() { return "page_on"; } public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned) throws JahiaException { JahiaPage thePage = null; try { thePage = (JahiaPage) this.getObject(); } catch ( Throwable t ) { t.printStackTrace(); } if (thePage != null) { this.setValue( Integer.toString(thePage.getID()) ); } //System.out.println(" value set: " + this.getValue()); JahiaPage clonedPage = null; JahiaField clonedField = null; if ((thePage != null) && (thePage.getPageType() == JahiaPage.TYPE_URL | thePage.getPageType() == JahiaPage.TYPE_LINK)) { clonedPage = ServicesRegistry.getInstance().getJahiaPageService(). createPage(thePage.getJahiaID(), newPageID, thePage.getPageType(), thePage.getTitle(), thePage.getPageTemplateID(), thePage.getRemoteURL(), thePage.getPageLinkID(), thePage.getCreator(), clonedAclID, null); clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). createJahiaField(0, this.getJahiaID(), newPageID, newctnid, this.getFieldDefID(), this.getType(), this.getConnectType(), (new Integer(clonedPage.getID())).toString(), this.getRank(), clonedAclID ); clonedField.setObject( clonedPage ); } else { if (!childrenCloned) { this.setValue(""); } clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). createJahiaField(0, this.getJahiaID(), newPageID, newctnid, this.getFieldDefID(), this.getType(), this.getConnectType(), this.getValue(), this.getRank(), clonedAclID ); clonedField.setObject( this.getObject() ); } //toDebug("cloneField(): value = "+this.getValue()); if (clonedField == null) { throw new JahiaException ("Could not clone field.", "Could not instanciate a new JahiaField object.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } clonedField.setRawValue(this.getRawValue()); clonedField.setProperties( (Hashtable)(this.getProperties()).clone() ); return clonedField; } public Object clone() { Object objItem = this.getObject(); JahiaPageField pf = new JahiaPageField (new Integer(ID), new Integer(jahiaID), new Integer(pageID), new Integer(ctnid), new Integer(fieldDefID), new Integer(fieldType), new Integer(connectType), fieldValue, new Integer(rank), new Integer(aclID) ); pf.setObject(objItem); return pf; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -