KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.ByteArrayInputStream JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 import org.apache.log4j.Logger;
36 import org.dom4j.Document;
37 import org.dom4j.Element;
38 import org.infoglue.cms.applications.common.VisualFormatter;
39 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
40 import org.infoglue.cms.controllers.kernel.impl.simple.CategoryController;
41 import org.infoglue.cms.controllers.kernel.impl.simple.ComponentPropertyDefinitionController;
42 import org.infoglue.cms.controllers.kernel.impl.simple.ContentCategoryController;
43 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
44 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
45 import org.infoglue.cms.controllers.kernel.impl.simple.ContentStateController;
46 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
47 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
48 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy;
49 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController;
50 import org.infoglue.cms.controllers.kernel.impl.simple.EventController;
51 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
52 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
53 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
54 import org.infoglue.cms.entities.content.ContentVO;
55 import org.infoglue.cms.entities.content.ContentVersion;
56 import org.infoglue.cms.entities.content.ContentVersionVO;
57 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
58 import org.infoglue.cms.entities.management.LanguageVO;
59 import org.infoglue.cms.entities.structure.QualifyerVO;
60 import org.infoglue.cms.entities.structure.SiteNodeVO;
61 import org.infoglue.cms.entities.workflow.EventVO;
62 import org.infoglue.cms.exception.AccessConstraintException;
63 import org.infoglue.cms.exception.Bug;
64 import org.infoglue.cms.exception.ConstraintException;
65 import org.infoglue.cms.exception.SystemException;
66 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
67 import org.infoglue.cms.util.CmsPropertyHandler;
68 import org.infoglue.cms.util.css.CSSHelper;
69 import org.infoglue.cms.util.dom.DOMBuilder;
70
71 import com.opensymphony.module.propertyset.PropertySet;
72 import com.opensymphony.module.propertyset.PropertySetManager;
73
74
75 public class ViewContentVersionAction extends InfoGlueAbstractAction
76 {
77     private final static Logger logger = Logger.getLogger(ViewContentVersionAction.class.getName());
78
79     private static final long serialVersionUID = 1L;
80     
81     private static CategoryController categoryController = CategoryController.getController();
82     private static ContentCategoryController contentCategoryController = ContentCategoryController.getController();
83
84     private Integer JavaDoc unrefreshedContentId = new Integer JavaDoc(0);
85     private Integer JavaDoc changeTypeId = new Integer JavaDoc(0);
86     private Integer JavaDoc newContentId = new Integer JavaDoc(0);
87     
88     private Integer JavaDoc digitalAssetId = null;
89     public ContentTypeDefinitionVO contentTypeDefinitionVO;
90     public List JavaDoc availableLanguages = null;
91     
92     private Integer JavaDoc languageId;
93     private Integer JavaDoc repositoryId;
94     private Integer JavaDoc currentEditorId;
95     private String JavaDoc attributeName = "";
96     private String JavaDoc textAreaId = "";
97     private boolean forceWorkingChange = false;
98             
99     private ContentVO contentVO;
100     protected ContentVersionVO contentVersionVO;
101     public List JavaDoc attributes = null;
102
103     private List JavaDoc repositories;
104     
105     //This is used for showing navigationdata
106
private Integer JavaDoc siteNodeId;
107
108     private Integer JavaDoc oldContentId = null;
109     private String JavaDoc assetKey = null;
110     private boolean treatAsLink = false;
111     
112     private Map JavaDoc WYSIWYGProperties = null;
113     
114     private String JavaDoc closeOnLoad = "false";
115     private String JavaDoc publishOnLoad = "false";
116
117     private boolean concurrentModification = false;
118     private long oldModifiedDateTime = -1;
119     
120     public String JavaDoc getQualifyerPath(String JavaDoc entity, String JavaDoc entityId)
121     {
122         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
123         try
124         {
125             if(entity.equalsIgnoreCase("Content"))
126             {
127                 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer JavaDoc(entityId));
128                 sb.insert(0, contentVO.getName() + "/");
129                 while(contentVO.getParentContentId() != null)
130                 {
131                     contentVO = ContentController.getContentController().getContentVOWithId(contentVO.getParentContentId());
132                     sb.insert(0, contentVO.getName() + "/");
133                 }
134             }
135             else if(entity.equalsIgnoreCase("SiteNode"))
136             {
137                 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(new Integer JavaDoc(entityId));
138                 sb.insert(0, siteNodeVO.getName() + "/");
139                 while(siteNodeVO.getParentSiteNodeId() != null)
140                 {
141                     siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVO.getParentSiteNodeId());
142                     sb.insert(0, siteNodeVO.getName() + "/");
143                 }
144             }
145         }
146         catch(Exception JavaDoc e)
147         {
148             e.printStackTrace();
149         }
150         return sb.toString();
151     }
152
153
154     public List JavaDoc getContentRelationQualifyers(String JavaDoc qualifyerXML)
155     {
156         logger.info("Content qualifyerXML:" + qualifyerXML);
157         return parseQualifyersFromXML(qualifyerXML, "contentId");
158     }
159
160     public List JavaDoc getSiteNodeRelationQualifyers(String JavaDoc qualifyerXML)
161     {
162         logger.info("Content qualifyerXML:" + qualifyerXML);
163         return parseQualifyersFromXML(qualifyerXML, "siteNodeId");
164     }
165
166     public List JavaDoc getComponentPropertyDefinitions(String JavaDoc componentPropertiesXML)
167     {
168         return ComponentPropertyDefinitionController.getController().parseComponentPropertyDefinitions(componentPropertiesXML);
169     }
170     
171     
172     private List JavaDoc parseQualifyersFromXML(String JavaDoc qualifyerXML, String JavaDoc currentEntityIdentifyer)
173     {
174         List JavaDoc qualifyers = new ArrayList JavaDoc();
175         
176         if(qualifyerXML == null || qualifyerXML.length() == 0)
177             return qualifyers;
178         
179         try
180         {
181             Document document = new DOMBuilder().getDocument(qualifyerXML);
182             
183             String JavaDoc entity = document.getRootElement().attributeValue("entity");
184             
185             List JavaDoc children = document.getRootElement().elements();
186             Iterator JavaDoc i = children.iterator();
187             while(i.hasNext())
188             {
189                 Element child = (Element)i.next();
190                 String JavaDoc id = child.getStringValue();
191                 
192                 QualifyerVO qualifyerVO = new QualifyerVO();
193                 qualifyerVO.setName(currentEntityIdentifyer);
194                 qualifyerVO.setValue(id);
195                 qualifyerVO.setPath(this.getQualifyerPath(entity, id));
196                 //qualifyerVO.setSortOrder(new Integer(i));
197
qualifyers.add(qualifyerVO);
198             }
199         }
200         catch(Exception JavaDoc e)
201         {
202             e.printStackTrace();
203         }
204         
205         return qualifyers;
206     }
207     
208     public ViewContentVersionAction()
209     {
210         this(new ContentVO(), new ContentVersionVO());
211     }
212     
213     public ViewContentVersionAction(ContentVO contentVO, ContentVersionVO contentVersionVO)
214     {
215         this.contentVO = contentVO;
216         this.contentVersionVO = contentVersionVO;
217     }
218
219     protected void initialize(Integer JavaDoc contentVersionId, Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
220     {
221         initialize(contentVersionId, contentId, languageId, false, true);
222     }
223     
224     protected void initialize(Integer JavaDoc contentVersionId, Integer JavaDoc contentId, Integer JavaDoc languageId, boolean fallBackToMasterLanguage, boolean checkPermission) throws ConstraintException, Exception JavaDoc
225     {
226         this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId);
227             
228         if(this.contentVO.getRepositoryId() != null && checkPermission && !hasAccessTo("Repository.Read", "" + this.contentVO.getRepositoryId()))
229         {
230             AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
231             ceb.add(new AccessConstraintException("Content.contentId", "1000"));
232             ceb.throwIfNotEmpty();
233         }
234
235         //this.contentVO = ContentController.getContentVOWithId(contentId);
236
this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentId);
237         this.availableLanguages = ContentController.getContentController().getRepositoryLanguages(contentId);
238         
239         if(contentVersionId == null)
240         {
241             //this.contentVersionVO = ContentVersionControllerProxy.getController().getACLatestActiveContentVersionVO(this.getInfoGluePrincipal(), contentId, languageId);
242
//this.contentVersionVO = ContentVersionController.getLatestActiveContentVersionVO(contentId, languageId);
243
this.contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
244             if(this.contentVersionVO == null && fallBackToMasterLanguage)
245             {
246                 //logger.info("repositoryId:" + repositoryId);
247
Integer JavaDoc usedRepositoryId = this.repositoryId;
248                 if(this.repositoryId == null && this.contentVO != null)
249                     usedRepositoryId = this.contentVO.getRepositoryId();
250                 
251                 LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(usedRepositoryId);
252                 //logger.info("MasterLanguage: " + masterLanguageVO);
253
this.contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, masterLanguageVO.getId());
254             }
255             
256             if(this.contentVersionVO != null)
257                 contentVersionId = contentVersionVO.getContentVersionId();
258         }
259
260         if(contentVersionId != null)
261             this.contentVersionVO = ContentVersionControllerProxy.getController().getACContentVersionVOWithId(this.getInfoGluePrincipal(), contentVersionId);
262             //this.contentVersionVO = ContentVersionController.getContentVersionVOWithId(contentVersionId);
263

