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:nbxml.Base.java

public void parseXml(String resource, ContentHandler contentHandler) throws SAXException, IOException {
    InputStream inputStream = getResourceAsStream(resource);
    InputSource inputSource = new InputSource(inputStream);
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();

    xmlReader.setContentHandler(contentHandler);
    xmlReader.parse(inputSource);//  ww w  . java 2  s.c o  m
}

From source file:com.thinkbiganalytics.feedmgr.nifi.NifiTemplateParser.java

public static String updateTemplateName(String nifiTemplate, String newName) throws Exception {

    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    Document doc = stringToDocument(nifiTemplate);

    InputSource source = new InputSource(new StringReader(nifiTemplate));

    Element element = (Element) xpath.compile("//template/name").evaluate(doc, XPathConstants.NODE);

    element.setTextContent(newName);/*from   ww w  .j av  a 2s  .  c o m*/
    return documentToString(doc);
}

From source file:com.orange.ngsi.model.UpdateContextModelTest.java

@Test
public void serializationXML() throws IOException, URISyntaxException, XPathExpressionException {

    String xml = xmlmapper.writeValueAsString(createUpdateContextTempSensor(0));

    String xpathExpr = "/updateContextRequest/contextElementList/contextElement[1]/entityId/id";
    XPath xPath = XPathFactory.newInstance().newXPath();
    String value = xPath.evaluate(xpathExpr, new InputSource(new StringReader(xml)));
    assertEquals("S1", value);
}

From source file:ar.com.zauber.commons.web.transformation.processors.impl.XalanXSLTScraperTest.java

/** */
@Test/*  w  ww .  j  a  v a2s  . c  o  m*/
public final void testInit() throws Exception {
    String encoding = "utf-8";
    DocumentProvider prov = new DocumentBuilderFactoryDocumentProvider();
    Reader reader = new StringReader("<xml/>");
    Document n = prov.parse(new InputSource(reader));
    Source xsltSource = new DOMSource(n);
    XalanXSLTScraper scraper = new XalanXSLTScraper(xsltSource, encoding);
}

From source file:be.fedict.eid.applet.service.signer.odf.ODFEntityResolver.java

public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    LOG.debug("resolveEntity");
    LOG.debug("publicId: " + publicId);
    LOG.debug("systemId: " + systemId);
    if ("-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN".equals(publicId)) {
        InputStream mathmlDtdInputStream = ODFEntityResolver.class.getResourceAsStream("/mmlents/mathml.dtd");
        InputSource inputSource = new InputSource(mathmlDtdInputStream);
        return inputSource;
    }//www  .  jav  a 2s . c om
    if (systemId.endsWith(".ent")) {
        String filename = FilenameUtils.getBaseName(systemId);
        LOG.debug("ent filename: " + filename);
        InputStream entInputStream = ODFEntityResolver.class
                .getResourceAsStream("/mmlents/" + filename + ".ent");
        InputSource inputSource = new InputSource(entInputStream);
        return inputSource;
    }
    LOG.warn("could not resolve: " + publicId);
    return null;
}

From source file:Main.java

public static Document parseStreamToXML(Reader in) {
    try {//from   w  ww .j  a  v  a2s.c  o  m
        // Use JAXP to create a document builder
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

        builderFactory.setExpandEntityReferences(false);
        builderFactory.setValidating(false);
        builderFactory.setNamespaceAware(true);
        builderFactory.setIgnoringComments(true);
        builderFactory.setCoalescing(true);
        builderFactory.setIgnoringElementContentWhitespace(true);

        return builderFactory.newDocumentBuilder().parse(new InputSource(in));
    } catch (ParserConfigurationException errParser) {
        throw new RuntimeException("Error getting XML parser", errParser);
    } catch (SAXException errSax) {
        throw new RuntimeException("Error parsing XML files", errSax);
    } catch (IOException errIO) {
        throw new RuntimeException("Error parsing XML files", errIO);
    }
}