KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > contenttool > actions > ViewRelationEditorAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.contenttool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.dom4j.Document;
31 import org.dom4j.Element;
32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.GroupPropertiesController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.RolePropertiesController;
37 import org.infoglue.cms.controllers.kernel.impl.simple.UserPropertiesController;
38 import org.infoglue.cms.entities.management.GroupProperties;
39 import org.infoglue.cms.entities.management.RoleProperties;
40 import org.infoglue.cms.entities.management.UserProperties;
41 import org.infoglue.cms.entities.structure.QualifyerVO;
42 import org.infoglue.cms.util.ConstraintExceptionBuffer;
43 import org.infoglue.cms.util.dom.DOMBuilder;
44
45 /**
46  * This action is the base action for all relation editors.
47  */

48
49 public abstract class ViewRelationEditorAction extends InfoGlueAbstractAction
50 {
51     //protected Integer contentVersionId = null;
52
protected Integer JavaDoc entityId = null;
53     protected String JavaDoc entityName = null;
54     //protected String contentVersionAttributeName= null;
55
protected String JavaDoc attributeName = null;
56     protected String JavaDoc updateAction = null;
57     
58     protected Integer JavaDoc repositoryId = null;
59     protected ConstraintExceptionBuffer ceb = null;
60     protected String JavaDoc qualifyerXML = null;
61     protected String JavaDoc relationXML = null;
62     protected String JavaDoc tree = null;
63     protected List JavaDoc repositories = null;
64     protected String JavaDoc path = null;
65     protected List JavaDoc qualifyers = null;
66     protected String JavaDoc currentAction = null;
67     protected String JavaDoc changeRepositoryAction = null;
68     protected String JavaDoc currentEntity = null;
69     protected String JavaDoc currentEntityIdentifyer = null;
70    
71     /*
72     public void setContentVersionId(Integer contentVersionId)
73     {
74         this.contentVersionId = contentVersionId;
75     }
76
77     public Integer getContentVersionId()
78     {
79         return this.contentVersionId;
80     }
81
82     public String getContentVersionAttributeName()
83     {
84         return contentVersionAttributeName;
85     }
86
87     public void setContentVersionAttributeName(String contentVersionAttributeName)
88     {
89         this.contentVersionAttributeName = contentVersionAttributeName;
90     }
91     */

92
93     public void setEntityId(Integer JavaDoc entityId)
94     {
95         this.entityId = entityId;
96     }
97
98     public Integer JavaDoc getEntityId()
99     {
100         return this.entityId;
101     }
102
103     public String JavaDoc getAttributeName()
104     {
105         return attributeName;
106     }
107
108     public void setAttributeName(String JavaDoc attributeName)
109     {
110         this.attributeName = attributeName;
111     }
112     
113     public void setRepositoryId(Integer JavaDoc repositoryId)
114     {
115         this.repositoryId = repositoryId;
116     }
117
118     public void setPath(String JavaDoc path)
119     {
120         this.path = path;
121     }
122     
123     public Integer JavaDoc getRepositoryId()
124     {
125         return this.repositoryId;
126     }
127
128     public void setQualifyerXML(String JavaDoc qualifyerXML)
129     {
130         this.qualifyerXML = qualifyerXML;
131     }
132     
133     public String JavaDoc getQualifyerXML()
134     {
135         return this.qualifyerXML;
136     }
137     
138     public String JavaDoc getTree()
139     {
140         return this.tree;
141     }
142
143     public void setTree(String JavaDoc tree)
144     {
145         this.tree = tree;
146     }
147     
148     public List JavaDoc getQualifyers()
149     {
150         return this.qualifyers;
151     }
152     
153     public String JavaDoc getCurrentEntity()
154     {
155         return this.currentEntity;
156     }
157
158     public void setCurrentEntity(String JavaDoc currentEntity)
159     {
160         this.currentEntity = currentEntity;
161     }
162
163     public String JavaDoc getCurrentEntityIdentifyer()
164     {
165         return this.currentEntityIdentifyer;
166     }
167
168     public void setCurrentEntityIdentifyer(String JavaDoc currentEntityIdentifyer)
169     {
170         this.currentEntityIdentifyer = currentEntityIdentifyer;
171     }
172
173     public String JavaDoc getCurrentAction()
174     {
175         return this.currentAction;
176     }
177
178     public String JavaDoc getChangeRepositoryAction()
179     {
180         return this.changeRepositoryAction;
181     }
182
183     public List JavaDoc getRepositories()
184     {
185         return repositories;
186     }
187     
188     public String JavaDoc getUpdateAction()
189     {
190         return updateAction;
191     }
192
193     public void setUpdateAction(String JavaDoc updateAction)
194     {
195         this.updateAction = updateAction;
196     }
197
198     public String JavaDoc getEntityName()
199     {
200         return entityName;
201     }
202
203     public void setEntityName(String JavaDoc entityName)
204     {
205         this.entityName = entityName;
206     }
207     
208     public abstract String JavaDoc getQualifyerPath(String JavaDoc entityId);
209     
210     
211     /**
212      * This method initializes the repositories-list and selects the first one if no other is selected.
213      * It also reads the relationXML from the content-version.
214      */

215     
216     protected void initialize() throws Exception JavaDoc
217     {
218         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
219
220         if(this.repositoryId == null)
221         {
222             this.repositoryId = (Integer JavaDoc)getHttpSession().getAttribute("repositoryId");
223             if(this.repositoryId == null)
224                 this.repositoryId = RepositoryController.getController().getFirstRepositoryVO().getRepositoryId();
225         }
226
227         //this.relationXML = ContentVersionController.getAttributeValue(getContentVersionId(), getContentVersionAttributeName(), false);
228
this.relationXML = getXML();
229         
230         boolean isFormDefinitionValid = true;
231         try
232         {
233             if(this.relationXML != null && this.relationXML.length() != 0)
234             {
235                 Document document = new DOMBuilder().getDocument(this.relationXML);
236                 this.qualifyers = parseQualifyersFromXML(this.relationXML);
237             }
238             else
239                 isFormDefinitionValid = false;
240         }
241         catch(Exception JavaDoc e)
242         {
243             isFormDefinitionValid = false;
244         }
245     }
246          
247     /**
248      * This is the default method which just initializes the view.
249      */

250
251     public String JavaDoc doExecute() throws Exception JavaDoc
252     {
253         initialize();
254
255         return "success";
256     }
257     
258     public String JavaDoc doChangeRepository() throws Exception JavaDoc
259     {
260         initialize();
261
262         return "success";
263     }
264     
265     /**
266      * Updates the qualifyer in the normal content version stucture.
267      */

268
269     public String JavaDoc doUpdateQualifyer() throws Exception JavaDoc
270     {
271         updateAttributeValue();
272         
273         initialize();
274         
275         return "success";
276     }
277     
278     /**
279      * Updates the qualifyer in the EntityProperties stucture.
280      */

281     public String JavaDoc doUpdateQualifyerInEntityProperties() throws Exception JavaDoc
282     {
283         if(this.entityName.equalsIgnoreCase(UserProperties.class.getName()))
284             UserPropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML);
285         else if(this.entityName.equalsIgnoreCase(RoleProperties.class.getName()))
286             RolePropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML);
287         else if(this.entityName.equalsIgnoreCase(GroupProperties.class.getName()))
288             GroupPropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML);
289     
290         initialize();
291     
292         return "success";
293     }
294         
295     
296     private List JavaDoc parseQualifyersFromXML(String JavaDoc qualifyerXML)
297     {
298         List JavaDoc qualifyers = new ArrayList JavaDoc();
299         
300         try
301         {
302             Document document = new DOMBuilder().getDocument(qualifyerXML);
303             
304             String JavaDoc entity = document.getRootElement().attributeValue("entity");
305             
306             List JavaDoc children = document.getRootElement().elements();
307             Iterator JavaDoc i = children.iterator();
308             while(i.hasNext())
309             {
310                 Element child = (Element)i.next();
311                 String JavaDoc id = child.getStringValue();
312                 
313                 QualifyerVO qualifyerVO = new QualifyerVO();
314                 qualifyerVO.setName(this.getCurrentEntityIdentifyer());
315                 qualifyerVO.setValue(id);
316                 qualifyerVO.setPath(this.getQualifyerPath(id));
317                 //qualifyerVO.setSortOrder(new Integer(i));
318
qualifyers.add(qualifyerVO);
319             }
320         }
321         catch(Exception JavaDoc e)
322         {
323             e.printStackTrace();
324         }
325         
326         return qualifyers;
327     }
328
329     /**
330      * A method that gets the XML that is the relations
331      */

332     
333     public String JavaDoc getXML()
334     {
335         try
336         {
337             if(this.entityName.equalsIgnoreCase(UserProperties.class.getName()))
338                 return UserPropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false);
339             if(this.entityName.equalsIgnoreCase(RoleProperties.class.getName()))
340                 return RolePropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false);
341             else if(this.entityName.equalsIgnoreCase(GroupProperties.class.getName()))
342                 return GroupPropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false);
343             else
344                 return ContentVersionController.getContentVersionController().getAttributeValue(getEntityId(), getAttributeName(), false);
345         }
346         catch(Exception JavaDoc e)
347         {
348             e.printStackTrace();
349         }
350         return "";
351     }
352      
353     /**
354      * This method is the common update method which assumes that the update is in a contentVersion.
355      */

356     
357     public void updateAttributeValue() throws Exception JavaDoc
358     {
359         ContentVersionController.getContentVersionController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML, this.getInfoGluePrincipal());
360     }
361
362
363
364 }
365
Popular Tags