264         if(this.forceWorkingChange && contentVersionVO != null && !contentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE))
265         {
266             ContentVersion contentVersion = ContentStateController.changeState(contentVersionVO.getContentVersionId(), ContentVersionVO.WORKING_STATE, "Edit on sight", false, this.getInfoGluePrincipal(), this.getContentId(), new ArrayList JavaDoc());
267             contentVersionId = contentVersion.getContentVersionId();
268             contentVersionVO = contentVersion.getValueObject();
269         }
270
271         if(this.contentTypeDefinitionVO != null)
272         {
273             this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().validateAndUpdateContentType(this.contentTypeDefinitionVO);
274             this.attributes = ContentTypeDefinitionController.getController().getContentTypeAttributes(this.contentTypeDefinitionVO.getSchemaValue());
275         }
276     }
277
278     public String JavaDoc doExecute() throws Exception JavaDoc
279     {
280         this.initialize(getContentVersionId(), getContentId(), this.languageId);
281         
282         String JavaDoc wysiwygEditor = CmsPropertyHandler.getWysiwygEditor();
283         if(wysiwygEditor == null || wysiwygEditor.equalsIgnoreCase("") || wysiwygEditor.equalsIgnoreCase("HTMLArea"))
284             return "success";
285         else
286             return "successForFCKEditor";
287     }
288     
289
290     public String JavaDoc doStandalone() throws Exception JavaDoc
291     {
292         this.initialize(getContentVersionId(), getContentId(), this.languageId);
293             
294         String JavaDoc wysiwygEditor = CmsPropertyHandler.getWysiwygEditor();
295         if(wysiwygEditor == null || wysiwygEditor.equalsIgnoreCase("") || wysiwygEditor.equalsIgnoreCase("HTMLArea"))
296             return "standalone";
297         else
298             return "standaloneForFCKEditor";
299     }
300
301     public String JavaDoc doBackground() throws Exception JavaDoc
302     {
303         this.initialize(getContentVersionId(), getContentId(), this.languageId);
304         return "background";
305     }
306     
307     public String JavaDoc doViewAssetsDialog() throws Exception JavaDoc
308     {
309         if(this.oldContentId != null)
310         {
311             this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getOldContentId());
312         }
313         else
314         {
315             if(getContentId() != null && getContentId().intValue() != -1)
316                 this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getContentId());
317         }
318         
319         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
320
321         return "viewAssetsDialog";
322     }
323
324     public String JavaDoc doViewAssetsDialogForFCKEditor() throws Exception JavaDoc
325     {
326         if(this.oldContentId != null)
327         {
328             this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getOldContentId());
329         }
330         else
331         {
332             if(getContentId() != null && getContentId().intValue() != -1)
333                 this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getContentId());
334         }
335         
336         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
337
338         return "viewAssetsDialogForFCKEditor";
339     }
340     
341     
342     public String JavaDoc doViewAssets() throws Exception JavaDoc
343     {
344         if(getContentId() != null && getContentId().intValue() != -1)
345         {
346             this.initialize(getContentVersionId(), getContentId(), this.languageId, true, false);
347         }
348
349         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
350
351         return "viewAssets";
352     }
353
354     public String JavaDoc doViewAssetsForFCKEditor() throws Exception JavaDoc
355     {
356         if(getContentId() != null && getContentId().intValue() != -1)
357         {
358             this.initialize(getContentVersionId(), getContentId(), this.languageId, true, false);
359         }
360
361         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
362
363         return "viewAssetsForFCKEditor";
364     }
365
366     public String JavaDoc doPreview() throws Exception JavaDoc
367     {
368         this.initialize(getContentVersionId(), getContentId(), this.languageId);
369         return "preview";
370     }
371
372     public String JavaDoc doDeleteDigitalAsset() throws Exception JavaDoc
373     {
374         ContentVersionController.getContentVersionController().deleteDigitalAssetRelation(getContentVersionId(), this.digitalAssetId);
375         //this.initialize(getContentVersionId(), getContentId(), this.languageId);
376
//return "success";
377
return doExecute();
378     }
379     
380     public String JavaDoc doDeleteDigitalAssetStandalone() throws Exception JavaDoc
381     {
382         ContentVersionController.getContentVersionController().deleteDigitalAssetRelation(getContentVersionId(), this.digitalAssetId);
383         //this.initialize(getContentVersionId(), getContentId(), this.languageId);
384
//return "success";
385
return doStandalone();
386     }
387     
388     public EventVO getEvent(Integer JavaDoc contentVersionId)
389     {
390         EventVO eventVO = null;
391         try
392         {
393             if(contentVersionId != null)
394             {
395                 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId);
396                 List JavaDoc events = EventController.getEventVOListForEntity(ContentVersion.class.getName(), contentVersion.getId());
397                 if(events != null && events.size() > 0)
398                     eventVO = (EventVO)events.get(0);
399             }
400         }
401         catch(Exception JavaDoc e)
402         {
403             logger.error("An error occurred when we tried to get any events for this version:" + e.getMessage(), e);
404         }
405         
406         return eventVO;
407     }
408
409     public List JavaDoc getContentPath()
410     {
411         ContentVO contentVO = this.contentVO;
412         List JavaDoc ret = new ArrayList JavaDoc();
413         // ret.add(0, contentVO);
414

415         while (contentVO.getParentContentId() != null)
416         {
417             try {
418                 contentVO = ContentControllerProxy.getController().getContentVOWithId(contentVO.getParentContentId());
419             } catch (SystemException e) {
420                 // TODO Auto-generated catch block
421
e.printStackTrace();
422             } catch (Bug e) {
423                 // TODO Auto-generated catch block
424
e.printStackTrace();
425             }
426             ret.add(0, contentVO);
427         }
428         return ret;
429     }
430
431     public java.lang.Integer JavaDoc getContentVersionId()
432     {
433         if(this.contentVersionVO != null)
434             return this.contentVersionVO.getContentVersionId();
435         else
436             return null;
437     }
438     
439     public void setContentVersionId(java.lang.Integer JavaDoc contentVersionId)
440     {
441         this.contentVersionVO.setContentVersionId(contentVersionId);
442     }
443         
444     public java.lang.Integer JavaDoc getContentId()
445     {
446         return this.contentVO.getContentId();
447     }
448         
449     public void setContentId(java.lang.Integer JavaDoc contentId)
450     {
451         this.contentVO.setContentId(contentId);
452     }
453     
454     public java.lang.Integer JavaDoc getContentTypeDefinitionId()
455     {
456         return this.contentTypeDefinitionVO.getContentTypeDefinitionId();
457     }
458
459     public String JavaDoc getContentTypeDefinitionName()
460     {
461         return this.contentTypeDefinitionVO.getName();
462     }
463             
464     public void setLanguageId(Integer JavaDoc languageId)
465     {
466         this.languageId = languageId;
467     }
468
469     public java.lang.Integer JavaDoc getLanguageId()
470     {
471         return this.languageId;
472     }
473     
474     public void setStateId(Integer JavaDoc stateId)
475     {
476         if(this.contentVersionVO != null)
477             this.contentVersionVO.setStateId(stateId);
478     }
479
480     public void setVersionComment(String JavaDoc versionComment)
481     {
482         if(this.contentVersionVO != null)
483             this.contentVersionVO.setVersionComment(versionComment);
484     }
485
486     public void setDigitalAssetId(Integer JavaDoc digitalAssetId)
487     {
488         this.digitalAssetId = digitalAssetId;
489     }
490     
491     public String JavaDoc getVersionComment()
492     {
493         return this.contentVersionVO.getVersionComment();
494     }
495     
496     public Integer JavaDoc getStateId()
497     {
498         return this.contentVersionVO.getStateId();
499     }
500
501     public Boolean JavaDoc getIsActive()
502     {
503         return this.contentVersionVO.getIsActive();
504     }
505             
506     public String JavaDoc getName()
507     {
508         return this.contentVO.getName();
509     }
510
511     public java.lang.Integer JavaDoc getRepositoryId()
512     {
513         if(this.contentVO != null && this.contentVO.getRepositoryId() != null)
514             return this.contentVO.getRepositoryId();
515         else
516             return this.repositoryId;
517     }
518
519     public List JavaDoc getAvailableLanguages()
520     {
521         return this.availableLanguages;
522     }
523
524     /**
525      * Returns a list of digital assets available for this content version.
526      */

