Search in sources :

Example 1 with XmlInheritanceProcessor

use of com.haulmont.cuba.gui.xml.XmlInheritanceProcessor in project cuba by cuba-platform.

the class ScreensHelper method getWindowElement.

@Nullable
protected Element getWindowElement(String src) throws FileNotFoundException {
    String text = resources.getResourceAsString(src);
    if (StringUtils.isNotEmpty(text)) {
        try {
            Document document = dom4JTools.readDocument(text);
            XmlInheritanceProcessor processor = beanLocator.getPrototype(XmlInheritanceProcessor.NAME, document, emptyMap());
            Element root = processor.getResultRoot();
            if (root.getName().equals(Window.NAME) || root.getName().equals(Fragment.NAME)) {
                return root;
            }
        } catch (RuntimeException e) {
            log.error("Can't parse screen file: ", src);
        }
    } else {
        throw new FileNotFoundException("File doesn't exist or empty: " + src);
    }
    return null;
}
Also used : Element(org.dom4j.Element) FileNotFoundException(java.io.FileNotFoundException) Document(org.dom4j.Document) XmlInheritanceProcessor(com.haulmont.cuba.gui.xml.XmlInheritanceProcessor) Nullable(javax.annotation.Nullable)

Example 2 with XmlInheritanceProcessor

use of com.haulmont.cuba.gui.xml.XmlInheritanceProcessor in project cuba by cuba-platform.

the class ScreensHelper method getWindowElement.

@Nullable
protected Element getWindowElement(String src) throws FileNotFoundException {
    String text = resources.getResourceAsString(src);
    if (StringUtils.isNotEmpty(text)) {
        try {
            Document document = Dom4j.readDocument(text);
            XmlInheritanceProcessor processor = new XmlInheritanceProcessor(document, EMPTY_MAP);
            Element root = processor.getResultRoot();
            if (root.getName().equals(Window.NAME))
                return root;
        } catch (RuntimeException e) {
            log.error("Can't parse screen file: ", src);
        }
    } else {
        throw new FileNotFoundException("File doesn't exist or empty: " + src);
    }
    return null;
}
Also used : Element(org.dom4j.Element) FileNotFoundException(java.io.FileNotFoundException) Document(org.dom4j.Document) XmlInheritanceProcessor(com.haulmont.cuba.gui.xml.XmlInheritanceProcessor) Nullable(javax.annotation.Nullable)

Example 3 with XmlInheritanceProcessor

use of com.haulmont.cuba.gui.xml.XmlInheritanceProcessor in project cuba by cuba-platform.

the class ScreenXmlLoader method createDocument.

protected Document createDocument(String template, Map<String, Object> params) {
    Document originalDocument = screenXmlParser.parseDescriptor(template);
    XmlInheritanceProcessor processor = beanLocator.getPrototype(XmlInheritanceProcessor.NAME, originalDocument, params);
    Element resultRoot = processor.getResultRoot();
    return resultRoot.getDocument();
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document) XmlInheritanceProcessor(com.haulmont.cuba.gui.xml.XmlInheritanceProcessor)

Aggregations

XmlInheritanceProcessor (com.haulmont.cuba.gui.xml.XmlInheritanceProcessor)3 Document (org.dom4j.Document)3 Element (org.dom4j.Element)3 FileNotFoundException (java.io.FileNotFoundException)2 Nullable (javax.annotation.Nullable)2