📄 jahiafieldbaseservice.java
字号:
JahiaFieldSet theSet = new JahiaFieldSet( jData ); for (int i=0; i < fieldIDs.size(); i++) { fieldID = (Integer) fieldIDs.elementAt(i); // is the 1st field already loaded in cache? if no we load ALL the fields // from the page... (not a perfect way to check if we need to!) if ((i==0) && (cacheFields.getValue(fieldIDs.elementAt(i))==null)) { Vector allFields = fieldsDB.db_load_all_fields_info_from_page(jData.params().getPage().getID()); for (int j=0; j<allFields.size(); j++) { JahiaField theNewField = (JahiaField)allFields.elementAt(j); cacheFields.setValue (theNewField, new Integer(theNewField.getID())); } } theField = loadField( fieldID.intValue(), jData.params() ); theSet.addField( (JahiaField) theField ); } return theSet; } // buildFieldStructureForPage /*** * Gets all field list IDs in a page (from page ID) * * @param pageID the page ID * @return a Vector of Field list IDs * */ public Vector getFieldIDsInPage( int pageID ) throws JahiaException { return f_utils.db_get_field_ids_in_page( pageID ); } // getFieldListIDsInPage /*** * Given a page ID, get all the IDs of the page links contained in * the page, whether of type DIRECT, INTERNAL or URL * * @param pageID the page ID * @return a Vector of Field list IDs * */ public Vector getPagefieldIDsInPage( int pageID ) throws JahiaException { return f_utils.db_get_pagefield_ids_in_page( pageID ); } // getPagefieldIDsInPage /*** * Gets a field ID from its name and page id * * @param fieldName the field name * @param pageID the page ID * @return a field id * */ public int getFieldID( String fieldName, int pageID ) throws JahiaException { return f_utils.db_get_field_id( fieldName, pageID ); } // getFieldListIDsInPage /*** * Get all the fields ID for a gived site (for the search engine) * * @param int the site id * @return a Vector of field ids * */ public Vector getAllFieldIDs(int siteID) throws JahiaException{ return f_utils.db_get_all_fields_id(siteID); } /*** * Get all the fields ID (for the search engine) * * @return a Vector of field ids * */ public Vector getAllFieldIDs() throws JahiaException { return f_utils.db_get_all_fields_id(); } // getAllFieldIDs /** * gets all the field definition ids * to be changed, using a fielddefinition cache instead and changing the def registry. * * @return a Vector of field definition ids * */ public Vector getAllFieldDefinitionIDs() throws JahiaException { return f_utils.db_get_all_field_definition_ids(); } // getAllFieldDefinitionIDs /*** * loads a field from the database, no other info than what's in the database * NO RIGHTS CHECKS! use another loadField method (with jParams) for that. * * @param fieldID the field ID * @return a JahiaField object * @see org.jahia.data.fields.JahiaField * */ public JahiaField loadField( int fieldID ) throws JahiaException { JahiaField theField = (JahiaField) cacheFields.getValue (new Integer(fieldID)); // not already in cache -> we must load it if (theField == null) { theField = fieldsDB.db_load_field( fieldID ); if (theField != null) { cacheFields.setValue (theField, new Integer(fieldID)); } else { throw new JahiaException ("Error loading field data", "Error loading field with ID " + Integer.toString(fieldID), JahiaException.DATABASE_ERROR, JahiaException.ERROR); } } return (JahiaField)theField.clone(); } // loadField /*** * loads a field from the database, according to the loadflags * NO RIGHTS CHECKS! use another loadField method (with jParams) for that. * * @param fieldID the field ID * @param loadFlag the load flags * @return a JahiaField object * @see org.jahia.data.fields.JahiaField * @see org.jahia.data.fields.LoadFlags * */ public JahiaField loadField( int fieldID, int loadFlag ) throws JahiaException { return loadField (fieldID, loadFlag, null); } // end loadField /*** * loads a field from the database, with all values * * @param fieldID the field ID * @param jParams the ParamBean object with request and response * @return a JahiaField object * @see org.jahia.data.fields.JahiaField * @see org.jahia.data.fields.LoadFlags * */ public JahiaField loadField( int fieldID, ParamBean jParams ) throws JahiaException { return loadField (fieldID, LoadFlags.ALL, jParams); } // loadField /*** * loads a field, and accept loadFlag and ParamBean <br> * uses loadField ( int fieldID ) method to access cache/database * * @param fieldID the field ID * @param loadFlag the load flags * @param jParam ParamBean * @return a JahiaField object */ // DJ 28.01.2001 added ACL support public JahiaField loadField( int fieldID, int loadFlag, ParamBean jParams ) throws JahiaException { JahiaField theField = loadField (fieldID); //toDebug("######## begin loadField fieldValue: "+theField.getValue()+"#########"); String fieldValue; // check fields ACL if (jParams == null) { // System.out.println ("loadField(" + theField.getDefinition().getName() + "): can't check ACL, method called without ParamBean"); } else { JahiaUser currentUser = jParams.getUser(); if (currentUser != null) { // System("loadField(" + theField.getDefinition().getName() + "): checking rights..."); // if the user has no read rights, return the field with an empty value. if (!theField.checkReadAccess (currentUser,jParams.getSiteID())) { //System.out.println ("loadField(" + theField.getDefinition().getName() + "): NO read rights! -> return an empty field"); if (theField.getValue().toUpperCase().indexOf("JAHIA_LINKONLY") == -1) { theField.setValue(""); // return an empty field } return theField; } // System.out.println ("loadField(" + theField.getDefinition().getName() + "): read rights OK"); } else { throw new JahiaException ("No user present !", "No current user defined in the params in loadField() method.", JahiaException.USER_ERROR, JahiaException.ERROR); } } // we get the field definition JahiaFieldDefinition theDef = JahiaFieldDefinitionsRegistry.getInstance( ).getDefinition( theField.getFieldDefID() ); int pageDefID = ServicesRegistry.getInstance().getJahiaPageService().lookupPage (theField.getPageID(), jParams).getPageTemplateID(); int fieldType = (theDef.getType(pageDefID) != FieldTypes.UNDEFINED) ? theDef.getType(pageDefID) : theField.getType(); // now we compose the content of fieldValue, depending of the field type and the loadFlag theField.load(loadFlag, jParams); if (theField.getValue().equals("<empty>")) { theField.setValue( "" ); } return theField; } // loadField /*** * saves a field if the user has the correct rights. * Check user's rights * * @param theField the JahiaField to save * @param parentAclID the Acl parent ID (or 0 to keep existing parent ACL ID) * @param jParam ParamBean * */ public void saveField( JahiaField theField, int parentAclID, ParamBean jParams ) throws JahiaException { String createField = ""; if (theField.getObject() instanceof String) { createField = (String)theField.getObject(); } // Check the ACL. if (jParams != null) { JahiaUser currentUser = jParams.getUser(); if (currentUser != null) { toDebug ("saveField(): checking rights..."); // if the user has no write rights, exit. // if fieldID = 0 then let's say the user can write (add) if ((!theField.checkWriteAccess (currentUser,jParams.getSiteID())) && (theField.getID()!=0)) { if ( createField.equals("createFieldWithCurrentID") ) { toDebug ("saveField(): write rights OK"); } else { toDebug ("saveField(): NO write right"); return; } } toDebug ("saveField(): write rights OK"); } else { throw new JahiaException ("No user present !", "No current user defined in the params in saveField() method.", JahiaException.USER_ERROR, JahiaException.ERROR); } } int savemode = 1; // 0 = create, 1 = update if ( createField.equals("createFieldWithCurrentID") ) { //toDebug("########### createFieldWithcurrentID- set savemode"); theField.setObject(null); // the fielID is given in theField, because we want to re-create the field savemode = 0; } if (theField.getID() == 0) { // gets the field id int theFieldID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement( "jahia_fields_data" ); theField.setID( theFieldID ); savemode = 0; // } int pageDefID = ServicesRegistry.getInstance().getJahiaPageService(). lookupPage (theField.getPageID(), null).getPageTemplateID(); String errorMsg = ""; if (theField.getDefinition().getName().equals("")) { errorMsg = "Error in FieldBaseService : field name value is an empty string"; } if (theField.getDefinition().getTitle(pageDefID).equals("")) { errorMsg = "Error in FieldBaseService : field title value is an empty string"; } if ( (theField.getValue() != null) && theField.getValue().equals("") ) { theField.setValue( "<empty>" ); } if (errorMsg != "") { //JahiaConsole.println( "JahiaFieldsDB", errorMsg ); throw new JahiaException( "Cannot update fields in the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } // determines field type int fieldType = theField.getDefinition().getType(pageDefID); if (fieldType == FieldTypes.UNDEFINED) { fieldType = theField.getType(); } // sets field value in tmpVal String tmpVal = ""; if (fieldType == FieldTypes.BIGTEXT) { tmpVal = "<text>"; } else if ( theField.getValue() != null ){ tmpVal = theField.getValue(); } // creates ACL, if needed if (theField.getAclID() == 0) { JahiaBaseACL acl = new JahiaBaseACL (); if (acl != null) { // create a new object by specifying the parent ACL ID (a container) if (!acl.create (parentAclID)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -