Example usage for javax.xml.parsers SAXParserFactory setXIncludeAware

List of usage examples for javax.xml.parsers SAXParserFactory setXIncludeAware

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParserFactory setXIncludeAware.

Prototype

public void setXIncludeAware(final boolean state) 

Source Link

Document

Set state of XInclude processing.

Usage

From source file:Main.java

/**
 * Convenience method: creates and returns a SAXParser.
 * //from  ww w  . ja v  a 2s  . c  o  m
 * @param namespaceAware specifies whether the parser produced 
 * by this code will provide support for XML namespaces
 * @param validating specifies whether the parser produced by 
 * this code will validate documents against their DTD
 * @param xIncludeAware specifies whether the parser produced by 
 * this code will process XIncludes
 * @return newly created SAXParser
 * @exception ParserConfigurationException if a parser cannot be created 
 * which satisfies the requested configuration
 * @exception SAXException for SAX errors
 */
public static SAXParser newSAXParser(boolean namespaceAware, boolean validating, boolean xIncludeAware)
        throws ParserConfigurationException, SAXException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(namespaceAware);
    factory.setValidating(validating);
    factory.setXIncludeAware(xIncludeAware);

    // For Xerces which otherwise, does not support "x-MacRoman".
    try {
        factory.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
    } catch (Exception ignored) {
    }

    return factory.newSAXParser();
}

From source file:net.sf.jasperreports.renderers.util.XmlDataSniffer.java

public static XmlSniffResult sniffXml(byte[] data) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);//from www .  j ava2s  .  co m
    factory.setNamespaceAware(false);
    factory.setXIncludeAware(false);
    setParserFeature(factory, FEATURE_EXTERNAL_GENERAL_ENTITIES, false);
    setParserFeature(factory, FEATURE_EXTERNAL_PARAMETER_ENTITIES, false);
    setParserFeature(factory, FEATURE_LOAD_EXTERNAL_DTD, false);

    SaxHandler handler = new SaxHandler();

    ByteArrayInputStream bais = new ByteArrayInputStream(data);

    try {
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(bais, handler);
        return new XmlSniffResult(handler.rootElementName);
    } catch (ValidXmlSAXException e) {
        return new XmlSniffResult(handler.rootElementName);
    } catch (SAXException | ParserConfigurationException | IOException e) {
        return null;
    }
}

From source file:com.google.code.docbook4j.renderer.BaseRenderer.java

protected SAXParserFactory createParserFactory() {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setXIncludeAware(true);
    factory.setNamespaceAware(true);/*  w  ww. j a  v  a2 s.c  o m*/
    return factory;
}

From source file:nl.armatiek.xslweb.configuration.WebApp.java

public XsltExecutable tryTemplatesCache(String transformationPath, ErrorListener errorListener)
        throws Exception {
    String key = FilenameUtils.normalize(transformationPath);
    XsltExecutable templates = templatesCache.get(key);
    if (templates == null) {
        logger.info("Compiling and caching stylesheet \"" + transformationPath + "\" ...");
        try {/* w  ww  .j  a  v  a2s  .c o m*/
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setNamespaceAware(true);
            spf.setXIncludeAware(true);
            spf.setValidating(false);
            SAXParser parser = spf.newSAXParser();
            XMLReader reader = parser.getXMLReader();
            Source source = new SAXSource(reader, new InputSource(transformationPath));
            XsltCompiler comp = processor.newXsltCompiler();
            comp.setErrorListener(errorListener);
            templates = comp.compile(source);
        } catch (Exception e) {
            logger.error("Could not compile stylesheet \"" + transformationPath + "\"", e);
            throw e;
        }
        if (!developmentMode) {
            templatesCache.put(key, templates);
        }
    }
    return templates;
}

From source file:com.agilejava.docbkx.maven.AbstractTransformerMojo.java

/**
 * Returns the SAXParserFactory used for constructing parsers.
 *///from   w  w w.  j  av a2  s  . c o m
private SAXParserFactory createParserFactory() {
    SAXParserFactory factory = new SAXParserFactoryImpl();
    factory.setXIncludeAware(getXIncludeSupported());
    return factory;
}

From source file:org.kalypso.mapserver.utils.MapFileUtilities.java

/**
 * This function loads a map file from XML.
 *
 * @param inputStream//from  w  ww. ja  va2s .  c o  m
 *          The input stream.
 * @return The contents of the map file.
 */
public static Map loadFromXML(final InputStream inputStream)
        throws JAXBException, SAXException, ParserConfigurationException, IOException {
    /* Create the unmarshaller. */
    final Unmarshaller unmarshaller = JC.createUnmarshaller();

    /* Get the sax parser factory. */
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setXIncludeAware(true);

    /* Get the xml reader. */
    final XMLReader xr = spf.newSAXParser().getXMLReader();
    xr.setContentHandler(unmarshaller.getUnmarshallerHandler());
    xr.parse(new InputSource(inputStream));

    return (Map) unmarshaller.getUnmarshallerHandler().getResult();
}

From source file:org.kalypso.ogc.gml.GisTemplateHelper.java

public static final Gismapview loadGisMapView(final InputSource is)
        throws JAXBException, SAXException, ParserConfigurationException, IOException {
    final Unmarshaller unmarshaller = TemplateUtilities.createGismapviewUnmarshaller();

    // XInclude awareness
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);//  w  w w .j a  va  2 s  .  co m
    spf.setXIncludeAware(true);
    final XMLReader xr = spf.newSAXParser().getXMLReader();
    xr.setContentHandler(unmarshaller.getUnmarshallerHandler());
    xr.parse(is);
    return (Gismapview) unmarshaller.getUnmarshallerHandler().getResult();
}