Package org.jdom2

Examples of org.jdom2.Document


    SAXBuilder builder = new SAXBuilder();
    String imsFNm = IMAGE_DIR + fnm;
    logger.info("Reading file: " + imsFNm);
    InputStream in = this.getClass().getResourceAsStream(imsFNm);
    try {
      Document document = builder.build(in);
      Element rootNode = document.getRootElement(); // images
      List<Element> imageList = rootNode.getChildren("image");
      for (Element image : imageList) {
        String name = image.getAttributeValue("name");
        ECrop crop;
        int maxCrop;
View Full Code Here


    }

    private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException {
        LinkedList<String> result = new LinkedList<String>();
        try {
            Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in));
            XMLOutputter out = new XMLOutputter();

            for (String xp : xpaths) {
                XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content());
                for (Content node : xpath.evaluate(doc)) {
View Full Code Here

  }

  @Test
  @Override // because omit still adds declaration....
  public void testOutputDocumentOmitDeclaration() {
    Document doc = new Document();
    doc.addContent(new Element("root"));
    FormatSetup setup = new FormatSetup() {
      @Override
      public void setup(Format fmt) {
        fmt.setOmitDeclaration(true);
      }
View Full Code Here

  @Test
    public void test_HighSurrogatePair() throws XMLStreamException, IOException, JDOMException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root>&#x10000; &#x10000;</root>"));
     
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream sw = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw, "ISO-8859-1");
View Full Code Here

    @Test
    public void test_HighSurrogatePairDecimal() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root>&#x10000; &#65536;</root>"));
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos, "ISO-8859-1");
      outputter.output(doc, xsw);
View Full Code Here

    @Test
    public void test_HighSurrogateAttPair() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root att=\"&#x10000; &#x10000;\" />"));
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos, "ISO-8859-1");
      outputter.output(doc, xsw);
View Full Code Here

    @Test
    public void test_HighSurrogateAttPairDecimal() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root att=\"&#x10000; &#65536;\" />"));
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos, "ISO-8859-1");
      outputter.output(doc, xsw);
View Full Code Here

    // Construct a raw surrogate pair character and confirm it outputs hex escaped
    @Test
    public void test_RawSurrogatePair() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root>\uD800\uDC00</root>"));
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos, "ISO-8859-1");
      outputter.output(doc, xsw);
View Full Code Here

    // Construct a raw surrogate pair character and confirm it outputs hex escaped, when UTF-8 too
    @Test
    public void test_RawSurrogatePairUTF8() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root>\uD800\uDC00</root>"));
      Format format = Format.getCompactFormat().setEncoding("UTF-8");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      StringWriter baos = new StringWriter();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos);
      outputter.output(doc, xsw);
View Full Code Here

    // Construct illegal XML and check if the parser notices
    @Test
    public void test_ErrorSurrogatePair() throws JDOMException, IOException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root></root>"));
      try {
        doc.getRootElement().setText("\uD800\uDBFF");
        fail("Illegal surrogate pair should have thrown an exception");
      }
      catch (IllegalDataException e) {
        // do nothing
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jdom2.Document

Copyright © 2018 www.massapicom. 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.