All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nlg.wrapper.stax.StaxStreamWriterUtil Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package nlg.wrapper.stax;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;


import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.Serializable;

public class StaxStreamWriterUtil implements Serializable {
    public static void setPrefix(JsonGenerator jsonGenerator, String prefix, String provNs) throws IOException {
        ToXmlGenerator xmlGenerator=(ToXmlGenerator)jsonGenerator;
        try {
            xmlGenerator.getStaxWriter().setPrefix(prefix, provNs);
        } catch (XMLStreamException e) {
            e.printStackTrace();
            throw new IOException(e);
        }
    }

    public static void writeNamespace(JsonGenerator jsonGenerator, String prefix, String provNs) throws IOException {
        try {
            ToXmlGenerator xmlGenerator=(ToXmlGenerator)jsonGenerator;
            xmlGenerator.getStaxWriter().writeNamespace(prefix, provNs);
        } catch (XMLStreamException e) {
            e.printStackTrace();
            throw new IOException(e);
        }
    }



    public static void writeAttribute(JsonGenerator jsonGenerator, String prefix, String namespace, String property, String str) {
        ToXmlGenerator xmlGenerator=(ToXmlGenerator)jsonGenerator;

        try {
            //xmlGenerator.getStaxWriter().
            xmlGenerator.getStaxWriter().writeAttribute(prefix, namespace, property, str);
        } catch (XMLStreamException e) {
            e.printStackTrace();
            throw new UnsupportedOperationException(e);
        }
    }

    public static void writeAttribute(JsonGenerator jsonGenerator, String property, String str) {
        ToXmlGenerator xmlGenerator=(ToXmlGenerator)jsonGenerator;

        try {
            //xmlGenerator.getStaxWriter().
            xmlGenerator.getStaxWriter().writeAttribute(property, str);
        } catch (XMLStreamException e) {
            e.printStackTrace();
            throw new UnsupportedOperationException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy