KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > managementtool > actions > ViewEntityPropertiesAction


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.managementtool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.apache.log4j.Logger;
32 import org.dom4j.Document;
33 import org.dom4j.Element;
34 import org.dom4j.Node;
35 import org.infoglue.cms.applications.common.VisualFormatter;
36 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
37 import org.infoglue.cms.controllers.kernel.impl.simple.CategoryController;
38 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
39 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
40 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController;
41 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
42 import org.infoglue.cms.controllers.kernel.impl.simple.PropertiesCategoryController;
43 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
44 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
45 import org.infoglue.cms.entities.content.ContentVO;
46 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
47 import org.infoglue.cms.entities.management.LanguageVO;
48 import org.infoglue.cms.entities.management.RepositoryVO;
49 import org.infoglue.cms.entities.structure.QualifyerVO;
50 import org.infoglue.cms.entities.structure.SiteNodeVO;
51 import org.infoglue.cms.exception.Bug;
52 import org.infoglue.cms.exception.SystemException;
53 import org.infoglue.cms.util.CmsPropertyHandler;
54 import org.infoglue.cms.util.dom.DOMBuilder;
55
56 public abstract class ViewEntityPropertiesAction extends InfoGlueAbstractAction
57 {
58     private final static Logger logger = Logger.getLogger(ViewEntityPropertiesAction.class.getName());
59
60     private static CategoryController categoryController = CategoryController.getController();
61     private static PropertiesCategoryController propertiesCategoryController = PropertiesCategoryController.getController();
62     
63     private String JavaDoc currentAction = "";
64     private String JavaDoc updateAction = "";
65     private String JavaDoc cancelAction = "";
66
67     private String JavaDoc toolbarKey = "";
68     private String JavaDoc titleKey = "";
69     private String JavaDoc arguments = "";
70     
71     private String JavaDoc entityName = null;
72     private Integer JavaDoc entityId = null;
73     
74     private String JavaDoc ownerEntityName = null;
75     private String JavaDoc ownerEntityId = null;
76     
77     private List JavaDoc availableLanguages;
78     private List JavaDoc contentTypeDefinitionVOList;
79     private List JavaDoc contentTypeAttributes;
80     private Integer JavaDoc contentTypeDefinitionId;
81     private Integer JavaDoc languageId;
82     private String JavaDoc attributeName = "";
83     private String JavaDoc textAreaId = "";
84
85     private ContentTypeDefinitionVO contentTypeDefinitionVO;
86     
87     public abstract String JavaDoc getXML();
88     
89     public abstract String JavaDoc getCancelAddress() throws Exception JavaDoc;
90
91     public abstract String JavaDoc getReturnAddress() throws Exception JavaDoc;
92
93     public void initialize() throws SystemException, Bug
94     {
95         this.setAvailableLanguages(LanguageController.getController().getLanguageVOList());
96         
97         if(this.getLanguageId() == null && this.getAvailableLanguages().size() > 0)
98             this.setLanguageId(((LanguageVO)this.getAvailableLanguages().get(0)).getLanguageId());
99         
100         logger.info("Language:" + this.languageId);
101     }
102     
103     
104     /**
105      * This method fetches a value from the xml that is the contentVersions Value. If the
106      * xml is null the property has not been created yet and no values are present.
107      */

108      
109     public String JavaDoc getAttributeValue(String JavaDoc key)
110     {
111         String JavaDoc value = "";
112         try
113         {
114             String JavaDoc xml = this.getXML();
115             if(xml != null)
116             {
117                 DOMBuilder domBuilder = new DOMBuilder();
118                 
119                 Document document = domBuilder.getDocument(xml);
120                 
121                 Node node = document.getRootElement().selectSingleNode("attributes/" + key);
122                 if(node != null)
123                 {
124                     value = node.getStringValue();
125                     if(value != null)
126                         value = new VisualFormatter().escapeHTML(value);
127                 }
128             }
129         }
130         catch(Exception JavaDoc e)
131         {
132             e.printStackTrace();
133         }
134
135         return value;
136     }
137
138     /**
139      * This method fetches a value from the xml that is the property Value. If the
140      * xml is null the contentVersion has not been created yet and no values are present.
141      */

142      
143     public String JavaDoc getUnescapedAttributeValue(String JavaDoc key)
144     {
145         String JavaDoc value = "";
146         try
147         {
148             String JavaDoc xml = this.getXML();
149             
150             int startTagIndex = xml.indexOf("<" + key + ">");
151             int endTagIndex = xml.indexOf("]]></" + key + ">");
152
153             if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length())
154             {
155                 value = xml.substring(startTagIndex + key.length() + 11, endTagIndex);
156             }
157         }
158         catch(Exception JavaDoc e)
159         {
160             e.printStackTrace();
161         }
162
163         return value;
164     }
165
166     /**
167      * This method fetches the blob from the database and saves it on the disk.
168      * Then it returnes a url for it
169      */

