Example usage for org.jdom2.input SAXBuilder setFeature

List of usage examples for org.jdom2.input SAXBuilder setFeature

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder setFeature.

Prototype

public void setFeature(final String name, final boolean value) 

Source Link

Document

This sets a feature on the SAX parser.

Usage

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat,
        boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from   w  w w  .j  a  v  a 2s  .  c  om
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }

        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}

From source file:org.jumpmind.metl.ui.views.design.EditXmlFormatPanel.java

License:Open Source License

protected void buildXpathChoices() {
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    Setting setting = component.findSetting(XmlFormatter.XML_FORMATTER_TEMPLATE);
    if (StringUtils.isNotBlank(setting.getValue())) {
        try {/*from  w w  w . j av  a 2 s .  com*/
            Document document = builder.build(new StringReader(setting.getValue()));
            xpathChoices = new HashSet<String>();
            buildXpathChoicesFromElement("/" + document.getRootElement().getName(), document.getRootElement());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.jumpmind.metl.ui.views.design.EditXmlParserPanel.java

License:Open Source License

protected void buildXpathChoices() {
    xpathChoices = new ArrayList<>();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    Setting setting = component.findSetting(XmlFormatter.XML_FORMATTER_TEMPLATE);
    if (StringUtils.isNotBlank(setting.getValue())) {
        try {/*from ww w . j  a  v a 2 s .  c om*/
            Document document = builder.build(new StringReader(setting.getValue()));
            buildXpathChoicesForElement("", document.getRootElement());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.jumpmind.metl.ui.views.design.ImportXmlTemplateWindow.java

License:Open Source License

protected void importXml(String text) {
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from  w  w  w. j a  v  a  2 s. c o m
        Document document = builder.build(new StringReader(text));
        String rootName = document.getRootElement().getName();
        if (rootName.equals("definitions")) {
            importFromWsdl(text);
        } else if (rootName.equals("schema")) {
            importFromXsd(text);
        } else {
            Notification note = new Notification("Unrecognized Content", "The XML file has a root element of "
                    + rootName + ", but expected \"definitions\" for WSDL or \"schema\" for XSD.");
            note.show(Page.getCurrent());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.springframework.data.solr.showcase.Application.java

License:Apache License

public static String readPMCFileTextBody(File file) {

    String bodytext = "";

    try {/*w  w w .  j  a va2 s . c o m*/

        SAXBuilder saxBuilder = new SAXBuilder();

        // saxBuilder.setValidation(false);

        saxBuilder.setFeature("http://xml.org/sax/features/validation", false);

        saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);

        saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

        try {

            // converted file to document object
            Document document = saxBuilder.build(file);

            // get root node from xml
            Element rootNode = document.getRootElement(); // article

            Element body = rootNode.getChild("body");

            if (body != null) {

                List<Element> bodychildren = body.getChildren();

                //int counter = 0;

                for (int i = 0; i < bodychildren.size(); i++) {

                    Element bc = bodychildren.get(i);

                    String sth = readElement(bc, "");

                    //System.out.println(++counter +  ") " + sth);

                    bodytext = bodytext.concat(sth);
                }

                //System.out.println(WordUtils.wrap(bodytext, 90));
            }
        } catch (JDOMException e) {

            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (IOException e1) {

        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    return bodytext;
}

From source file:password.pwm.util.java.XmlUtil.java

License:Open Source License

private static SAXBuilder getBuilder() {
    final SAXBuilder builder = new SAXBuilder();
    builder.setExpandEntities(false);/*from ww w.  jav a2  s.c o  m*/
    builder.setValidation(false);
    builder.setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);
    return builder;
}

From source file:se.miun.itm.input.util.xml.SAXBuilderQueue.java

License:Open Source License

private static SAXBuilder createBuilder(boolean verify) {
    SAXBuilder builder = new SAXBuilder();
    builder.setFeature(VALIDATION_SCHEMA, verify);
    builder.setFeature(VALIDATION, verify);
    builder.setFeature(CHECKING, verify);
    return builder;
}