Example usage for org.xml.sax.helpers XMLReaderFactory createXMLReader

List of usage examples for org.xml.sax.helpers XMLReaderFactory createXMLReader

Introduction

In this page you can find the example usage for org.xml.sax.helpers XMLReaderFactory createXMLReader.

Prototype

public static XMLReader createXMLReader(String className) throws SAXException 

Source Link

Document

Attempt to create an XML reader from a class name.

Usage

From source file:org.smartfrog.projects.alpine.xmlutils.ParserHelper.java

/**
 * create Xerces. look first for xerces, then for the sun version
 *
 * @return a copy of Xerces//w w  w. j a v  a2 s.  c o m
 * @throws org.xml.sax.SAXException if neither implementation coudl be loaded
 */
public static XMLReader createBaseXercesInstance() throws SAXException {
    XMLReader xerces;
    try {
        xerces = XMLReaderFactory.createXMLReader(PARSER_XERCES);
    } catch (SAXException e) {
        log.info("Failed to find Xerces; using the Java 1.5+ parser");
        xerces = XMLReaderFactory.createXMLReader(PARSER_JAVA_15);
    }
    return xerces;
}

From source file:org.smartfrog.services.cddlm.cdl.XmlHelper.java

/**
 * create our XML parser. We are relying on xerces here, and will fail if it
 * is not found.//from   w w w.  j ava2 s.co m
 *
 * @param validate
 * @return
 * @throws org.xml.sax.SAXException
 */
public static XMLReader createXmlParser(boolean validate) throws SAXException {
    XMLReader xerces = null;
    try {
        xerces = XMLReaderFactory.createXMLReader(PARSER_NAME);
        setFeature(xerces, "http://apache.org/xml/features/validation/schema", validate);
        setFeature(xerces, "http://apache.org/xml/features/validation/schema-full-checking", validate);
        setFeature(xerces, "http://apache.org/xml/features/standard-uri-conformant", true);
        setFeature(xerces, "http://apache.org/xml/features/disallow-doctype-decl", true);
        setFeature(xerces, "http://xml.org/sax/features/external-general-entities", false);
    } catch (SAXException e) {
        throw e;
    }
    return xerces;
}

From source file:org.topazproject.xml.transform.EntityResolvingSource.java

private static XMLReader createXMLReader(EntityResolver resolver) throws SAXException {
    try {/* w w w. j  a v a  2  s .com*/
        XMLReader rdr = XMLReaderFactory.createXMLReader(xmlReaderCName);
        rdr.setEntityResolver(resolver);
        return rdr;
    } catch (SAXException se) {
        log.error("Unable to create XMLReader from " + xmlReaderCName, se);
        throw se;
    }
}

From source file:org.xwiki.portlet.view.HTMLStreamFilter.java

/**
 * {@inheritDoc}//from www . ja va 2 s. c om
 * 
 * @see StreamFilter#filter(Reader, Writer)
 */
public void filter(Reader reader, Writer writer) {
    try {
        XMLReader xmlReader = XMLReaderFactory.createXMLReader("org.cyberneko.html.parsers.SAXParser");
        xmlReader.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment", true);
        xmlReader.setProperty("http://cyberneko.org/html/properties/names/elems", "match");
        xmlReader.setProperty("http://cyberneko.org/html/properties/names/attrs", "no-change");

        XMLReader parent = xmlReader;
        for (XMLFilter filter : filters) {
            filter.setParent(parent);
            parent = filter;
        }

        XHTMLWriter xhtmlWriter = new XHTMLWriter(writer);
        xhtmlWriter.setParent(parent);
        xhtmlWriter.parse(new InputSource(reader));
    } catch (Exception e) {
        LOG.error("Failed to rewrite servlet HTML.", e);
    }
}

From source file:org.yawlfoundation.yawl.unmarshal.YawlXMLSpecificationValidator.java

/**
 * Sets the checker up for a run.//from  www.j a  v  a 2s . c om
 * @param version the version of the schema
 * @return a reader configured to do the checking.
 * @throws SAXException
 */
private XMLReader setUpChecker(String version) throws SAXException {
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    if (YSpecification.isValidVersion(version)) {
        parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
                getSchemaLocation(version));
    } else {
        throw new RuntimeException("Version [" + version + "] is not valid version.");
    }
    parser.setContentHandler(this);
    parser.setErrorHandler(this);
    parser.setFeature("http://xml.org/sax/features/validation", true);
    parser.setFeature("http://apache.org/xml/features/validation/schema", true);
    parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
    return parser;
}