1 23 24 package org.infoglue.cms.applications.managementtool.actions; 25 26 import java.io.File ; 27 import java.io.PrintWriter ; 28 import java.io.StringWriter ; 29 import java.util.HashMap ; 30 import java.util.Map ; 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 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 repositoryId = null; 54 55 private String WYSIWYGProperties = ""; 56 private String StylesXML = ""; 57 58 public String doExecute() throws Exception 59 { 60 return "success"; 61 } 62 63 public String doViewStylesXML() throws Exception 64 { 65 return "successStylesXML"; 66 } 67 68 71 72 public String getWYSIWYGProperties() throws Exception 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 args = new HashMap (); 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 (WYSIWYGConfigBytes, "UTF-8"); 90 } 91 } 92 93 logger.info("this.WYSIWYGProperties:" + this.WYSIWYGProperties); 94 } 95 catch(Exception 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 (CmsPropertyHandler.getContextRootPath() + "cms/contenttool/WYSIWYGConfig.js")); 105 } 106 catch (Exception e1) 107 { 108 e1.printStackTrace(); 109 } 110 111 } 112 113 Map parameters = new HashMap (); 114 parameters.put("request", this.getRequest()); 115 116 StringWriter tempString = new StringWriter (); 117 PrintWriter pw = new PrintWriter (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 129 130 public String 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 args = new HashMap (); 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 (StylesXMLBytes, "UTF-8"); 147 } 148 } 149 } 150 catch(Exception 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 (CmsPropertyHandler.getContextRootPath() + "cms/contenttool/StylesXML.xml")); 160 } 161 catch (Exception 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 repositoryId) 173 { 174 this.repositoryId = repositoryId; 175 } 176 } 177 | Popular Tags |