KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.io.StringWriter JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
34 import org.infoglue.cms.io.FileHelper;
35 import org.infoglue.cms.util.CmsPropertyHandler;
36 import org.infoglue.deliver.util.VelocityTemplateProcessor;
37
38 import com.opensymphony.module.propertyset.PropertySet;
39 import com.opensymphony.module.propertyset.PropertySetManager;
40
41 /**
42  * This class/action returns the WYSIWYG configuration in full.
43  *
44  * @author Mattias Bogeblad
45  */

46
47 public class WYSIWYGPropertiesAction extends InfoGlueAbstractAction
48 {
49     private final static Logger logger = Logger.getLogger(WYSIWYGPropertiesAction.class.getName());
50
51     private static final long serialVersionUID = 1L;
52
53     private Integer JavaDoc repositoryId = null;
54
55     private String JavaDoc WYSIWYGProperties = "";
56     private String JavaDoc StylesXML = "";
57     
58     public String JavaDoc doExecute() throws Exception JavaDoc
59     {
60         return "success";
61     }
62
63     public String JavaDoc doViewStylesXML() throws Exception JavaDoc
64     {
65         return "successStylesXML";
66     }
67
68     /**
69      * This method gets the WYSIWYG Properties
70      */

71     
72     public String JavaDoc getWYSIWYGProperties() throws Exception JavaDoc
73     {
74         try
75         {
76             this.WYSIWYGProperties = getPrincipalPropertyValue("WYSIWYGConfig", false);
77             logger.info("WYSIWYGProperties:" + WYSIWYGProperties);
78             if(this.WYSIWYGProperties == null || this.WYSIWYGProperties.equalsIgnoreCase("") && this.repositoryId != null)
79             {
80                 logger.info("Getting WYSIWYGProperties for repository...");
81                 Map JavaDoc args = new HashMap JavaDoc();
82                 args.put("globalKey", "infoglue");
83                 PropertySet ps = PropertySetManager.getInstance("jdbc", args);
84                 
85                 byte[] WYSIWYGConfigBytes = ps.getData("repository_" + this.repositoryId + "_WYSIWYGConfig");
86                 logger.info("WYSIWYGConfigBytes:" + WYSIWYGConfigBytes);
87                 if(WYSIWYGConfigBytes != null)
88                 {
89                     this.WYSIWYGProperties = new String JavaDoc(WYSIWYGConfigBytes, "UTF-8");
90                 }
91             }
92              
93             logger.info("this.WYSIWYGProperties:" + this.WYSIWYGProperties);
94         }
95         catch(Exception JavaDoc e)
96         {
97             logger.error("Could not fetch WYSIWYG Configuration: " + e.getMessage(), e);
98         }
99         finally
100         {
101             try
102             {
103                 if(this.WYSIWYGProperties == null || this.WYSIWYGProperties.equals(""))
104                     this.WYSIWYGProperties = FileHelper.getFileAsString(new File JavaDoc(CmsPropertyHandler.getContextRootPath() + "cms/contenttool/WYSIWYGConfig.js"));
105             }
106             catch (Exception JavaDoc e1)
107             {
108                 e1.printStackTrace();
109             }
110             
111         }
112
113         Map JavaDoc parameters = new HashMap JavaDoc();
114         parameters.put("request", this.getRequest());
115         
116         StringWriter JavaDoc tempString = new StringWriter JavaDoc();
117         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(tempString);
118         new VelocityTemplateProcessor().renderTemplate(parameters, pw, this.WYSIWYGProperties);
119         this.WYSIWYGProperties = tempString.toString();
120
121         this.getResponse().setContentType("text/javascript");
122         
123         return this.WYSIWYGProperties;
124     }
125
126     /**
127      * This method gets the Styles XML
128      */

129     
130     public String JavaDoc getStylesXML()
131     {
132         try
133         {
134             this.StylesXML = getPrincipalPropertyValue("StylesXML", false);
135             logger.info("this.StylesXML:" + this.StylesXML);
136             if(this.StylesXML == null || this.StylesXML.equalsIgnoreCase("") && this.repositoryId != null)
137             {
138                 logger.info("Getting StylesXML for repository...");
139                 Map JavaDoc args = new HashMap JavaDoc();
140                 args.put("globalKey", "infoglue");
141                 PropertySet ps = PropertySetManager.getInstance("jdbc", args);
142                 
143                 byte[] StylesXMLBytes = ps.getData("repository_" + this.repositoryId + "_StylesXML");
144                 if(StylesXMLBytes != null)
145                 {
146                     this.StylesXML = new String JavaDoc(StylesXMLBytes, "UTF-8");
147                 }
148             }
149         }
150         catch(Exception JavaDoc e)
151         {
152             logger.error("Could not fetch Styles XML: " + e.getMessage(), e);
153         }
154         finally
155         {
156             try
157             {
158                 if(this.StylesXML == null || this.StylesXML.equals(""))
159                     this.StylesXML = FileHelper.getFileAsString(new File JavaDoc(CmsPropertyHandler.getContextRootPath() + "cms/contenttool/StylesXML.xml"));
160             }
161             catch (Exception JavaDoc e1)
162             {
163                 e1.printStackTrace();
164             }
165         }
166         
167         this.getResponse().setContentType("text/xml");
168         return this.StylesXML;
169     }
170
171     
172     public void setRepositoryId(Integer JavaDoc repositoryId)
173     {
174         this.repositoryId = repositoryId;
175     }
176 }
177
Popular Tags