170     
171     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
172     {
173         String JavaDoc imageHref = null;
174         try
175         {
176             imageHref = DigitalAssetController.getDigitalAssetUrl(digitalAssetId);
177         }
178         catch(Exception JavaDoc e)
179         {
180             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
181             imageHref = e.getMessage();
182         }
183         
184         return imageHref;
185     }
186     
187     
188     /**
189      * This method fetches the blob from the database and saves it on the disk.
190      * Then it returnes a url for it
191      */

192     
193     public String JavaDoc getDigitalAssetThumbnailUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
194     {
195         String JavaDoc imageHref = null;
196         try
197         {
198             imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(digitalAssetId);
199         }
200         catch(Exception JavaDoc e)
201         {
202             logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e);
203             imageHref = e.getMessage();
204         }
205         
206         return imageHref;
207     }
208
209     /**
210      * Gets the path to a content/sitenode.
211      * @param entity
212      * @param entityId
213      * @return
214      */

215
216     public String JavaDoc getQualifyerPath(String JavaDoc entity, String JavaDoc entityId)
217     {
218         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
219         try
220         {
221             if(entity.equalsIgnoreCase("Content"))
222             {
223                 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer JavaDoc(entityId));
224                 sb.insert(0, contentVO.getName() + "/");
225                 while(contentVO.getParentContentId() != null)
226                 {
227                     contentVO = ContentController.getContentController().getContentVOWithId(contentVO.getParentContentId());
228                     sb.insert(0, contentVO.getName() + "/");
229                 }
230             }
231             else if(entity.equalsIgnoreCase("SiteNode"))
232             {
233                 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(new Integer JavaDoc(entityId));
234                 sb.insert(0, siteNodeVO.getName() + "/");
235                 while(siteNodeVO.getParentSiteNodeId() != null)
236                 {
237                     siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVO.getParentSiteNodeId());
238                     sb.insert(0, siteNodeVO.getName() + "/");
239                 }
240             }
241         }
242         catch(Exception JavaDoc e)
243         {
244             e.printStackTrace();
245         }
246         return sb.toString();
247     }
248     
249     /**
250      * Returns the content relation qualifyers
251      * @param qualifyerXML
252      * @return
253      */

254
255     public List JavaDoc getContentRelationQualifyers(String JavaDoc qualifyerXML)
256     {
257         logger.info("Content qualifyerXML:" + qualifyerXML);
258         return parseQualifyersFromXML(qualifyerXML, "contentId");
259     }
260
261     /**
262      * Returns the sitenode relation qualifyers
263      * @param qualifyerXML
264      * @return
265      */

266
267     public List JavaDoc getSiteNodeRelationQualifyers(String JavaDoc qualifyerXML)
268     {
269         logger.info("Content qualifyerXML:" + qualifyerXML);
270         return parseQualifyersFromXML(qualifyerXML, "siteNodeId");
271     }
272
273     /**
274      * Parses qualifyers from an XML
275      * @param qualifyerXML
276      * @return
277      */

