1 14 15 package webEditor.core; 16 17 import java.io.*; 18 19 import org.w3c.dom.*; 20 import org.apache.xerces.parsers.DOMParser; 21 import org.apache.regexp.RE; 22 23 import webEditor.util.*; 24 25 26 30 public class presentation 31 { 32 35 private String wEd_root; 36 37 40 private Document configDoc = null; 41 42 45 private String dataDir; 46 47 50 private String tplDir; 51 52 55 private String editTplDir; 56 57 60 private String showTplDir; 61 62 65 private String configTplDir; 66 67 70 private String serverName; 71 72 75 private String docRoot; 76 77 public presentation (configuration initParam) 78 { 79 xml_parser confParser = new xml_parser (); 80 this.configDoc = confParser.writeDOM ("general", initParam.returnData()); 81 82 String categoryName = "directories"; 83 84 this.wEd_root = initParam.readValue ("webEditor_Root","wEd_root"); 85 this.dataDir = initParam.readValue (categoryName,"dataDir"); 86 this.dataDir = this.wEd_root + "/" + this.dataDir; 87 88 this.tplDir = initParam.readValue (categoryName,"tplDir"); 89 this.tplDir = this.dataDir + "/" + this.tplDir; 90 this.editTplDir = this.tplDir + "/editor"; 91 this.showTplDir = this.tplDir + "/presentation"; 92 this.configTplDir = this.tplDir + "/config"; 93 } 94 95 102 public String showTextEditor(Document newsDoc, String mode, String browserType) 103 { 104 String templateFile = "/editor.xsl"; 105 try { 106 RE r = new RE("MSIE"); 107 if ( mode.equals ("rich") && (r.match (browserType)) ) { 108 templateFile = "/editor-ie.xsl"; 111 112 } 116 newsDoc = this.addConfiguration (newsDoc, this.configDoc); 118 } 119 catch (Exception e) { 120 e.printStackTrace(); 121 } 122 123 String outputString = null; 124 String templateName = new File 126 (this.editTplDir + templateFile).getAbsolutePath(); 127 templateName = "file:" + templateName; 128 try { 129 xsl_transform transform = new xsl_transform (); 130 outputString = transform.processDOM (newsDoc, templateName); 131 } 132 catch (Exception e) { 133 e.printStackTrace(); 134 } 135 136 return (outputString); 137 } 138 139 145 public String showImgEditor(Document newsDoc, String newsSection) 146 { 147 String outputString = null; 148 String templateName = new File 150 (this.editTplDir + "/image.xsl").getAbsolutePath(); 151 templateName = "file:" + templateName; 152 newsDoc = this.addConfiguration (newsDoc, this.configDoc); 154 try { 155 xsl_transform transform = new xsl_transform (); 156 outputString = transform.processDOM (newsDoc, templateName); 157 } 158 catch (Exception e) { 159 e.printStackTrace(); 160 } 161 162 return (outputString); 163 } 164 165 171 public String showIndex (Document indexDoc, String mode) 172 { 173 String outputString = null; 174 String templatePath = null; 175 176 if ( mode == "edit" ) { 178 templatePath = this.editTplDir; 179 } 180 else { 181 templatePath = this.showTplDir; 182 } 183 184 String templateName = new File 185 (templatePath + "/index.xsl").getAbsolutePath(); 186 templateName = "file:" + templateName; 187 188 indexDoc = this.addConfiguration (indexDoc, this.configDoc); 190 try { 191 xsl_transform transform = new xsl_transform (); 192 outputString = transform.processDOM (indexDoc, templateName); 193 } 194 catch (Exception e) { 195 e.printStackTrace(); 196 } 197 198 return (outputString); 199 } 200 201 207 208 public String showDoc (Document newsDoc, String mode) 209 { 210 String outputString = null; 211 String templateFile = null; 212 213 if ( mode == "show" ) { 215 templateFile = "/doc.xsl"; 216 } 217 else { 218 templateFile = "/htmldoc.xsl"; 219 } 220 221 String templateName = new File 222 (this.showTplDir+ templateFile).getAbsolutePath(); 223 templateName = "file:" + templateName; 224 newsDoc = this.addConfiguration (newsDoc, this.configDoc); 226 try { 227 xsl_transform transform = new xsl_transform (); 228 outputString = transform.processDOM (newsDoc, templateName); 229 } 230 catch (Exception e) { 231 e.printStackTrace(); 232 } 233 234 return (outputString); 235 } 236 237 242 public String showConfig (Document configDoc) 243 { 244 String outputString = null; 245 String templateName = new File 247 (this.configTplDir + "/sample.xsl").getAbsolutePath(); 248 templateName = "file:" + templateName; 249 configDoc = this.addConfiguration (configDoc, this.configDoc); 251 try { 252 xsl_transform transform = new xsl_transform (); 253 outputString = transform.processDOM (configDoc, templateName); 254 } 255 catch (Exception e) { 256 e.printStackTrace(); 257 } 258 259 return (outputString); 260 } 261 262 263 268 public String showConfigEditor (Document configDoc) 269 { 270 String outputString = null; 271 String templateName = new File 273 (this.configTplDir + "/edit-config.xsl").getAbsolutePath(); 274 templateName = "file:" + templateName; 275 configDoc = this.addConfiguration (configDoc, this.configDoc); 277 try { 278 xsl_transform transform = new xsl_transform (); 279 outputString = transform.processDOM (configDoc, templateName); 280 } 281 catch (Exception e) { 282 e.printStackTrace(); 283 } 284 285 return (outputString); 286 } 287 288 289 296 public Document addConfiguration (Document doc, Document config) 297 { 298 Element root = doc.getDocumentElement(); 300 301 Element item = doc.createElement ("configuration"); 302 item.appendChild (doc.importNode (config.getDocumentElement(), true)); 303 304 root.appendChild (item); 305 306 return (doc); 307 } 308 309 } 310 | Popular Tags |