Example usage for org.dom4j.io SAXReader setValidation

List of usage examples for org.dom4j.io SAXReader setValidation

Introduction

In this page you can find the example usage for org.dom4j.io SAXReader setValidation.

Prototype

public void setValidation(boolean validation) 

Source Link

Document

Sets the validation mode.

Usage

From source file:org.pentaho.pac.server.config.PentahoObjectsConfig.java

License:Open Source License

public PentahoObjectsConfig(String xml) throws DocumentException {
    SAXReader reader = new SAXReader();
    reader.setValidation(false);
    setDocument(reader.read(new ByteArrayInputStream(xml.getBytes())));
}

From source file:org.pentaho.platform.config.PentahoObjectsConfig.java

License:Open Source License

public PentahoObjectsConfig(String xml) throws DocumentException {
    SAXReader reader = XMLParserFactoryProducer.getSAXReader(null);
    reader.setValidation(false);
    setDocument(reader.read(new ByteArrayInputStream(xml.getBytes())));
}

From source file:org.sipfoundry.sipxconfig.test.XmlUnitHelper.java

License:Contributor Agreement License

/**
 * Loads XML document from class resource
 *
 * @param klass - for locating the file - pass this.class
 * @param name name of the file in the same directory as klass
 * @return newly read DOM4J document/*  w  ww.ja va2 s .  co m*/
 */
public static Document loadDocument(Class klass, String name) throws DocumentException {
    InputStream stream = klass.getResourceAsStream(name);
    SAXReader reader = new SAXReader();
    reader.setValidation(false);
    return reader.read(stream);
}

From source file:servlets.LoaderSoa10g.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("Ciauz");
    String path = request.getParameter("indirizzo").trim();

    File dir = new File(path);
    File[] directoryListing = dir.listFiles();
    if (directoryListing != null) {
        for (File child : directoryListing) {
            try {
                SAXReader reader = new SAXReader();
                reader.setValidation(false);
                Document document = reader.read(path + "/" + child.getName());
                Element root = document.getRootElement();
                System.out.println(root.getNamespace());
            } catch (DocumentException e) {
                e.printStackTrace();/*from  w w  w  .ja va  2 s  .c o  m*/
            }
        }
    } else {
        // Handle the case where dir is not really a directory.
        // Checking dir.isDirectry() above would not be sufficient
        // to avoid race conditions with another process that deletes
        // directories.
    }
}

From source file:uidserver.Config.java

public Config(String configFilePath) {
    File configFile = new File(configFilePath);
    if (configFile.exists()) {
        try {/*from   w w w  .j  ava2 s.  c  o  m*/
            SAXReader reader = new SAXReader();
            reader.addHandler("/config", new ElementHandler() {
                @Override
                public void onStart(ElementPath elementPath) {

                }

                @Override
                public void onEnd(ElementPath elementPath) {
                    Element row = elementPath.getCurrent();
                    readElement(row);
                    row.detach();
                }

                private void readElement(Element row) {
                    List<Element> nodes = row.elements();
                    if (!nodes.isEmpty()) {
                        for (Element node : nodes) {
                            String name = node.getName().toLowerCase();
                            String value = node.getText();
                            switch (name) {
                            case "logpath":
                                logPath = new File(value);
                                break;
                            case "port":
                                port = value;
                                break;
                            case "timeout":
                                timeOut = Integer.valueOf(value);
                                break;
                            case "uidfile":
                                uidFile = new File(value);
                                break;
                            }

                        }

                    } else {
                        System.out.println("Error: empty elements in config file, please add correct setup");
                        System.exit(0);
                    }

                }

            });

            reader.setValidation(false);
            Document document = reader.read(configFile);
            if (logPath != null && port != null && uidFile != null) {
                if (!logPath.exists()) {
                    if (!logPath.mkdirs()) {
                        System.out.println("Failed to create log file: " + logPath.getAbsoluteFile());
                        System.out.println("Please setup correct log file path");
                        System.exit(0);
                    }
                }

            } else {
                System.out.println("Please set up correct Port/LogFile/UidFile");
                System.exit(0);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Error during reading xml config file, please double check file content");
            System.exit(0);
        }
    } else {
        System.out.println("The specified config file: " + configFile.getAbsolutePath() + " doesn't exist");
        System.out.println("Please key in correct config file path");
        System.exit(0);
    }
}