1 package org.jahia.clipbuilder.html.web.html.Impl.JDom; 2 3 import java.util.*; 4 5 import org.jahia.clipbuilder.html.bean.*; 6 import org.jahia.clipbuilder.html.web.*; 7 import org.jahia.clipbuilder.html.web.html.*; 8 import org.jdom.*; 9 import org.jdom.output.*; 10 import org.org.apache.commons.httpclient.*; 11 12 18 public class JDomHTMLDocument implements HTMLDocument { 19 20 private UrlBean urlBean; 22 private List framesList; 23 24 private JDomHTMLTransformer transformer; 26 private String charEncoding; 27 private ArrayList headChildrenList = new ArrayList(); 29 30 private org.jdom.Document originalDocument; 32 private org.jdom.Document transformedDocument; 33 private org.jdom.Document documentWhithParamsLabel; 34 private org.jdom.Document chewDocument; 35 private org.jdom.Document userDocument; 36 37 private Hashtable selectedPartHash = new Hashtable(); 39 private Hashtable paramsHashtable = new Hashtable(); 40 private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(JDomHTMLDocument.class); 41 42 43 50 public JDomHTMLDocument(UrlBean uBean, org.jdom.Document doc) throws URIException { 51 this(doc); 52 setUrlBean(uBean); 53 } 54 55 56 63 public JDomHTMLDocument(UrlBean uBean, org.w3c.dom.Document w3cDoc) throws URIException { 64 org.jdom.input.DOMBuilder builder = new org.jdom.input.DOMBuilder(); 65 org.jdom.Document jdomDoc = builder.build(w3cDoc); 66 getDocumentAsString(jdomDoc); 67 setOriginalDocument(jdomDoc); 68 setUrlBean(uBean); 69 } 70 71 72 78 public JDomHTMLDocument(org.jdom.Document doc) throws URIException { 79 setOriginalDocument(doc); 80 } 81 82 83 84 89 public void setUrlBean(UrlBean urlBean) { 90 this.urlBean = urlBean; 91 } 92 93 94 99 public void setTransformer(JDomHTMLTransformer transformer) { 100 this.transformer = transformer; 101 } 102 103 104 109 public void setOriginalDocument(org.jdom.Document originalDocument) { 110 this.originalDocument = originalDocument; 111 } 112 113 114 119 public void setCharEncoding(String charEncoding) { 120 this.charEncoding = charEncoding; 121 } 122 123 124 129 public void setFramesList(List framesList) { 130 this.framesList = framesList; 131 } 132 133 134 135 136 141 public java.util.List getTransformationErrors() { 142 return getTransformer().getLastParsingErrors(); 143 } 144 145 146 152 public String getSelectPartFromHash(String hash) { 153 Element ele = getElementFromHash(hash); 154 ele.detach(); 155 org.jdom.Document doc = new org.jdom.Document(ele); 156 return this.getDocumentAsString(doc); 157 } 158 159 160 165 public String getOriginalDocumentAsString() { 166 return getDocumentAsString(this.getOriginalDocument()); 167 } 168 169 170 176 public String getTransformedDocumentAsString() { 177 logger.debug("[ Get transformed document as sring ]"); 178 return getDocumentAsString(getTransformedDocument()); 179 } 180 181 182 183 189 public String getChewDocumentAsString(String tagName) { 190 return getDocumentAsString(getChewDocument(tagName)); 191 } 192 193 194 199 public String getUserDocumentAsString() { 200 return getDocumentAsString(getUserDocument()); 201 } 202 203 204 205 211 public String getDocumentWhithParamLabelAsString() { 212 return getDocumentAsString(getDocumentWhithParamsLabel()); 213 } 214 215 216 221 public org.jdom.Document getTransformedDocument() { 222 if (getTransformer() == null) { 223 getTransformer().buildTransformedDocument(); 224 } 225 226 return transformedDocument; 227 } 228 229 230 235 public UrlBean getUrlBean() { 236 return urlBean; 237 } 238 239 240 245 public org.jdom.Document getOriginalDocument() { 246 return originalDocument; 247 } 248 249 250 255 public HTMLTransformer getTransformer() { 256 return transformer; 257 } 258 259 260 265 public String getCharEncoding() { 266 return charEncoding; 267 } 268 269 270 275 public List getFramesList() { 276 return framesList; 277 } 278 279 280 281 286 protected void setTransformedDocument(org.jdom.Document transformedDocument) { 287 this.transformedDocument = transformedDocument; 288 } 289 290 291 296 protected void setParamsHashtable(Hashtable paramsHashtable) { 297 this.paramsHashtable = paramsHashtable; 298 } 299 300 301 307 protected void setDocumentWhithParamsLabel(org.jdom.Document 308 documentWhithParamsLabel) { 309 this.documentWhithParamsLabel = documentWhithParamsLabel; 310 } 311 312 313 318 protected void setChewDocument(org.jdom.Document chewDocument) { 319 this.chewDocument = chewDocument; 320 } 321 322 323 328 protected void setUserDocument(org.jdom.Document userDocument) { 329 this.userDocument = userDocument; 330 } 331 332 333 338 protected ArrayList getAllHeadChildrenList() { 339 return headChildrenList; 340 } 341 342 343 348 protected Hashtable getParamsHashtable() { 349 return paramsHashtable; 350 } 351 352 353 359 protected org.jdom.Document getDocumentWhithParamsLabel() { 360 if (this.documentWhithParamsLabel == null) { 361 try { 362 getTransformer().buildDocumentWhithLabel(); 363 } 364 catch (Exception ex) { 365 logger.error("[C an't build the wanted document] "); 366 ex.printStackTrace(); 367 } 368 } 369 370 return documentWhithParamsLabel; 371 } 372 373 374 380 protected org.jdom.Document getChewDocument(String tagName) { 381 if (this.chewDocument == null) { 382 getTransformer().buildChewDocument(tagName); 383 } 384 return chewDocument; 385 } 386 387 388 393 protected org.jdom.Document getUserDocument() { 394 if (this.userDocument == null) { 395 getTransformer().buildUserDocument(); 396 } 397 return userDocument; 398 } 399 400 401 407 protected String getParamDefaultValue(String name) { 408 return (String ) getParamsHashtable().get(name); 409 } 410 411 412 417 protected Enumeration getAllParamsName() { 418 return getParamsHashtable().keys(); 419 } 420 421 422 428 protected void addHeadChildrenList(Element ele) { 429 this.headChildrenList.add(ele); 430 } 431 432 433 439 protected void addHash(String hash, Element ele) { 440 this.selectedPartHash.put(hash, ele); 441 } 442 443 444 450 protected void addParam(String name, String defaultValue) { 451 getParamsHashtable().put(name, defaultValue); 452 } 453 454 455 461 private Element getElementFromHash(String hash) { 462 return (Element) selectedPartHash.get(hash); 463 } 464 465 466 472 private String getDocumentAsString(org.jdom.Document doc) { 473 String res = "<p> Error !!! </p>"; 474 try { 475 org.w3c.dom.Document domDoc = new org.jdom.output.DOMOutputter().output(doc); 476 XMLOutputter serializer = new XMLOutputter(); 478 Format format = org.jdom.output.Format.getPrettyFormat(); 480 String encoding = "ISO-8859-1"; 481 format.setEncoding(encoding); 482 serializer.setFormat(format); 483 484 res = serializer.outputString(doc); 485 res = org.jahia.clipbuilder.html.util.DomUtilities.getDocumentAsString(domDoc); 486 logger.debug("[ document from neko and jdom ] "); 487 488 } 489 catch (Exception ex) { 490 logger.error("[document from neko and jdom: can't get the transformed document] "); 491 ex.printStackTrace(); 492 } 493 494 return res; 495 } 496 497 } 498 | Popular Tags |