List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.haulmont.cuba.gui.settings.SettingsImpl.java
License:Apache License
@Override public Element get(final String componentId) { checkLoaded();/*w w w . ja va 2s . co m*/ Element componentsRoot = root.element("components"); if (componentsRoot == null) { componentsRoot = root.addElement("components"); } for (Element e : ((List<Element>) componentsRoot.elements())) { if (componentId.equals(e.attributeValue("name"))) { return e; } } Element e = componentsRoot.addElement("component"); e.addAttribute("name", componentId); return e; }
From source file:com.haulmont.cuba.gui.xml.XmlInheritanceProcessor.java
License:Apache License
private void addNewElement(Element resultElem, Element element, Set<Element> justAdded) { String idx = element.attributeValue(new QName("index", extNs)); Element newElement;//w w w.jav a2 s. c o m if (StringUtils.isBlank(idx)) { newElement = resultElem.addElement(element.getName()); } else { newElement = DocumentHelper.createElement(element.getName()); @SuppressWarnings("unchecked") List<Element> elements = resultElem.elements(); int index = Integer.parseInt(idx); if (index < 0 || index > elements.size()) { String message = String.format( "Incorrect extension XML for screen. Could not paste new element %s to position %s", newElement.getName(), index); throw new DevelopmentException(message, ParamsMap.of("element", newElement.getName(), "index", index)); } elements.add(index, newElement); } justAdded.add(newElement); process(newElement, element); }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected void encodeEntity(Entity entity, HashSet<Entity> visited, View view, Element parentEl) throws Exception { if (entity == null) { parentEl.addAttribute("null", "true"); return;/*from w w w . j a v a 2 s . co m*/ } if (!readPermitted(entity.getMetaClass())) throw new IllegalAccessException(); Element instanceEl = parentEl.addElement("instance"); instanceEl.addAttribute("id", EntityLoadInfo.create(entity).toString()); boolean entityAlreadyVisited = !visited.add(entity); if (entityAlreadyVisited) { return; } if (entity instanceof BaseGenericIdEntity) { byte[] securityToken = BaseEntityInternalAccess.getSecurityToken((BaseGenericIdEntity) entity); if (securityToken != null) { BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity; instanceEl.addElement("__securityToken").setText(Base64.getEncoder().encodeToString(securityToken)); String[] filteredAttributes = BaseEntityInternalAccess.getFilteredAttributes(baseGenericIdEntity); if (filteredAttributes != null) { Element filteredAttributesElement = instanceEl.addElement("__filteredAttributes"); Arrays.stream(filteredAttributes) .forEach(obj -> filteredAttributesElement.addElement("a").setText(obj)); } } } MetaClass metaClass = entity.getMetaClass(); List<MetaProperty> orderedProperties = ConverterHelper.getActualMetaProperties(metaClass, entity); for (MetaProperty property : orderedProperties) { if (metadataTools.isPersistent(property) && !PersistenceHelper.isLoaded(entity, property.getName())) { continue; } if (!attrViewPermitted(metaClass, property.getName())) continue; if (!isPropertyIncluded(view, property) && !DynamicAttributesUtils.isDynamicAttribute(property.getName())) { continue; } Object value = entity.getValue(property.getName()); switch (property.getType()) { case DATATYPE: if (property.equals(metadataTools.getPrimaryKeyProperty(metaClass)) && !property.getJavaType().equals(String.class)) { // skipping id for non-String-key entities continue; } Element fieldEl = instanceEl.addElement("field"); fieldEl.addAttribute("name", property.getName()); if (value != null) { fieldEl.setText(property.getRange().asDatatype().format(value)); } else if (!DynamicAttributesUtils.isDynamicAttribute(property.getName())) { encodeNull(fieldEl); } break; case ENUM: fieldEl = instanceEl.addElement("field"); fieldEl.addAttribute("name", property.getName()); if (value == null) { encodeNull(fieldEl); } else { fieldEl.setText(property.getRange().asEnumeration().format(value)); } break; case COMPOSITION: case ASSOCIATION: MetaClass meta = propertyMetaClass(property); //checks if the user permitted to read a property if (!readPermitted(meta)) { break; } View propertyView = null; if (view != null) { ViewProperty vp = view.getProperty(property.getName()); if (vp != null) propertyView = vp.getView(); } if (!property.getRange().getCardinality().isMany()) { Element referenceEl = instanceEl.addElement("reference"); referenceEl.addAttribute("name", property.getName()); encodeEntity((Entity) value, visited, propertyView, referenceEl); } else { Element collectionEl = instanceEl.addElement("collection"); collectionEl.addAttribute("name", property.getName()); if (value == null) { encodeNull(collectionEl); break; } for (Object childEntity : (Collection) value) { encodeEntity((Entity) childEntity, visited, propertyView, collectionEl); } } break; default: throw new IllegalStateException("Unknown property type"); } } }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }/*www. jav a2 s. c o m*/ if (isUsePresentations()) { element.addAttribute("textSelection", String.valueOf(component.isTextSelectionEnabled())); } Element columnsElem = element.element("columns"); if (columnsElem != null) { element.remove(columnsElem); } columnsElem = element.addElement("columns"); Object[] visibleColumns = component.getVisibleColumns(); for (Object column : visibleColumns) { Element colElem = columnsElem.addElement("columns"); colElem.addAttribute("id", column.toString()); int width = component.getColumnWidth(column); if (width > -1) colElem.addAttribute("width", String.valueOf(width)); Boolean visible = !component.isColumnCollapsed(column); colElem.addAttribute("visible", visible.toString()); } MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId(); if (sortProperty != null) { Boolean sortAscending = component.isSortAscending(); columnsElem.addAttribute("sortProperty", sortProperty.toString()); columnsElem.addAttribute("sortAscending", sortAscending.toString()); } return true; }
From source file:com.haulmont.cuba.web.gui.components.WebDataGrid.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }/*from w w w. j a va2 s. c o m*/ Element columnsElem = element.element("columns"); if (columnsElem != null) { element.remove(columnsElem); } columnsElem = element.addElement("columns"); List<Column> visibleColumns = getVisibleColumns(); for (Column column : visibleColumns) { Element colElem = columnsElem.addElement("columns"); colElem.addAttribute("id", column.toString()); double width = column.getWidth(); if (width > -1) { colElem.addAttribute("width", String.valueOf(width)); } colElem.addAttribute("collapsed", Boolean.toString(column.isCollapsed())); } List<com.vaadin.data.sort.SortOrder> sortOrders = component.getSortOrder(); if (!sortOrders.isEmpty()) { com.vaadin.data.sort.SortOrder sortOrder = sortOrders.get(0); columnsElem.addAttribute("sortProperty", sortOrder.getPropertyId().toString()); columnsElem.addAttribute("sortDirection", sortOrder.getDirection().toString()); } return true; }
From source file:com.haulmont.cuba.web.gui.components.WebGroupTable.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }// w w w .j ava2 s . com super.saveSettings(element); Element groupPropertiesElement = element.element("groupProperties"); if (groupPropertiesElement != null) { element.remove(groupPropertiesElement); } groupPropertiesElement = element.addElement("groupProperties"); final Collection<?> groupProperties = component.getGroupProperties(); for (Object groupProperty : groupProperties) { if (getNotCollapsedColumns().contains(getColumn(groupProperty.toString()))) { final Element groupPropertyElement = groupPropertiesElement.addElement("property"); groupPropertyElement.addAttribute("id", groupProperty.toString()); } } return true; }
From source file:com.haulmont.cuba.web.gui.components.WebSplitPanel.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }/* www.j av a 2s.c om*/ Element e = element.element("position"); if (e == null) { e = element.addElement("position"); } e.addAttribute("value", String.valueOf(component.getSplitPosition())); e.addAttribute("unit", String.valueOf(component.getSplitPositionUnit())); return true; }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlWriter.java
License:Apache License
protected void writeRootBand(Report report, Element root) { ReportBand rootBandDefinition = report.getRootBand(); Element rootBandDefinitionElement = root.addElement("rootBand"); writeBandDefinition(rootBandDefinitionElement, rootBandDefinition); }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlWriter.java
License:Apache License
protected void writeInputParameters(Report report, Element root) { Element reportTemplatesElement = root.addElement("parameters"); if (report.getReportParameters() != null) { for (ReportParameter reportParameter : report.getReportParameters()) { Element reportTemplateElement = reportTemplatesElement.addElement("parameter"); reportTemplateElement.addAttribute("name", reportParameter.getName()); reportTemplateElement.addAttribute("alias", reportParameter.getAlias()); reportTemplateElement.addAttribute("required", String.valueOf(reportParameter.getRequired())); reportTemplateElement.addAttribute("class", reportParameter.getParameterClass().getCanonicalName()); if (reportParameter instanceof ReportParameterWithDefaultValue && ((ReportParameterWithDefaultValue) reportParameter).getDefaultValue() != null) { reportTemplateElement.addAttribute("defaultValue", ((ReportParameterWithDefaultValue) reportParameter).getDefaultValue()); }/*from w w w.jav a 2 s . c om*/ } } }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlWriter.java
License:Apache License
protected void writeValueFormats(Report report, Element root) { Element reportTemplatesElement = root.addElement("formats"); for (ReportFieldFormat reportFieldFormat : report.getReportFieldFormats()) { Element reportTemplateElement = reportTemplatesElement.addElement("format"); reportTemplateElement.addAttribute("name", reportFieldFormat.getName()); reportTemplateElement.addAttribute("format", reportFieldFormat.getFormat()); }//from w ww. j av a 2 s. com }