1 4 package org.jahia.data.fields; 5 6 import java.util.Properties ; 7 8 import org.jahia.data.ConnectionTypes; 9 import org.jahia.data.FormDataManager; 10 import org.jahia.data.applications.ApplicationBean; 11 import org.jahia.exceptions.JahiaException; 12 import org.jahia.params.ParamBean; 13 import org.jahia.registries.ServicesRegistry; 14 import org.jahia.services.fields.ContentApplicationField; 15 import org.jahia.services.fields.ContentField; 16 import org.jahia.services.version.EntrySaveRequest; 17 import org.jahia.utils.JahiaTools; 18 19 public class JahiaApplicationField extends JahiaField implements JahiaAllowApplyChangeToAllLangField 20 { 21 22 private static org.apache.log4j.Logger logger = 23 org.apache.log4j.Logger.getLogger(JahiaApplicationField.class); 24 25 30 public JahiaApplicationField(Integer ID, 31 Integer jahiaID, 32 Integer pageID, 33 Integer ctnid, 34 Integer fieldDefID, 35 Integer fieldType, 36 Integer connectType, 37 String fieldValue, 38 Integer rank, 39 Integer aclID, 40 Integer versionID, 41 Integer versionStatus, 42 String languageCode) 43 { 44 super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType, 45 fieldValue, rank, aclID, versionID, versionStatus, languageCode); 46 47 if ( isShared() ){ 48 this.languageCode = ContentField.SHARED_LANGUAGE; 49 } 50 51 } 53 54 public void load(int loadFlag, ParamBean jParams) 55 throws JahiaException 56 { 57 this.setObject(this.getValue()); 59 try { 60 logger.debug("Loading application field..."); 61 62 ContentApplicationField contentApplicationField = (ContentApplicationField)ContentApplicationField.getField(getID()); 63 logger.debug("value=" + getValue()); 64 65 String val = contentApplicationField.getValue(jParams); 66 67 this.setValue(JahiaTools.replacePattern(FormDataManager.getInstance().htmlEncode(val),"@","@")); 68 69 } catch ( Throwable t ){ 70 logger.error("Problem loading application field value for field " + getID(), t); 71 this.setValue("Exception loading application data :\n" + t.getMessage()); 72 } 73 74 118 } 119 120 public boolean save(ParamBean jParams) 121 throws JahiaException 122 { 123 switch (this.getConnectType()) 124 { 125 case (ConnectionTypes.LOCAL) : 126 127 if ( this.getValue() != null && !this.getValue().equals("<empty>") ){ 128 int appID = Integer.parseInt(this.getValue()); 129 ApplicationBean app = ServicesRegistry.getInstance() 130 .getJahiaApplicationsManagerService() 131 .getApplication(appID); 132 133 if ( app != null ){ 134 135 String oldAppID = (String )this.getObject(); 137 if ( (oldAppID!=null) && !oldAppID.equals(this.getValue()) ){ 138 139 ApplicationBean oldApp = ServicesRegistry 141 .getInstance() 142 .getJahiaApplicationsManagerService() 143 .getApplication(Integer.parseInt(oldAppID)); 144 145 ServicesRegistry.getInstance() 146 .getJahiaApplicationsManagerService() 147 .deleteApplicationGroups(oldApp,this); 148 } 149 150 ServicesRegistry.getInstance() 152 .getJahiaApplicationsManagerService() 153 .createApplicationGroups(app,this); 154 } 155 EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(),this.getLanguageCode()); 156 ContentApplicationField contentField = (ContentApplicationField)ContentField.getField(this.getID()); 157 contentField.setAppID(appID,saveRequest); 158 break; 159 } 160 } 161 return true; 162 } 163 164 public void delete(ParamBean jParams) 165 throws JahiaException 166 { 167 switch (this.getConnectType()) 168 { 169 case (ConnectionTypes.LOCAL) : 170 188 break; 189 } 190 } 191 192 public String getEngineName() 193 { 194 return "org.jahia.engines.shared.Application_Field"; 195 } 196 197 public String getFieldContent4Ranking() 198 throws JahiaException 199 { 200 String fieldInfo = ""; 201 String appIDStr = (String )this.getObject(); 202 int appID = 0; 203 if (appIDStr != null) 204 { 205 try { 206 appID = Integer.parseInt(appIDStr); 207 } catch (NumberFormatException nfe) { 208 ; 209 } 210 } 211 212 ApplicationBean app = ServicesRegistry.getInstance(). 213 getJahiaApplicationsManagerService(). 214 getApplication(appID); 215 216 if (app != null) 217 { 218 fieldInfo = app.getName(); 219 } 220 else 221 { 222 fieldInfo = this.getValue(); 223 } 224 return fieldInfo; 225 } 226 227 public String getIconNameOff() 228 { 229 return "application"; 230 } 231 232 public String getIconNameOn() 233 { 234 return "application_on"; 235 } 236 237 public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned) 238 throws JahiaException 239 { 240 JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService(). 241 createJahiaField(0, this.getJahiaID(), 242 newPageID, newctnid, 243 this.getFieldDefID(), this.getType(), 244 this.getConnectType(), 245 (String )this.getObject(), this.getRank(), 246 clonedAclID, this.getVersionID(), this.getWorkflowState(), 247 this.getLanguageCode()); 248 249 if (clonedField == null) 251 { 252 throw new JahiaException ("Could not clone field.", 253 "Could not instanciate a new JahiaField object.", 254 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY); 255 } 256 257 clonedField.setRawValue(this.getRawValue()); 258 clonedField.setObject( this.getObject() ); 259 clonedField.setProperties( (Properties )(this.getProperties()).clone() ); 260 261 return clonedField; 262 } 263 264 public Object clone() 265 { 266 Object objItem = this.getObject(); 267 JahiaApplicationField app = new JahiaApplicationField (new Integer (ID), new Integer (jahiaID), 268 new Integer (pageID), 269 new Integer (ctnid), 270 new Integer (fieldDefID), 271 new Integer (fieldType), 272 new Integer (connectType), 273 fieldValue, new Integer (rank), 274 new Integer (aclID), 275 new Integer (versionID), 276 new Integer (workflowState), 277 new String (getLanguageCode()) ); 278 app.setObject(objItem); 279 return app; 280 } 281 282 285 public boolean isShared (){ 286 return true; 287 } 288 289 295 public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams) 296 throws JahiaException { 297 if ( aField == null ){ 298 return; 299 } 300 aField.setValue(this.getValue()); 301 aField.setRawValue(this.getValue()); 302 aField.setObject(this.getObject()); 303 } 304 305 } 306 | Popular Tags |