527     
528     public List JavaDoc getDigitalAssets()
529     {
530         List JavaDoc digitalAssets = null;
531         
532         try
533         {
534             if(this.contentVersionVO != null && this.contentVersionVO.getContentVersionId() != null)
535             {
536                 digitalAssets = DigitalAssetController.getDigitalAssetVOList(this.contentVersionVO.getContentVersionId());
537             }
538         }
539         catch(Exception JavaDoc e)
540         {
541             logger.warn("We could not fetch the list of digitalAssets: " + e.getMessage(), e);
542         }
543         
544         return digitalAssets;
545     }
546     
547     /**
548      * Returns a list of digital assets available for this content version.
549      */

550     
551     public List JavaDoc getInheritedDigitalAssets()
552     {
553         List JavaDoc digitalAssets = null;
554         
555         try
556         {
557             if(this.contentVO != null && this.contentVO.getContentId() != null && this.contentVO.getContentId().intValue() != -1)
558             {
559                 digitalAssets = DigitalAssetController.getDigitalAssetVOList(this.contentVO.getContentId(), this.languageId, true);
560             }
561             /*
562             if(this.contentVersionVO != null && this.contentVersionVO.getContentVersionId() != null)
563             {
564                 digitalAssets = DigitalAssetController.getDigitalAssetVOList(this.contentVersionVO.getContentVersionId());
565             }
566             */

567         }
568         catch(Exception JavaDoc e)
569         {
570             logger.warn("We could not fetch the list of digitalAssets: " + e.getMessage(), e);
571         }
572         
573         return digitalAssets;
574     }
575
576
577     /**
578      * This method fetches the blob from the database and saves it on the disk.
579      * Then it returnes a url for it
580      */

