Example usage for javax.xml.parsers DocumentBuilderFactory setXIncludeAware

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

Introduction

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

Prototype

public void setXIncludeAware(final boolean state) 

Source Link

Document

Set state of XInclude processing.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);// w w  w . j  av  a 2 s  . co  m
    factory.setXIncludeAware(true);
    DocumentBuilder parser = factory.newDocumentBuilder();
    System.out.println("aware: " + parser.isXIncludeAware());
    Document document = parser.parse(args[0]);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    Source source = new DOMSource(document);
    Result output = new StreamResult(System.out);
    transformer.transform(source, output);
}

From source file:Main.java

private static DocumentBuilderFactory getDocumentBuilderFactory() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//  ww  w.j  a va  2  s. c o m
    factory.setXIncludeAware(true);
    return factory;
}

From source file:Main.java

public static DocumentBuilderFactory getDBF(boolean namespaceaware) {
    DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
    fac.setValidating(false);/*from  w w w .  j  a v a 2  s.c o m*/
    fac.setNamespaceAware(namespaceaware);
    fac.setXIncludeAware(true);

    return fac;
}

From source file:Main.java

public static DocumentBuilderFactory getDBF(final boolean namespaceaware) {
    DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
    fac.setValidating(false);//from  ww w .j  a  v  a  2 s .  co  m
    fac.setNamespaceAware(namespaceaware);
    fac.setXIncludeAware(true);

    return fac;
}

From source file:Main.java

/**
 * Get a DocumentBuilder that is namespace aware.
 * @return a namespace-aware DocumentBuilder.
 *//*from w  ww  . ja v a  2s  .  com*/
public static DocumentBuilder getDocumentBuilder() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    dbf.setXIncludeAware(false);
    dbf.setExpandEntityReferences(true);
    dbf.setCoalescing(false);

    //dbf.setFeature("http://xml.org/sax/features/namespaces", false);
    //dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    dbf.setFeature("http://xml.org/sax/features/validation", false);
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

    return dbf.newDocumentBuilder();
}

From source file:Main.java

private static DocumentBuilder newDocumentBuilder(Schema schema, boolean isNamespaceAware,
        boolean isXIncludeAware) throws SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(isNamespaceAware);
    factory.setXIncludeAware(isXIncludeAware);
    if (schema != null) {
        factory.setSchema(schema);/*from ww w . java 2 s  .  com*/
        factory.setValidating(false);
    }
    DocumentBuilder builder = null;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
        // there is something seriously wrong
        throw new RuntimeException(ex);
    }
    return builder;
}

From source file:Main.java

private static DocumentBuilder getDocumentBuilder() {
    try {/*from w w  w .j a  v a2 s . com*/
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating(false);
        factory.setXIncludeAware(false);
        return factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

private static void setUpSecurity(DocumentBuilderFactory dbFactory) throws ParserConfigurationException {
    dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    dbFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
    dbFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    dbFactory.setXIncludeAware(false);
    dbFactory.setExpandEntityReferences(false);
}

From source file:com.pieframework.model.repository.ModelStore.java

/**
 * @param xmlFile//w  w w. j  a va 2 s  .  c  o m
 * @param writer
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws TransformerException
 */
protected static void processXIncludes(File xmlFile, Writer writer)
        throws ParserConfigurationException, SAXException, IOException, TransformerException {

    final InputStream xml = new FileInputStream(xmlFile);

    // This sets the base where XIncludes are resolved
    InputSource i = new InputSource(xml);
    i.setSystemId(xmlFile.toURI().toString());

    // Configure Document Builder
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setXIncludeAware(true);
    factory.setNamespaceAware(true);
    factory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
    DocumentBuilder docBuilder = factory.newDocumentBuilder();

    if (!docBuilder.isXIncludeAware()) {
        throw new IllegalStateException();
    }

    // Parse the InputSource
    Document doc = docBuilder.parse(i);

    // output
    Source source = new DOMSource(doc);
    Result result = new StreamResult(writer);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(source, result);
}

From source file:com.viettel.ws.client.JDBCUtil.java

/**
 * Create Empty Document//from  ww w .j  av a2s.  c o m
 *
 * @return A empty document
 * @throws ParserConfigurationException - If error when create document
 */
public static Document createDocument() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setFeature(FEATURE_GENERAL_ENTITIES, false);
    factory.setFeature(FEATURE_PARAMETER_ENTITIES, false);
    factory.setXIncludeAware(false);
    factory.setExpandEntityReferences(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();

    Element results = doc.createElement("Results");
    doc.appendChild(results);
    return doc;
}