KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > fields > JahiaSmallTextField


1 // JahiaSmallTextField
2
// YG 17.07.2001
3

4 package org.jahia.data.fields;
5
6 import java.util.Properties JavaDoc;
7
8 import org.jahia.data.ConnectionTypes;
9 import org.jahia.data.FormDataManager;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.params.ParamBean;
12 import org.jahia.registries.ServicesRegistry;
13 import org.jahia.services.fields.ContentField;
14 import org.jahia.services.fields.ContentSmallTextField;
15 import org.jahia.services.version.EntrySaveRequest;
16 import org.jahia.sharing.FieldSharingManager;
17
18 public class JahiaSmallTextField extends JahiaField implements JahiaSimpleField, JahiaAllowApplyChangeToAllLangField
19 {
20
21         /***
22         * constructor
23         * YG 17.07.2001
24         *
25         */

26     public JahiaSmallTextField(Integer JavaDoc ID,
27                             Integer JavaDoc jahiaID,
28                             Integer JavaDoc pageID,
29                             Integer JavaDoc ctnid,
30                             Integer JavaDoc fieldDefID,
31                             Integer JavaDoc fieldType,
32                             Integer JavaDoc connectType,
33                             String JavaDoc fieldValue,
34                             Integer JavaDoc rank,
35                             Integer JavaDoc aclID,
36                             Integer JavaDoc versionID,
37                             Integer JavaDoc versionStatus,
38                             String JavaDoc languageCode)
39     {
40         super(ID, jahiaID, pageID, ctnid, fieldDefID, fieldType, connectType,
41               fieldValue, rank, aclID, versionID, versionStatus, languageCode);
42
43         if ( isShared() ){
44             this.languageCode = ContentField.SHARED_LANGUAGE;
45         }
46
47     } // end constructor
48

49
50     public void load(int loadFlag, ParamBean jParams)
51     throws JahiaException
52     {
53         switch (this.getConnectType())
54         {
55             case (ConnectionTypes.LOCAL) :
56                 //this.setValue(this.getValue());
57
if (!this.getValue().equals("<empty>")) {
58                     String JavaDoc fieldValue = this.getValue();
59                     this.setRawValue(fieldValue);
60                     this.setValue(FormDataManager.getInstance().htmlEncode(fieldValue));
61                 }
62                 break;
63             case (ConnectionTypes.DATASOURCE) :
64             if ((loadFlag & LoadFlags.DATASOURCE) != 0) {
65                 this.setValue( FieldSharingManager.getInstance().getRemoteFieldValue(
66                     this.getValue() ));
67             }
68         }
69
70     }
71
72     public String JavaDoc getEngineName()
73     {
74         return "org.jahia.engines.shared.SmallText_Field";
75     }
76
77     public boolean save(ParamBean jParams)
78     throws JahiaException
79     {
80         // 0 for parentAclID in saveField, because field already exists
81
// -> field already has an aclID
82
// -> no need to create a new one
83

84         //ServicesRegistry.getInstance().getJahiaFieldService().saveField( theField, 0, jParams );
85
EntrySaveRequest saveRequest = new EntrySaveRequest(jParams.getUser(),getLanguageCode());
86         ContentSmallTextField contentField = (ContentSmallTextField)ContentField.getField(getID());
87         contentField.setText(getValue(),saveRequest);
88         ServicesRegistry.getInstance().getJahiaSearchService().indexField(getID(), true, jParams, true);
89         return true;
90     }
91
92     public String JavaDoc getValue() {
93         return fieldValue;
94     }
95
96     public void delete(ParamBean jParams)
97     throws JahiaException
98     {
99         ;
100     }
101
102     public String JavaDoc getFieldContent4Ranking()
103     {
104         return this.getValue();
105     }
106
107     public String JavaDoc getIconNameOff()
108     {
109         return "smalltext";
110     }
111
112     public String JavaDoc getIconNameOn()
113     {
114         return "smalltext_on";
115     }
116
117     public JahiaField cloneField(int newctnid, int newPageID, int clonedAclID, boolean childrenCloned)
118     throws JahiaException
119     {
120         JahiaField clonedField = ServicesRegistry.getInstance().getJahiaFieldService().
121                                  createJahiaField(0, this.getJahiaID(),
122                                  newPageID, newctnid,
123                                  this.getFieldDefID(), this.getType(),
124                                  this.getConnectType(),
125                                  this.getValue(), this.getRank(),
126                                  clonedAclID, this.getVersionID(), this.getWorkflowState(),
127                                  this.getLanguageCode());
128
129         //toDebug("cloneField(): value = "+this.getValue());
130
if (clonedField == null)
131         {
132             throw new JahiaException ("Could not clone field.",
133                 "Could not instanciate a new JahiaField object.",
134                 JahiaException.PAGE_ERROR, JahiaException.CRITICAL_SEVERITY);
135         }
136
137         clonedField.setRawValue(this.getRawValue());
138         clonedField.setObject( this.getObject() );
139         clonedField.setProperties( (Properties JavaDoc)(this.getProperties()).clone() );
140
141         return clonedField;
142     }
143
144     public Object JavaDoc clone()
145     {
146         Object JavaDoc objItem = this.getObject();
147
148         JahiaSmallTextField st = new JahiaSmallTextField (new Integer JavaDoc(ID), new Integer JavaDoc(jahiaID),
149                                         new Integer JavaDoc(pageID),
150                                         new Integer JavaDoc(ctnid),
151                                         new Integer JavaDoc(fieldDefID),
152                                         new Integer JavaDoc(fieldType),
153                                         new Integer JavaDoc(connectType),
154                                         fieldValue, new Integer JavaDoc(rank),
155                                         new Integer JavaDoc(aclID),
156                                         new Integer JavaDoc(versionID),
157                                         new Integer JavaDoc(workflowState),
158                                         new String JavaDoc(getLanguageCode()) );
159         st.setObject(objItem);
160         return st;
161     }
162
163     /**
164      * Is this kind of field shared (i.e. not one version for each language, but one version for every language)
165      */

166     public boolean isShared (){
167         return false;
168     }
169
170     /**
171      * Copy the internal value of current language to another language.
172      * Must be implemented by conctrete field for specific implementation.
173      *
174      * @param aField A same field in another language
175      */

176     public void copyValueInAnotherLanguage (JahiaField aField,ParamBean jParams)
177     throws JahiaException {
178         if ( aField == null ){
179             return;
180         }
181         aField.setValue(this.getValue());
182         aField.setRawValue(this.getValue());
183         aField.setObject(this.getObject());
184     }
185
186 }
187
Popular Tags