581     
582     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
583     {
584         String JavaDoc imageHref = null;
585         try
586         {
587             imageHref = DigitalAssetController.getDigitalAssetUrl(digitalAssetId);
588         }
589         catch(Exception JavaDoc e)
590         {
591             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
592             imageHref = e.getMessage();
593         }
594         
595         return imageHref;
596     }
597     
598     
599     /**
600      * This method fetches the blob from the database and saves it on the disk.
601      * Then it returnes a url for it
602      */

603     
604     public String JavaDoc getDigitalAssetThumbnailUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
605     {
606         String JavaDoc imageHref = null;
607         try
608         {
609             imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(digitalAssetId);
610         }
611         catch(Exception JavaDoc e)
612         {
613             logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e);
614             imageHref = e.getMessage();
615         }
616         
617         return imageHref;
618     }
619
620     
621     /**
622      * This method fetches the blob from the database and saves it on the disk.
623      * Then it returnes a url for it
624      */

625     
626     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
627     {
628         String JavaDoc imageHref = null;
629         try
630         {
631             imageHref = DigitalAssetController.getDigitalAssetUrl(contentId, languageId);
632         }
633         catch(Exception JavaDoc e)
634         {
635             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
636             imageHref = e.getMessage();
637         }
638         
639         return imageHref;
640     }
641     
642     
643     /**
644      * This method fetches the blob from the database and saves it on the disk.
645      * Then it returnes a url for it
646      */

