List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
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 ww w. j a va 2s . com*/ } 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.restapi.XMLConverter2.java
License:Apache License
protected void encodeNull(Element element) { element.addAttribute("null", "true"); }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }//from ww w .j a v a 2s . 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; }// ww w . j a v a 2s. 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; }//from w w w. j a va 2s . c o m 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.WebResizableTextArea.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled() || !isResizable()) { return false; }/*from ww w.jav a2s. c o m*/ String width = String.valueOf(getWidth()) + wrapper.getWidthUnits().toString(); String height = String.valueOf(getHeight()) + wrapper.getHeightUnits().toString(); element.addAttribute("width", width); element.addAttribute("height", height); 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; }/*from www . j av a2 s .c o m*/ 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
@Override public String buildXml(Report report) { try {//www .j a va 2 s. com Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("report"); root.addAttribute("name", report.getName()); writeTemplates(report, root); writeInputParameters(report, root); writeValueFormats(report, root); writeRootBand(report, root); StringWriter stringWriter = new StringWriter(); new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()).write(document); return stringWriter.toString(); } catch (IOException e) { throw new ReportingException(e); } }
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 .j av a 2 s . c o m*/ } } }
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 ww w . j av a 2 s.c o m }