📄 undefined_field.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// Undefined_Field// EV 14.01.20001//// handleField( mode, jParams )//package org.jahia.engines.shared;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.data.*; // JahiaData, ConnectionTypesimport org.jahia.params.*; // ParamBeanimport org.jahia.engines.*; // JahiaEngine interfaceimport org.jahia.data.fields.*; // JahiaField, FieldTypesimport org.jahia.data.containers.*; // JahiaContainerimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.data.categories.*; // JahiaCategoriesimport org.jahia.services.pages.*;import org.jahia.services.acl.*;public class Undefined_Field{ private static final String CLASS_NAME = Undefined_Field.class.getName(); private static Undefined_Field theObject = null; private static final String JSP_FILE = "/jsp/jahia/engines/shared/undefined_field.jsp"; /*** * getInstance * AK 19.12.2000 * */ public static synchronized Undefined_Field getInstance() { if (theObject == null) { theObject = new Undefined_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 { int mode = modeInt.intValue(); JahiaField theField = (JahiaField) engineMap.get( "theField" ); switch (mode) { case (JahiaEngine.LOAD_MODE) : return composeEngineMap( jParams, engineMap, theField ); case (JahiaEngine.UPDATE_MODE) : return getFormData( jParams, engineMap, theField ); case (JahiaEngine.SAVE_MODE) : return saveData( jParams, engineMap, theField ); } return false; } // end handleField /*** * 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 { boolean out = true; String choosedType = ""; String fieldTypeStr = jParams.getRequest().getParameter( "_" + new Integer(theField.getID()).toString() ); choosedType += jParams.getRequest().getParameter( "choosedType" ); System.out.println("fieldType: "+fieldTypeStr); if ( choosedType.equals("yes") && (fieldTypeStr != null) ) { try { int fieldType = Integer.parseInt( fieldTypeStr ); JahiaField f = ServicesRegistry.getInstance(). getJahiaFieldService(). createJahiaField( theField.getID(), theField.getJahiaID(), theField.getPageID(), theField.getctnid(), theField.getFieldDefID(), fieldType, theField.getConnectType(), theField.getValue(), theField.getRank(), theField.getAclID() ); String flag = (String)engineMap.get("updateField"); if (flag == null) { JahiaContainer theContainer = (JahiaContainer)engineMap.get("theContainer"); theContainer.setField(f); engineMap.put("theContainer", theContainer); } //JahiaFieldDefinition fDef = JahiaFieldDefinitionsRegistry. //getInstance(). //getDefinition(theField.getFieldDefID()); //fDef.setType( fieldType, fDef.getID() ); //JahiaFieldDefinitionsRegistry.getInstance(). // setDefinition( fDef ); theField = f; // theField.setType( fieldType ); engineMap.put( "theField", f ); } catch (NumberFormatException nfe) { theField.setType( 0 ); out = false; } } if (!choosedType.equals("yes")) { theField.setType( 0 ); } return out; } // end getFormData /*** * saves data in datasource * * @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 saveData( ParamBean jParams, HashMap engineMap, JahiaField theField ) throws JahiaException { // nothing to do here ! return true; } // end saveData /*** * 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 { 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 ) { // soon obsolete Hashtable typesList = FieldTypes.getInstance().getFieldTypes(); Hashtable typesList2 = new Hashtable(); // check which types must be inserted in the undefined field list int pageID = theField.getPageID(); JahiaPage thePage = ServicesRegistry.getInstance().getJahiaPageService().lookupPage( pageID ); String defValue = theField.getDefinition().getDefaultValue(thePage.getPageTemplateID()); try { if (defValue.toUpperCase().indexOf("JAHIA_MASKTYPE") != -1) { defValue = defValue.substring( defValue.indexOf("[")+1,defValue.indexOf("]") ); //System.out.println(defValue); } int defValueInt = Integer.parseInt(defValue); if (defValueInt == -1) { typesList2 = typesList; } else { Enumeration keys = typesList.keys(); Hashtable loadFlags = LoadFlags.getInstance().getLoadFlags(); int loadFlag = 0; int i = -1; while (keys.hasMoreElements()) { i++; String theKey = (String) keys.nextElement(); loadFlag = ( (Integer)loadFlags.get((Integer) typesList.get( theKey )) != null ) ? ((Integer)loadFlags.get((Integer) typesList.get( theKey ))).intValue() : 0; boolean flag = ((defValueInt & loadFlag) == loadFlag) ? true: false; int f = defValueInt & loadFlag; //System.out.println("******** the Key:"+ theKey +" deValInt: "+defValueInt +" loadFlag: "+loadFlag +" d & l: "+f); if ( flag ) { typesList2.put(theKey, (Integer) typesList.get( theKey )); } } } } catch (NumberFormatException e) { typesList2.put( "Limited text", (Integer) typesList.get( "Limited text" ) ); typesList2.put( "Free text", (Integer) typesList.get( "Free text" ) ); typesList2.put( "Application", (Integer) typesList.get( "Application" ) ); } engineMap.put( "typesList", typesList2 ); // new version Vector categoryList = JahiaCategories.getInstance().getList(); engineMap.put( "categoryList", categoryList ); theField.setValue( FormDataManager.getInstance().formDecode(theField.getValue()) ); output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, JSP_FILE ); theField.setValue( FormDataManager.getInstance().decode(theField.getValue()) ); } else { output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, JahiaEngine.NOT_EDITABLE_FIELD ); } engineMap.put( "fieldForm", output ); return true; } // end composeEngineMap} // end SmallText
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -