Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.gote.pojo.Tournament.java

License:Apache License

/**
 * Load Tournament from XML//from  ww  w .  ja v a 2  s . co m
 * 
 * @param pRoot Tournament element
 */
public void fromXML(Element pRoot) {
    if (pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_NAME) != null) {
        setTitle(pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_NAME).getValue());
    } else {
        LOGGER.log(Level.SEVERE, "The attribute " + TournamentGOTEUtil.ATT_TOURNAMENT_NAME + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_SERVER) != null) {
        setServerType(pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_SERVER).getValue());
    } else {
        LOGGER.log(Level.SEVERE, "The attribute " + TournamentGOTEUtil.ATT_TOURNAMENT_NAME + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART) != null) {
        setStartDate(new DateTime(pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART).getValue()));
    } else {
        LOGGER.log(Level.SEVERE, "The attribute " + TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND) != null) {
        setEndDate(new DateTime(pRoot.attribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND).getValue()));
    } else {
        LOGGER.log(Level.SEVERE, "The attribute " + TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND + " is null");
    }

    Element elementTournamentRules = pRoot.element(TournamentGOTEUtil.TAG_RULES);
    if (elementTournamentRules != null) {
        TournamentRules tournamentRules = new TournamentRules();
        tournamentRules.fromXML(elementTournamentRules);
        setTournamentRules(tournamentRules);
    } else {
        LOGGER.log(Level.SEVERE, "The element " + TournamentGOTEUtil.TAG_RULES + " is null");
    }

    Element elementPlayers = pRoot.element(TournamentGOTEUtil.TAG_PLAYERS);
    if (elementPlayers != null) {
        List<Player> players = new ArrayList<Player>();
        @SuppressWarnings("unchecked")
        List<Element> playersElements = elementPlayers.elements(TournamentGOTEUtil.TAG_PLAYER);
        if (playersElements != null && !playersElements.isEmpty()) {
            for (Element playerElement : playersElements) {
                Player player = new Player();
                player.fromXML(playerElement);
                players.add(player);
            }
        } else {
            LOGGER.log(Level.WARNING, "No player has been found");
        }
        setParticipantsList(players);
    } else {
        LOGGER.log(Level.SEVERE, "The element " + TournamentGOTEUtil.TAG_ROUNDS + " is null");
    }

    Element elementRounds = pRoot.element(TournamentGOTEUtil.TAG_ROUNDS);
    if (elementRounds != null) {
        List<Round> rounds = new ArrayList<Round>();
        @SuppressWarnings("unchecked")
        List<Element> roundsElements = elementRounds.elements(TournamentGOTEUtil.TAG_ROUND);
        if (roundsElements != null && !roundsElements.isEmpty()) {
            for (Element roundElement : roundsElements) {
                Round round = new Round();
                round.fromXML(roundElement, this);
                rounds.add(round);
            }
        } else {
            LOGGER.log(Level.WARNING, "No round has been found");
        }
        setRounds(rounds);
    } else {
        LOGGER.log(Level.SEVERE, "The element " + TournamentGOTEUtil.TAG_ROUNDS + " is null");
    }
}

From source file:com.gote.pojo.TournamentRules.java

License:Apache License

/**
 * Load TournamentRules from XML/*from   w ww. j  a  v  a 2  s  .  com*/
 * 
 * @param pRoot Element
 */
public void fromXML(Element pRoot) {
    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_TAG) != null) {
        setTag(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_TAG).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_TAG + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_KOMI) != null) {
        setKomi(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_KOMI).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_KOMI + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_SIZE) != null) {
        setSize(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_SIZE).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_SIZE + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_TIMESYSTEM) != null) {
        setTimeSystem(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_TIMESYSTEM).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_TIMESYSTEM + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BASICTIME) != null) {
        setBasicTime(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BASICTIME).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_BASICTIME + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BYODURATION) != null) {
        setByoYomiDuration(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BYODURATION).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_BYODURATION + " is null");
    }

    if (pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BYOPERIODS) != null) {
        setNumberOfByoYomi(pRoot.attribute(TournamentGOTEUtil.ATT_RULES_BYOPERIODS).getValue());
    } else {
        LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_RULES_BYOPERIODS + " is null");
    }
}

