KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
25  * Work in progress
26  * @author Stefan Sik
27  */

28 package org.infoglue.cms.applications.contenttool.actions;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34
35 import org.apache.log4j.Logger;
36 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
37 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
38 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
39 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy;
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.RepositoryController;
43 import org.infoglue.cms.entities.content.ContentVO;
44 import org.infoglue.cms.entities.content.ContentVersionVO;
45 import org.infoglue.cms.entities.content.DigitalAssetVO;
46 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
47 import org.infoglue.cms.entities.management.LanguageVO;
48 import org.infoglue.cms.exception.Bug;
49 import org.infoglue.cms.exception.ConstraintException;
50 import org.infoglue.cms.exception.SystemException;
51 import org.infoglue.deliver.util.MathHelper;
52
53
54 public class ViewAssetListAction extends InfoGlueAbstractAction
55 {
56     private final static Logger logger = Logger.getLogger(ViewAssetListAction.class.getName());
57
58     /**
59      * Action class for the DigitalAsset Browser.
60      * TODO: Improve performance by adding more specialized
61      * methods in DigitalAssetController to search and filter assets
62      */

63     private static final long serialVersionUID = 1707633990701035545L;
64
65     public ContentTypeDefinitionVO contentTypeDefinitionVO;
66     private Integer JavaDoc maxResultCount = new Integer JavaDoc(20); // TODO: Configuration
67
public List JavaDoc availableLanguages = null;
68     
69     private Integer JavaDoc languageId;
70     private Integer JavaDoc repositoryId;
71     private ContentVO contentVO;
72     public List JavaDoc attributes = null;
73
74     private List JavaDoc repositories;
75     private List JavaDoc filters;
76     private String JavaDoc filter = "";
77     
78     private String JavaDoc assetKey = null;
79     private boolean treatAsLink = false;
80     private boolean showLeafs =false;
81     
82     private HashMap JavaDoc contentMap = new HashMap JavaDoc();
83     
84     public ViewAssetListAction()
85     {
86         this(new ContentVO());
87     }
88     
89     public ViewAssetListAction(ContentVO contentVO)
90     {
91         this.contentVO = contentVO;
92     }
93
94     private void createContentIdList(ContentVO parent) throws ConstraintException, SystemException
95     {
96         contentMap.put(parent.getContentId(), parent.getName());
97         
98         List JavaDoc children = ContentControllerProxy.getController().getContentChildrenVOList(parent.getContentId());
99         for(Iterator JavaDoc i=children.iterator();i.hasNext();)
100         {
101             ContentVO cvo = (ContentVO) i.next();
102             createContentIdList(cvo);
103         }
104     }
105     
106     protected void initialize(Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
107     {
108         this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId);
109         createContentIdList(this.contentVO);
110     }
111
112     public String JavaDoc doExecute() throws Exception JavaDoc
113     {
114         if(getContentId() != null && getContentId().intValue() != -1)
115             this.initialize(getContentId(), this.languageId);
116         
117         return "success";
118     }
119     
120     public String JavaDoc doBrowser() throws Exception JavaDoc
121     {
122         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true);
123         
124         /*
125          * TODO: Create the filters through some configuration
126          */

127         
128         filters = new ArrayList JavaDoc();
129         filters.add(new FilterVO("All", ""));
130         filters.add(new FilterVO("Images", "image/.*"));
131         filters.add(new FilterVO("GIF Images", ".*gif"));
132         filters.add(new FilterVO("JPEG Images", ".*jpeg"));
133         filters.add(new FilterVO("PNG Images", ".*png"));
134         filters.add(new FilterVO("Documents", ".*word.*|.*excel.*|.*pdf.*"));
135         filters.add(new FilterVO("compressed", ".*compressed"));
136         
137         return "browser";
138     }
139     
140     
141     public String JavaDoc getContentPath(Integer JavaDoc contentId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
142     {
143         ContentVO contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId);
144         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
145
146         while (contentVO.getParentContentId() != null)
147         {
148             try
149             {
150                 contentVO = ContentControllerProxy.getController().getContentVOWithId(contentVO.getParentContentId());
151             }
152             catch (SystemException e)
153             {
154                 e.printStackTrace();
155             }
156             catch (Bug e)
157             {
158                 e.printStackTrace();
159             }
160             ret.insert(0, "" + contentVO.getContentId() + ",");
161         }
162         ret.append("" + contentId);
163         return ret.toString();
164     }
165     
166
167     public MathHelper getMathHelper()
168     {
169         return new MathHelper();
170     }
171     
172     public java.lang.Integer JavaDoc getContentId()
173     {
174         return this.contentVO.getContentId();
175     }
176         
177     public void setContentId(java.lang.Integer JavaDoc contentId)
178     {
179         this.contentVO.setContentId(contentId);
180     }
181     
182     public java.lang.Integer JavaDoc getContentTypeDefinitionId()
183     {
184         return this.contentTypeDefinitionVO.getContentTypeDefinitionId();
185     }
186
187     public String JavaDoc getContentTypeDefinitionName()
188     {
189         return this.contentTypeDefinitionVO.getName();
190     }
191             
192     public void setLanguageId(Integer JavaDoc languageId)
193     {
194         this.languageId = languageId;
195     }
196
197     public java.lang.Integer JavaDoc getLanguageId()
198     {
199         return this.languageId;
200     }
201     
202     public String JavaDoc getName()
203     {
204         return this.contentVO.getName();
205     }
206
207     public java.lang.Integer JavaDoc getRepositoryId()
208     {
209         if(this.contentVO != null && this.contentVO.getRepositoryId() != null)
210             return this.contentVO.getRepositoryId();
211         else
212             return this.repositoryId;
213     }
214
215     public List JavaDoc getAvailableLanguages()
216     {
217         return this.availableLanguages;
218     }
219
220     /**
221      * Returns a list of digital assets available for this content and all the child contents.
222      */