278
279     private List JavaDoc parseQualifyersFromXML(String JavaDoc qualifyerXML, String JavaDoc currentEntityIdentifyer)
280     {
281         List JavaDoc qualifyers = new ArrayList JavaDoc();
282         
283         if(qualifyerXML == null || qualifyerXML.length() == 0)
284             return qualifyers;
285         
286         try
287         {
288             Document document = new DOMBuilder().getDocument(qualifyerXML);
289             
290             String JavaDoc entity = document.getRootElement().attributeValue("entity");
291             
292             List JavaDoc children = document.getRootElement().elements();
293             Iterator JavaDoc i = children.iterator();
294             while(i.hasNext())
295             {
296                 Element child = (Element)i.next();
297                 String JavaDoc id = child.getStringValue();
298                 
299                 QualifyerVO qualifyerVO = new QualifyerVO();
300                 qualifyerVO.setName(currentEntityIdentifyer);
301                 qualifyerVO.setValue(id);
302                 qualifyerVO.setPath(this.getQualifyerPath(entity, id));
303                 //qualifyerVO.setSortOrder(new Integer(i));
304
qualifyers.add(qualifyerVO);
305             }
306         }
307         catch(Exception JavaDoc e)
308         {
309             e.printStackTrace();
310         }
311         
312         return qualifyers;
313     }
314
315     
316     /**
317      * Return the listing of Category attributes for this type of Content
318      */

319
320     public List JavaDoc getDefinedCategoryKeys()
321     {
322         try
323         {
324             if(getContentTypeDefinitionVO() != null)
325                 return ContentTypeDefinitionController.getController().getDefinedCategoryKeys(getContentTypeDefinitionVO().getSchemaValue());
326         }
327         catch(Exception JavaDoc e)
328         {
329             logger.warn("We could not fetch the list of defined category keys: " + e.getMessage(), e);
330         }
331
332         return Collections.EMPTY_LIST;
333     }
334
335     /**
336      * Returns the Category tree for the given Category id.
337      * @param categoryId The base Category
338      * @return A list of all Children (and their children, etc)
339      */