647     
648     public String JavaDoc getDigitalAssetThumbnailUrl(Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
649     {
650         String JavaDoc imageHref = null;
651         try
652         {
653             imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(contentId, languageId);
654         }
655         catch(Exception JavaDoc e)
656         {
657             logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e);
658             imageHref = e.getMessage();
659         }
660         
661         return imageHref;
662     }
663     
664
665     
666     /**
667      * This method fetches a value from the xml that is the contentVersions Value. If the
668      * contentVersioVO is null the contentVersion has not been created yet and no values are present.
669      */

670      
671     public String JavaDoc getAttributeValue(String JavaDoc key)
672     {
673         String JavaDoc value = "";
674         
675         //System.out.println("this.contentVersionVO:" + this.contentVersionVO);
676

677         if(this.contentVersionVO != null)
678         {
679             try
680             {
681                 logger.info("key:" + key);
682                 logger.info("VersionValue:" + this.contentVersionVO.getVersionValue());
683         
684                 String JavaDoc xml = this.contentVersionVO.getVersionValue();
685                 
686                 int startTagIndex = xml.indexOf("<" + key + ">");
687                 int endTagIndex = xml.indexOf("]]></" + key + ">");
688
689                 if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length())
690                 {
691                     value = xml.substring(startTagIndex + key.length() + 11, endTagIndex);
692                     value = new VisualFormatter().escapeHTML(value);
693                 }
694                 
695                 /*
696                 InputSource inputSource = new InputSource(new StringReader(this.contentVersionVO.getVersionValue()));
697                 
698                 DOMParser parser = new DOMParser();
699                 parser.parse(inputSource);
700                 Document document = parser.getDocument();
701                 NodeList nl = document.getDocumentElement().getChildNodes();
702                 Node n = nl.item(0);
703
704                 nl = n.getChildNodes();
705                 for(int i=0; i<nl.getLength(); i++)
706                 {
707                     n = nl.item(i);
708                     if(n.getNodeName().equalsIgnoreCase(key))
709                     {
710                         if(n.getFirstChild() != null && n.getFirstChild().getNodeValue() != null)
711                         {
712                             value = n.getFirstChild().getNodeValue();
713                             logger.info("Getting value: " + value);
714
715                             //logger.info("VersionValue:" + value);
716                             if(value != null)
717                                 value = new VisualFormatter().escapeHTML(value);
718                             
719                             break;
720                         }
721                     }
722                 }
723                 */

724             }
725             catch(Exception JavaDoc e)
726             {
727                 e.printStackTrace();
728             }
729         }
730         
731         logger.info("value:" + value);
732         
733         return value;
734     }
735     
736     /**
737      * This method fetches a value from the xml that is the contentVersions Value. If the
738      * contentVersioVO is null the contentVersion has not been created yet and no values are present.
739      */

