Examples of StAXStreamOutputter


Examples of org.jdom2.output.StAXStreamOutputter

    root.addContent(new Text(" "));
    root.addContent(new Text("x"));
    root.addContent(new Text(" "));
    Format mf = Format.getRawFormat();
    mf.setTextMode(TextMode.TRIM_FULL_WHITE);
    StAXStreamOutputter xout = new StAXStreamOutputter(mf);
    StringWriter sw = new StringWriter();
    XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
    xout.output(root, xsw);
    assertEquals("<root> x </root>", sw.toString());
  }
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

    assertEquals("<root> x </root>", sw.toString());
  }

  @Test
  public void testClone() {
    StAXStreamOutputter xo = new StAXStreamOutputter();
    assertTrue(xo != xo.clone());
  }
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

  @Test
  public void testToString() {
    Format fmt = Format.getCompactFormat();
    fmt.setLineSeparator("\n\t ");
    StAXStreamOutputter out = new StAXStreamOutputter(fmt);
    assertNotNull(out.toString());
  }
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

   * The effect is that we compare the StAX string output with the re-parsed
   * value of the input.
   */
 
    private void roundTripDocument(Document doc) {
      StAXStreamOutputter xout = new StAXStreamOutputter(Format.getRawFormat());
      // create a String representation of the input.
      if (doc.hasRootElement()) {
        normalizeAttributes(doc.getRootElement());
      }
     
      try {
        StringWriter sw = new StringWriter();
        XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
          xout.output(doc, xsw);
          xsw.close();
          String expect = sw.toString();
         
        // convert the input to a SAX Stream

          StAXStreamBuilder sbuilder = new StAXStreamBuilder();
         
          char[] chars = expect.toCharArray();
          CharArrayReader car = new CharArrayReader(chars);
          XMLStreamReader xsr = sinfactory.createXMLStreamReader(car);
         
      Document backagain = sbuilder.build(xsr);
      xsr.close();
     
      // get a String representation of the round-trip.
        if (backagain.hasRootElement()) {
          normalizeAttributes(backagain.getRootElement());
        }
        StringWriter swb = new StringWriter();
        xsw = soutfactory.createXMLStreamWriter(swb);
      xout.output(backagain, xsw);
      String actual = swb.toString();
     
        assertEquals(expect, actual);
    } catch (Exception e) {
      failException("Failed to round-trip the document with exception: "
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

    }
   
    private void roundTripElement(Element emt) {
     
      try {
          StAXStreamOutputter xout = new StAXStreamOutputter(Format.getRawFormat());

          StringWriter sw = new StringWriter();
          XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
          xout.output(emt, xsw);
          xsw.close();
          String expect = sw.toString();
         
          StAXStreamBuilder sbuilder = new StAXStreamBuilder();
         
          XMLStreamReader xsr = sinfactory.createXMLStreamReader(new StringReader(expect));
          assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT);
          assertTrue(xsr.hasNext());
          xsr.next();
         
      Element backagain = (Element)sbuilder.fragment(xsr);

      // convert the input to a SAX Stream

      sw.getBuffer().setLength(0);
          xsw = soutfactory.createXMLStreamWriter(sw);
          xout.output(backagain, xsw);
          xsw.close();
         
          String actual = sw.toString();
          assertEquals(expect, actual);
    } catch (Exception e) {
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

    }
    }
   
    private void roundTripFragment(List<Content> content) {
      try {
          StAXStreamOutputter xout = new StAXStreamOutputter(Format.getRawFormat());

          StringWriter sw = new StringWriter();
          XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
          xout.output(content, xsw);
          xsw.close();
          String expect = sw.toString();
         
          StAXStreamBuilder sbuilder = new StAXStreamBuilder();
         
          XMLStreamReader xsr = sinfactory.createXMLStreamReader(new StringReader(expect));
//          assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT);
//          assertTrue(xsr.hasNext());
//          xsr.next();
         
      List<Content> backagain = sbuilder.buildFragments(xsr, new DefaultStAXFilter());

      // convert the input to a SAX Stream

      sw.getBuffer().setLength(0);
          xsw = soutfactory.createXMLStreamWriter(sw);
          xout.output(backagain, xsw);
          xsw.close();
         
          String actual = sw.toString();
          assertEquals(expect, actual);
    } catch (Exception e) {
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

     
    }
   
    private void roundTripFragment(Content content) {
      try {
          StAXStreamOutputter xout = new StAXStreamOutputter(Format.getRawFormat());

          StringWriter sw = new StringWriter();
          XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
          switch(content.getCType()) {
            case CDATA :
                  xout.output((CDATA)content, xsw);
                  break;
            case Text:
                  xout.output((Text)content, xsw);
                  break;
            case Comment:
                  xout.output((Comment)content, xsw);
                  break;
            case DocType:
                  xout.output((DocType)content, xsw);
                  break;
            case Element:
                  xout.output((Element)content, xsw);
                  break;
            case EntityRef:
                  xout.output((EntityRef)content, xsw);
                  break;
            case ProcessingInstruction:
                  xout.output((ProcessingInstruction)content, xsw);
                  break;
            default:
              throw new IllegalStateException(content.getCType().toString());
          }
          xsw.close();
          String expect = sw.toString();
         
          StAXStreamBuilder sbuilder = new StAXStreamBuilder();
         
      Content backagain = sbuilder.fragment(
          sinfactory.createXMLStreamReader(new StringReader(expect)));

      // convert the input to a SAX Stream

      sw.getBuffer().setLength(0);
          xsw = soutfactory.createXMLStreamWriter(sw);
          switch(content.getCType()) {
            case CDATA :
                  xout.output((CDATA)backagain, xsw);
                  break;
            case Text:
                  xout.output((Text)backagain, xsw);
                  break;
            case Comment:
                  xout.output((Comment)backagain, xsw);
                  break;
            case DocType:
                  xout.output((DocType)backagain, xsw);
                  break;
            case Element:
                  xout.output((Element)backagain, xsw);
                  break;
            case EntityRef:
                  xout.output((EntityRef)backagain, xsw);
                  break;
            case ProcessingInstruction:
                  xout.output((ProcessingInstruction)backagain, xsw);
                  break;
            default:
              throw new IllegalStateException(backagain.getCType().toString());
          }
          xsw.close();
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

    private int from = 0, to = -1;
   
    public OutWrapper(Format format) {
      try {
        xwriter = soutfactory.createXMLStreamWriter(swriter);
        stax = new StAXStreamOutputter(format);
      } catch (Exception xse) {
        throw new IllegalStateException("Cannot construct: See Cause", xse);
      }
    }
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

      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");
      outputter.output(doc, xsw);
      String xml = sw.toString();
      assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + format.getLineSeparator() +
                   "<root>&#xd800;&#xdc00; &#xd800;&#xdc00;</root>" + format.getLineSeparator(), xml);
    }
View Full Code Here

Examples of org.jdom2.output.StAXStreamOutputter

    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);
      String xml = baos.toString();
      assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + format.getLineSeparator() +
                   "<root>&#xd800;&#xdc00; &#xd800;&#xdc00;</root>" + format.getLineSeparator(), xml);
    }
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.