Example usage for org.dom4j.io SAXReader SAXReader

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

Introduction

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

Prototype

public SAXReader() 

Source Link

Usage

From source file:com.googlecode.starflow.engine.xml.ProcessDefineParser.java

License:Apache License

public static Document createDocument(String xml) {
    SAXReader reader = new SAXReader();
    Document document = null;//from  w w  w .  j  a v  a  2 s  .c om
    try {
        document = reader.read(new StringReader(xml));
    } catch (Exception e) {
        throw new StarFlowParserException("???", e);
    }
    return document;
}

From source file:com.gote.importexport.ExportTournamentForOpenGotha.java

License:Apache License

/**
 * Build a Document object from File content
 * //from   w w w .  j  a va 2 s  . co  m
 * @param pContent String
 * @return Document
 */
private Document getDocumentFromContent(String pContent) {
    SAXReader reader = new SAXReader();
    try {
        return reader.read(new StringReader(pContent));
    } catch (DocumentException e) {
        LOGGER.log(Level.SEVERE, "DocumentException, creation stopped : " + e);
        return null;
    }
}

From source file:com.gote.importexport.ImportTournamentFromGOTE.java

License:Apache License

@Override
public Tournament createTournamentFromConfig(File pFile) {
    LOGGER.log(Level.INFO, "Loading tournament from file " + pFile);

    Tournament tournament = new Tournament();
    String content = ImportExportUtil.getFileContent(pFile);
    if (content == null) {
        LOGGER.log(Level.SEVERE, "File \"" + pFile.getPath() + "\" content is null");
        return null;
    }//from  w w  w.ja v  a  2 s .c  om

    SAXReader reader = new SAXReader();
    Document document;
    try {
        document = reader.read(new StringReader(content));
    } catch (DocumentException e) {
        LOGGER.log(Level.SEVERE, "DocumentException, creation stopped : " + e);
        return null;
    }

    Element pElementTournament = document.getRootElement();

    boolean initSuccess = initTournament(tournament, pElementTournament);

    if (initSuccess) {
        return tournament;
    } else {
        return null;
    }
}

From source file:com.gote.importexport.ImportTournamentFromOpenGotha.java

License:Apache License

@Override
public Tournament createTournamentFromConfig(File pFile) {

    LOGGER.log(Level.INFO, "A new tournament is going to be created from the file : " + pFile.getPath());

    Tournament tournament = new Tournament();
    String content = ImportExportUtil.getFileContent(pFile);

    if (content == null) {
        LOGGER.log(Level.SEVERE, "File \"" + pFile.getPath() + "\" content is null");
        return null;
    }/*w  w w.j  a  v a2  s  .c  o  m*/

    SAXReader reader = new SAXReader();
    Document document;
    try {
        document = reader.read(new StringReader(content));
    } catch (DocumentException e) {
        LOGGER.log(Level.SEVERE, "DocumentException, creation stopped : " + e);
        return null;
    }

    Element pElementTournament = document.getRootElement();

    boolean initSuccess = initTournament(tournament, pElementTournament);

    if (initSuccess) {
        return tournament;
    } else {
        return null;
    }
}

From source file:com.haulmont.chile.core.datatypes.Datatypes.java

License:Apache License

private Datatypes() {
    SAXReader reader = new SAXReader();
    URL resource = Datatypes.class.getResource("/datatypes.xml");
    if (resource == null) {
        log.info("Can't find /datatypes.xml, using default datatypes settings");
        resource = Datatypes.class.getResource("/com/haulmont/chile/core/datatypes/datatypes.xml");
    }//from  w w  w  .  j av a  2  s  .  c  o m

    try {
        Document document = reader.read(resource);
        Element element = document.getRootElement();

        List<Element> datatypeElements = element.elements("datatype");
        for (Element datatypeElement : datatypeElements) {
            String datatypeClassName = datatypeElement.attributeValue("class");
            try {
                Datatype datatype;
                Class<Datatype> datatypeClass = ReflectionHelper.getClass(datatypeClassName);
                try {
                    final Constructor<Datatype> constructor = datatypeClass.getConstructor(Element.class);
                    datatype = constructor.newInstance(datatypeElement);
                } catch (Throwable e) {
                    datatype = datatypeClass.newInstance();
                }

                __register(datatype);
            } catch (Throwable e) {
                log.error(String.format("Fail to load datatype '%s'", datatypeClassName), e);
            }
        }
    } catch (DocumentException e) {
        log.error("Fail to load datatype settings", e);
    }
}

From source file:com.haulmont.cuba.core.sys.AbstractViewRepository.java

License:Apache License