223     public List JavaDoc getInheritedDigitalAssets()
224     {
225         List JavaDoc digitalAssets = new ArrayList JavaDoc();
226         
227         try
228         {
229             for(Iterator JavaDoc i = contentMap.keySet().iterator();i.hasNext();)
230             {
231                 Integer JavaDoc _contentId = (Integer JavaDoc) i.next();
232                 DigitalAssetCollection collection = new DigitalAssetCollection(_contentId, (String JavaDoc) contentMap.get(_contentId));
233                 collection.setContentPath(getContentPath(_contentId));
234                 
235                 if(filter.length() > 0)
236                 {
237                     for(Iterator JavaDoc assetIterator=DigitalAssetController.getDigitalAssetVOList(_contentId, this.languageId, true).iterator();assetIterator.hasNext();)
238                     {
239                         DigitalAssetVO digitalAssetVO = (DigitalAssetVO) assetIterator.next();
240                         if(digitalAssetVO.getAssetContentType().matches(filter))
241                         {
242                             collection.getAssets().add(digitalAssetVO);
243                         }
244                     }
245                 }
246                 else
247                 {
248                     collection.getAssets().addAll(DigitalAssetController.getDigitalAssetVOList(_contentId, this.languageId, true));
249                 }
250                 
251                 
252                 ContentVersionVO contentVersionVO = getLatestContentVersionVO(_contentId);
253                 if(contentVersionVO != null)
254                 {
255                     collection.setContentVersionId(contentVersionVO.getContentVersionId());
256                     collection.setLocked(ContentVersionVO.WORKING_STATE.compareTo(contentVersionVO.getStateId())!=0);
257                 }
258                 
259                 digitalAssets.add(collection);
260             }
261         }
262         catch(Exception JavaDoc e)
263         {
264             logger.warn("We could not fetch the list of digitalAssets: " + e.getMessage(), e);
265         }
266         
267         return digitalAssets;
268     }
269
270
271     /**
272      * This method fetches the blob from the database and saves it on the disk.
273      * Then it returnes a url for it
274      */

275     
276     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
277     {
278         String JavaDoc imageHref = null;
279         try
280         {
281             imageHref = DigitalAssetController.getDigitalAssetUrl(digitalAssetId);
282         }
283         catch(Exception JavaDoc e)
284         {
285             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
286             imageHref = e.getMessage();
287         }
288         
289         return imageHref;
290     }
291     
292     
293     /**
294      * This method fetches the blob from the database and saves it on the disk.
295      * Then it returnes a url for it
296      */

297     
298     public String JavaDoc getDigitalAssetThumbnailUrl(Integer JavaDoc digitalAssetId) throws Exception JavaDoc
299     {
300         String JavaDoc imageHref = null;
301         try
302         {
303             imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(digitalAssetId);
304         }
305         catch(Exception JavaDoc e)
306         {
307             logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e);
308             imageHref = e.getMessage();
309         }
310         
311         return imageHref;
312     }
313
314     
315     /**
316      * This method fetches the blob from the database and saves it on the disk.
317      * Then it returnes a url for it
318      */

319     
320     public String JavaDoc getDigitalAssetUrl(Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
321     {
322         String JavaDoc imageHref = null;
323         try
324         {
325             imageHref = DigitalAssetController.getDigitalAssetUrl(contentId, languageId);
326         }
327         catch(Exception JavaDoc e)
328         {
329             logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e);
330             imageHref = e.getMessage();
331         }
332         
333         return imageHref;
334     }
335     
336     
337     /**
338      * This method fetches the blob from the database and saves it on the disk.
339      * Then it returnes a url for it
340      */

