Example usage for javax.xml.parsers DocumentBuilder reset

List of usage examples for javax.xml.parsers DocumentBuilder reset

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder reset.

Prototype

public void reset() 

Source Link

Document

Reset this DocumentBuilder to its original configuration.

DocumentBuilder is reset to the same state as when it was created with DocumentBuilderFactory#newDocumentBuilder() .

Usage

From source file:Main.java

public static Document newDocument(boolean namespaceaware) throws Exception {
    DocumentBuilder builder = getSyncDocumentBuilder(namespaceaware);
    Document doc = builder.newDocument();
    builder.reset();
    return doc;//from   w ww . j  a v  a  2s. c  o  m
}

From source file:Main.java

public static Document buildDocumentFromSource(InputSource is, boolean namespaceaware)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilder builder = getSyncDocumentBuilder(namespaceaware);
    //Parse the document
    Document doc = builder.parse(is);
    builder.reset();
    return doc;//from ww w .j a v  a2  s . co m
}

From source file:Main.java

public static Document parse(String text) throws IOException, SAXException {
    final DocumentBuilder documentBuilder = DOCUMENT_BUILDER.get();
    final Document document = documentBuilder.parse(new InputSource(new StringReader(text)));
    documentBuilder.reset();
    return document;
}

From source file:Main.java

public static Document parse(File f)
        throws TransformerException, IOException, SAXException, ParserConfigurationException {
    DocumentBuilder db = documentBuilder();
    try {//from w w w .  j a  va 2  s .c o  m
        return db.parse(f);
    } finally {
        db.reset();
    }
}

From source file:Main.java

public static Document parse(String uri)
        throws TransformerException, IOException, SAXException, ParserConfigurationException {
    DocumentBuilder db = documentBuilder();
    try {/* ww  w .  j a  v a  2  s  . c  o  m*/
        return db.parse(uri);
    } finally {
        db.reset();
    }
}

From source file:Main.java

public static Document parse(InputStream stream)
        throws TransformerException, IOException, SAXException, ParserConfigurationException {
    DocumentBuilder db = documentBuilder();
    try {/* w ww  .j av  a  2  s. c  o  m*/
        return db.parse(stream);
    } finally {
        db.reset();
    }
}

From source file:Main.java

public static Document parse(File f, ErrorHandler errorHandler)
        throws TransformerException, IOException, SAXException, ParserConfigurationException {
    DocumentBuilder db = documentBuilder();
    db.setErrorHandler(errorHandler);// w  w  w.j a v a  2s.c  om
    try {
        return db.parse(f);
    } finally {
        db.reset();
    }
}

From source file:com.honnix.jaxo.core.internal.pool.DocumentBuilderObjectFactory.java

@Override
public void passivateObject(DocumentBuilder documentBuilder) throws Exception {
    documentBuilder.reset();
}

From source file:com.threadswarm.imagefeedarchiver.parser.RssDOMFeedParser.java

@Override
public RssChannel readFeed(String feedBody) throws FeedParserException {
    DocumentBuilder docBuilder = docBuilderLocal.get();
    docBuilder.reset();
    RssChannel rssChannel = null;//w  w  w . j a  v a2  s.  c o m
    Reader reader = null;
    try {
        reader = new StringReader(feedBody);
        Document document = docBuilder.parse(new InputSource(reader));
        rssChannel = parseChannel(document);
    } catch (SAXException | IOException e) {
        LOGGER.error("An Exception was thrown while attempting to parse the feed as an XML document");
        throw new FeedParserException(
                "An Exception occurred while attempting to parse an RSS feed from a String", e);
    } finally {
        IOUtils.closeQuietly(reader);
        docBuilder.reset();
    }

    return rssChannel;
}

From source file:MSUmpire.SpectrumParser.mzXMLReadUnit.java