From source file:com.haulmont.cuba.core.app.EntitySnapshotManager.java

License:Apache License

protected void replaceClasses(Element element, Map<Class, Class> classMapping) {
    // translate XML
    for (Map.Entry<Class, Class> classEntry : classMapping.entrySet()) {
        Class beforeClass = classEntry.getKey();
        Class afterClass = classEntry.getValue();

        checkNotNull(beforeClass);// w  w w . j  a  va 2  s .  c om
        checkNotNull(afterClass);

        // If BeforeClass != AfterClass
        if (!beforeClass.equals(afterClass)) {
            String beforeClassName = beforeClass.getCanonicalName();
            String afterClassName = afterClass.getCanonicalName();

            if (beforeClassName.equals(element.getName())) {
                element.setName(afterClassName);
            }

            Attribute classAttribute = element.attribute("class");
            if ((classAttribute != null) && beforeClassName.equals(classAttribute.getValue())) {
                classAttribute.setValue(afterClassName);
            }
        }
    }
}

From source file:com.haulmont.cuba.core.global.filter.FilterParser.java

License:Apache License

protected Condition createCondition(Element conditionElement) {
    Condition condition;/*from w ww  .  ja  v a 2s  .c  o m*/
    String conditionName;

    if (conditionElement.attributeValue("locCaption") == null) {
        conditionName = conditionElement.attributeValue("name");
    } else {
        conditionName = conditionElement.attributeValue("locCaption");
    }

    if ("c".equals(conditionElement.getName())) {
        condition = new Clause(conditionName, conditionElement.getText(), getJoinValue(conditionElement),
                conditionElement.attributeValue("operatorType"), conditionElement.attributeValue("type"));
        // support unary conditions without parameters in text (e.g. "is null")
        for (Element paramElem : Dom4j.elements(conditionElement, "param")) {
            Set<ParameterInfo> params = ParametersHelper.parseQuery(":" + paramElem.attributeValue("name"));
            Attribute javaClass = paramElem.attribute("javaClass");
            if (javaClass != null) {
                for (ParameterInfo param : params) {
                    try {
                        param.setJavaClass(Class.forName(javaClass.getValue()));
                        param.setConditionName(conditionName);
                        param.setValue(paramElem.getText());
                    } catch (ClassNotFoundException e) {
                        //do not fail
                    }

                    if (condition.getParameters().contains(param)) {
                        for (ParameterInfo parameterInfo : condition.getParameters()) {
                            if (parameterInfo.equals(param)) {
                                parameterInfo.setJavaClass(param.getJavaClass());
                                parameterInfo.setConditionName(param.getConditionName());
                                parameterInfo.setValue(param.getValue());
                            }
                        }
                    }
                }
            }

            condition.getParameters().addAll(params);
        }
    } else {
        condition = new LogicalCondition(conditionName, LogicalOp.fromString(conditionElement.getName()));
    }

    return condition;
}

From source file:com.haulmont.cuba.gui.app.core.restore.EntityRestore.java

License:Apache License

protected void buildLayout() {
    Object value = entities.getValue();
    if (value != null) {
        MetaClass metaClass = (MetaClass) value;
        MetaProperty deleteTsMetaProperty = metaClass.getProperty("deleteTs");
        if (deleteTsMetaProperty != null) {
            if (entitiesTable != null) {
                tablePanel.remove(entitiesTable);
            }//from   w  w  w . j  a va 2 s .co  m
            if (filter != null) {
                tablePanel.remove(filter);
            }

            ComponentsFactory componentsFactory = AppConfig.getFactory();

            entitiesTable = componentsFactory.createComponent(Table.class);
            entitiesTable.setFrame(frame);

            restoreButton = componentsFactory.createComponent(Button.class);
            restoreButton.setId("restore");
            restoreButton.setCaption(getMessage("entityRestore.restore"));

            ButtonsPanel buttonsPanel = componentsFactory.createComponent(ButtonsPanel.class);
            buttonsPanel.add(restoreButton);
            entitiesTable.setButtonsPanel(buttonsPanel);

            RowsCount rowsCount = componentsFactory.createComponent(RowsCount.class);
            entitiesTable.setRowsCount(rowsCount);

            final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
            Formatter dateTimeFormatter = propertyValue -> {
                if (propertyValue == null) {
                    return StringUtils.EMPTY;
                }

                return dateTimeFormat.format(propertyValue);
            };

            //collect properties in order to add non-system columns first
            LinkedList<Table.Column> nonSystemPropertyColumns = new LinkedList<>();
            LinkedList<Table.Column> systemPropertyColumns = new LinkedList<>();
            List<MetaProperty> metaProperties = new ArrayList<>();
            for (MetaProperty metaProperty : metaClass.getProperties()) {
                //don't show embedded & multiple referred entities
                Range range = metaProperty.getRange();
                if (isEmbedded(metaProperty) || range.getCardinality().isMany()
                        || metadataTools.isSystemLevel(metaProperty)
                        || (range.isClass() && metadataTools.isSystemLevel(range.asClass()))) {
                    continue;
                }

                metaProperties.add(metaProperty);
                Table.Column column = new Table.Column(metaClass.getPropertyPath(metaProperty.getName()));
                if (!metadataTools.isSystem(metaProperty)) {
                    column.setCaption(getPropertyCaption(metaClass, metaProperty));
                    nonSystemPropertyColumns.add(column);
                } else {
                    column.setCaption(metaProperty.getName());
                    systemPropertyColumns.add(column);
                }

                if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
                    column.setFormatter(dateTimeFormatter);
                }
            }

            for (Table.Column column : nonSystemPropertyColumns) {
                entitiesTable.addColumn(column);
            }

            for (Table.Column column : systemPropertyColumns) {
                entitiesTable.addColumn(column);
            }

            DsContext dsContext = getDsContext();
            if (entitiesDs != null) {
                ((DsContextImplementation) dsContext).unregister(entitiesDs);
            }

            entitiesDs = DsBuilder.create(dsContext).setId("entitiesDs").setMetaClass(metaClass)
                    .setView(buildView(metaClass, metaProperties)).buildGroupDatasource();

            entitiesDs.setQuery("select e from " + metaClass.getName() + " e "
                    + "where e.deleteTs is not null order by e.deleteTs");

            entitiesDs.setSoftDeletion(false);
            entitiesDs.refresh();
            entitiesTable.setDatasource(entitiesDs);

            String filterId = metaClass.getName().replace("$", "") + "GenericFilter";

            filter = componentsFactory.createComponent(Filter.class);
            filter.setId(filterId);
            filter.setFrame(getFrame());

            StringBuilder sb = new StringBuilder("");
            for (MetaProperty property : metaClass.getProperties()) {
                AnnotatedElement annotatedElement = property.getAnnotatedElement();
                if (annotatedElement
                        .getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class) != null) {
                    sb.append(property.getName()).append("|");
                }
            }
            Element filterElement = Dom4j
                    .readDocument(String.format("<filter id=\"%s\">\n"
                            + "    <properties include=\".*\" exclude=\"\"/>\n" + "</filter>", filterId))
                    .getRootElement();

            String excludedProperties = sb.toString();
            if (StringUtils.isNotEmpty(excludedProperties)) {
                Element properties = filterElement.element("properties");
                properties.attribute("exclude")
                        .setValue(excludedProperties.substring(0, excludedProperties.lastIndexOf("|")));
            }
            filter.setXmlDescriptor(filterElement);
            filter.setUseMaxResults(true);
            filter.setDatasource(entitiesDs);

            entitiesTable.setSizeFull();

            entitiesTable.setMultiSelect(true);
            Action restoreAction = new ItemTrackingAction("restore")
                    .withCaption(getMessage("entityRestore.restore")).withHandler(event -> showRestoreDialog());
            entitiesTable.addAction(restoreAction);
            restoreButton.setAction(restoreAction);

            tablePanel.add(filter);
            tablePanel.add(entitiesTable);
            tablePanel.expand(entitiesTable, "100%", "100%");

            entitiesTable.refresh();

            ((FilterImplementation) filter).loadFiltersAndApplyDefault();
        }
    }
}

