Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.haulmont.cuba.gui.components.filter.condition.CustomCondition.java

License:Apache License

public CustomCondition(Element element, String messagesPack, String filterComponentName,
        Datasource datasource) {// ww w . jav a2s .  co m
    super(element, messagesPack, filterComponentName, datasource);

    if (isBlank(caption)) {
        locCaption = element.attributeValue("locCaption");
    } else {
        MessageTools messageTools = AppBeans.get(MessageTools.NAME);
        locCaption = messageTools.loadString(messagesPack, caption);
    }

    entityAlias = element.attributeValue("entityAlias");

    Element joinElement = element.element("join");
    if (joinElement != null) {
        this.join = joinElement.getText();
    } else {
        //for backward compatibility
        this.join = element.attributeValue("join");
    }

}

From source file:com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition.java

License:Apache License

public DynamicAttributesCondition(Element element, String messagesPack, String filterComponentName,
        Datasource datasource) {/*www . j a v a  2  s  .  com*/
    super(element, messagesPack, filterComponentName, datasource);

    propertyPath = element.attributeValue("propertyPath");

    MessageTools messageTools = AppBeans.get(MessageTools.NAME);
    locCaption = isBlank(caption) ? element.attributeValue("locCaption")
            : messageTools.loadString(messagesPack, caption);

    entityAlias = element.attributeValue("entityAlias");
    text = element.getText();
    join = element.attributeValue("join");
    categoryId = UUID.fromString(element.attributeValue("category"));
    String categoryAttributeValue = element.attributeValue("categoryAttribute");
    if (!Strings.isNullOrEmpty(categoryAttributeValue)) {
        categoryAttributeId = UUID.fromString(categoryAttributeValue);
    } else {
        //for backward compatibility
        List<Element> paramElements = Dom4j.elements(element, "param");
        for (Element paramElement : paramElements) {
            if (BooleanUtils.toBoolean(paramElement.attributeValue("hidden", "false"), "true", "false")) {
                categoryAttributeId = UUID.fromString(paramElement.getText());
                String paramName = paramElement.attributeValue("name");
                text = text.replace(":" + paramName, "'" + categoryAttributeId + "'");
            }
        }
    }

    isCollection = Boolean.parseBoolean(element.attributeValue("isCollection"));
    resolveParam(element);
}

From source file:com.haulmont.cuba.gui.components.filter.condition.PropertyCondition.java

License:Apache License

public PropertyCondition(Element element, String messagesPack, String filterComponentName,
        Datasource datasource) {//from   w  w w .ja  v a 2s . co  m
    super(element, messagesPack, filterComponentName, datasource);

    String text = element.getText();
    if (operator != Op.DATE_INTERVAL) {
        Matcher matcher = PATTERN_NULL.matcher(text);
        if (!matcher.matches()) {
            matcher = PATTERN_NOT_IN.matcher(text);
            if (!matcher.matches()) {
                matcher = PATTERN.matcher(text);
            }
            if (!matcher.matches()) {
                throw new IllegalStateException("Unable to build condition from: " + text);
            }
        }

        if (operator == null) {
            operator = Op.fromJpqlString(matcher.group(2));
        }

        String prop = matcher.group(1);
        entityAlias = prop.substring(0, prop.indexOf('.'));
    } else {
        entityAlias = "{E}";
        param.setDateInterval(true);
    }
}

From source file:com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionDescriptor.java

License:Apache License

protected String getJoinValue() {
    Element joinElement = element.element("join");
    String join;//  ww  w  .  ja v  a  2s.c o m
    if (joinElement != null) {
        join = joinElement.getText();
    } else {
        //for backward compatibility
        join = element.attributeValue("join");
    }
    return join;
}

From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java

License:Apache License

@Override
public void applySettings(Element element) {
    Element groupBoxExpandedEl = element.element("groupBoxExpanded");
    if (groupBoxExpandedEl != null) {
        Boolean expanded = Boolean.valueOf(groupBoxExpandedEl.getText());
        groupBoxLayout.setExpanded(expanded);
    }/* ww w  .  jav  a  2s.  c  o  m*/
}

From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java

License:Apache License

@Override
public boolean saveSettings(Element element) {
    Boolean changed = false;//from  w w  w . ja  v  a 2  s .c om
    Element e = element.element("defaultFilter");
    if (e == null)
        e = element.addElement("defaultFilter");

    UUID defaultId = null;
    Boolean applyDefault = false;

    for (FilterEntity filter : filterEntities) {
        if (BooleanUtils.isTrue(filter.getIsDefault())) {
            defaultId = filter.getId();
            applyDefault = filter.getApplyDefault();
            break;
        }
    }

    String newDef = defaultId != null ? defaultId.toString() : null;
    Attribute attr = e.attribute("id");
    String oldDef = attr != null ? attr.getValue() : null;
    if (!Objects.equals(oldDef, newDef)) {
        if (newDef == null && attr != null) {
            e.remove(attr);
        } else {
            if (attr == null)
                e.addAttribute("id", newDef);
            else
                attr.setValue(newDef);
        }
        changed = true;
    }
    Boolean newApplyDef = BooleanUtils.isTrue(applyDefault);
    Attribute applyDefaultAttr = e.attribute("applyDefault");
    Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false;
    if (!Objects.equals(oldApplyDef, newApplyDef)) {
        if (applyDefaultAttr != null) {
            applyDefaultAttr.setValue(newApplyDef.toString());
        } else {
            e.addAttribute("applyDefault", newApplyDef.toString());
        }
        changed = true;
    }

    Element groupBoxExpandedEl = element.element("groupBoxExpanded");
    if (groupBoxExpandedEl == null)
        groupBoxExpandedEl = element.addElement("groupBoxExpanded");

    Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText());
    Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
    if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
        groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
        changed = true;
    }

    return changed;
}

From source file:com.haulmont.cuba.gui.components.validators.ScriptValidator.java

License:Apache License

public ScriptValidator(Element element, String messagesPack) {
    this.script = element.getText();
    innerScript = StringUtils.isNotBlank(script);
    if (!innerScript) {
        scriptPath = element.attributeValue("script");
    }//from  w w  w. j  ava2s .c  om
    message = element.attributeValue("message");
    this.messagesPack = messagesPack;
}

From source file:com.haulmont.cuba.gui.model.impl.ScreenDataImpl.java

License:Apache License

protected String loadQuery(Element queryEl) {
    return queryEl.getText().trim();
}

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 .java 2 s. 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

private void loadQuery(Element element, CollectionDatasource datasource) {
    Element queryElem = element.element("query");
    if (queryElem != null) {
        Element filterElem = queryElem.element("filter");

        String query = queryElem.getText();
        if (!StringUtils.isBlank(query)) {
            if (filterElem != null)
                datasource.setQuery(query, new QueryFilter(filterElem));
            else/*ww  w  .  j  a  va  2  s .c  o  m*/
                datasource.setQuery(query);
        }
    }
}