List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:edu.ku.brc.util.services.GenericKMLGenerator.java
License:Open Source License
/** * Generates KML output based on the current points, names and descriptions given to the generator. * // w w w.j av a 2 s. co m * @return a String containing the generated KML */ public Document generateKML() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("kml").addAttribute("xmlns", KML_NAMESPACE_DECL); Element kmlDocument = root.addElement("Document"); if (StringUtils.isNotEmpty(description)) { kmlDocument.addElement("description").addText(description); } // setup the custom style, if any of these are non-null generateStyle(kmlDocument, placemarkIconURL, balloonStyleBgColor, balloonStyleTextColor, balloonStyleText); // generate a placemark for each point for (Pair<Double, Double> point : points) { String name = pointNameMap.get(point); String htmlDesc = pointDescMap.get(point); buildPlacemark(kmlDocument, point, name, balloonStyleTextColor, htmlDesc, placemarkIconURL); } return document; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.AbstractStudyCalendarXmlCollectionSerializer.java
License:BSD License
public Document createDocument(Collection<R> rs) { Document document = DocumentHelper.createDocument(); Element element = createCollectionRootElement(); for (R r : rs) { element.add(createElement(r, true)); }/*from w w w.j a v a 2s .c o m*/ configureRootElement(element); document.add(element); return document; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.AbstractStudyCalendarXmlSerializer.java
License:BSD License
public Document createDocument(R root) { Document document = DocumentHelper.createDocument(); Element element = createElement(root); configureRootElement(element);// w w w . j a v a 2 s. c om document.add(element); return document; }
From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java
public static Document toXML(Map m) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("response"); doc.setRootElement(root);/*from w ww .ja v a2 s . c o m*/ Iterator keys = m.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); Object val = m.get(key); Element e = root.addElement(key); if (val instanceof String) { e.setText(val.toString()); } else if (val instanceof Collection) { Collection col = (Collection) val; for (Iterator it = col.iterator(); it.hasNext();) { Object o = it.next(); Element sub = e.addElement("value"); if (o instanceof Map) { Map valmap = (Map) o; Iterator fields = valmap.keySet().iterator(); while (fields.hasNext()) { String field = (String) fields.next(); Element sub2 = sub.addElement(field); sub2.setText(valmap.get(field).toString()); } } else { sub.setText(o.toString()); } } } else if (val instanceof Map) { Map m2 = (Map) val; for (Iterator it = m2.keySet().iterator(); it.hasNext();) { String k2 = (String) it.next(); String v2 = (String) m2.get(k2); Element sub = e.addElement("value"); sub.addAttribute("key", k2); sub.setText(v2); } } else if (val instanceof Exception) { Exception ex = (Exception) val; e.addElement("p").setText(ex.toString()); StackTraceElement[] elem = ex.getStackTrace(); for (int i = 0; i < elem.length; i++) { e.addElement("p").setText(elem[i].toString()); } } else { e.setText(String.valueOf(val)); } } return doc; }
From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java
public static String toHTML(Map m) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("html"); doc.setRootElement(root);/* w w w . jav a2 s. c o m*/ Element body = root.addElement("body"); Element table = body.addElement("table"); Iterator keys = m.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); Object val = m.get(key); Element row = table.addElement("tr"); Element keyCell = row.addElement("td"); keyCell.setText(key); Element valCell = row.addElement("td"); if (val instanceof String) { valCell.setText(val.toString()); } else if (val instanceof Collection) { Collection col = (Collection) val; for (Iterator it = col.iterator(); it.hasNext();) { Element p = valCell.addElement("p"); Object o = it.next(); if (o instanceof Map) { Map valmap = (Map) o; Iterator fields = valmap.keySet().iterator(); while (fields.hasNext()) { String field = (String) fields.next(); String value = (String) valmap.get(field); p.addText(field + ": " + value); if (fields.hasNext()) { p.addElement("br"); } } } else { p.setText(o.toString()); } } } else if (val instanceof Map) { Map m2 = (Map) val; for (Iterator it = m2.keySet().iterator(); it.hasNext();) { String k2 = (String) it.next(); String v2 = (String) m2.get(k2); Element div = valCell.addElement("div"); div.setText(k2 + ": " + v2); } } else if (val instanceof Exception) { Exception ex = (Exception) val; valCell.addElement("p").setText(ex.toString()); StackTraceElement[] elem = ex.getStackTrace(); for (int i = 0; i < elem.length; i++) { valCell.addText(elem[i].toString()); valCell.addElement("br"); } } } return doc.asXML(); }
From source file:edu.umd.cs.findbugs.XDocsBugReporter.java
License:Open Source License
public XDocsBugReporter(Project project) { this.project = project; this.bugCollection = new SortedBugCollection(project); this.document = DocumentHelper.createDocument(); this.root = document.addElement(ROOT_ELEMENT_NAME); }
From source file:edu.upenn.cis.orchestra.workloadgenerator.GeneratorJournal.java
License:Apache License
/** * Serializes the journal in the format below. The peer and maping elements * are as in the Orchestra schema file.//from w w w .j av a 2 s . c o m * * <pre> * <?xml version="1.0" encoding="UTF-8"?> * <!--00:50:07 06/12/08 EDT * {integers=1, inout=true, oracle=0, skip=0, cutoff=1024, password=password, addBypasses=1, deletions=1, * username=xyz, relsize=15, tukwila=0, fanout=2, olivier=1, schemas=3, dbalias=BIOTBS, insertions=2, * iterations=2, seed=0, mappingsServer=jdbc:db2://localhost:50000, bidir=0, updateAlias=null, addPeers=1, * coverage=1.0, deleteBypasses=1, maxcycles=-1, peers=3, filename=prot, mincycles=-1, deletePeers=1}--> * <deltas> * <iteration idx="0"> * <operation type="addPeer" name="P0"/> * <operation type="addPeer" name="P1"> * <mapping name="M0"/> * <mapping name="M2"/> * </operation> * <operation type="addPeer" name="P2"> * <mapping name="M1"/> * </operation> * </iteration> * <iteration idx="1"> * <operation type="addPeer" name="P3"> * <mapping name="M3"/> * </operation> * <operation type="deletePeer" name="P0"/> * </iteration> * <iteration idx="2"> * <operation type="addPeer" name="P4"> * <mapping name="M4"/> * <mapping name="M5"/> * <mapping name="M6"/> * </operation> * <operation type="deletePeer" name="P2"/> * <operation type="addBypass" name="M23"/> * <operation type="deleteBypass" name="M2"/> * </iteration> * <peer name="P0" address="localhost"> * </peer> * <mapping name="M0" materialized="true"> * </mapping> * </deltas> * * </pre> * * @param params * run parameters, see <code>Generator</code>. * @return serialzed <code>GeneratorJournal</code>. */ @SuppressWarnings("unchecked") public Document serialize(Map<String, Object> params) { // TODO: this method copies code from MetadataXml, needs refactoring. Document deltasDoc = DocumentHelper.createDocument(); deltasDoc.addComment(WorkloadGeneratorUtils.stamp() + "\n" + params); Element deltas = deltasDoc.addElement("deltas"); List<Integer> indexes = new LinkedList<Integer>(_operations.keySet()); Collections.sort(indexes); for (Integer idx : indexes) { Element iteration = deltas.addElement("iteration").addAttribute("idx", idx.toString()); List<List<String>> operations = _operations.get(idx); for (List<String> operation : operations) { Element opElement = iteration.addElement("operation").addAttribute("type", operation.get(0)) .addAttribute("name", operation.get(1)); if ("addPeer".equals(operation.get(0))) { if (null == _peersToMaps.get(operation.get(1))) { continue; } for (String mapping : _peersToMaps.get(operation.get(1))) { opElement.addElement("mapping").addAttribute("name", mapping); } } } } for (int i = 0; i < _peers.size(); i++) { Element peer = deltas.addElement("peer").addAttribute("name", "P" + i).addAttribute("address", "localhost"); int j = _peers.get(i); Element schema = peer.addElement("schema").addAttribute("name", "S" + j); for (int k = 0; k < _logicalSchemas.get(j).size(); k++) { for (String var : iovariations((Boolean) params.get("inout"))) { Element relation = schema.addElement("relation") .addAttribute("name", WorkloadGeneratorUtils.relname(i, j, k) + var) .addAttribute("materialized", "true"); if ((Double) params.get("coverage") == 1) { relation.addAttribute("noNulls", "true"); } String hasLocalData; if (Generator.peerHasLocalData(i, (Integer) params.get("topology"), (Integer) params.get("modlocal"), (Integer) params.get("peers"), (Integer) params.get("fanout"))) { hasLocalData = "true"; } else { hasLocalData = "false"; } relation.addAttribute("hasLocalData", hasLocalData); relation.addElement("dbinfo").addAttribute("schema", (String) params.get("username")) .addAttribute("table", WorkloadGeneratorUtils.relname(i, j, k) + var); relation.addElement("field").addAttribute("name", "KID").addAttribute("type", "integer") .addAttribute("key", "true"); for (String att : _logicalSchemas.get(j).get(k)) { relation.addElement("field").addAttribute("name", att).addAttribute("type", MetadataXml.universalType(att, params)); } } } } for (int k = 0; k < _mappings.size(); k++) { int i = (Integer) _mappings.get(k).get(1); int j = (Integer) _mappings.get(k).get(2); List<String> x = (List<String>) _mappings.get(k).get(3); List<String> source = MetadataXml.selectAtoms(i, "KID", x, "_", _logicalSchemas, _peers, (Boolean) params.get("addValueAttr"), true); // _ means don't care List<String> target = MetadataXml.selectAtoms(j, "KID", x, "-", _logicalSchemas, _peers, (Boolean) params.get("addValueAttr"), false); // - means null Element mapping = deltas.addElement("mapping").addAttribute("name", "M" + k) .addAttribute("materialized", "true"); if (1 == (Integer) params.get("bidir")) { mapping.addAttribute("bidirectional", "true"); } Element head = mapping.addElement("head"); for (String atom : target) { Element atomElem = head.addElement("atom"); if (1 == (Integer) params.get("bidir")) { atomElem.addAttribute("del", "true"); } atomElem.addText(atom); } Element body = mapping.addElement("body"); for (String atom : source) { Element atomElem = body.addElement("atom"); if (1 == (Integer) params.get("bidir")) { atomElem.addAttribute("del", "true"); } atomElem.addText(atom); } } return deltasDoc; }
From source file:edu.upenn.cis.orchestra.workloadgenerator.MetadataXml.java
License:Apache License
@SuppressWarnings("unchecked") public void metadataXml(List<List<List<String>>> schemas, List<Integer> peers, List<List<Object>> mappings, String extension) {/*from w w w . j a va 2 s.c o m*/ Writer writer = null; if (null == _params.get("filename")) { writer = new PrintWriter(System.out); } else { try { if (!"".equals(extension)) { extension = "." + extension; } writer = new FileWriter((String) _params.get("filename") + extension + ".schema"); // + ".schema.new"); } catch (IOException e) { throw new IllegalStateException("Unable to create schema file.", e); } } Document document = DocumentHelper.createDocument(); document.addComment(WorkloadGeneratorUtils.stamp() + "\n" + _params); Element catalog = document.addElement("catalog").addAttribute("recMode", "false").addAttribute("name", (String) _params.get("filename")); catalog.addElement("migrated").setText("true"); for (int i = 0; i < peers.size(); i++) { if (null == peers.get(i)) { continue; } Element peer = catalog.addElement("peer").addAttribute("name", "P" + i).addAttribute("address", "localhost"); int j = peers.get(i); Element schema = peer.addElement("schema").addAttribute("name", "S" + j); for (int k = 0; k < schemas.get(j).size(); k++) { for (String var : iovariations()) { Element relation = schema.addElement("relation") .addAttribute("name", WorkloadGeneratorUtils.relname(i, j, k) + var) .addAttribute("materialized", "true"); if ((Double) _params.get("coverage") == 1) { relation.addAttribute("noNulls", "true"); } String hasLocalData; if (Generator.peerHasLocalData(i, (Integer) _params.get("topology"), (Integer) _params.get("modlocal"), (Integer) _params.get("peers"), (Integer) _params.get("fanout"))) { hasLocalData = "true"; } else { hasLocalData = "false"; } relation.addAttribute("hasLocalData", hasLocalData); relation.addElement("dbinfo").addAttribute("schema", (String) _params.get("username")) .addAttribute("table", WorkloadGeneratorUtils.relname(i, j, k) + var); relation.addElement("field").addAttribute("name", "KID").addAttribute("type", "integer") .addAttribute("key", "true"); for (String att : schemas.get(j).get(k)) { if ((Boolean) _params.get("addValueAttr") && att.equals(Relation.valueAttrName)) { relation.addElement("field").addAttribute("name", att).addAttribute("type", "integer") .addAttribute("key", "true"); } else { relation.addElement("field").addAttribute("name", att).addAttribute("type", universalType(att, _params)); } } } } } for (int k = 0; k < mappings.size(); k++) { if (null == mappings.get(k)) { continue; } int i = (Integer) mappings.get(k).get(0); int j = (Integer) mappings.get(k).get(1); List<String> x = (List<String>) mappings.get(k).get(2); List<String> source = selectAtoms(i, "KID", x, "_", schemas, peers, (Boolean) _params.get("addValueAttr"), true); // _ means don't care List<String> target = selectAtoms(j, "KID", x, "-", schemas, peers, (Boolean) _params.get("addValueAttr"), false); // - means null Element mapping = catalog.addElement("mapping").addAttribute("name", "M" + k) .addAttribute("materialized", "true"); if (1 == (Integer) _params.get("bidir")) { mapping.addAttribute("bidirectional", "true"); } Element head = mapping.addElement("head"); for (String atom : target) { Element atomElem = head.addElement("atom"); if (1 == (Integer) _params.get("bidir")) { atomElem.addAttribute("del", "true"); } atomElem.addText(atom); } Element body = mapping.addElement("body"); for (String atom : source) { Element atomElem = body.addElement("atom"); if (1 == (Integer) _params.get("bidir")) { atomElem.addAttribute("del", "true"); } atomElem.addText(atom); } } Element mappingsElem = catalog.addElement("engine").addElement("mappings"); if (1 == (Integer) _params.get("tukwila")) { mappingsElem.addAttribute("type", "tukwila").addAttribute("host", "localhost").addAttribute("port", "7777"); } else { mappingsElem.addAttribute("type", "sql") .addAttribute("server", (String) _params.get("mappingsServer") + "/" // "jdbc:db2://localhost:50000/" + _params.get("dbalias")) .addAttribute("username", (String) _params.get("username")) .addAttribute("password", (String) _params.get("password")); } if (null != _params.get("updateAlias")) { catalog.addElement("updates") .addAttribute("server", "jdbc:db2://localhost:50000/" + _params.get("updateAlias")) .addAttribute("username", (String) _params.get("username")) .addAttribute("password", (String) _params.get("password")); } // Output some default (dummy) reconciliation store info Element store = catalog.addElement("store"); store.addElement("update").addAttribute("type", "bdb").addAttribute("hostname", "localhost") .addAttribute("port", "777"); store.addElement("state").addAttribute("type", "hash"); // Output trust conditions saying that everyone trusts everyone for (int i = 0; i < peers.size(); i++) { if (null == peers.get(i)) { continue; } int j = peers.get(i); Element trustConditions = catalog.addElement("trustConditions").addAttribute("peer", "P" + i) .addAttribute("schema", "S" + j); for (int i2 = 0; i2 < peers.size(); i2++) { if (null == peers.get(i2)) { continue; } int j2 = peers.get(i2); if (i != i2) { for (int k2 = 0; k2 < schemas.get(j2).size(); k2++) { trustConditions.addElement("trusts").addAttribute("pid", "P" + i2) .addAttribute("pidType", "STRING").addAttribute("pidType", "STRING") .addAttribute("priority", "5") .addAttribute("relation", WorkloadGeneratorUtils.relname(i2, j2, k2)); } } } } try { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(document); writer.flush(); writer.close(); } catch (IOException e) { throw new IllegalStateException("Problem writing schema file.", e); } }
From source file:edu.vt.middleware.ldap.dsml.Dsmlv1.java
License:Open Source License
/** * This will take the results of a prior LDAP query and convert it to a DSML * <code>Document</code>.//from w ww.j a v a 2 s.c o m * * @param result <code>LdapResult</code> * * @return <code>Document</code> */ public Document createDsml(final LdapResult result) { final Namespace ns = new Namespace("dsml", "http://www.dsml.org/DSML"); final Document doc = DocumentHelper.createDocument(); final Element dsmlElement = doc.addElement(new QName("dsml", ns)); final Element entriesElement = dsmlElement.addElement(new QName("directory-entries", ns)); // build document object from result if (result != null) { for (LdapEntry le : result.getEntries()) { final Element entryElement = this.createDsmlEntry(new QName("entry", ns), le, ns); entriesElement.add(entryElement); } } return doc; }
From source file:edu.vt.middleware.ldap.dsml.Dsmlv2.java
License:Open Source License
/** * This will take the results of a prior LDAP query and convert it to a DSML * <code>Document</code>./*w ww . ja v a 2 s . c om*/ * * @param result <code>LdapResult</code> * * @return <code>Document</code> */ public Document createDsml(final LdapResult result) { final Namespace ns = new Namespace("", "urn:oasis:names:tc:DSML:2:0:core"); final Document doc = DocumentHelper.createDocument(); final Element dsmlElement = doc.addElement(new QName("batchResponse", ns)); final Element entriesElement = dsmlElement.addElement(new QName("searchResponse", ns)); // build document object from results if (result != null) { for (LdapEntry le : result.getEntries()) { final Element entryElement = this.createDsmlEntry(new QName("searchResultEntry", ns), le, ns); entriesElement.add(entryElement); } } final Element doneElement = entriesElement.addElement(new QName("searchResultDone", ns)); final Element codeElement = doneElement.addElement(new QName("resultCode", ns)); codeElement.addAttribute("code", "0"); return doc; }