Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

In this page you can find the example usage for org.dom4j Element elements.

Prototype

List<Element> elements(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:com.haulmont.cuba.gui.WindowManager.java

License:Apache License

protected Map<String, Object> createParametersMap(WindowInfo windowInfo, Map<String, Object> params) {
    Map<String, Object> map = new HashMap<>(params.size());

    Element element = windowInfo.getDescriptor();
    if (element != null) {
        Element paramsElement = element.element("params") != null ? element.element("params") : element;
        if (paramsElement != null) {
            @SuppressWarnings({ "unchecked" })
            List<Element> paramElements = paramsElement.elements("param");
            for (Element paramElement : paramElements) {
                String name = paramElement.attributeValue("name");
                String value = paramElement.attributeValue("value");
                if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
                    Boolean booleanValue = Boolean.valueOf(value);
                    map.put(name, booleanValue);
                } else {
                    map.put(name, value);
                }//from   ww  w  .  j  ava2  s. co  m
            }
        }
    }
    map.putAll(params);

    return map;
}

From source file:com.haulmont.cuba.gui.xml.data.DsContextLoader.java

License:Apache License

public DsContext loadDatasources(@Nullable Element element, @Nullable DsContext parent) {
    if (element == null) {
        context = new DsContextImpl(dataservice);
        if (parent != null)
            context.setParent(parent);/*  w w w  .ja v  a2s  .c  o m*/
        return context;
    }

    String contextClass = element.attributeValue("class");
    if (StringUtils.isEmpty(contextClass)) {
        final Element contextClassElement = element.element("class");
        if (contextClassElement != null) {
            contextClass = contextClassElement.getText();
            if (StringUtils.isEmpty(contextClass)) {
                throw new IllegalStateException("Can't find dsContext class name");
            }
            context = createDsContext(contextClass, contextClassElement);
        } else {
            context = new DsContextImpl(dataservice);
        }
    } else {
        context = createDsContext(contextClass, null);
    }
    if (parent != null) {
        context.setParent(parent);
    }

    builder = DsBuilder.create(context);

    //noinspection unchecked
    List<Element> elements = element.elements("datasource");
    for (Element ds : elements) {
        Datasource datasource = loadDatasource(ds);
        setLoadDynamicAttributes(ds, datasource);
    }

    //noinspection unchecked
    elements = element.elements("hierarchicalDatasource");
    for (Element ds : elements) {
        Datasource datasource = loadHierarchicalDatasource(ds);
        setLoadDynamicAttributes(ds, datasource);
    }

    //noinspection unchecked
    elements = element.elements("collectionDatasource");
    for (Element ds : elements) {
        CollectionDatasource datasource = loadCollectionDatasource(ds);
        setLoadDynamicAttributes(ds, datasource);
    }

    //noinspection unchecked
    elements = element.elements("groupDatasource");
    for (Element ds : elements) {
        Datasource datasource = loadGroupDatasource(ds);
        setLoadDynamicAttributes(ds, datasource);
    }

    //noinspection unchecked
    elements = element.elements("runtimePropsDatasource");
    for (Element ds : elements) {
        loadRuntimePropsDatasource(ds);
    }

    //noinspection unchecked
    elements = element.elements("valueCollectionDatasource");
    for (Element ds : elements) {
        loadValueCollectionDatasource(ds);
    }

    //noinspection unchecked
    elements = element.elements("valueGroupDatasource");
    for (Element ds : elements) {
        loadValueGroupDatasource(ds);
    }

    //noinspection unchecked
    elements = element.elements("valueHierarchicalDatasource");
    for (Element ds : elements) {
        loadValueHierarchicalDatasource(ds);
    }

    context.executeLazyTasks();

    return context;
}

From source file:com.haulmont.cuba.gui.xml.data.DsContextLoader.java

License:Apache License