public ScanData Parse() throws ParserConfigurationException, SAXException, IOException, DataFormatException {
    if (XMLtext.replaceFirst("</scan>", "").contains("</scan>")) {
        XMLtext = XMLtext.replaceFirst("</scan>", "");
    }//from   w  ww  . j  a  va  2  s.c  o m
    if (!XMLtext.contains("</scan>")) {
        XMLtext += "</scan>";
    }
    ScanData scan = new ScanData();
    final DocumentBuilder docBuilder = tls.get();
    docBuilder.reset();
    InputSource input = new InputSource(new StringReader(XMLtext));
    Document doc = null;
    try {
        doc = docBuilder.parse(input);
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        Logger.getRootLogger().error(XMLtext);
    }
    Node root = doc.getFirstChild();
    for (int i = 0; i < root.getAttributes().getLength(); i++) {
        switch (root.getAttributes().item(i).getNodeName()) {
        case ("num"):
            scan.ScanNum = Integer.parseInt(root.getAttributes().item(i).getNodeValue());
            break;
        case ("centroided"): {
            if ("1".equals(root.getAttributes().item(i).getNodeValue())) {
                scan.centroided = true;
            } else {
                scan.centroided = false;
            }
            break;
        }
        case ("msLevel"):
            scan.MsLevel = Integer.parseInt(root.getAttributes().item(i).getNodeValue());
            break;
        case ("scanType"):
            scan.scanType = root.getAttributes().item(i).getNodeValue();
            break;
        case ("peaksCount"):
            scan.PeaksCountString = Integer.parseInt(root.getAttributes().item(i).getNodeValue());
            break;
        case ("retentionTime"):
            scan.RetentionTime = Float.parseFloat(root.getAttributes().item(i).getNodeValue().substring(2,
                    root.getAttributes().item(i).getNodeValue().indexOf("S"))) / 60f;
            break;
        case ("lowMz"): {
            String value = root.getAttributes().item(i).getNodeValue();
            if ("inf".equals(value)) {
                value = String.valueOf(Float.MIN_VALUE);
            }
            scan.StartMz = Float.parseFloat(value);
            break;
        }
        case ("highMz"): {
            String value = root.getAttributes().item(i).getNodeValue();
            if ("inf".equals(value)) {
                value = String.valueOf(Float.MAX_VALUE);
            }
            scan.EndMz = Float.parseFloat(value);
            break;
        }
        case ("startMz"):
            scan.StartMz = Float.parseFloat(root.getAttributes().item(i).getNodeValue());
            break;
        case ("endMz"): {
            String value = root.getAttributes().item(i).getNodeValue();
            if ("inf".equals(value)) {
                value = String.valueOf(Float.MAX_VALUE);
            }
            scan.EndMz = Float.parseFloat(value);
            break;
        }
        case ("basePeakMz"): {
            String value = root.getAttributes().item(i).getNodeValue();
            if ("inf".equals(value)) {
                value = String.valueOf(Float.MAX_VALUE);
            }
            scan.BasePeakMz = Float.parseFloat(value);
            break;
        }
        case ("basePeakIntensity"):
            scan.BasePeakIntensity = Float.parseFloat(root.getAttributes().item(i).getNodeValue());
            break;
        case ("totIonCurrent"):
            scan.SetTotIonCurrent(Float.parseFloat(root.getAttributes().item(i).getNodeValue()));
            break;
        }
    }
    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
        Node childNode = root.getChildNodes().item(i);
        switch (childNode.getNodeName()) {
        case ("precursorMz"): {
            scan.PrecursorMz = Float.parseFloat(childNode.getTextContent());
            for (int j = 0; j < childNode.getAttributes().getLength(); j++) {
                switch (childNode.getAttributes().item(j).getNodeName()) {
                case ("precursorScanNum"):
                    scan.precursorScanNum = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue());
                    break;
                case ("precursorIntensity"):
                    scan.PrecursorIntensity = Float
                            .parseFloat(childNode.getAttributes().item(j).getNodeValue());
                    break;
                case ("precursorCharge"):
                    scan.PrecursorCharge = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue());
                    break;
                case ("activationMethod"):
                    scan.ActivationMethod = childNode.getAttributes().item(j).getNodeValue();
                    break;
                case ("windowWideness"):
                    scan.windowWideness = Float.parseFloat(childNode.getAttributes().item(j).getNodeValue());
                    break;
                }
            }
            break;
        }
        case ("peaks"): {
            for (int j = 0; j < childNode.getAttributes().getLength(); j++) {
                switch (childNode.getAttributes().item(j).getNodeName()) {
                case ("compressionType"):
                    scan.compressionType = childNode.getAttributes().item(j).getNodeValue();
                    break;
                case ("precision"):
                    scan.precision = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue());
                    break;
                }
            }
            ParsePeakString(scan, childNode.getTextContent());
            break;
        }
        }
        childNode = null;
    }
    if ("calibration".equals(scan.scanType)) {
        scan.MsLevel = -1;
    }
    XMLtext = null;
    scan.Data.Finalize();
    return scan;
}