1 13 20 package org.jahia.engines.shared; 21 22 import java.util.HashMap ; 23 24 import org.apache.log4j.Logger; 25 import org.jahia.data.ConnectionTypes; 26 import org.jahia.data.FormDataManager; 27 import org.jahia.data.containers.JahiaContainer; 28 import org.jahia.data.fields.JahiaField; 29 import org.jahia.engines.EngineMessages; 30 import org.jahia.engines.EngineParams; 31 import org.jahia.engines.JahiaEngine; 32 import org.jahia.engines.JahiaEngineTools; 33 import org.jahia.exceptions.JahiaException; 34 import org.jahia.params.ParamBean; 35 import org.jahia.registries.EnginesRegistry; 36 import org.jahia.registries.ServicesRegistry; 37 import org.jahia.services.acl.JahiaBaseACL; 38 import org.jahia.utils.JahiaTools; 39 40 public class Boolean_Field 41 { 42 43 private static Logger logger = Logger.getLogger(Boolean_Field.class); 44 45 private static Boolean_Field theObject = null; 46 private static final String JSP_FILE = "/jsp/jahia/engines/shared/boolean_field.jsp"; 47 public static final String READONLY_JSP = "/jsp/jahia/engines/shared/readonly_boolean_field.jsp"; 48 49 50 55 public static synchronized Boolean_Field getInstance() 56 { 57 if (theObject == null) { 58 theObject = new Boolean_Field(); 59 } 60 return theObject; 61 } 63 64 65 74 public boolean handleField( ParamBean jParams, Integer modeInt, HashMap engineMap ) 75 throws JahiaException 76 { 77 int mode = modeInt.intValue(); 78 JahiaField theField = (JahiaField) engineMap.get( "theField" ); 79 switch (mode) 80 { 81 case (JahiaEngine.LOAD_MODE) : return composeEngineMap( jParams, engineMap, theField ); 82 case (JahiaEngine.UPDATE_MODE) : return getFormData( jParams, engineMap, theField ); 83 case (JahiaEngine.SAVE_MODE) : return saveData( jParams, engineMap, theField ); 84 } 85 return false; 86 } 88 89 90 99 private boolean getFormData( ParamBean jParams, HashMap engineMap, JahiaField theField ) 100 throws JahiaException 101 { 102 boolean out = true; 103 104 String fieldValue = jParams.getRequest().getParameter( "_" + new Integer (theField.getID()).toString() ); 105 String engineParams = jParams.getRequest().getParameter( "engine_params" ); 106 fieldValue = JahiaTools.replacePattern(fieldValue,"|","|"); 107 108 109 EngineParams eParams = new EngineParams( engineParams ); 110 String localSwitch = eParams.getParameter( "localswitch" ); 111 String dataSourceUrl = eParams.getParameter( "dsurl" ); 112 113 if (dataSourceUrl != null) { 114 theField.setValue( dataSourceUrl ); 115 theField.setConnectType( ConnectionTypes.DATASOURCE ); 116 } else if (localSwitch != null) { 117 theField.setValue( theField.getDefinition().getDefaultValue( jParams.getPage().getPageTemplateID() ) ); 118 theField.setConnectType( ConnectionTypes.LOCAL ); 119 } else if (fieldValue != null) { 120 EngineMessages resultMessages = new EngineMessages(); 121 if (FormDataManager.getInstance().checkIntegrity(fieldValue, resultMessages)) { 122 theField.setValue( fieldValue); 123 } else { 124 theField.setValue( fieldValue ); 125 out = false; 126 } 127 } 128 129 return out; 130 } 132 133 134 143 private boolean saveData( ParamBean jParams, HashMap engineMap, JahiaField theField ) 144 throws JahiaException 145 { 146 logger.debug("Saving Field " + theField.getDefinition().getName() + " : " + theField.getValue() ); 147 return theField.save(jParams); 148 } 150 151 152 161 private boolean composeEngineMap( ParamBean jParams, HashMap engineMap, JahiaField theField ) 162 throws JahiaException 163 { 164 165 boolean editable = false; 166 JahiaContainer theContainer = (JahiaContainer)engineMap.get("theContainer"); 167 if ( theContainer == null ){ 168 editable = true; 170 } else { 171 HashMap ctnListFieldAcls = (HashMap ) engineMap 172 .get("ctnListFieldAcls"); 173 174 if (theContainer.getListID() != 0 && ctnListFieldAcls != null 175 && ctnListFieldAcls.size() > 0) { 176 JahiaBaseACL acl = JahiaEngineTools.getCtnListFieldACL( 177 ctnListFieldAcls, theField.getID()); 178 if (acl != null) { 179 editable = acl.getPermission(jParams.getUser(), 180 JahiaBaseACL.WRITE_RIGHTS, true); 181 } 182 } else { 183 editable = true; 184 } 185 } 186 187 String output = ""; 188 189 if ( editable ){ 190 191 String localSwitchUrl = "ReloadEngine('localswitch" + EngineParams.VALUE_TOKEN + "yes')"; 192 engineMap.put( "localSwitchUrl", localSwitchUrl ); 193 194 String dataSourceConnectUrl = ""; 195 JahiaEngine dsEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine( "selectdatasource" ); 196 dataSourceConnectUrl = dsEngine.renderLink( jParams, theField ); 197 engineMap.put( "dataSourceConnectUrl", dataSourceConnectUrl ); 198 199 String dataSourceIDUrl = ""; 200 dsEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine( "viewdatasourceid" ); 201 dataSourceIDUrl = dsEngine.renderLink( jParams, theField ); 202 engineMap.put( "dataSourceIDUrl", dataSourceIDUrl ); 203 204 theField.setValue( FormDataManager.getInstance().formEncode(theField.getValue()) ); 205 output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, JSP_FILE ); 206 } else { 207 output = ServicesRegistry.getInstance().getJahiaFetcherService().fetchServlet( jParams, READONLY_JSP ); 208 } 209 210 engineMap.put( "fieldForm", output ); 211 212 return true; 213 } 215 216 } | Popular Tags |