From source file:com.haulmont.cuba.gui.components.AbstractComponentGenerationStrategy.java

License:Apache License

protected Component createComponentInternal(ComponentGenerationContext context) {
    MetaClass metaClass = context.getMetaClass();
    MetaPropertyPath mpp = resolveMetaPropertyPath(metaClass, context.getProperty());
    Element xmlDescriptor = context.getXmlDescriptor();

    if (mpp != null) {
        Range mppRange = mpp.getRange();
        if (mppRange.isDatatype()) {
            Class type = mppRange.asDatatype().getJavaClass();

            MetaProperty metaProperty = mpp.getMetaProperty();
            if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
                CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
                if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
                    return createEnumField(context);
                }//w  w w.j a  v a 2 s  .  co m
            }

            if (xmlDescriptor != null && "true".equalsIgnoreCase(xmlDescriptor.attributeValue("link"))) {
                return createDatatypeLinkField(context);
            } else {
                boolean hasMaskAttribute = xmlDescriptor != null && xmlDescriptor.attribute("mask") != null;

                if (type.equals(String.class)) {
                    if (hasMaskAttribute) {
                        return createMaskedField(context);
                    } else {
                        return createStringField(context, mpp);
                    }
                } else if (type.equals(UUID.class)) {
                    return createUuidField(context);
                } else if (type.equals(Boolean.class)) {
                    return createBooleanField(context);
                } else if (type.equals(java.sql.Date.class) || type.equals(Date.class)) {
                    return createDateField(context);
                } else if (type.equals(Time.class)) {
                    return createTimeField(context);
                } else if (Number.class.isAssignableFrom(type)) {
                    if (hasMaskAttribute) {
                        return createMaskedField(context);
                    } else {
                        Field currencyField = createCurrencyField(context, mpp);
                        if (currencyField != null) {
                            return currencyField;
                        }

                        return createNumberField(context);
                    }
                }
            }
        } else if (mppRange.isClass()) {
            MetaProperty metaProperty = mpp.getMetaProperty();
            Class<?> javaType = metaProperty.getJavaType();

            if (FileDescriptor.class.isAssignableFrom(javaType)) {
                return createFileUploadField(context);
            }

            if (!Collection.class.isAssignableFrom(javaType)) {
                return createEntityField(context, mpp);
            }
        } else if (mppRange.isEnum()) {
            return createEnumField(context);
        }
    }

    return null;
}

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

License:Apache License

protected void addMultiplePropertyDescriptors(Element element, List<AbstractConditionDescriptor> descriptors,
        Filter filter) {/* ww w  .  j  a v  a2  s .  c om*/
    String includeRe = element.attributeValue("include");
    String excludeRe = element.attributeValue("exclude");
    addMultiplePropertyDescriptors(includeRe, excludeRe, descriptors, filter);

    if (element.attribute("excludeProperties") != null) {
        String excludeProperties = element.attributeValue("excludeProperties");
        if (StringUtils.isNotEmpty(excludeProperties)) {
            excludedProperties = Arrays.asList(excludeProperties.replace(" ", "").split(","));
        }
    }
}

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 ww.  ja va 2  s. co  m
    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.xml.layout.loaders.AbstractComponentLoader.java

License:Apache License

protected void loadStyleName(Component component, Element element) {
    if (element.attribute("stylename") != null) {
        component.setStyleName(element.attributeValue("stylename"));
    }/*from   www.j av  a 2  s  .  c om*/
}

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

License:Apache License

protected void loadCaption(Component.HasCaption component, Element element) {
    if (element.attribute("caption") != null) {
        String caption = element.attributeValue("caption");

        caption = loadResourceString(caption);
        component.setCaption(caption);//w  w w .  j av a2s. com
    }
}