📄 jahiafieldbaseservice.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// JahiaFieldBaseService// EV 31.10.2000// DJ 05.01.2001 Changed almost everything// EV 08.01.2001 Cleaned up all this mess ;)//package org.jahia.services.fields;import java.util.*; // Vectorimport java.lang.reflect.*; // Constructor, Classimport java.io.*;import java.sql.*;import org.jahia.exceptions.JahiaException;import org.jahia.bin.*; // Jahiaimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.params.*; // ParamBeanimport org.jahia.data.*; // JahiaDataimport org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.data.applications.*; // ApplicationBeanimport org.jahia.data.fields.*; // JahiaField, FieldTypesimport org.jahia.data.containers.*; // JahiaContainerimport org.jahia.data.files.*; // JahiaFile,JahiaFileFieldimport org.jahia.data.cache.*; // JahiaCacheimport org.jahia.data.events.*; // JahiaEventimport org.jahia.engines.filemanager.*; // Filemanager_Engineimport org.jahia.services.cache.*; // JahiaCacheFactoryimport org.jahia.services.fields.*; // JahiaFieldsDBimport org.jahia.services.filemanager.*; // Filemanager, Folderimport org.jahia.services.containers.*; // JahiaContainerServiceimport org.jahia.settings.*; // SettingsBeanimport org.jahia.sharing.*; // JahiaDataSourceManagerimport org.jahia.services.files.*; // Jahia Files Servicesimport org.jahia.services.applications.*; // Jahia Applications Serviceimport org.jahia.services.search.*; // Jahia Search Engineimport org.jahia.services.usermanager.JahiaUser; // JahiaUserimport org.jahia.params.*; // ParamBeanimport org.jahia.services.acl.JahiaBaseACL;import org.jahia.services.acl.ACLNotFoundException;import org.apache.regexp.*; // Regular Expressionimport org.jahia.utils.properties.*; // PropertiesManagerimport org.jahia.data.JahiaDOMObject;public class JahiaFieldBaseService extends JahiaFieldService { private static String serviceName; private static JahiaFieldBaseService m_Instance = null; private static SettingsBean jSettings; private JahiaFieldsDB fieldsDB; private JahiaFieldDefinitionsDB f_defs; private JahiaFieldUtilsDB f_utils; private String jahiaVarDiskPath; private Hashtable fieldClassNames; private static int MAX_CACHED_OBJECTS = 20000; private static JahiaSimpleCache cacheFields; /*** * constructor * */ protected JahiaFieldBaseService() { JahiaConsole.println( "JahiaFieldBaseService", "***** Starting up the Field Services *****" ); } // end constructor /*** * Return an instance of this class * */ public static synchronized JahiaFieldBaseService getInstance(){ if ( m_Instance == null ) { m_Instance = new JahiaFieldBaseService(); } return m_Instance; } // end getInstance /*** * inits the service cache and settings * * @param jSettings Settings to let the sevice where to save files, i.e. * */ public void init( JahiaPrivateSettings jSettings ) { this.jSettings = new SettingsBean( jSettings ); fieldsDB = new JahiaFieldsDB( this.jSettings ); f_defs = new JahiaFieldDefinitionsDB(); f_utils = new JahiaFieldUtilsDB(); jahiaVarDiskPath = jSettings.jahiaVarDiskPath; // get the hashtable which give the class name // which correspond to the field type. fieldClassNames = FieldTypes.getInstance().getFieldClassNames(); cacheFields = JahiaCacheFactory.getInstance().createJahiaSimpleCache("FieldCache", "Caches the JahiaFields as they are stored in the DB", MAX_CACHED_OBJECTS); createFileDefinitionRepository(); } // end init//--------------------------------------------------------------------------------------- /** * create a JahiaField. * The only method to instanciate a new JahiaField * It call the constructor corresponding to the field type. * This method must NOT be called directly, * but only by JahiaFieldSet.declareField() * and JahiaFieldDB.db_load_field(). */ public JahiaField createJahiaField(int ID, int jahiaID, int pageID, int ctnid, int fieldDefID, int fieldType, int connectType, String fieldValue, int rank, int aclID ) throws JahiaException { JahiaField theField; try { // define the types of the parameter of the constructor Class theParams[] = {Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer"), Class.forName("java.lang.String"), Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer")}; toDebug( "createJahiaField - fieldType: "+fieldType+" classe: " +fieldClassNames.get(new Integer(fieldType)) ); // get the constructor by its name // the name come from the hashtable Constructor thisConstructor = Class.forName((String)fieldClassNames. get(new Integer(fieldType))). getDeclaredConstructor(theParams); // the parameter values of the constructor Object args[] = {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)}; // call the constructor theField = (JahiaField)thisConstructor.newInstance(args); } catch(ClassNotFoundException cnfe) { toDebug("createJahiaField: (class nf) "+cnfe.toString()); throw new JahiaException ("JahiaFieldBaseService:createJahiaField", "Class not found!", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } catch(NoSuchMethodException nsme) { toDebug("createJahiaField: (method nf) "+nsme.toString()); throw new JahiaException ("JahiaFieldBaseService:createJahiaField", "Method not found!", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } catch(IllegalAccessException iae) { toDebug("createJahiaField: (illegal access) "+iae.toString()); throw new JahiaException ("JahiaFieldBaseService:createJahiaField", "Illegal access", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } catch(InvocationTargetException ite) { toDebug("createJahiaField: (invocation) "+ ite.toString()); throw new JahiaException ("JahiaFieldBaseService:createJahiaField", "InvocationTarget exception", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } catch(InstantiationException ie) { toDebug("createJahiaField: (instantiation) "+ie.toString()); throw new JahiaException ("JahiaFieldBaseService:createJahiaField", "Instantiation exception", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } // return the new JahiaField return theField; } /** * clone page field * * @param fieldID the field to clone. * @param newPageID The Id of the new page to which the cloned field must * belong to. */ public synchronized void cloneField (int fieldID, int newPageID, int parentAclID) throws JahiaException { // get the field object JahiaField theField = loadField(fieldID); // clone field JahiaField clonedField = cloneField(theField, 0, newPageID, parentAclID, false); } /** * clone page field * * @param fieldID the field to clone. * @param newctnid the id of the container which contains the field * equal 0 if the field is in a page. * @param newPageID The Id of the new page to which the cloned field must * belong to. */ public synchronized JahiaField cloneField (JahiaField theField, int newctnid, int newPageID, int parentAclID, boolean childrenCloned) throws JahiaException { // get the field object toDebug ("cloneField(): begin"); theField = loadField(theField.getID(), LoadFlags.ALL, null); if (theField == null) { throw new JahiaException ("Could not clone field.", "Could not get the JahiaField object.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } //cloneACl int aclID = theField.getAclID(); JahiaBaseACL aclObj = new JahiaBaseACL(aclID); if (aclObj == null) { throw new JahiaException ("Could not clone container.", "Could not get JahiaBaseACL object.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } JahiaBaseACL clonedACL = (JahiaBaseACL)aclObj.clone(); if (clonedACL == null) { throw new JahiaException ("Could not clone container.", "Could not clone acl.", JahiaException.PAGE_ERROR, JahiaException.CRITICAL); } clonedACL.setParentID(parentAclID); // clone field //JahiaField clonedField = new JahiaField(0, theField.getJahiaID(), newPageID, newctnid, // theField.getFieldDefID(), theField.getType(), // theField.getConnectType(), theField.getValue(), // theField.getRank(), clonedACL.getID() ); JahiaField clonedField = null; clonedField = theField.cloneField(newctnid, newPageID, clonedACL.getID(), childrenCloned); /* if (theField.getType() == FieldTypes.DATE) { clonedField = theField.cloneField(newctnid, newPageID, clonedACL.getID()); } else { clonedField = createJahiaField(0, theField.getJahiaID(), newPageID, newctnid, theField.getFieldDefID(), theField.getType(), theField.getConnectType(), theField.getValue(), theField.getRank(), clonedACL.getID() ); toDebug("cloneField(): value = "+theField.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(theField.getRawValue()); clonedField.setObject( theField.getObject() ); clonedField.setProperties( (Hashtable)(theField.getProperties()).clone() ); } */ // saves field toDebug ("cloneField(): call saveField"); //System.out.println("value cloned: "+ clonedField.getValue()); saveField( clonedField, parentAclID, null ); return clonedField; } /*** * Builds the field structure for the specified page * * @param jData JahiaData * @return a JahiaFieldSet object * */ public JahiaFieldSet buildFieldStructureForPage( JahiaData jData ) throws JahiaException { JahiaField theField; Integer fieldID; // loads all the fields of the page Vector fieldIDs = getFieldIDsInPage( jData.params().getPage().getID() ); // composes the JahiaFieldSet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -