KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.dom4j.Document;
30 import org.dom4j.Node;
31 import org.infoglue.cms.applications.common.VisualFormatter;
32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy;
36 import org.infoglue.cms.controllers.kernel.impl.simple.UserPropertiesController;
37 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
38 import org.infoglue.cms.entities.management.LanguageVO;
39 import org.infoglue.cms.entities.management.UserPropertiesVO;
40 import org.infoglue.cms.security.InfoGluePrincipal;
41 import org.infoglue.cms.util.dom.DOMBuilder;
42
43 public class ViewSystemUserPropertiesAction extends InfoGlueAbstractAction
44 {
45     private final static Logger logger = Logger.getLogger(ViewSystemUserPropertiesAction.class.getName());
46
47     private static final long serialVersionUID = 1L;
48
49     private final String JavaDoc currentAction = "ViewSystemUserProperties.action";
50     private final String JavaDoc updateAction = "UpdateSystemUserProperties";
51     private final String JavaDoc labelKey = "SystemUser Properties";
52     private final String JavaDoc title = "SystemUser Properties";
53     private final String JavaDoc extraParameters = "";
54     
55     private String JavaDoc userName;
56     private UserPropertiesVO userPropertiesVO;
57     private List JavaDoc userPropertiesVOList;
58     private List JavaDoc availableLanguages;
59     private List JavaDoc contentTypeDefinitionVOList;
60     private List JavaDoc attributes;
61     private ContentTypeDefinitionVO contentTypeDefinitionVO;
62     private Integer JavaDoc contentTypeDefinitionId;
63     private Integer JavaDoc languageId;
64     private Integer JavaDoc currentEditorId;
65     private String JavaDoc attributeName = "";
66     private String JavaDoc textAreaId = "";
67     
68     
69     /**
70      * Initializes all properties needed for the usecase.
71      * @param systemUserId
72      * @throws Exception
73      */

74
75     protected void initialize(String JavaDoc userName) throws Exception JavaDoc
76     {
77         this.availableLanguages = LanguageController.getController().getLanguageVOList();
78         
79         if(this.languageId == null && this.availableLanguages.size() > 0)
80             this.languageId = ((LanguageVO)this.availableLanguages.get(0)).getLanguageId();
81         
82         logger.info("Language:" + this.languageId);
83         
84         List JavaDoc contentTypeDefinitionVOList = UserPropertiesController.getController().getContentTypeDefinitionVOList(userName);
85         if(contentTypeDefinitionVOList != null && contentTypeDefinitionVOList.size() > 0)
86             this.contentTypeDefinitionVO = (ContentTypeDefinitionVO)contentTypeDefinitionVOList.get(0);
87         
88         logger.info("contentTypeDefinitionVO:" + contentTypeDefinitionVO.getName());
89         
90         InfoGluePrincipal infoGluePrincipal = UserControllerProxy.getController().getUser(userName);
91         userPropertiesVOList = UserPropertiesController.getController().getUserPropertiesVOList(userName, this.languageId);
92         if(userPropertiesVOList != null && userPropertiesVOList.size() > 0)
93         {
94             this.userPropertiesVO = (UserPropertiesVO)userPropertiesVOList.get(0);
95             this.contentTypeDefinitionId = this.userPropertiesVO.getLanguageId();
96         }
97         else
98         {
99             this.contentTypeDefinitionId = this.contentTypeDefinitionVO.getContentTypeDefinitionId();
100         }
101
102         this.attributes = ContentTypeDefinitionController.getController().getContentTypeAttributes(this.contentTypeDefinitionVO.getSchemaValue());
103     
104         logger.info("attributes:" + this.attributes.size());
105         logger.info("availableLanguages:" + this.availableLanguages.size());
106     }
107
108     public String JavaDoc doExecute() throws Exception JavaDoc
109     {
110         this.initialize(getUserName());
111         
112         return "success";
113     }
114         
115     /**
116      * This method fetches a value from the xml that is the contentVersions Value. If the
117      * contentVersioVO is null the contentVersion has not been created yet and no values are present.
118      */

119      
120     public String JavaDoc getAttributeValue(String JavaDoc key)
121     {
122         logger.info("Getting: " + key);
123         String JavaDoc value = "";
124         try
125         {
126             String JavaDoc xml = this.getXML();
127             if(xml != null)
128             {
129                 logger.info("key:" + key);
130                 logger.info("XML:" + this.getXML());
131                 
132                 DOMBuilder domBuilder = new DOMBuilder();
133                 
134                 Document document = domBuilder.getDocument(this.getXML());
135                 logger.info("rootElement:" + document.getRootElement().asXML());
136                 
137                 Node node = document.getRootElement().selectSingleNode("attributes/" + key);
138                 if(node != null)
139                 {
140                     value = node.getStringValue();
141                     logger.info("Getting value: " + value);
142                     if(value != null)
143                         value = new VisualFormatter().escapeHTML(value);
144                 }
145             }
146         }
147         catch(Exception JavaDoc e)
148         {
149             e.printStackTrace();
150         }
151
152         return value;
153     }
154     
155     public List JavaDoc getAvailableLanguages()
156     {
157         return this.availableLanguages;
158     }
159     
160     public Integer JavaDoc getContentTypeDefinitionId()
161     {
162         return this.contentTypeDefinitionId;
163     }
164     
165     public UserPropertiesVO getUserPropertiesVO()
166     {
167         return userPropertiesVO;
168     }
169
170     public String JavaDoc getExtraParameters()
171     {
172         return extraParameters;
173     }
174
175     public String JavaDoc getLabelKey()
176     {
177         return labelKey;
178     }
179
180     public String JavaDoc getTitle()
181     {
182         return title;
183     }
184
185     public String JavaDoc getUpdateAction()
186     {
187         return updateAction;
188     }
189
190     public String JavaDoc getCurrentAction()
191     {
192         return currentAction;
193     }
194
195     public String JavaDoc getXML()
196     {
197         return (this.userPropertiesVO == null) ? null : this.userPropertiesVO.getValue();
198     }
199
200     public Integer JavaDoc getLanguageId()
201     {
202         return languageId;
203     }
204
205     public void setLanguageId(Integer JavaDoc languageId)
206     {
207         this.languageId = languageId;
208     }
209
210     public Integer JavaDoc getCurrentEditorId()
211     {
212         return currentEditorId;
213     }
214
215     public void setCurrentEditorId(Integer JavaDoc integer)
216     {
217         currentEditorId = integer;
218     }
219
220     public String JavaDoc getAttributeName()
221     {
222         return this.attributeName;
223     }
224
225     public void setAttributeName(String JavaDoc attributeName)
226     {
227         this.attributeName = attributeName;
228     }
229
230     public String JavaDoc getTextAreaId()
231     {
232         return this.textAreaId;
233     }
234
235     public void setTextAreaId(String JavaDoc textAreaId)
236     {
237         this.textAreaId = textAreaId;
238     }
239     
240     /**
241      * This method returns the attributes in the content type definition for generation.
242      */

243     
244     public List JavaDoc getContentTypeAttributes()
245     {
246         return this.attributes;
247     }
248     
249     public String JavaDoc getUserName()
250     {
251         return this.userName;
252     }
253
254     public void setUserName(String JavaDoc userName)
255     {
256         this.userName = userName;
257     }
258
259 }
260
Popular Tags