340     
341     public List JavaDoc getAvailableCategories(Integer JavaDoc categoryId)
342     {
343         try
344         {
345             String JavaDoc protectCategories = CmsPropertyHandler.getProtectCategories();
346             if(protectCategories != null && protectCategories.equalsIgnoreCase("true"))
347                 return getCategoryController().getAuthorizedActiveChildren(categoryId, this.getInfoGluePrincipal());
348             else
349                 return getCategoryController().findAllActiveChildren(categoryId);
350         }
351         catch(Exception JavaDoc e)
352         {
353             logger.warn("We could not fetch the list of categories: " + e.getMessage(), e);
354         }
355
356         return Collections.EMPTY_LIST;
357     }
358
359     
360     public CategoryController getCategoryController()
361     {
362         return categoryController;
363     }
364     
365     public PropertiesCategoryController getPropertiesCategoryController()
366     {
367         return propertiesCategoryController;
368     }
369
370     public String JavaDoc getArguments()
371     {
372         return arguments;
373     }
374     
375     public String JavaDoc getTitleKey()
376     {
377         return titleKey;
378     }
379     
380     public String JavaDoc getToolbarKey()
381     {
382         return toolbarKey;
383     }
384
385     public String JavaDoc getCurrentAction()
386     {
387         return currentAction;
388     }
389     
390     public void setCurrentAction(String JavaDoc currentAction)
391     {
392         this.currentAction = currentAction;
393     }
394     
395     public String JavaDoc getEntityName()
396     {
397         return entityName;
398     }
399     
400     public void setEntityName(String JavaDoc entityName)
401     {
402         this.entityName = entityName;
403     }
404     
405     public String JavaDoc getUpdateAction()
406     {
407         return updateAction;
408     }
409     
410     public void setUpdateAction(String JavaDoc updateAction)
411     {
412         this.updateAction = updateAction;
413     }
414     
415     public void setArguments(String JavaDoc arguments)
416     {
417         this.arguments = arguments;
418     }
419     
420     public void setTitleKey(String JavaDoc titleKey)
421     {
422         this.titleKey = titleKey;
423     }
424     
425     public void setToolbarKey(String JavaDoc toolbarKey)
426     {
427         this.toolbarKey = toolbarKey;
428     }
429     
430     public Integer JavaDoc getEntityId()
431     {
432         return entityId;
433     }
434     
435     public void setEntityId(Integer JavaDoc entityId)
436     {
437         this.entityId = entityId;
438     }
439     
440     public String JavaDoc getOwnerEntityId()
441     {
442         return ownerEntityId;
443     }
444     
445     public void setOwnerEntityId(String JavaDoc ownerEntityId)
446     {
447         this.ownerEntityId = ownerEntityId;
448     }
449     
450     public String JavaDoc getOwnerEntityName()
451     {
452         return ownerEntityName;
453     }
454     
455     public void setOwnerEntityName(String JavaDoc ownerEntityName)
456     {
457         this.ownerEntityName = ownerEntityName;
458     }
459     
460     public List JavaDoc getAvailableLanguages()
461     {
462         return availableLanguages;
463     }
464     
465     public void setAvailableLanguages(List JavaDoc availableLanguages)
466     {
467         this.availableLanguages = availableLanguages;
468     }
469     
470     public Integer JavaDoc getContentTypeDefinitionId()
471     {
472         return contentTypeDefinitionId;
473     }
474     
475     public void setContentTypeDefinitionId(Integer JavaDoc contentTypeDefinitionId)
476     {
477         this.contentTypeDefinitionId = contentTypeDefinitionId;
478     }
479     
480     public ContentTypeDefinitionVO getContentTypeDefinitionVO()
481     {
482         return contentTypeDefinitionVO;
483     }
484     
485     public void setContentTypeDefinitionVO(ContentTypeDefinitionVO contentTypeDefinitionVO)
486     {
487         this.contentTypeDefinitionVO = contentTypeDefinitionVO;
488     }
489     
490     public List JavaDoc getContentTypeDefinitionVOList()
491     {
492         return contentTypeDefinitionVOList;
493     }
494     
495     public void setContentTypeDefinitionVOList(List JavaDoc contentTypeDefinitionVOList)
496     {
497         this.contentTypeDefinitionVOList = contentTypeDefinitionVOList;
498     }
499     
500     public Integer JavaDoc getLanguageId()
501     {
502         return languageId;
503     }
504     
505     public void setLanguageId(Integer JavaDoc languageId)
506     {
507         this.languageId = languageId;
508     }
509     
510     public String JavaDoc getTextAreaId()
511     {
512         return textAreaId;
513     }
514     
515     public void setTextAreaId(String JavaDoc textAreaId)
516     {
517         this.textAreaId = textAreaId;
518     }
519     
520     public String JavaDoc getAttributeName()
521     {
522         return attributeName;
523     }
524     
525     public void setAttributeName(String JavaDoc attributeName)
526     {
527         this.attributeName = attributeName;
528     }
529     
530     public List JavaDoc getContentTypeAttributes()
531     {
532         return contentTypeAttributes;
533     }
534     
535     public void setAttributes(List JavaDoc contentTypeAttributes)
536     {
537         this.contentTypeAttributes = contentTypeAttributes;
538     }
539     
540     
541     public String JavaDoc getCancelAction()
542     {
543         return cancelAction;
544     }
545     
546     public void setCancelAction(String JavaDoc cancelAction)
547     {
548         this.cancelAction = cancelAction;
549     }
550 }
551
Popular Tags