Example usage for org.xml.sax InputSource InputSource

List of usage examples for org.xml.sax InputSource InputSource

Introduction

In this page you can find the example usage for org.xml.sax InputSource InputSource.

Prototype

public InputSource(Reader characterStream) 

Source Link

Document

Create a new input source with a character stream.

Usage

From source file:org.anodyneos.jse.cron.CronDaemon.java

public static void main(String[] args) throws Exception {
    try {//  www.j av a  2 s.  c  om
        InputSource source = new InputSource(args[0]);
        CronDaemon server = new CronDaemon(source);
        server.start();
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw e;
    }
}

From source file:Main.java

public static Document loadXml(String xml) {
    InputSource inputSource = new InputSource(new StringReader(xml));
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {/*from   w  w  w. j a  v a 2  s .  c  o m*/
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(inputSource);
        return doc;
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}

From source file:Main.java

public static String format(String xml) throws Exception {
    InputSource src = new InputSource(new StringReader(xml));
    Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
    Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

    System.setProperty(DOMImplementationRegistry.PROPERTY,
            "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();

    writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
    return writer.writeToString(document);
}

From source file:Main.java

public static <T> Object generateXML2Object(String str, Class cls) throws JAXBException {

    InputSource is;// w  w w .  j a  va  2  s.c om
    Object obj = null;

    is = new InputSource(new StringReader(str));
    JAXBContext jaxbContext = JAXBContext.newInstance(cls);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    obj = cls.cast(jaxbUnmarshaller.unmarshal(is));

    return obj;
}

From source file:Main.java

public static Document parse(String xml) throws Exception {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new InputSource(new StringReader(xml)));
}

From source file:Main.java

public static Document parseStream(final InputStream xmlis) {
    try {//from w w w  .j a  v a2s  .c  o  m
        return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(xmlis));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document load(String uri) {
    return load(new InputSource(uri));
}

From source file:Main.java

public static Document load(String xml) throws Exception {
    DocumentBuilder builder = getDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(xml)));
    return document;
}

From source file:Main.java

public static NodeList extractNodeList(XPath xpath, String nodePath, String xmlString) {
    InputSource inputSource = new InputSource(new StringReader(xmlString));

    try {/*from   w w  w.j av  a  2  s.com*/
        return (NodeList) xpath.evaluate(nodePath, inputSource, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        return null;
    }
}

From source file:Main.java

public static synchronized Document riskyParse(String text) throws Exception {
    InputSource is = new InputSource(new StringReader(text));
    return parser.parse(is);
}