List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.haulmont.cuba.core.sys.persistence.MappingFileCreator.java
License:Apache License
private Document createDocument(Map<Class<?>, List<Attr>> mappings) { Document doc = DocumentHelper.createDocument(); Element rootEl = doc.addElement("entity-mappings", XMLNS); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); rootEl.add(xsi);/*from w ww . jav a 2s . c o m*/ rootEl.addAttribute(new QName("schemaLocation", xsi), SCHEMA_LOCATION); rootEl.addAttribute("version", PERSISTENCE_VER); for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(MappedSuperclass.class) != null) { Element entityEl = rootEl.addElement("mapped-superclass", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Entity.class) != null) { Element entityEl = rootEl.addElement("entity", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); entityEl.addAttribute("name", entry.getKey().getAnnotation(Entity.class).name()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Embeddable.class) != null) { Element entityEl = rootEl.addElement("embeddable", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } return doc; }
From source file:com.haulmont.cuba.core.sys.persistence.PersistenceConfigProcessor.java
License:Apache License
public void create() { if (sourceFileNames == null || sourceFileNames.isEmpty()) throw new IllegalStateException("Source file list not set"); if (StringUtils.isBlank(outFileName)) throw new IllegalStateException("Output file not set"); Map<String, String> classes = new LinkedHashMap<>(); Map<String, String> properties = new HashMap<>(); properties.putAll(DbmsSpecificFactory.getDbmsFeatures(storeName).getJpaParameters()); for (String fileName : sourceFileNames) { Document doc = getDocument(fileName); Element puElem = findPersistenceUnitElement(doc.getRootElement()); if (puElem == null) throw new IllegalStateException( "No persistence unit named 'cuba' found among multiple units inside " + fileName); addClasses(puElem, classes);//from w w w . ja va 2s. c o m addProperties(puElem, properties); } for (String name : AppContext.getPropertyNames()) { if (name.startsWith("eclipselink.")) { properties.put(name, AppContext.getProperty(name)); } } if (!Stores.isMain(storeName)) properties.put(PersistenceImplSupport.PROP_NAME, storeName); File outFile; try { outFile = new File(outFileName).getCanonicalFile(); } catch (IOException e) { throw new RuntimeException(e); } outFile.getParentFile().mkdirs(); boolean ormXmlCreated = true; String disableOrmGenProp = AppContext.getProperty("cuba.disableOrmXmlGeneration"); if (!Boolean.parseBoolean(disableOrmGenProp)) { MappingFileCreator mappingFileCreator = new MappingFileCreator(classes.values(), properties, outFile.getParentFile()); ormXmlCreated = mappingFileCreator.create(); } String fileName = sourceFileNames.get(sourceFileNames.size() - 1); Document doc = getDocument(fileName); Element rootElem = doc.getRootElement(); Element puElem = findPersistenceUnitElement(rootElem); if (puElem == null) throw new IllegalStateException( "No persistence unit named 'cuba' found among multiple units inside " + fileName); String puName = AppContext.getProperty("cuba.persistenceUnitName"); if (!StringUtils.isEmpty(puName)) { if (!Stores.isMain(storeName)) puName = puName + "_" + storeName; puElem.addAttribute("name", puName); } for (Element element : new ArrayList<>(Dom4j.elements(puElem, "class"))) { puElem.remove(element); } puElem.addElement("provider").setText("org.eclipse.persistence.jpa.PersistenceProvider"); if (ormXmlCreated) { puElem.addElement("mapping-file").setText("orm.xml"); } for (String className : classes.values()) { puElem.addElement("class").setText(className); } puElem.addElement("exclude-unlisted-classes"); Element propertiesEl = puElem.element("properties"); if (propertiesEl != null) puElem.remove(propertiesEl); propertiesEl = puElem.addElement("properties"); for (Map.Entry<String, String> entry : properties.entrySet()) { Element element = propertiesEl.addElement("property"); element.addAttribute("name", entry.getKey()); element.addAttribute("value", entry.getValue()); } log.info("Creating file " + outFile); OutputStream os = null; try { os = new FileOutputStream(outFileName); Dom4j.writeDocument(doc, true, os); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(os); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopGroupBox.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }/*from w w w . j a v a2s. c om*/ Element groupBoxElement = element.element("groupBox"); if (groupBoxElement != null) { element.remove(groupBoxElement); } groupBoxElement = element.addElement("groupBox"); groupBoxElement.addAttribute("expanded", BooleanUtils.toStringTrueFalse(isExpanded())); return true; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSplitPanel.java
License:Apache License
@Override public boolean saveSettings(Element element) { if (!isSettingsEnabled()) { return false; }// ww w . ja v a2 s . co m if (!positionChanged) { return false; // most probably user didn't change the divider location } int location = impl.getUI().getDividerLocation(impl); Element e = element.element("position"); if (e == null) { e = element.addElement("position"); } e.addAttribute("value", String.valueOf(location)); return true; }
From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
License:Apache License
@Override public boolean saveSettings(Element element) { element.addAttribute("horizontalScroll", String.valueOf(table.isHorizontalScrollEnabled())); saveFontPreferences(element);/*w ww . j a va2 s. co m*/ Element columnsElem = element.element("columns"); if (columnsElem != null) { element.remove(columnsElem); } columnsElem = element.addElement("columns"); final List<TableColumn> visibleTableColumns = table.getColumns(); final List<Table.Column> visibleColumns = new ArrayList<>(); for (TableColumn tableColumn : visibleTableColumns) { visibleColumns.add((Table.Column) tableColumn.getIdentifier()); } List<TableColumn> columns = table.getColumns(true); Collections.sort(columns, new Comparator<TableColumn>() { @SuppressWarnings("SuspiciousMethodCalls") @Override public int compare(TableColumn col1, TableColumn col2) { if (col1 instanceof TableColumnExt && !((TableColumnExt) col1).isVisible()) { return 1; } if (col2 instanceof TableColumnExt && !((TableColumnExt) col2).isVisible()) { return -1; } int i1 = visibleColumns.indexOf(col1.getIdentifier()); int i2 = visibleColumns.indexOf(col2.getIdentifier()); return Integer.compare(i1, i2); } }); for (TableColumn column : columns) { Element colElem = columnsElem.addElement("column"); colElem.addAttribute("id", column.getIdentifier().toString()); int width = column.getWidth(); colElem.addAttribute("width", String.valueOf(width)); if (column instanceof TableColumnExt) { Boolean visible = ((TableColumnExt) column).isVisible(); colElem.addAttribute("visible", visible.toString()); } } if (table.getRowSorter() != null) { TableColumn sortedColumn = table.getSortedColumn(); List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortedColumn != null && !sortKeys.isEmpty()) { columnsElem.addAttribute("sortColumn", String.valueOf(sortedColumn.getIdentifier())); columnsElem.addAttribute("sortOrder", sortKeys.get(0).getSortOrder().toString()); } } return true; }
From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
License:Apache License
protected void saveFontPreferences(Element element) { if (table.getFont() != null) { Font font = table.getFont(); Map<TextAttribute, ?> attributes = font.getAttributes(); // save content font element.addAttribute("fontFamily", font.getFamily()); element.addAttribute("fontSize", Integer.toString(font.getSize())); element.addAttribute("fontStyle", Integer.toString(font.getStyle())); element.addAttribute("fontUnderline", Boolean.toString(attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON)); }// www . j a v a2s .co m }
From source file:com.haulmont.cuba.gui.app.core.entityinspector.EntityInspectorEditor.java
License:Apache License
/** * Adds field to the specified field group. * If the field should be custom, adds it to the specified customFields collection * which can be used later to create fieldGenerators * * @param metaProperty meta property of the item's property which field is creating * @param item entity instance containing given property * @param fieldGroup field group to which created field will be added * @param customFields if the field is custom it will be added to this collection * @param required true if the field is required * @param custom true if the field is custom *///from w w w .j a va 2s .co m protected void addField(MetaClass metaClass, MetaProperty metaProperty, Entity item, FieldGroup fieldGroup, boolean required, boolean custom, boolean readOnly, Collection<FieldGroup.FieldConfig> customFields) { if (!attrViewPermitted(metaClass, metaProperty)) return; if ((metaProperty.getType() == MetaProperty.Type.COMPOSITION || metaProperty.getType() == MetaProperty.Type.ASSOCIATION) && !entityOpPermitted(metaProperty.getRange().asClass(), EntityOp.READ)) return; FieldGroup.FieldConfig field = fieldGroup.createField(metaProperty.getName()); field.setProperty(metaProperty.getName()); field.setCaption(getPropertyCaption(metaClass, metaProperty)); field.setCustom(custom); field.setRequired(required); field.setEditable(!readOnly); field.setWidth("100%"); if (requireTextArea(metaProperty, item)) { Element root = DocumentHelper.createElement("textArea"); root.addAttribute("rows", "3"); field.setXmlDescriptor(root); } if (focusFieldId == null && !readOnly) { focusFieldId = field.getId(); focusFieldGroup = fieldGroup; } if (required) { field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName())); } fieldGroup.addField(field); if (custom) customFields.add(field); }
From source file:com.haulmont.cuba.gui.components.filter.condition.AbstractCondition.java
License:Apache License
public void toXml(Element element, Param.ValueProperty valueProperty) { String text = getText();/*from w w w. j av a 2 s . c o m*/ if (StringUtils.isNotBlank(text)) element.addCDATA(text); element.addAttribute("name", name); if (javaClass != null) element.addAttribute("class", javaClass.getName()); if (caption != null) element.addAttribute("caption", caption); if (unary) element.addAttribute("unary", "true"); if (inExpr) element.addAttribute("inExpr", "true"); if (hidden) element.addAttribute("hidden", "true"); if (required) element.addAttribute("required", "true"); if (Boolean.TRUE.equals(useUserTimeZone)) element.addAttribute("useUserTimeZone", "true"); if (operator != null) { element.addAttribute("operatorType", operator.name()); } if (param != null) { param.toXml(element, valueProperty); if (entityParamWhere != null) element.addAttribute("paramWhere", entityParamWhere); if (entityParamView != null) element.addAttribute("paramView", entityParamView); } if (width != null) { element.addAttribute("width", width.toString()); } }
From source file:com.haulmont.cuba.gui.components.filter.condition.CustomCondition.java
License:Apache License
@Override public void toXml(Element element, Param.ValueProperty valueProperty) { super.toXml(element, valueProperty); element.addAttribute("type", ConditionType.CUSTOM.name()); if (isBlank(caption)) { element.addAttribute("locCaption", locCaption); }//from ww w. j a va2s. co m element.addAttribute("entityAlias", entityAlias); if (!isBlank(join)) { Element joinElement = element.addElement("join"); joinElement.addCDATA(join); } if (operator != null) { element.addAttribute("operatorType", operator.name()); } }
From source file:com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition.java
License:Apache License
@Override public void toXml(Element element, Param.ValueProperty valueProperty) { super.toXml(element, valueProperty); element.addAttribute("type", ConditionType.RUNTIME_PROPERTY.name()); if (isBlank(caption)) { element.addAttribute("locCaption", locCaption); }/*from w w w. j a v a2 s .com*/ element.addAttribute("category", categoryId.toString()); element.addAttribute("categoryAttribute", categoryAttributeId.toString()); element.addAttribute("entityAlias", entityAlias); if (!isBlank(propertyPath)) { element.addAttribute("propertyPath", propertyPath); } if (!isBlank(join)) { element.addAttribute("join", StringEscapeUtils.escapeXml(join)); } if (isCollection) { element.addAttribute("isCollection", "true"); } }