Search in sources :

Example 1 with XmlPrettyPrinterBuilderOperation

use of org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation in project whole by wholeplatform.

the class AbstractXsiPersistenceKit method doWriteModel.

@Override
protected void doWriteModel(IEntity model, IPersistenceProvider pp) throws Exception {
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(pp.getOutputStream(), pp.getEncoding()));
    XmlPrettyPrinterBuilderOperation op = new XmlPrettyPrinterBuilderOperation(printWriter);
    ITemplate template = getXsiModelTemplate(model, pp.getEncoding());
    template.apply(op);
    printWriter.flush();
}
Also used : XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) OutputStreamWriter(java.io.OutputStreamWriter) ITemplate(org.whole.lang.templates.ITemplate) PrintWriter(java.io.PrintWriter)

Example 2 with XmlPrettyPrinterBuilderOperation

use of org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation in project whole by wholeplatform.

the class XmlPrettyPrinterBuilderTest method comparePrettyPrints.

private void comparePrettyPrints(String filename) throws Exception {
    IEntity model = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream(filename)));
    StringWriter stringWriter = new StringWriter();
    XmlPrettyPrinterBuilderOperation xppbop = new XmlPrettyPrinterBuilderOperation(new PrintWriter(stringWriter, true));
    new ModelTemplate(model).apply(new XmlGenericBuilderAdapter((IXmlBuilder) xppbop.wGetBuilder(XmlLanguageKit.URI)));
    assertEquals(toPrettyPrintString(model), stringWriter.toString());
}
Also used : XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Example 3 with XmlPrettyPrinterBuilderOperation

use of org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation in project whole by wholeplatform.

the class XmlPrettyPrinterBuilderTest method _testPerformance.

public void _testPerformance() {
    IEntity model = new BPELModel().create();
    PrintStream nullPrintStream = new PrintStream(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
        // do nothing
        }
    });
    try {
        long timestamp = new Date().getTime();
        for (int i = 0; i < 1000; i++) {
            XmlPrettyPrinterBuilderOperation op = new XmlPrettyPrinterBuilderOperation(new PrintWriter(nullPrintStream));
            XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
            ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
            new ModelTemplate(model).apply(xmlOp);
            ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
        }
        long timediff = new Date().getTime() - timestamp;
        System.out.println("PrettyPrinterBuilder elapsed time: " + timediff + "ms");
        timestamp = new Date().getTime();
        for (int i = 0; i < 1000; i++) XmlBuilderPersistenceKit.instance().writeModel(model, new StreamPersistenceProvider(nullPrintStream));
        timediff = new Date().getTime() - timestamp;
        System.out.println("PrettyPrinterVisitor elapsed time: " + timediff + "ms");
    } catch (Exception e) {
        fail();
    }
}
Also used : PrintStream(java.io.PrintStream) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) BPELModel(org.whole.lang.models.codebase.BPELModel) OutputStream(java.io.OutputStream) IOException(java.io.IOException) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) Date(java.util.Date) IOException(java.io.IOException) XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)3 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)3 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)2 IEntity (org.whole.lang.model.IEntity)2 ModelTemplate (org.whole.lang.templates.ModelTemplate)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 BPELModel (org.whole.lang.models.codebase.BPELModel)1 ITemplate (org.whole.lang.templates.ITemplate)1 XmlStoreProducerBuilder (org.whole.lang.xml.util.XmlStoreProducerBuilder)1 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)1