Examples of OutputDocument


Examples of net.htmlparser.jericho.OutputDocument

  }

  public String changeTagCase(String contents, boolean uppercase) {
    Source source = new Source(contents);
    source.fullSequentialParse();
    OutputDocument outputDocument = new OutputDocument(source);
    List<Tag> tags = source.getAllTags();
    int pos = 0;
    for (Tag tag : tags) {
      Element tagElement = tag.getElement();
      if (tagElement == null) {
        System.out.println(tag.getName());
      } else {
        StartTag startTag = tagElement.getStartTag();
        Attributes attributes = startTag.getAttributes();
        if (attributes != null) {
          for (Attribute attribute : startTag.getAttributes()) {
            if (uppercase) {
              outputDocument.replace(attribute.getNameSegment(), attribute.getNameSegment().toString()
                  .toUpperCase());
            } else {
              outputDocument.replace(attribute.getNameSegment(), attribute.getNameSegment().toString()
                  .toLowerCase());
            }
          }
        }
        if (uppercase) {
          outputDocument.replace(tag.getNameSegment(), tag.getNameSegment().toString().toUpperCase());
        } else {
          outputDocument.replace(tag.getNameSegment(), tag.getNameSegment().toString().toLowerCase());
        }
        pos = tag.getEnd();
      }
    }
    return outputDocument.toString();
  }
View Full Code Here

Examples of net.htmlparser.jericho.OutputDocument

                || StringUtils.inArray(name, macroDirective);
    }

    public String filter(String key, String value) {
        Source source = new Source(value);
        OutputDocument document = new OutputDocument(source);
        replaceChildren(source, source, document);
        return document.toString();
    }
View Full Code Here

Examples of net.htmlparser.jericho.OutputDocument

    protected abstract String extractTextToReplaceReference(Element labelParentDiv, Element label);
   
    public String replace(String htmlContent) {
        Source source = new Source(htmlContent);
        source.fullSequentialParse();
        OutputDocument outputDocument = new OutputDocument(source);
        List<Element> references = source.getAllElementsByClass("reference");
        for (Element reference : references) {
            String labelId = reference.getAttributeValue("href").replace("#", "");
            Element label = source.getElementById(labelId);

            Element div = findLabelContainer(label);
            if (!isValidDiv(div)) {
                outputDocument.replace(reference, reference.toString().replace("*", "?"));
                LOG.warn("Could not resolve label: " + labelId);
                continue;
            }

            String text = extractTextToReplaceReference(div, label);
            outputDocument.replace(reference, reference.toString().replace("*", text));
        }
        return outputDocument.toString();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.