protected void loadDatasources(Element element, Datasource datasource) {
    //noinspection unchecked
    List<Element> elements = element.elements("datasource");
    for (Element ds : elements) {
        final String property = ds.attributeValue("property");
        loadDatasource(ds, datasource, property);
    }/*from  w  ww .  ja  va  2  s  .  c o  m*/

    //noinspection unchecked
    elements = element.elements("collectionDatasource");
    for (Element ds : elements) {
        final String property = ds.attributeValue("property");
        loadCollectionDatasource(ds, datasource, property);
    }

    //noinspection unchecked
    elements = element.elements("groupDatasource");
    for (Element ds : elements) {
        final String property = ds.attributeValue("property");
        loadGroupDatasource(ds, datasource, property);
    }

    //noinspection unchecked
    elements = element.elements("hierarchicalDatasource");
    for (Element ds : elements) {
        final String property = ds.attributeValue("property");
        loadHierarchicalDatasource(ds, datasource, property);
    }

    //noinspection unchecked
    elements = element.elements("runtimePropsDatasource");
    for (Element ds : elements) {
        loadRuntimePropsDatasource(ds);
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractFieldLoader.java

License:Apache License

protected void loadValidators(Field component, Element element) {
    @SuppressWarnings({ "unchecked" })
    List<Element> validatorElements = element.elements("validator");

    if (!validatorElements.isEmpty()) {
        for (Element validatorElement : validatorElements) {
            Field.Validator validator = loadValidator(validatorElement);
            if (validator != null) {
                component.addValidator(validator);
            }/*from  w  ww  .jav  a  2 s  . c o  m*/
        }

    } else if (component.getDatasource() != null) {
        MetaProperty property = component.getMetaProperty();
        Field.Validator validator = getDefaultValidator(property);
        if (validator != null) {
            component.addValidator(validator);
        }
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractTableLoader.java

License:Apache License

protected List<Table.Column> loadColumns(Table component, Element columnsElement, CollectionDatasource ds) {
    List<Table.Column> columns = new ArrayList<>();
    //noinspection unchecked
    for (Element columnElement : (Collection<Element>) columnsElement.elements("column")) {
        String visible = columnElement.attributeValue("visible");
        if (StringUtils.isEmpty(visible) || Boolean.parseBoolean(visible)) {
            columns.add(loadColumn(columnElement, ds));
        }/*from ww  w . j  a  v  a 2 s .  co m*/
    }
    return columns;
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractTableLoader.java

License:Apache License

protected void loadValidators(Table component, Element element) {
    @SuppressWarnings("unchecked")
    List<Element> validatorElements = element.elements("validator");

    for (Element validatorElement : validatorElements) {
        final Field.Validator validator = loadValidator(validatorElement);
        if (validator != null) {
            component.addValidator(validator);
        }/*w  w w .j  av  a  2  s  .  com*/
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.DataGridLoader.java

License:Apache License

protected List<Column> loadColumns(DataGrid component, Element columnsElement, CollectionDatasource ds) {
    List<Column> columns = new ArrayList<>();
    //noinspection unchecked
    for (Element columnElement : (Collection<Element>) columnsElement.elements("column")) {
        columns.add(loadColumn(component, columnElement, ds));
    }/*from w  ww  .  j av  a  2  s . c o  m*/
    return columns;
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.FieldGroupLoader.java

License:Apache License

protected List<FieldGroup.FieldConfig> loadFields(FieldGroup resultComponent, Element element, Datasource ds,
        @Nullable String columnWidth) {
    @SuppressWarnings("unchecked")
    List<Element> fieldElements = element.elements("field");
    if (!fieldElements.isEmpty()) {
        return loadFields(resultComponent, fieldElements, ds, columnWidth);
    }//from   w  w  w  .j a  v  a 2s  . co  m
    return Collections.emptyList();
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.FieldGroupLoader.java

License:Apache License

protected void loadValidators(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
    Element descriptor = field.getXmlDescriptor();
    @SuppressWarnings("unchecked")
    List<Element> validatorElements = (descriptor == null) ? null : descriptor.elements("validator");
    if (validatorElements != null) {
        if (!validatorElements.isEmpty()) {
            for (Element validatorElement : validatorElements) {
                Field.Validator validator = loadValidator(validatorElement);
                if (validator != null) {
                    field.addValidator(validator);
                }/*  w w  w  .j a v a 2 s.  c o m*/
            }
        }
    } else {
        Datasource ds;
        if (field.getDatasource() == null) {
            ds = resultComponent.getDatasource();
        } else {
            ds = field.getDatasource();
        }

        if (ds != null) {
            MetaClass metaClass = ds.getMetaClass();
            MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(field.getProperty());

            if (metaPropertyPath != null) {
                MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
                Field.Validator validator = null;
                if (descriptor == null) {
                    validator = getDefaultValidator(metaProperty);
                } else if (!"timeField".equals(descriptor.attributeValue("field"))) {
                    validator = getDefaultValidator(metaProperty); //In this case we no need to use validator
                }

                if (validator != null) {
                    field.addValidator(validator);
                }
            }
        }
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.GridLayoutLoader.java

License:Apache License

@Override
public void createComponent() {
    resultComponent = (GridLayout) factory.createComponent(GridLayout.NAME);
    loadId(resultComponent, element);// w w w . j a  v  a  2  s.c  o  m

    Element columnsElement = element.element("columns");
    if (columnsElement == null) {
        throw new GuiDevelopmentException("'grid' element must contain 'columns' element",
                context.getFullFrameId(), "Grid ID", resultComponent.getId());
    }

    Element rowsElement = element.element("rows");
    if (rowsElement == null) {
        throw new GuiDevelopmentException("'grid' element must contain 'rows' element",
                context.getFullFrameId(), "Grid ID", resultComponent.getId());
    }

    int columnCount;
    @SuppressWarnings("unchecked")
    final List<Element> columnElements = columnsElement.elements("column");
    if (columnElements.size() == 0) {
        try {
            columnCount = Integer.parseInt(columnsElement.attributeValue("count"));
        } catch (NumberFormatException e) {
            throw new GuiDevelopmentException(
                    "'grid' element must contain either a set of 'column' elements or a 'count' attribute",
                    context.getFullFrameId(), "Grid ID", resultComponent.getId());
        }
        resultComponent.setColumns(columnCount);
        for (int i = 0; i < columnCount; i++) {
            resultComponent.setColumnExpandRatio(i, 1);
        }
    } else {
        String countAttr = columnsElement.attributeValue("count");
        if (StringUtils.isNotEmpty(countAttr)) {
            throw new GuiDevelopmentException(
                    "'grid' element can't contain a set of 'column' elements and a 'count' attribute",
                    context.getFullFrameId(), "Grid ID", resultComponent.getId());
        }
        columnCount = columnElements.size();
        resultComponent.setColumns(columnCount);
        int i = 0;
        for (Element columnElement : columnElements) {
            String flex = columnElement.attributeValue("flex");
            if (!StringUtils.isEmpty(flex)) {
                resultComponent.setColumnExpandRatio(i, Float.parseFloat(flex));
            }
            i++;
        }
    }

    @SuppressWarnings("unchecked")
    List<Element> rowElements = rowsElement.elements("row");
    Set<Element> invisibleRows = new HashSet<>();

    int rowCount = 0;
    for (Element rowElement : rowElements) {
        String visible = rowElement.attributeValue("visible");
        if (!StringUtils.isEmpty(visible)) {
            Boolean value = Boolean.valueOf(visible);

            if (BooleanUtils.toBoolean(value)) {
                rowCount++;
            } else {
                invisibleRows.add(rowElement);
            }
        } else {
            rowCount++;
        }
    }

    resultComponent.setRows(rowCount);

    int j = 0;
    for (Element rowElement : rowElements) {
        final String flex = rowElement.attributeValue("flex");
        if (!StringUtils.isEmpty(flex)) {
            resultComponent.setRowExpandRatio(j, Float.parseFloat(flex));
        }
        j++;
    }

    spanMatrix = new boolean[columnCount][rowElements.size()];

    int row = 0;
    for (Element rowElement : rowElements) {
        if (!invisibleRows.contains(rowElement)) {
            createSubComponents(resultComponent, rowElement, row);
            row++;
        }
    }
}