1 13 package org.jahia.services.fields; 14 15 import org.jahia.data.ConnectionTypes; 16 import org.jahia.exceptions.JahiaException; 17 import org.jahia.params.ParamBean; 18 import org.jahia.resourcebundle.ResourceBundleMarker; 19 import org.jahia.services.version.ActivationTestResults; 20 import org.jahia.services.version.ContentObjectEntryState; 21 import org.jahia.services.version.EntrySaveRequest; 22 import org.jahia.services.version.StateModificationContext; 23 import org.jahia.utils.xml.XMLSerializationOptions; 24 import org.jahia.utils.xml.XmlWriter; 25 26 import java.io.IOException ; 27 import java.util.Hashtable ; 28 import java.util.Set ; 29 import java.util.Vector ; 30 31 public class ContentSmallTextSharedLangField extends ContentField 32 implements ContentSimpleField { 33 private static org.apache.log4j.Logger logger 34 = org.apache.log4j.Logger.getLogger (ContentSmallTextSharedLangField.class); 35 36 protected ContentSmallTextSharedLangField (Integer ID, 37 Integer jahiaID, 38 Integer pageID, 39 Integer ctnid, 40 Integer fieldDefID, 41 Integer fieldType, 42 Integer connectType, 43 Integer aclID, 44 Vector activeAndStagingEntryStates, 45 Hashtable activeAndStagedDBValues) { 46 super (ID.intValue (), jahiaID.intValue (), pageID.intValue (), ctnid.intValue (), fieldDefID.intValue (), 47 fieldType.intValue (), connectType.intValue (), aclID.intValue (), activeAndStagingEntryStates, 48 activeAndStagedDBValues); 49 } 50 51 public static synchronized ContentSmallTextSharedLangField createSmallText (int siteID, 52 int pageID, 53 int containerID, 54 int fieldDefID, 55 int parentAclID, 56 int aclID, 57 String text, 58 ParamBean jParams) 59 throws JahiaException { 60 ContentSmallTextSharedLangField result = 61 (ContentSmallTextSharedLangField) ContentField.createField (siteID, pageID, 62 containerID, fieldDefID, 63 ContentFieldTypes.SMALLTEXT_SHARED_LANG, 64 ConnectionTypes.LOCAL, 65 parentAclID, aclID); 66 EntrySaveRequest saveRequest = new EntrySaveRequest (jParams.getUser (), 68 ContentField.SHARED_LANGUAGE); 69 result.setText (text, saveRequest); 70 return result; 71 } 72 73 82 public String getValue (ParamBean jParams, ContentObjectEntryState entryState) 83 throws JahiaException { 84 if (entryState == null) { 85 return ""; 86 } 87 String result = this.getDBValue (entryState); 88 89 if (result == null || result.equals ("<empty>")) { 90 result = new String (); 91 } 92 return result; 93 } 94 95 99 public void setText (String value, EntrySaveRequest saveRequest) throws JahiaException { 100 if (!ContentField.SHARED_LANGUAGE.equals (saveRequest.getLanguageCode ())) { 101 logger.debug ("Found non shared language in setting, enforcing shared language..."); 102 saveRequest.setLanguageCode (ContentField.SHARED_LANGUAGE); 103 } 104 preSet (value, saveRequest); 105 } 106 107 115 public String getValueForSearch (ParamBean jParams, 116 ContentObjectEntryState entryState) throws JahiaException { 117 return getDBValue (entryState); 119 } 120 121 137 public ActivationTestResults changeEntryState (ContentObjectEntryState fromEntryState, 138 ContentObjectEntryState toEntryState, 139 ParamBean jParams, 140 StateModificationContext stateModifContext) 141 throws JahiaException { 142 return new ActivationTestResults (); 143 } 144 145 protected ActivationTestResults isContentValidForActivation ( 146 Set languageCodes, 147 ParamBean jParams, 148 StateModificationContext stateModifContext) throws JahiaException { 149 150 return new ActivationTestResults (); 151 } 152 153 156 public boolean isShared () { 157 return true; 158 } 159 160 181 protected void serializeContentToXML (XmlWriter xmlWriter, 182 XMLSerializationOptions 183 xmlSerializationOptions, 184 ContentObjectEntryState entryState, 185 ParamBean paramBean) 186 throws IOException { 187 try { 188 String result = ResourceBundleMarker.getValue (getDBValue (entryState), 190 paramBean.getLocale ()); 191 xmlWriter.writeCData (result); 192 } catch (JahiaException je) { 193 logger.debug ("Error while serializing shared small text field to XML : ", je); 194 } 195 } 196 197 } 198 | Popular Tags |