List of usage examples for org.dom4j DocumentFactory createElement
public Element createElement(String name)
From source file:fr.gouv.culture.vitam.database.DbTable.java
License:Open Source License
public Element getElement(boolean data) { DocumentFactory factory = DocumentFactory.getInstance(); Element table = factory.createElement(DbSchema.TABLE_FIELD); table.addAttribute(DbSchema.NAME_ATTRIBUTE, name); table.addAttribute(DbSchema.DESCRIPTION_ATTRIBUTE, description); table.addAttribute(DbSchema.RANK_ATTRIBUTE, Integer.toString(rank)); table.addAttribute(DbSchema.TYPE_ATTRIBUTE, type.toString()); if (datafile != null) { table.addAttribute(DbSchema.DATAFILE_ATTRIBUTE, datafile); }/*w ww . j av a 2s . c o m*/ if (fields != null) { Element efields = factory.createElement(DbSchema.FIELDS_FIELD); for (DbField field : fields) { Element efield = field.getElement(); efields.add(efield); } efields.addAttribute(DbSchema.NB_ATTRIBUTE, Integer.toString(fields.size())); table.add(efields); } if (primaryKeys != null) { Element efields = factory.createElement(DbSchema.PRIMARY_KEYS_FIELD); for (DbField field : primaryKeys) { Element pk = factory.createElement(DbSchema.PRIMARY_KEY_FIELD); pk.addAttribute(DbSchema.NAME_ATTRIBUTE, field.name); efields.add(pk); } table.add(efields); } if (indexes != null) { Element efields = factory.createElement(DbSchema.INDEXES_FIELD); for (String idx : indexes.keySet()) { Element index = factory.createElement(DbSchema.INDEX_FIELD); index.addAttribute(DbSchema.NAME_ATTRIBUTE, idx); for (DbField field : indexes.get(idx)) { Element efield = factory.createElement(DbSchema.FIELD_FIELD); efield.addAttribute(DbSchema.NAME_ATTRIBUTE, field.name); index.add(efield); } efields.add(index); } efields.addAttribute(DbSchema.NB_ATTRIBUTE, Integer.toString(indexes.size())); table.add(efields); } if (constraints != null) { Element efields = factory.createElement(DbSchema.CONSTRAINTS_FIELD); for (String name : constraints.keySet()) { Element index = factory.createElement(DbSchema.CONSTRAINT_FIELD); index.addAttribute(DbSchema.FIELD_FIELD, name); DbField field = constraints.get(name); index.addAttribute(DbSchema.TARGETTABLE_ATTRIBUTE, field.table.name); index.addAttribute(DbSchema.TARGETFIELD_ATTRIBUTE, field.name); efields.add(index); } efields.addAttribute(DbSchema.NB_ATTRIBUTE, Integer.toString(constraints.size())); table.add(efields); } if (data && rows != null && rows.size() > 0) { Element erows = factory.createElement(DbSchema.ROWS_FIELD); erows.addAttribute(DbSchema.NB_ATTRIBUTE, Integer.toString(rows.size())); for (DbTableRow row : rows) { Element erow = row.getElement(); erows.add(erow); } table.add(erows); } return table; }
From source file:fr.gouv.culture.vitam.database.DbTableRow.java
License:Open Source License
public Element getElement() { DocumentFactory factory = DocumentFactory.getInstance(); Element row = factory.createElement(DbSchema.ROW_FIELD); row.addAttribute(DbSchema.RANK_ATTRIBUTE, Integer.toString(rank)); row.addAttribute(DbSchema.NB_ATTRIBUTE, Integer.toString(values.size())); for (DbFieldValue value : values) { Element evalue = value.getElement(); row.add(evalue);//ww w .j a va2s . c o m } return row; }
From source file:fr.gouv.culture.vitam.database.model.DbCondition.java
License:Open Source License
public Element toElement() { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement(DbSchema.CONDITION_FIELD); root.addAttribute(DbSchema.OPERATOR_ATTRIBUTE, operator.name()); for (int i = 0; i < operands.length; i++) { Element op = factory.createElement(DbSchema.OPERAND_FIELD); op.addAttribute("rank", Integer.toString(i)); if (operands[i] instanceof DbField) { op.addAttribute(DbSchema.TYPE_ATTRIBUTE, DbField.class.getSimpleName()); } else {// www . java2 s. c om op.addAttribute(DbSchema.TYPE_ATTRIBUTE, operands[i].getClass().getSimpleName()); } op.setText(operands[i].toString()); root.add(op); } return root; }
From source file:fr.gouv.culture.vitam.database.model.DbSelect.java
License:Open Source License
public Element toElement() { cleanTableFrom();// w w w . j ava2s .c o m DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement(DbSchema.DBSELECT_FIELD); root.addAttribute(DbSchema.OFFSET_ATTRIBUTE, Integer.toString(offset)); root.addAttribute(DbSchema.LIMIT_ATTRIBUTE, Integer.toString(limit)); if (selected.isEmpty()) { return root; } Element select = factory.createElement(DbSchema.SELECTED_FIELD); for (DbField field : selected) { Element efield = factory.createElement(DbSchema.FIELD_FIELD); efield.setText(field.toString()); select.add(efield); } root.add(select); Element from = factory.createElement(DbSchema.FROM_FIELD); for (DbTable table : fromTables.values()) { Element efield = factory.createElement(DbSchema.TABLE_FIELD); efield.setText(table.toString()); from.add(efield); } root.add(from); if (!conditions.isEmpty()) { Element econd = factory.createElement(DbSchema.CONDITIONS_FIELD); for (DbCondition condition : conditions) { Element efield = condition.toElement(); econd.add(efield); } root.add(econd); } if (!orderByAsc.isEmpty()) { Element eorder = factory.createElement(DbSchema.ORDERASC_FIELD); for (DbField field : orderByAsc.values()) { Element efield = factory.createElement(DbSchema.FIELD_FIELD); efield.setText(field.toString()); eorder.add(efield); } root.add(eorder); } if (!orderByDesc.isEmpty()) { Element eorder = factory.createElement(DbSchema.ORDERDESC_FIELD); for (DbField field : orderByDesc.values()) { Element efield = factory.createElement(DbSchema.FIELD_FIELD); efield.setText(field.toString()); eorder.add(efield); } root.add(eorder); } return root; }
From source file:fr.gouv.culture.vitam.writer.XmlWriter.java
License:Open Source License
/** * @param file// ww w.j av a2 s . com * @param rootname */ public XmlWriter(File file, String rootname) { this.file = file; this.rootname = rootname; DocumentFactory factory = DocumentFactory.getInstance(); document = factory.createDocument(StaticValues.CURRENT_OUTPUT_ENCODING); Element root = factory.createElement(rootname); document.setRootElement(root); }
From source file:fr.gouv.culture.vitam.writer.XmlWriter.java
License:Open Source License
public void write() throws IOException { FileOutputStream out = new FileOutputStream(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING); XMLWriter writer = new XMLWriter(out, format); writer.write(document);//from w w w . java2s . com writer.close(); out.close(); document.clearContent(); document = null; DocumentFactory factory = DocumentFactory.getInstance(); document = factory.createDocument(StaticValues.CURRENT_OUTPUT_ENCODING); Element root = factory.createElement(rootname); document.setRootElement(root); StaticValues.freeMemory(); }
From source file:gjset.data.PlayerData.java
License:Open Source License
/** * Return a representation of the player. * * @return// ww w . ja va2 s . c o m */ public Element getXMLRepresentation() { DocumentFactory documentFactory = DocumentFactory.getInstance(); Element playerElement = documentFactory.createElement("player"); playerElement.addAttribute("id", "" + id); Element pointsElement = documentFactory.createElement("points"); pointsElement.setText("" + points); playerElement.add(pointsElement); Element penaltyElement = documentFactory.createElement("penalty"); penaltyElement.setText("" + penalty); playerElement.add(penaltyElement); Element nameElement = documentFactory.createElement("name"); nameElement.setText(name); playerElement.add(nameElement); Element wantsToDrawElement = documentFactory.createElement("wanttodraw"); wantsToDrawElement.setText("" + wantsToDraw); playerElement.add(wantsToDrawElement); return playerElement; }
From source file:gjset.tools.MessageUtils.java
License:Open Source License
/** * Wraps a message with enclosing tags and a comm version. * * @param messageElement/*from w w w . j av a 2 s.co m*/ * @return */ public static Element wrapMessage(Element messageElement) { DocumentFactory documentFactory = DocumentFactory.getInstance(); Element rootElement = documentFactory.createElement("combocards"); Element versionElement = documentFactory.createElement("version"); versionElement.setText(GameConstants.COMM_VERSION); rootElement.add(versionElement); rootElement.add(messageElement); return rootElement; }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaEntitesImpl.java
License:Open Source License
private byte[] exportGraphML(EntiteDto entiteDto, FiltreStatut filtreStatut, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);//from www. ja v a 2s . co m construitTableauStats(graph, entiteDto); buildGraphMlTree(graph, entiteDto, mapIdLiOuvert, filtreStatut); ajoutLogoMairie(graph); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaFichesPosteImpl.java
License:Open Source License
private byte[] exportGraphML(FichePosteTreeNodeDto node, boolean isAfficheAgent, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);/*from w ww. j a v a 2 s. c o m*/ construitTableauStats(graph, this.entiteDto); mapFichesPosteSuperieureByService = EntityUtils.getFichesPosteChefDeService(node); buildGraphMlTree(graph, node, mapIdLiOuvert, isAfficheAgent, null); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }