Package org.zanata.xml

Examples of org.zanata.xml.StreamSerializer


            // writing any output. This should enable RESTEasy to return an
            // error instead of simply aborting the output stream.
            if (iter.hasNext())
                iter.peek();

            StreamSerializer stream = new StreamSerializer(output);
            stream.writeXMLDeclaration();
            stream.write(new DocType("tmx", "http://www.lisa.org/tmx/tmx14.dtd"));
            stream.writeNewLine();

            Element tmx = new Element("tmx");
            tmx.addAttribute(new Attribute("version", "1.4"));
            startElem(stream, tmx);

            indent(stream);
            writeElem(stream, exportStrategy.buildHeader());

            indent(stream);
            Element body = new Element("body");
            startElem(stream, body);

            while (iter.hasNext()) {
                T tu = iter.next();
                writeIfComplete(stream, tu);
                ++tuCount;
            }
            indent(stream);
            endElem(stream, body);
            endElem(stream, tmx);
            stream.flush();
        } finally {
            close();
            log.info("streaming output stopped for: {}, TU count={}", jobName,
                    tuCount);
        }
View Full Code Here


public class StreamSerializerTest {

    @Test
    public void sanityTest() throws IOException {
        OutputStream out = new ByteArrayOutputStream();
        StreamSerializer serializer = new StreamSerializer(out);

        serializer.writeXMLDeclaration();
        Element rootElement = new Element("root");
        rootElement.addAttribute(new Attribute("rootAttr", "rootAttrVal"));
        serializer.writeStartTag(rootElement);

        Element sub1 = new Element("sub");
        sub1.addAttribute(new Attribute("subAttr", "subAttrVal"));
        serializer.write(sub1);

        Element sub2 = new Element("sub");
        sub2.addAttribute(new Attribute("xml:lang", XMLConstants.XML_NS_URI,
                "en"));
        serializer.write(sub2);

        serializer.writeEndTag(rootElement);
        serializer.flush();
        String output = out.toString();

        assertThat(output,
                startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
        String expected =
View Full Code Here

TOP

Related Classes of org.zanata.xml.StreamSerializer

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.