Examples of MCSDOMContentHandler


Examples of com.volantis.mcs.dom.MCSDOMContentHandler

     * @throws org.xml.sax.SAXException
     */
    private static Node parseXml(String xml)
            throws IOException, SAXException {
       
        MCSDOMContentHandler domParser = new MCSDOMContentHandler();
        XMLReader saxParser =
            new com.volantis.xml.xerces.parsers.SAXParser();
        saxParser.setContentHandler(domParser);
        StringReader stringReader = new StringReader(xml);
        InputSource source = new InputSource(stringReader);
        saxParser.parse(source);
        return domParser.getDocument().getRootElement();
    }
View Full Code Here

Examples of com.volantis.mcs.dom.MCSDOMContentHandler

     *
     * @throws SAXException a SAXException or a parser-specific exception
     */
    public static XMLReader getReader() throws SAXException {
        XMLReader reader;
        MCSDOMContentHandler handler = new MCSDOMContentHandler();

        try {
            reader = XMLReaderFactory.createXMLReader();
        } catch (Exception e) {
            reader = XMLReaderFactory.createXMLReader(defaultParser);
View Full Code Here

Examples of com.volantis.mcs.dom.MCSDOMContentHandler

            throws ProtocolException {
       
        super(value);
       
        // Create the SAX and DOM Parsers, and link them.
        MCSDOMContentHandler domParser = new MCSDOMContentHandler();
        // Note: explicit package for SAXParser to be clear about it's source.
        XMLReader saxParser =
                new com.volantis.xml.xerces.parsers.SAXParser();
        // No entity resolver, so SAX parser will do default entity resolution.
        // Paul says this is OK.
        // No dtd handler, so any dtd events will be ignored, which is fine
        // since we do not expect to get any for XML "fragments".
        // Use the DOM parsers nodeValue handler.
        saxParser.setContentHandler(domParser);
        // Use a specific error handler since we have specific needs here.
        saxParser.setErrorHandler(new ErrorHandler() {
            public void warning(SAXParseException e) {
                // Log and continue.
                logger.warn("parsing-problem", new Object[]{DOMScript.this},
                        adjust(e));
            }

            public void error(SAXParseException e) throws SAXException {
                // Adjust and throw the exception, it will be logged above.
                throw adjust(e);
            }

            public void fatalError(SAXParseException e) throws SAXException {
                // Adjust and throw the exception, it will be logged above.
                throw adjust(e);
            }

            /**
             * Adjusts a SAXParseException so that it's column number does not
             * include the synthetic root element that we add before parsing.
             *
             * @param e original exception
             * @return the adjusted exception.
             */
            private SAXParseException adjust(SAXParseException e) {
                int colNo = e.getColumnNumber() - ROOT_ELEMENT.length() - 2;
                return new ExtendedSAXParseException(e.getLocalizedMessage(), null, null,
                        e.getLineNumber(), colNo);
            }
        });

        // Find the XML we need to parse. Note that we wrap the task in an
        // element to convert even simple text into valid XML.
        String validXml = "<" + ROOT_ELEMENT + ">" + value +
                "</" + ROOT_ELEMENT + ">";
        try {
            // Parse the XML.
            StringReader stringReader = new StringReader(validXml);
            InputSource source = new InputSource(stringReader);
            saxParser.parse(source);
        } catch (SAXException e) {
            throw new ProtocolException(
                        exceptionLocalizer.format("parsing-error", this), e);
        } catch (IOException e) {
            // NOTE: we are currently reading from a string, so this ought
            // never to happen anyway.
            throw new ProtocolException(
                        exceptionLocalizer.format("parsing-error", this), e);
        }
           
        // Add the parsed nodeValue into the dom, minus the root element.
        Document document = domParser.getDocument();
        Element root = document.getRootElement();

        // Save our instance variables.
        nodeValue = root.getHead();
    }
View Full Code Here

Examples of com.volantis.mcs.dom.MCSDOMContentHandler

     */
    protected Element createElementFromString(String s)
            throws ProtocolException {

        // Create the SAX and DOM Parsers, and link them.
        MCSDOMContentHandler domParser = new MCSDOMContentHandler();
        // Note: explicit package for SAXParser to be clear about it's source.
        XMLReader saxParser =
                new com.volantis.xml.xerces.parsers.SAXParser();
        saxParser.setContentHandler(domParser);

        try {
            // Parse the XML.
            StringReader stringReader = new StringReader(s);
            InputSource source = new InputSource(stringReader);
            saxParser.parse(source);
        } catch(SAXException e) {
            throw new ProtocolException(
                        exceptionLocalizer.format("parse-error", s), e);
        } catch(IOException e) {
            // NOTE: we are currently reading from a string, so this ought
            // never to happen anyway.
            throw new ProtocolException(
                        exceptionLocalizer.format("parse-error", s), e);
        }

        // Add the parsed nodeValue into the dom, minus the root element.
        Document document = domParser.getDocument();

        return document.getRootElement();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.