740      
741     public String JavaDoc getUnescapedAttributeValue(String JavaDoc key)
742     {
743         String JavaDoc value = "";
744         if(this.contentVersionVO != null)
745         {
746             try
747             {
748                 logger.info("key:" + key);
749                 logger.info("VersionValue:" + this.contentVersionVO.getVersionValue());
750                 
751                 String JavaDoc xml = this.contentVersionVO.getVersionValue();
752                 
753                 int startTagIndex = xml.indexOf("<" + key + ">");
754                 int endTagIndex = xml.indexOf("]]></" + key + ">");
755
756                 if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length())
757                 {
758                     value = xml.substring(startTagIndex + key.length() + 11, endTagIndex);
759                 }
760
761                 /*
762                 InputSource inputSource = new InputSource(new StringReader(this.contentVersionVO.getVersionValue()));
763                 
764                 DOMParser parser = new DOMParser();
765                 parser.parse(inputSource);
766                 Document document = parser.getDocument();
767                 NodeList nl = document.getDocumentElement().getChildNodes();
768                 Node n = nl.item(0);
769
770                 nl = n.getChildNodes();
771                 for(int i=0; i<nl.getLength(); i++)
772                 {
773                     n = nl.item(i);
774                     if(n.getNodeName().equalsIgnoreCase(key))
775                     {
776                         if(n.getFirstChild() != null && n.getFirstChild().getNodeValue() != null)
777                         {
778                             value = n.getFirstChild().getNodeValue();
779                             logger.info("Getting value: " + value);
780                             break;
781                         }
782                     }
783                 }
784                 */

785             }
786             catch(Exception JavaDoc e)
787             {
788                 e.printStackTrace();
789             }
790         }
791         //logger.info("value:" + value);
792
return value;
793     }
794     
795     /**
796      * This method returns the attributes in the content type definition for generation.
797      */

798     
799     public List JavaDoc getContentTypeAttributes()
800     {
801         return this.attributes;
802     }
803
804     public ContentVersionVO getContentVersionVO()
805     {
806         return contentVersionVO;
807     }
808
809     /**
810      * This method gets the WYSIWYG Properties
811      */

812     
813     public Map JavaDoc getWYSIWYGProperties() throws Exception JavaDoc
814     {
815         if(this.WYSIWYGProperties != null)
816             return this.WYSIWYGProperties;
817         
818         //First we got the values from repository properties...
819
Map JavaDoc args = new HashMap JavaDoc();
820         args.put("globalKey", "infoglue");
821         PropertySet ps = PropertySetManager.getInstance("jdbc", args);
822         
823         byte[] WYSIWYGConfigBytes = ps.getData("repository_" + this.getRepositoryId() + "_WYSIWYGConfig");
824         if(WYSIWYGConfigBytes != null)
825         {
826             Properties JavaDoc properties = new Properties JavaDoc();
827             properties.load(new ByteArrayInputStream JavaDoc(WYSIWYGConfigBytes));
828             this.WYSIWYGProperties = properties;
829         }
830         
831         //Now we add the overridden parameters in role/user properties.
832
Map JavaDoc principalWYSIWYGProperties = getPrincipalPropertyHashValues("WYSIWYGConfig", false);
833         
834         if(this.WYSIWYGProperties != null)
835         {
836             logger.info("this.WYSIWYGProperties:" + this.WYSIWYGProperties.size());
837             
838             //Clear sections of the configuration if overridden
839
if(principalWYSIWYGProperties.containsKey("toolbar_line0_position0"))
840             {
841                 for(int lineIndex=0; lineIndex<3; lineIndex++)
842                 {
843                     for(int colIndex=0; colIndex<30; colIndex++)
844                     {
845                         WYSIWYGProperties.remove("toolbar_line" + lineIndex + "_position" + colIndex);
846                     }
847                 }
848             }
849     
850             if(principalWYSIWYGProperties.containsKey("css.url.0"))
851             {
852                 for(int index=0; index<10; index++)
853                 {
854                     WYSIWYGProperties.remove("css.url." + index);
855                 }
856             }
857     
858             if(principalWYSIWYGProperties.containsKey("css.class.0"))
859             {
860                 for(int index=0; index<50; index++)
861                 {
862                     WYSIWYGProperties.remove("css.class." + index);
863                 }
864             }
865         }
866         else
867         {
868             this.WYSIWYGProperties = new HashMap JavaDoc();
869         }
870         
871         //Now we add the new properties
872
this.WYSIWYGProperties.putAll(principalWYSIWYGProperties);
873         
874         return this.WYSIWYGProperties;
875     }
876     
877     /**
878      * This method returns a list of css-classes available to the WYSIWYG.
879      */

