List of usage examples for org.dom4j DocumentFactory createElement
public Element createElement(String name)
From source file:com.jonschang.ai.ga.GenericGene.java
License:LGPL
@Override public Element getXml() { DocumentFactory f = DocumentFactory.getInstance(); Element toRet = f.createElement("gene"); toRet.addAttribute("name", this.getName()); toRet.addAttribute("expressiveness", this.getExpressiveness().toString()); return toRet; }
From source file:com.jonschang.ai.ga.GenericPhenotype.java
License:LGPL
public Element getXml() throws XmlException { DocumentFactory f = DocumentFactory.getInstance(); Element toRet = f.createElement("phenotype"); toRet.addAttribute("class", "com.jonschang.ai.ga.GenericPhenotype"); toRet.addAttribute("score", ((Double) (score != null ? score : 0.0)).toString()); Element geneEle = null;/*from w w w . java 2 s. c o m*/ for (Gene gene : this.genes) { toRet.add(gene.getXml()); } return toRet; }
From source file:com.liferay.portlet.PortletPreferencesSerializer.java
License:Open Source License
public static String toXML(PortletPreferencesImpl prefs) throws SystemException { try {//from ww w . j ava2s .co m Map preferences = prefs.getPreferences(); DocumentFactory docFactory = DocumentFactory.getInstance(); Element portletPreferences = docFactory.createElement("portlet-preferences"); Iterator itr = preferences.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); Preference preference = (Preference) entry.getValue(); Element prefEl = docFactory.createElement("preference"); Element nameEl = docFactory.createElement("name"); nameEl.addText(preference.getName()); prefEl.add(nameEl); String[] values = preference.getValues(); for (int i = 0; i < values.length; i++) { Element valueEl = docFactory.createElement("value"); valueEl.addText(values[i]); prefEl.add(valueEl); } if (preference.isReadOnly()) { Element valueEl = docFactory.createElement("read-only"); valueEl.addText("true"); } portletPreferences.add(prefEl); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(baos, OutputFormat.createCompactFormat()); writer.write(portletPreferences); return baos.toString(); } catch (IOException ioe) { throw new SystemException(ioe); } }
From source file:com.sun.tools.xjc.reader.dtd.bindinfo.BIUserConversion.java
License:Open Source License
/** Adds all built-in conversions into the given map. */ static void addBuiltinConversions(BindInfo bi, Map m) { DocumentFactory f = DocumentFactory.getInstance(); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "boolean") .addAttribute("type", "java.lang.Boolean").addAttribute("parse", "getBoolean"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "byte") .addAttribute("type", "java.lang.Byte").addAttribute("parse", "parseByte"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "short") .addAttribute("type", "java.lang.Short").addAttribute("parse", "parseShort"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "int") .addAttribute("type", "java.lang.Integer").addAttribute("parse", "parseInt"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "long") .addAttribute("type", "java.lang.Long").addAttribute("parse", "parseLong"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "float") .addAttribute("type", "java.lang.Float").addAttribute("parse", "parseFloat"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "double") .addAttribute("type", "java.lang.Double").addAttribute("parse", "parseDouble"))); }
From source file:de.hasait.eclipse.common.xml.XDocument.java
License:Apache License
/** * // w w w. ja v a2 s . co m */ public XDocument(final String encoding, final String rootElementName) { super(); DocumentFactory df = DocumentFactory.getInstance(); _document = df.createDocument(encoding); _document.setRootElement(df.createElement(rootElementName)); }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default database element to the given parentElement (<contentdbs>) * @param parent//from w w w .j a va2s . co m * @param implClass * @return the created contentdb-element */ public static Element addContentDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("contentdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbkey"); database.add(elem); elem.add(factory.createText("(Enter database key here)")); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("title"); database.add(elem); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("design"); database.add(elem); elem.addAttribute("provider", "none"); elem.addAttribute("mode", ""); elem.addAttribute("key", ""); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("storedqueries")); database.add(factory.createElement("fieldmappings")); Element cache = database.addElement("cache"); cache.addAttribute("path", ""); cache.addAttribute("type", "de.innovationgate.wgpublisher.cache.WGACacheHSQLDB"); cache.addAttribute("maxpages", "3000"); //lucene config per db Element luceneDBConfig = factory.createElement("lucene"); luceneDBConfig.addAttribute("enabled", "false"); luceneDBConfig.addElement("itemrules"); LuceneIndexItemRule.addDefaultRule(luceneDBConfig); luceneDBConfig.addElement("filerules"); LuceneIndexFileRule.addDefaultRule(luceneDBConfig); database.add(luceneDBConfig); // Client restrictions Element clientrestrictions = database.addElement("clientrestrictions"); clientrestrictions.addAttribute("enabled", "false"); clientrestrictions.addElement("restrictions"); parent.add(database); return database; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default persDbElement to the given parentElement (<personalisationdbs>) * @param parent/*from www .j a v a 2s . co m*/ * @param implClass * @return the created persDbElement */ public static Element addPersDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("personalisationdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("persconfig"); database.add(elem); elem.addAttribute("mode", "auto"); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("userclasses")); parent.add(database); return database; }
From source file:fr.gouv.culture.vitam.database.DbField.java
License:Open Source License
public Element getElement() { DocumentFactory factory = DocumentFactory.getInstance(); Element field = factory.createElement(name); field.addAttribute(DbSchema.DESCRIPTION_ATTRIBUTE, description); field.addAttribute(DbSchema.TYPE_ATTRIBUTE, GenericDBType.getType(type, length)); field.addAttribute(DbSchema.LENGTH_ATTRIBUTE, Integer.toString(length)); field.addAttribute(DbSchema.NULLABLE_ATTRIBUTE, Boolean.toString(nullable)); return field; }
From source file:fr.gouv.culture.vitam.database.DbFieldValue.java
License:Open Source License
public Element getElement() { DocumentFactory factory = DocumentFactory.getInstance(); Element value = factory.createElement(field.name); try {/*from w w w . ja va 2 s . c o m*/ String sval = getValueAsString(); if (sval != null) { value.setText(sval); } } catch (WaarpDatabaseSqlException e) { value.addAttribute(DbSchema.ERROR_ATTRIBUTE, "value error"); } return value; }
From source file:fr.gouv.culture.vitam.database.DbSchema.java
License:Open Source License
public Element getElement(boolean recursive, boolean data) { DocumentFactory factory = DocumentFactory.getInstance(); Element schema = factory.createElement(SCHEMA_FIELD); schema.addAttribute(NAME_ATTRIBUTE, name); schema.addAttribute(DESCRIPTION_ATTRIBUTE, description); if (identifier != null) { Element eltidentifier = factory.createElement(IDENTIFIER_FIELD); eltidentifier.addAttribute(TYPE_ATTRIBUTE, identifier.type.name()); eltidentifier.addAttribute(DATAFILE_ATTRIBUTE, identifier.refDataFile); switch (identifier.type) { case CSVTYPE: eltidentifier.addAttribute(SEPARATOR_ATTRIBUTE, identifier.separator); break; case MULTIPLETYPE: { Element poslistm = factory.createElement(MULTIPLEPOSITIONS_FIELD); for (int[] posmul : identifier.positionsMultiple) { Element poslist = factory.createElement(POSITIONS_FIELD); for (int ipos : posmul) { Element pos = factory.createElement(POSITION_FIELD); pos.setText(Integer.toString(ipos)); poslist.add(pos);// w w w .j a v a 2 s.com } poslistm.add(poslist); } eltidentifier.add(poslistm); } break; case UNIQUETYPE: { Element poslist = factory.createElement(POSITIONS_FIELD); for (int ipos : identifier.positions) { Element pos = factory.createElement(POSITION_FIELD); pos.setText(Integer.toString(ipos)); poslist.add(pos); } eltidentifier.add(poslist); } break; } schema.add(eltidentifier); } if (constructionOrder != null) { Element order = factory.createElement(ORDER_FIELD); int rank = 0; for (String table : constructionOrder) { Element etable = factory.createElement(TABLE_FIELD); etable.addAttribute(RANK_ATTRIBUTE, Integer.toString(rank)); etable.setText(table); order.add(etable); rank++; } schema.add(order); } if (recursive) { schema.addAttribute(NB_ATTRIBUTE, Integer.toString(tables.size())); for (DbTable table : tables) { if (data && table.getRows() != null && table.getRows().size() > 0) { Element etable = table.getElement(data); schema.add(etable); } else { Element etable = table.getElement(false); if (data) { // fill data using file try { XmlWriter.loadDbTableDataFromFile(this, table, etable); } catch (IOException e) { logger.warn(StaticValues.LBL.error_error.get() + e); } catch (WaarpDatabaseSqlException e) { logger.warn(StaticValues.LBL.error_error.get() + e); } } schema.add(etable); } } } return schema; }