@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);
   }
 }
예제 #2
0
 public static void main(String[] args) throws Exception {
   String sourceUrlString = "data/test.html";
   if (args.length == 0)
     System.err.println("Using default argument of \"" + sourceUrlString + '"');
   else sourceUrlString = args[0];
   if (sourceUrlString.indexOf(':') == -1) sourceUrlString = "file:" + sourceUrlString;
   System.out.println("\nSource URL:");
   System.out.println(sourceUrlString);
   URL url = new URL(sourceUrlString);
   Source source = new Source(url);
   System.out.println("\nDocument Title:");
   Element titleElement = source.getFirstElement(HTMLElementName.TITLE);
   System.out.println(titleElement != null ? titleElement.getContent().toString() : "(none)");
   System.out.println("\nSource.getEncoding():");
   System.out.println(source.getEncoding());
   System.out.println("\nSource.getEncodingSpecificationInfo():");
   System.out.println(source.getEncodingSpecificationInfo());
   System.out.println("\nSource.getPreliminaryEncodingInfo():");
   System.out.println(source.getPreliminaryEncodingInfo());
 }
예제 #3
0
 private static String getTitle(Source source) {
   Element titleElement = source.getFirstElement(HTMLElementName.TITLE);
   if (titleElement == null) return null;
   // TITLE element never contains other tags so just decode it collapsing whitespace:
   return CharacterReference.decodeCollapseWhiteSpace(titleElement.getContent());
 }
예제 #4
0
 private String delimitFieldValues(String source) {
   Source result = new Source(source.replace("<br>", ";").replace("<br/>", ";"));
   return getValueFieldText(result.getFirstElement());
 }