880     
881     public List JavaDoc getCSSRules(String JavaDoc url)
882     {
883         logger.info("url:" + url);
884         CSSHelper cssHelper = CSSHelper.getHelper();
885         cssHelper.setCSSUrl(url);
886         
887         return cssHelper.getCSSRules();
888     }
889
890     /**
891      * This method returns a infoglue-specific PropertySet
892      */

893
894     public boolean getEnableCSSPlugin() throws Exception JavaDoc
895     {
896         boolean enableCSSPlugin = false;
897         
898         Map JavaDoc properties = getWYSIWYGProperties();
899
900         String JavaDoc enableCSSPluginString = (String JavaDoc)properties.get("enableCSSPlugin");
901         if(enableCSSPluginString != null && enableCSSPluginString.trim().equalsIgnoreCase("true"))
902         {
903             enableCSSPlugin = true;
904         }
905         
906         return enableCSSPlugin;
907     }
908     
909     /**
910      * This method returns a infoglue-specific PropertySet
911      */

912
913     public List JavaDoc getCSSList() throws Exception JavaDoc
914     {
915         List JavaDoc cssList = new ArrayList JavaDoc();
916         
917         Map JavaDoc properties = getWYSIWYGProperties();
918
919         int index = 0;
920         String JavaDoc cssUrl = (String JavaDoc)properties.get("css.url." + index);
921         while(cssUrl != null)
922         {
923             cssList.add(cssUrl);
924             index++;
925             cssUrl = (String JavaDoc)properties.get("css.url." + index);
926         }
927         
928         return cssList;
929     }
930     
931     /**
932      * This method returns a infoglue-specific PropertySet
933      */

934
935     public List JavaDoc getAllowedClasses() throws Exception JavaDoc
936     {
937         List JavaDoc allowedClasses = new ArrayList JavaDoc();
938         
939         Map JavaDoc properties = getWYSIWYGProperties();
940         
941         int index = 0;
942         String JavaDoc cssUrl = (String JavaDoc)properties.get("css.class." + index);
943         while(cssUrl != null)
944         {
945             allowedClasses.add(cssUrl);
946             index++;
947             cssUrl = (String JavaDoc)properties.get("css.class." + index);
948         }
949         
950         return allowedClasses;
951     }
952     
953     
954     /**
955      * This method returns the base-url to the delivery-engine.
956      */

957     
958     public String JavaDoc getDeliveryBaseUrl()
959     {
960         String JavaDoc previewDeliveryUrl = CmsPropertyHandler.getPreviewDeliveryUrl();
961         int index = previewDeliveryUrl.lastIndexOf("/");
962         if(index > 0)
963         {
964             previewDeliveryUrl = previewDeliveryUrl.substring(0, index);
965         }
966         return previewDeliveryUrl;
967     }
968
969     /**
970      * Return the listing of Category attributes for this type of Content
971      */

972     public List JavaDoc getDefinedCategoryKeys()
973     {
974         try
975         {
976             if(contentTypeDefinitionVO != null)
977                 return ContentTypeDefinitionController.getController().getDefinedCategoryKeys(contentTypeDefinitionVO.getSchemaValue());
978         }
979         catch(Exception JavaDoc e)
980         {
981             logger.warn("We could not fetch the list of defined category keys: " + e.getMessage(), e);
982         }
983
984         return Collections.EMPTY_LIST;
985     }
986
987     /**
988      * Returns the Category tree for the given Category id.
989      * @param categoryId The base Category
990      * @return A list of all Children (and their children, etc)
991      */

992     public List JavaDoc getAvailableCategories(Integer JavaDoc categoryId)
993     {
994         try
995         {
996             String JavaDoc protectCategories = CmsPropertyHandler.getProtectCategories();
997             if(protectCategories != null && protectCategories.equalsIgnoreCase("true"))
998                 return categoryController.getAuthorizedActiveChildren(categoryId, this.getInfoGluePrincipal());
999             else
1000                return categoryController.findAllActiveChildren(categoryId);
1001        }
1002        catch(Exception JavaDoc e)
1003        {
1004            logger.warn("We could not fetch the list of categories: " + e.getMessage(), e);
1005        }
1006
1007        return Collections.EMPTY_LIST;
1008    }
1009
1010    /**
1011     * Returns all current Category relationships for th specified attrbiute name
1012     * @param attribute
1013     * @return
1014     */

