Example usage for org.jdom2.input.sax XMLReaders XSDVALIDATING

List of usage examples for org.jdom2.input.sax XMLReaders XSDVALIDATING

Introduction

In this page you can find the example usage for org.jdom2.input.sax XMLReaders XSDVALIDATING.

Prototype

XMLReaders XSDVALIDATING

To view the source code for org.jdom2.input.sax XMLReaders XSDVALIDATING.

Click Source Link

Document

The XSD-validating Singleton

Usage

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static Document loadDocument(URL configs, boolean validate) {
    Document properties;/*  w  w w . j  a  v a 2s.  com*/
    SAXBuilder docBuilder;
    if (validate) {
        docBuilder = new SAXBuilder(XMLReaders.XSDVALIDATING);
    } else {
        docBuilder = new SAXBuilder(XMLReaders.NONVALIDATING);
    }
    try {
        properties = docBuilder.build(configs);
    } catch (NullPointerException ex) {
        LoggerFactory.getLogger(LouieProperties.class)
                .error("Failed to load properties file. Defaults will be used.\n{}", ex.toString());
        System.out.println(ex.getMessage());
        List<Server> empty = Collections.emptyList();
        Server.processServers(empty);
        return null;
    } catch (IOException | JDOMException ex) {
        Matcher match = missingElem.matcher(ex.getMessage());
        if (match.matches()) {
            LoggerFactory.getLogger(LouieProperties.class).info("No schema located: no validation performed.");
            return loadDocument(configs, false);
        } else {
            String error = "Properties file error! All services shutdown";
            ServiceManager.recordError(error, ex);
            LoggerFactory.getLogger(LouieProperties.class).error("{}\n{}", error, ex.toString());
            List<Server> empty = Collections.emptyList();
            ServiceProperties.globalDisable(); //brute disable
            Server.processServers(empty);
            return null;
        }
    }
    document = new XMLOutputter().outputString(properties);
    return properties;
}

From source file:de.andrena.tools.macker.rule.RuleSetBuilder.java

License:Open Source License

public RuleSetBuilder() {
    saxBuilder = new SAXBuilder(XMLReaders.XSDVALIDATING);
}

From source file:XMLReader.ReadXMLFile.java

License:Open Source License

public static List<String> ReadKeywords(String lang, String xmlSource) {
    Namespace ns = Namespace.getNamespace("nsKeywords", "http://www.w3.org/keywords");
    SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
    List<String> keywords = new ArrayList<String>();

    try {/*from w ww  . jav a 2s. c om*/
        Element rootNode = builder.build(xmlSource).getRootElement();
        Element leng = rootNode.getChild(lang, ns);
        List<Element> lista = leng.getChildren("keyword", ns);

        for (Element e : lista)
            keywords.add(e.getTextNormalize());
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
    return keywords;
}