Search in sources :

Example 56 with DocumentException

use of org.dom4j.DocumentException in project cuba by cuba-platform.

the class UserSetHelper method addEntities.

public static String addEntities(String filterXml, Collection ids) {
    Document document;
    try {
        document = DocumentHelper.parseText(filterXml);
    } catch (DocumentException e) {
        throw new RuntimeException(e);
    }
    Element param = document.getRootElement().element("and").element("c").element("param");
    String currentIds = param.getTextTrim();
    Set<String> set = parseSet(currentIds);
    String listOfIds = createIdsString(set, ids);
    param.setText(listOfIds);
    return document.asXML();
}
Also used : DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 57 with DocumentException

use of org.dom4j.DocumentException in project cuba by cuba-platform.

the class AbstractViewRepository method addFile.

protected void addFile(Element commonRootElem, String fileName) {
    if (readFileNames.contains(fileName))
        return;
    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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 58 with DocumentException

use of org.dom4j.DocumentException in project cuba by cuba-platform.

the class AppComponents method getDescriptorDoc.

private Document getDescriptorDoc(AppComponent component) {
    String descriptorPath = component.getDescriptorPath();
    InputStream descrStream = getClass().getClassLoader().getResourceAsStream(descriptorPath);
    if (descrStream == null) {
        throw new RuntimeException(String.format("App component descriptor was not found in '%s'", descriptorPath));
    }
    try {
        SAXReader reader = new SAXReader();
        return reader.read(new InputStreamReader(descrStream, StandardCharsets.UTF_8));
    } catch (DocumentException e) {
        throw new RuntimeException(String.format("Error reading app component descriptor '%s'", descriptorPath), e);
    } finally {
        try {
            descrStream.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException)

Example 59 with DocumentException

use of org.dom4j.DocumentException in project cuba by cuba-platform.

the class DesktopThemeLoaderImpl method readXmlDocument.

private Document readXmlDocument(Resource resource) throws IOException {
    Document doc;
    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;
}
Also used : InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 60 with DocumentException

use of org.dom4j.DocumentException in project cuba by cuba-platform.

the class MetadataLoader method loadDatatypesFromClasspathResource.

protected void loadDatatypesFromClasspathResource() {
    SAXReader reader = new SAXReader();
    URL resource = Datatypes.class.getResource(getGetDatatypesResourcePath());
    if (resource != null) {
        log.info("Loading datatypes from " + resource);
        try {
            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);
        }
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) AnnotatedElement(java.lang.reflect.AnnotatedElement) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document) URL(java.net.URL) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Aggregations

DocumentException (org.dom4j.DocumentException)123 Document (org.dom4j.Document)80 SAXReader (org.dom4j.io.SAXReader)73 Element (org.dom4j.Element)51 IOException (java.io.IOException)45 File (java.io.File)27 InputStream (java.io.InputStream)21 StringReader (java.io.StringReader)15 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)10 XMLWriter (org.dom4j.io.XMLWriter)9 InputSource (org.xml.sax.InputSource)9 FileInputStream (java.io.FileInputStream)7 URL (java.net.URL)7 List (java.util.List)7 Node (org.dom4j.Node)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 FileNotFoundException (java.io.FileNotFoundException)5 Reader (java.io.Reader)5