@Override
 public String getHTML() {
   if (tmpTpl != null) {
     String tt = tmpTpl;
     tmpTpl = null;
     return tt;
   }
   try {
     String html = this.getCompiler().compile(getTemplate(), getContext());
     if (forceStyle) {
       Source source = new Source(html);
       Attributes attrs = source.getFirstElement().getAttributes();
       if (attrs != null) {
         // id
         // class
         // style
         // name
         for (int i = 0; i < attrs.size(); i++) {
           Attribute attr = attrs.get(i);
           String name = attr.getName();
           String value = attr.getValue();
           // System.out.println(name  + ":" + value);
           if (name.equals("id")) {
             this.id = attr.getValue();
           } else {
             setAttribute(name, value);
           }
         }
       }
       html = JavascriptUtil.javaScriptEscape(html);
       tmpTpl = html;
     } else {
       html = JavascriptUtil.javaScriptEscape(html);
     }
     return html;
   } catch (Exception e) {
     e.printStackTrace();
     return "<h1>There was an error<h1><p>"
         + JavascriptUtil.javaScriptEscape(e.getMessage())
         + "</p>";
     // throw new IllegalStateException(e);
   }
 }
Esempio n. 2
0
 private void processStartTag(StartTag tag) {
   if ("<".equals(tag.getTagType().getStartDelimiter())) {
     Element e = document.createElement(tag.getNameSegment().toString());
     stack.push(new Level(tag));
     writer.write("<");
     writer.write(tag.getNameSegment().toString());
     Attributes attributes = tag.getAttributes();
     if (!attributes.isEmpty()) {
       for (Attribute attribute : attributes) {
         processAttribute(attribute);
       }
     }
     if (tag.toString().trim().endsWith("/>") || tag.isEmptyElementTag()) {
       stack.pop();
       writer.write("/>");
     } else {
       writer.write(">");
     }
   } else {
     writer.write(tag.toString());
   }
 }