Example usage for org.w3c.dom.ls LSInput setCharacterStream

List of usage examples for org.w3c.dom.ls LSInput setCharacterStream

Introduction

In this page you can find the example usage for org.w3c.dom.ls LSInput setCharacterStream.

Prototype

public void setCharacterStream(java.io.Reader characterStream);

Source Link

Document

An attribute of a language and binding dependent type that represents a stream of 16-bit units.

Usage

From source file:edu.ur.ir.ir_import.service.DefaultCollectionImportService.java

/**
 * Load the dspace collection information from the xml file.
 * @throws DuplicateNameException /*from  w w w.  j  av a  2s  .com*/
 * 
 * @see edu.ur.dspace.load.CollectionImporter#getCollections(java.io.File)
 */
private void getCollections(File communityXmlFile, Repository repo, ZipFile zip)
        throws IOException, DuplicateNameException {
    if (log.isDebugEnabled()) {
        log.debug("get collections");
    }
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;

    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }

    DOMImplementation impl = builder.getDOMImplementation();
    DOMImplementationLS domLs = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSInput lsIn = domLs.createLSInput();
    LSParser parser = domLs.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    lsIn.setEncoding("UTF-8");

    FileInputStream fileInputStream;
    try {
        fileInputStream = new FileInputStream(communityXmlFile);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
    }
    InputStreamReader inputStreamReader;
    try {
        inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
    lsIn.setCharacterStream(inputStreamReader);

    Document doc = parser.parse(lsIn);
    Element root = doc.getDocumentElement();

    NodeList nodeList = root.getChildNodes();

    log.debug("node list length = " + nodeList.getLength());
    for (int index = 0; index < nodeList.getLength(); index++) {
        Node child = nodeList.item(index);
        importCollection(child, repo, zip);
    }
}

From source file:org.xwiki.platform.patchservice.web.PatchServiceAction.java

private Document parseString(String content) {
    try {/*from   w  w w .j av  a2 s . c  o m*/
        DOMImplementationLS lsImpl = (DOMImplementationLS) DOMImplementationRegistry.newInstance()
                .getDOMImplementation("LS 3.0");
        LSInput input = lsImpl.createLSInput();
        input.setCharacterStream(new StringReader(content));
        LSParser p = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
        return p.parse(input);
    } catch (Exception ex) {
        return null;
    }
}