341     
342     public String JavaDoc getDigitalAssetThumbnailUrl(Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
343     {
344         String JavaDoc imageHref = null;
345         try
346         {
347             imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(contentId, languageId);
348         }
349         catch(Exception JavaDoc e)
350         {
351             logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e);
352             imageHref = e.getMessage();
353         }
354         
355         return imageHref;
356     }
357     
358
359     public void setRepositoryId(Integer JavaDoc repositoryId)
360     {
361         this.repositoryId = repositoryId;
362     }
363     
364     public List JavaDoc getRepositories()
365     {
366         return repositories;
367     }
368     
369     public String JavaDoc getAssetKey()
370     {
371         return assetKey;
372     }
373     
374     public void setAssetKey(String JavaDoc assetKey)
375     {
376         this.assetKey = assetKey;
377     }
378     
379     public boolean getTreatAsLink()
380     {
381         return treatAsLink;
382     }
383     
384     public void setTreatAsLink(boolean treatAsLink)
385     {
386         this.treatAsLink = treatAsLink;
387     }
388     
389     public ContentVO getContentVO()
390     {
391         return contentVO;
392     }
393     
394     
395     protected ContentVersionVO getLatestContentVersionVO(Integer JavaDoc contentId) throws SystemException, Exception JavaDoc
396     {
397         Integer JavaDoc contentVersionId = null;
398         ContentVersionVO contentVersionVO = null;
399         contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
400
401         Integer JavaDoc usedRepositoryId = this.repositoryId;
402         if(this.repositoryId == null && this.contentVO != null)
403             usedRepositoryId = this.contentVO.getRepositoryId();
404         
405         LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(usedRepositoryId);
406         contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, masterLanguageVO.getId());
407         
408         if(contentVersionVO != null)
409             contentVersionId = contentVersionVO.getContentVersionId();
410         
411
412         if(contentVersionId != null)
413             contentVersionVO = ContentVersionControllerProxy.getController().getACContentVersionVOWithId(this.getInfoGluePrincipal(), contentVersionId);
414         
415         return contentVersionVO;
416
417         /*
418         if(this.forceWorkingChange && contentVersionVO != null && !contentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE))
419         {
420             ContentVersion contentVersion = ContentStateController.changeState(contentVersionVO.getContentVersionId(), ContentVersionVO.WORKING_STATE, "Edit on sight", false, this.getInfoGluePrincipal(), this.getContentId(), new ArrayList());
421             contentVersionId = contentVersion.getContentVersionId();
422             contentVersionVO = contentVersion.getValueObject();
423         }
424         */

425         
426     }
427     
428     public class FilterVO
429     {
430         private String JavaDoc name = null;
431         private String JavaDoc value = null;
432         public FilterVO(String JavaDoc name, String JavaDoc value) {
433             super();
434             this.name = name;
435             this.value = value;
436         }
437         public String JavaDoc getName() {
438             return name;
439         }
440         public void setName(String JavaDoc name) {
441             this.name = name;
442         }
443         public String JavaDoc getValue() {
444             return value;
445         }
446         public void setValue(String JavaDoc value) {
447             this.value = value;
448         }
449     }
450     
451     public class DigitalAssetCollection
452     {
453         List JavaDoc assets = new ArrayList JavaDoc();
454         String JavaDoc contentPath = null;
455         Integer JavaDoc contentId = null;
456         Integer JavaDoc contentVersionId = null;
457         boolean locked = false;
458         Integer JavaDoc languageId = null;
459         String JavaDoc contentName = null;
460         
461         
462         public DigitalAssetCollection(Integer JavaDoc contentId, String JavaDoc contentName)
463         {
464             this.contentId = contentId;
465             this.contentName = contentName;
466         }
467         public List JavaDoc getAssets()
468         {
469             return assets;
470         }
471         public void setAssets(List JavaDoc assets)
472         {
473             this.assets = assets;
474         }
475         public Integer JavaDoc getContentId()
476         {
477             return contentId;
478         }
479         public void setContentId(Integer JavaDoc contentId)
480         {
481             this.contentId = contentId;
482         }
483         public String JavaDoc getContentName()
484         {
485             return contentName;
486         }
487         public void setContentName(String JavaDoc contentName)
488         {
489             this.contentName = contentName;
490         }
491         public String JavaDoc getContentPath()
492         {
493             return contentPath;
494         }
495         public void setContentPath(String JavaDoc contentPath)
496         {
497             this.contentPath = contentPath;
498         }
499         public Integer JavaDoc getContentVersionId() {
500             return contentVersionId;
501         }
502         public void setContentVersionId(Integer JavaDoc contentVersionId) {
503             this.contentVersionId = contentVersionId;
504         }
505         public Integer JavaDoc getLanguageId() {
506             return languageId;
507         }
508         public void setLanguageId(Integer JavaDoc languageId) {
509             this.languageId = languageId;
510         }
511         public boolean isLocked() {
512             return locked;
513         }
514         public void setLocked(boolean locked) {
515             this.locked = locked;
516         }
517         
518     }
519
520     public boolean isShowLeafs() {
521         return showLeafs;
522     }
523
524     public void setShowLeafs(boolean showLeafs) {
525         this.showLeafs = showLeafs;
526     }
527
528     public List JavaDoc getFilters() {
529         return filters;
530     }
531
532     public String JavaDoc getFilter() {
533         return filter;
534     }
535
536     public void setFilter(String JavaDoc filter) {
537         this.filter = filter;
538     }
539
540 }
541
Popular Tags