1015    public List JavaDoc getRelatedCategories(String JavaDoc attribute)
1016    {
1017        try
1018        {
1019            if(this.contentVersionVO != null && this.contentVersionVO.getContentVersionId() != null)
1020                return contentCategoryController.findByContentVersionAttribute(attribute, contentVersionVO.getContentVersionId());
1021        }
1022        catch(Exception JavaDoc e)
1023        {
1024            logger.warn("We could not fetch the list of defined category keys: " + e.getMessage(), e);
1025        }
1026
1027        return Collections.EMPTY_LIST;
1028    }
1029    
1030    public ContentVersionVO getMasterContentVersionVO(Integer JavaDoc contentId, Integer JavaDoc repositoryId) throws SystemException, Exception JavaDoc
1031    {
1032        LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(repositoryId);
1033        return ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, masterLanguageVO.getId());
1034    }
1035
1036    public ContentVersionVO getLatestContentVersionVO(Integer JavaDoc contentId, Integer JavaDoc languageId) throws SystemException, Exception JavaDoc
1037    {
1038        return ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
1039    }
1040
1041    public Integer JavaDoc getCurrentEditorId()
1042    {
1043        return currentEditorId;
1044    }
1045
1046    public void setCurrentEditorId(Integer JavaDoc integer)
1047    {
1048        currentEditorId = integer;
1049    }
1050
1051    public String JavaDoc getAttributeName()
1052    {
1053        return this.attributeName;
1054    }
1055
1056    public void setAttributeName(String JavaDoc attributeName)
1057    {
1058        this.attributeName = attributeName;
1059    }
1060
1061    public String JavaDoc getTextAreaId()
1062    {
1063        return this.textAreaId;
1064    }
1065
1066    public void setTextAreaId(String JavaDoc textAreaId)
1067    {
1068        this.textAreaId = textAreaId;
1069    }
1070
1071    public Integer JavaDoc getSiteNodeId()
1072    {
1073        return this.siteNodeId;
1074    }
1075
1076    public void setSiteNodeId(Integer JavaDoc siteNodeId)
1077    {
1078        this.siteNodeId = siteNodeId;
1079    }
1080
1081    public void setRepositoryId(Integer JavaDoc repositoryId)
1082    {
1083        this.repositoryId = repositoryId;
1084    }
1085    
1086    public List JavaDoc getRepositories()
1087    {
1088        return repositories;
1089    }
1090    
1091    public String JavaDoc getAssetKey()
1092    {
1093        return assetKey;
1094    }
1095    
1096    public void setAssetKey(String JavaDoc assetKey)
1097    {
1098        this.assetKey = assetKey;
1099    }
1100    
1101    public Integer JavaDoc getOldContentId()
1102    {
1103        return oldContentId;
1104    }
1105    
1106    public void setOldContentId(Integer JavaDoc oldContentId)
1107    {
1108        this.oldContentId = oldContentId;
1109    }
1110    
1111    public boolean getTreatAsLink()
1112    {
1113        return treatAsLink;
1114    }
1115    
1116    public void setTreatAsLink(boolean treatAsLink)
1117    {
1118        this.treatAsLink = treatAsLink;
1119    }
1120    
1121    public ContentVO getContentVO()
1122    {
1123        return contentVO;
1124    }
1125    
1126    public String JavaDoc getCloseOnLoad()
1127    {
1128        return closeOnLoad;
1129    }
1130    
1131    public void setCloseOnLoad(String JavaDoc closeOnLoad)
1132    {
1133        this.closeOnLoad = closeOnLoad;
1134    }
1135    
1136    public Integer JavaDoc getNewContentId()
1137    {
1138        return newContentId;
1139    }
1140    
1141    public void setNewContentId(Integer JavaDoc newContentId)
1142    {
1143        this.newContentId = newContentId;
1144    }
1145    
1146    public void setContentVersionVO(ContentVersionVO contentVersionVO)
1147    {
1148        this.contentVersionVO = contentVersionVO;
1149    }
1150    
1151    public ContentTypeDefinitionVO getContentTypeDefinitionVO()
1152    {
1153        return contentTypeDefinitionVO;
1154    }
1155
1156    public boolean getConcurrentModification()
1157    {
1158        return concurrentModification;
1159    }
1160
1161    public void setConcurrentModification(boolean concurrentModification)
1162    {
1163        this.concurrentModification = concurrentModification;
1164    }
1165
1166    public long getOldModifiedDateTime()
1167    {
1168        return oldModifiedDateTime;
1169    }
1170
1171    public void setOldModifiedDateTime(long oldModifiedDateTime)
1172    {
1173        this.oldModifiedDateTime = oldModifiedDateTime;
1174    }
1175    
1176    public void setForceWorkingChange(boolean forceWorkingChange)
1177    {
1178        this.forceWorkingChange = forceWorkingChange;
1179    }
1180
1181    public String JavaDoc getPublishOnLoad() {
1182        return publishOnLoad;
1183    }
1184
1185    public void setPublishOnLoad(String JavaDoc publishOnLoad) {
1186        this.publishOnLoad = publishOnLoad;
1187    }
1188}
1189
Popular Tags