1 13 package org.jahia.services.fields; 14 15 import org.apache.regexp.RE; 16 import org.apache.regexp.RESyntaxException; 17 import org.jahia.data.ConnectionTypes; 18 import org.jahia.exceptions.JahiaException; 19 import org.jahia.params.ParamBean; 20 import org.jahia.params.DummyServletRequestWrapper; 21 import org.jahia.registries.ServicesRegistry; 22 import org.jahia.services.version.ActivationTestResults; 23 import org.jahia.services.version.ContentObjectEntryState; 24 import org.jahia.services.version.EntrySaveRequest; 25 import org.jahia.services.version.StateModificationContext; 26 import org.jahia.utils.xml.XMLSerializationOptions; 27 import org.jahia.utils.xml.XmlWriter; 28 29 import java.io.IOException ; 30 import java.util.Hashtable ; 31 import java.util.Set ; 32 import java.util.Vector ; 33 34 37 public class ContentApplicationField extends ContentField { 38 39 private static org.apache.log4j.Logger logger = 40 org.apache.log4j.Logger.getLogger (ContentApplicationField.class); 41 42 protected ContentApplicationField (Integer ID, 43 Integer jahiaID, 44 Integer pageID, 45 Integer ctnid, 46 Integer fieldDefID, 47 Integer fieldType, 48 Integer connectType, 49 Integer aclID, 50 Vector activeAndStagingEntryStates, 51 Hashtable activeAndStagedDBValues) { 52 super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), ctnid.intValue (), 53 fieldDefID.intValue (), 54 fieldType.intValue (), connectType.intValue (), aclID.intValue (), 55 activeAndStagingEntryStates, activeAndStagedDBValues); 56 } 57 58 public static synchronized ContentApplicationField createApplication (int siteID, 59 int pageID, 60 int containerID, 61 int fieldDefID, 62 int parentAclID, 63 int aclID, 64 int appID, 65 ParamBean jParams) 66 throws JahiaException { 67 ContentApplicationField result = 68 (ContentApplicationField) ContentField.createField (siteID, pageID, 69 containerID, fieldDefID, 70 ContentFieldTypes.APPLICATION, 71 ConnectionTypes.LOCAL, 72 parentAclID, aclID); 73 EntrySaveRequest saveRequest = new EntrySaveRequest (jParams.getUser (), 74 ContentField.SHARED_LANGUAGE); 75 76 result.setAppID (appID, saveRequest); 77 return result; 78 } 79 80 81 88 public String getValue (ParamBean jParams, ContentObjectEntryState entryState) 89 throws JahiaException { 90 91 logger.debug ("Loading app value..."); 92 93 ServicesRegistry tmpServicesRegistry = ServicesRegistry.getInstance (); 94 95 String appID = getDBValue (entryState); 96 if (appID.equals ("<empty>")) { 97 return new String (); 98 } 99 100 String tmpValue = ""; 101 102 if (jParams != null && jParams.getRealRequest() != null 103 && !(jParams.getRealRequest() instanceof DummyServletRequestWrapper)) { 104 tmpValue = ServicesRegistry.getInstance (). 105 getJahiaApplicationsDispatchingService (). 106 getAppOutput (this.getID (), appID, jParams); 107 } 108 if (tmpValue != null) { 109 try { 110 tmpValue = (new RE ("</?html>", RE.MATCH_CASEINDEPENDENT)). 111 subst (tmpValue, ""); 112 } catch (RESyntaxException e) { 113 logger.debug (".getValue, exeption : " + e.toString ()); 114 } 115 116 try { 117 tmpValue = new StringBuffer ().append ("<html>"). 118 append (tmpValue).append ("</html>").toString (); 119 } catch (Throwable t) { 120 t.printStackTrace (); 121 } 122 } else { 124 tmpValue = new String (); 125 } 126 return tmpValue; 127 } 128 129 133 public void setAppID (int value, EntrySaveRequest saveRequest) throws JahiaException { 134 ContentObjectEntryState verInfo = preSet (String.valueOf (value), saveRequest); 135 logger.debug ("Saving application field..."); 136 } 137 138 146 public String getValueForSearch (ParamBean jParams, ContentObjectEntryState entryState) 147 throws JahiaException { 148 return getDBValue (entryState); 150 } 151 152 168 public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState, 169 ContentObjectEntryState toEntryState, 170 ParamBean jParams, 171 StateModificationContext stateModifContext) 172 throws JahiaException { 173 return new ActivationTestResults (); 174 } 175 176 protected ActivationTestResults isContentValidForActivation ( 177 Set languageCodes, 178 ParamBean jParams, 179 StateModificationContext stateModifContext) throws JahiaException { 180 181 return new ActivationTestResults (); 182 } 183 184 189 public boolean isShared () { 190 return true; 191 } 192 193 214 protected void serializeContentToXML (XmlWriter xmlWriter, 215 XMLSerializationOptions xmlSerializationOptions, 216 ContentObjectEntryState entryState, 217 ParamBean paramBean) throws IOException { 218 219 222 xmlWriter.writeCData ("NOT YET IMPLEMENTED"); 223 } 224 225 protected boolean isEntryInitialized (ContentObjectEntryState curEntryState) 226 throws JahiaException { 227 String entryValue = getDBValue(curEntryState); 228 if (entryValue == null) { 229 return false; 230 } 231 if (!entryValue.equals("") && 232 !entryValue.equals("<empty>")) { 233 return true; 234 } 235 return false; 236 } 237 238 239 } 240 | Popular Tags |