Example usage for java.io StringReader StringReader

List of usage examples for java.io StringReader StringReader

Introduction

In this page you can find the example usage for java.io StringReader StringReader.

Prototype

public StringReader(String s) 

Source Link

Document

Creates a new string reader.

Usage

From source file:edu.duke.cabig.c3pr.rules.common.XMLUtil.java

public static Object unmarshal(String xml) throws RuleException {
    try {//from   www.  jav a2  s.  co  m
        Unmarshaller unmarshaller = JAXBContext.newInstance("edu.duke.cabig.c3pr.rules.brxml")
                .createUnmarshaller();
        log.debug("reading the rule:" + xml);
        return unmarshaller.unmarshal(new StringReader(xml));
    } catch (JAXBException e) {
        throw new RuleException(e.getMessage(), e);
    }
}

From source file:Main.java

/**
 * Parses XML document//from w  ww  . j av a2  s .com
 * @param string XML document as string
 * @return XML document as object
 * @throws IOException if error reading document
 * @throws SAXException if provided string is not an XML
 * @throws ParserConfigurationException if unable to create parser
 */
public static Document toDocument(String string)
        throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new InputSource(new StringReader(string)));
}

From source file:jp.go.nict.langrid.commons.jxpath.JXPathUtil.java

/**
 * // w ww  .  j  av  a2  s.c o  m
 * 
 */
public static JXPathContext newXMLContext(String anXml) throws IOException, SAXException {
    DocumentBuilder builder = DocumentUtil.newDocumentBuilder();
    return JXPathContext.newContext(builder.parse(new InputSource(new StringReader(anXml))));
}

From source file:Main.java

public static final boolean isWellFormedXml(final String string) throws Exception {
    return isWellFormedXml(new InputSource(new StringReader(string)));
}

From source file:Main.java

public static Document getXMLDocument(String xmlContent) {

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    Document xmlDocument = null;/*from   w  w  w .j  a  v  a2s  . c om*/
    builderFactory.setValidating(false);
    builderFactory.setNamespaceAware(true);
    try {
        DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
        try {
            xmlDocument = documentBuilder.parse(new InputSource(new StringReader(xmlContent)));
        } catch (SAXException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    return xmlDocument;

}

From source file:com.hangum.tadpole.commons.sql.map.SQLMap.java

public static SqlMapClient getInstance(UserDBDAO dbInfo) throws Exception {
    String config = getConfig(dbInfo);

    return SqlMapClientBuilder.buildSqlMapClient(new StringReader(config));
}

From source file:edu.harvard.i2b2.previousquery.QueryListNamesClient.java

public static OMElement getQueryPayLoad(String XMLstr) throws Exception {
    StringReader strReader = new StringReader(XMLstr);
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader reader = xif.createXMLStreamReader(strReader);

    StAXOMBuilder builder = new StAXOMBuilder(reader);
    OMElement lineItem = builder.getDocumentElement();
    //System.out.println("Line item string " + lineItem.toString());
    return lineItem;
}

From source file:Main.java

public static Document createDocument(InputSource inputSource)
        throws SAXException, ParserConfigurationException, IOException {
    Document doc = null;//from  w  w w. j av a  2  s  . co m
    DocumentBuilderFactory factory = createDocumentBuilderFactory();
    DocumentBuilder builder = createDocumentBuilder(factory);
    builder.setEntityResolver(new EntityResolver() {
        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    doc = builder.parse(inputSource);
    return doc;
}

From source file:cn.vlabs.duckling.vwb.ui.action.HtmlValidateUtil.java

public static boolean checkHtmlTextValidate(String content) {
    if (StringUtils.isBlank(content)) {
        return true;
    }/*ww  w  . j  a v  a 2s . c om*/

    if (!containsInvalidateUrl(content)) {
        return true;
    }

    SAXBuilder builder = new SAXBuilder("org.cyberneko.html.parsers.SAXParser", true);
    try {
        Document doc = builder.build(new StringReader(content));
        Element e = doc.getRootElement();
        List<Element> forms = new ArrayList<Element>();
        fillFormElement(e, forms);
        for (Element form : forms) {
            String actionStr = form.getAttributeValue("action");
            getInvalidateFormAction().contains(actionStr);
            return false;
        }
    } catch (Throwable e) {
        log.error("?html?", e);
    }

    return true;
}

From source file:co.runrightfast.core.utils.JsonUtils.java

static javax.json.JsonObject toJsonObject(@NonNull final JsonObject json) {
    try (final JsonReader reader = Json.createReader(new StringReader(json.encode()))) {
        return reader.readObject();
    }//from  w w w  . j  a  v a  2s. c  o  m
}