KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author Stefan Sik
26  * @since 1.4
27  */

28
29 package org.infoglue.cms.applications.contenttool.actions;
30
31 import java.io.UnsupportedEncodingException JavaDoc;
32 import java.net.URLEncoder JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Iterator JavaDoc;
35
36 import org.apache.log4j.Logger;
37 import org.dom4j.Document;
38 import org.dom4j.DocumentHelper;
39 import org.dom4j.Element;
40 import org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction;
41 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
42 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
43 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
44 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController;
45 import org.infoglue.cms.controllers.kernel.impl.simple.TransactionHistoryController;
46 import org.infoglue.cms.entities.content.ContentVersionVO;
47 import org.infoglue.cms.entities.content.DigitalAssetVO;
48 import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl;
49 import org.infoglue.cms.entities.kernel.BaseEntityVO;
50 import org.infoglue.cms.entities.management.LanguageVO;
51 import org.infoglue.cms.entities.management.TransactionHistoryVO;
52 import org.infoglue.cms.exception.Bug;
53 import org.infoglue.cms.exception.ConstraintException;
54 import org.infoglue.cms.exception.SystemException;
55 import org.infoglue.cms.security.InfoGluePrincipal;
56 import org.infoglue.cms.treeservice.ss.ContentNodeSupplier;
57
58 import com.frovi.ss.Tree.INodeSupplier;
59
60 public class SimpleContentXmlAction extends SimpleXmlServiceAction
61 {
62     private final static Logger logger = Logger.getLogger(SimpleContentXmlAction.class.getName());
63
64     private static final long serialVersionUID = 1L;
65     
66     private static String JavaDoc TYPE_FOLDER = "ContentFolder";
67     private static String JavaDoc TYPE_ITEM = "ContentItem";
68     private String JavaDoc digitalAssetKey;
69     private Integer JavaDoc digitalAssetId;
70     private Integer JavaDoc languageId;
71
72     public INodeSupplier getNodeSupplier() throws SystemException
73     {
74         ContentNodeSupplier sup = new ContentNodeSupplier(getRepositoryId(), this.getInfoGluePrincipal());
75         sup.setShowLeafs(showLeafs.compareTo("yes")==0);
76         sup.setAllowedContentTypeIds(allowedContentTypeIds);
77         return sup;
78     }
79     
80     public String JavaDoc doDigitalAssets() throws Exception JavaDoc
81     {
82         String JavaDoc ret = "";
83         DigitalAssetVO digitalAssetVO = null;
84
85         if (digitalAssetId != null) {
86             digitalAssetVO = DigitalAssetController
87                     .getDigitalAssetVOWithId(digitalAssetId);
88         } else {
89             digitalAssetVO = DigitalAssetController.getDigitalAssetVO(
90                     parent, languageId, digitalAssetKey, true);
91         }
92
93         ret = "<digitalAssetInfo>"
94                 + "<assetURL>"
95                 + DigitalAssetController.getDigitalAssetUrl(digitalAssetVO.getId())
96                 + "</assetURL>"
97                 + "<assetId>"
98                 + digitalAssetVO.getId()
99                 + "</assetId>"
100                 + "</digitalAssetInfo>";
101
102         return ret;
103     }
104     
105     
106     public ContentVersionVO getLatestContentVersionVO(Integer JavaDoc contentId, Integer JavaDoc languageId)
107     {
108         ContentVersionVO contentVersionVO = null;
109         try
110         {
111             contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
112         }
113         catch(Exception JavaDoc e)
114         {
115             logger.error("An error occurred when we tried to get the latest version for the content:" + e.getMessage(), e);
116         }
117         
118         return contentVersionVO;
119     }
120
121     public Element getContentVersionElement(Integer JavaDoc contentVersionId) throws SystemException, Bug, UnsupportedEncodingException JavaDoc
122     {
123         ContentVersionController contentVersionController = ContentVersionController.getContentVersionController();
124         ContentVersionVO vo = contentVersionController.getContentVersionVOWithId(contentVersionId);
125         return getContentVersionElement(vo);
126     }
127     
128     public Element getContentVersionElement(ContentVersionVO vo) throws SystemException, Bug, UnsupportedEncodingException JavaDoc
129     {
130         Element element = DocumentHelper.createElement("contentVersion");
131         Element head = DocumentHelper.createElement("head");
132         Element value = DocumentHelper.createElement("value");
133
134         head.addAttribute("id", "" + vo.getContentVersionId());
135         head.addAttribute("languageId", "" + vo.getLanguageId());
136         head.addAttribute("languageName", vo.getLanguageName());
137         head.addAttribute("isActive", "" + vo.getIsActive());
138
139         TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController();
140         TransactionHistoryVO transactionHistoryVO = transactionHistoryController.getLatestTransactionHistoryVOForEntity(ContentVersionImpl.class, vo.getContentVersionId());
141         if(transactionHistoryVO!=null)
142             head.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime()));
143         // head.addAttribute("mod", formatDate(vo.getModifiedDateTime()));
144
value.addCDATA(URLEncoder.encode(vo.getVersionValue(),"UTF-8"));
145         element.add(head);
146         element.add(value);
147         return element;
148     }
149     
150     /*
151      * Returns document for a single contentVersion (parent)
152      */

153     public String JavaDoc doContentVersion() throws Exception JavaDoc
154     {
155         Document doc = DocumentHelper.createDocument();
156         doc.add(getContentVersionElement(parent));
157         return out(getFormattedDocument(doc));
158     }
159     
160     /*
161      * Returns all contentVersions for a given content (parent)
162      */

163     public String JavaDoc doContentVersions() throws Exception JavaDoc
164     {
165         Document doc = DocumentHelper.createDocument();
166         Element root = doc.addElement("contentVersions");
167         Collection JavaDoc availableLanguages = ContentController.getContentController().getRepositoryLanguages(parent);
168         for(Iterator JavaDoc i=availableLanguages.iterator();i.hasNext();)
169         {
170             LanguageVO lvo = (LanguageVO) i.next();
171             ContentVersionVO vo = getLatestContentVersionVO(parent, lvo.getLanguageId());
172             if(vo!=null)
173                 root.add(getContentVersionElement(vo));
174         }
175         
176         ContentVersionController contentVersionController = ContentVersionController.getContentVersionController();
177         return out(getFormattedDocument(doc));
178     }
179
180     /* (non-Javadoc)
181      * @see org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction#getRootEntityVO(java.lang.Integer, org.infoglue.cms.security.InfoGluePrincipal)
182      */

183     protected BaseEntityVO getRootEntityVO(Integer JavaDoc repositoryId, InfoGluePrincipal principal) throws ConstraintException, SystemException {
184         return ContentControllerProxy.getController().getRootContentVO(repositoryId, principal.getName());
185     }
186     
187 }
188
Popular Tags