protected void addFile(Element commonRootElem, String fileName) {
    if (readFileNames.contains(fileName))
        return;// w ww .jav  a2s.  co  m

    log.debug("Deploying views config: " + fileName);
    readFileNames.add(fileName);

    InputStream stream = null;
    try {
        stream = resources.getResourceAsStream(fileName);
        if (stream == null) {
            throw new IllegalStateException("Resource is not found: " + fileName);
        }

        SAXReader reader = new SAXReader();
        Document doc;
        try {
            doc = reader.read(new InputStreamReader(stream, StandardCharsets.UTF_8));
        } catch (DocumentException e) {
            throw new RuntimeException("Unable to parse view file " + fileName, e);
        }
        Element rootElem = doc.getRootElement();

        for (Element includeElem : Dom4j.elements(rootElem, "include")) {
            String incFile = includeElem.attributeValue("file");
            if (!StringUtils.isBlank(incFile))
                addFile(commonRootElem, incFile);
        }

        for (Element viewElem : Dom4j.elements(rootElem, "view")) {
            commonRootElem.add(viewElem.createCopy());
        }
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:com.haulmont.cuba.core.sys.AbstractViewRepository.java

License:Apache License

public void deployViews(Reader xml) {
    lock.readLock().lock();//w  w w .ja  v a  2  s .  c om
    try {
        checkInitialized();
    } finally {
        lock.readLock().unlock();
    }

    SAXReader reader = new SAXReader();
    Document doc;
    try {
        doc = reader.read(xml);
    } catch (DocumentException e) {
        throw new RuntimeException("Unable to read views xml", e);
    }
    Element rootElem = doc.getRootElement();

    for (Element includeElem : Dom4j.elements(rootElem, "include")) {
        String file = includeElem.attributeValue("file");
        if (!StringUtils.isBlank(file))
            deployViews(file);
    }

    for (Element viewElem : Dom4j.elements(rootElem, "view")) {
        deployView(rootElem, viewElem);
    }
}

From source file:com.haulmont.cuba.core.sys.AppComponents.java

License:Apache License

private Document getDescriptorDoc(AppComponent component) throws IOException, DocumentException {
    String descriptorPath = component.getDescriptorPath();
    InputStream descrStream = getClass().getClassLoader().getResourceAsStream(descriptorPath);
    if (descrStream == null)
        throw new RuntimeException("App component descriptor was not found in '" + descriptorPath + "'");
    try {//from  w  w w.  j  av a2  s. c o m
        SAXReader reader = new SAXReader();
        return reader.read(new InputStreamReader(descrStream, StandardCharsets.UTF_8));
    } catch (DocumentException e) {
        throw new RuntimeException("Error reading app component descriptor '" + descriptorPath + "'", e);
    } finally {
        IOUtils.closeQuietly(descrStream);
    }
}

From source file:com.haulmont.cuba.core.sys.MetadataLoader.java

License:Apache License

protected void loadDatatypesFromClasspathResource() {
    SAXReader reader = new SAXReader();
    URL resource = Datatypes.class.getResource(getGetDatatypesResourcePath());
    if (resource != null) {
        log.info("Loading datatypes from " + resource);
        try {/*from  www.j  a v  a2s .co m*/
            Document document = reader.read(resource);
            Element element = document.getRootElement();

            List<Element> datatypeElements = Dom4j.elements(element, "datatype");
            for (Element datatypeElement : datatypeElements) {
                String datatypeClassName = datatypeElement.attributeValue("class");
                try {
                    Datatype datatype;
                    Class<Datatype> datatypeClass = ReflectionHelper.getClass(datatypeClassName);
                    try {
                        final Constructor<Datatype> constructor = datatypeClass.getConstructor(Element.class);
                        datatype = constructor.newInstance(datatypeElement);
                    } catch (Throwable e) {
                        datatype = datatypeClass.newInstance();
                    }

                    String id = datatypeElement.attributeValue("id");
                    if (Strings.isNullOrEmpty(id))
                        id = guessDatatypeId(datatype);
                    datatypeRegistry.register(datatype, id, true);
                } catch (Throwable e) {
                    log.error(String.format("Fail to load datatype '%s'", datatypeClassName), e);
                }
            }
        } catch (DocumentException e) {
            log.error("Fail to load datatype settings", e);
        }
    }
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

License:Apache License

private Document readXmlDocument(Resource resource) throws IOException {
    Document doc;/*www  .j ava  2  s . com*/
    InputStream stream = null;
    try {
        stream = resource.getInputStream();
        try {
            SAXReader reader = new SAXReader();
            doc = reader.read(stream);
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return doc;
}