Java Code Examples for org.jdom2.Document#setRootElement()
The following examples show how to use
org.jdom2.Document#setRootElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetadataController.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
private String writeXML(ThreddsMetadata.VariableGroup vars) { Document doc = new Document(); Element elem = new Element("variables", Catalog.defNS); doc.setRootElement(elem); if (vars.getVocabulary() != null) elem.setAttribute("vocabulary", vars.getVocabulary()); if (vars.getVocabUri() != null) elem.setAttribute("href", vars.getVocabUri().href, Catalog.xlinkNS); List<ThreddsMetadata.Variable> varList = vars.getVariableList(); for (ThreddsMetadata.Variable v : varList) { elem.addContent(writeVariable(v)); } XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); return fmt.outputString(doc); }
Example 2
Source File: SchedulingService.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
/** * adds new activities from YAWL model specification to document in right * order, e.g. if another worklet with new activities was started update * times of all activities beginning at last activity which has a time * TODO@tbe: returns false also, if order of activities was changed * * @param doc * @return true, if new activity was added */ public void extendRUPFromYAWLModel(Document doc, Set<String> addedActivityNames) throws Exception { String caseId = XMLUtils.getCaseId(doc); Element rupElement = new Element(XML_RUP); rupElement.addContent(_pgc.getActivityElements(caseId)); boolean changed = XMLUtils.mergeElements(rupElement, doc.getRootElement()); addedActivityNames.addAll(getDiffActivityNames(doc.getRootElement(), rupElement)); doc.setRootElement(rupElement); if (changed) { _log.info("Extract RUP of case Id " + caseId + " from YAWL specification: " + Utils.document2String(doc, false)); } }
Example 3
Source File: YDecomposition.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
/** * This method returns the list of data from a decomposition. According to * its declared output parameters. Only useful for Beta 4 and above. * The data inside this decomposition is groomed so to speak so that the * output data is returned in sequence. Furthermore no internal variables, \ * or input only parameters are returned. * @return a JDom Document of the output data. */ public Document getOutputData() { //create a new output document to return Document outputDoc = new Document(); Element root = _data.getRootElement(); outputDoc.setRootElement(new Element(root.getName())); //now prepare a list of output params to iterate over. List<YParameter> outputParamsList = new ArrayList<YParameter>( getOutputParameters().values()); Collections.sort(outputParamsList); for (YParameter parameter : outputParamsList) { Element child = root.getChild(parameter.getPreferredName()); outputDoc.getRootElement().addContent(child.clone()); } return outputDoc; }
Example 4
Source File: TestYExternalCondition.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
public void testMovingIdentifiers() throws YStateException, YDataStateException, YQueryException, YSchemaBuildingException, YPersistenceException { YIdentifier id = new YIdentifier(null); assertTrue(id.getLocations().size() == 0); assertFalse(id.getLocations().contains(_condition)); _condition.add(null, id); assertTrue("locations should contain C1 ", id.getLocations().contains(_condition) && id.getLocations().size() == 1); assertTrue(id.getLocations().contains(_condition)); assertTrue(_aTask.t_enabled(id)); YIdentifier childID = null; childID = (YIdentifier) _aTask.t_fire(null).get(0); assertTrue("locations should be empty ", id.getLocations().size() == 1); assertTrue(id.getLocations().iterator().next().equals(_aTask)); assertFalse(id.getLocations().contains(_condition)); _aTask.t_start(null, childID); Document d = new Document();d.setRootElement(new Element("data")); _aTask.t_complete(null, childID, d); assertTrue(_condition2.getAmount(id) == 1); assertTrue(id.getLocations().contains(_condition2) && id.getLocations().size() == 1); }
Example 5
Source File: MCRObjectFactory.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Creates a {@link Document} suitable for * {@link MCRObject#MCRObject(Document)}. The metadata element of this * mycore object is empty. The create and modify date are set to * "right now". */ public static Document getSampleObject(MCRObjectID id) { Document xml = new Document(); Element root = createRootElement(id); xml.setRootElement(root); root.addContent(createStructureElement()); root.addContent(createMetadataElement(id)); root.addContent(createServiceElement()); return xml; }
Example 6
Source File: GPXFileWriter.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
public static void writeGeonames(List<Geonames.Geoname> names, File target, Context context) throws IOException { Document doc = new Document(); Element gpx = new Element("gpx", NS); Namespace xsi = Namespace.getNamespace("xsi", XSI); gpx.addNamespaceDeclaration(xsi); Namespace bpt2 = Namespace.getNamespace("bpt2", BPT); gpx.addNamespaceDeclaration(bpt2); gpx.setAttribute("schemaLocation", XSD, xsi); gpx.setAttribute(new Attribute("version", "1.1")); gpx.setAttribute(new Attribute("creator", CREATOR)); Collection<Element> wpts = new ArrayList<>(); for (Geonames.Geoname name : names) { Element wpt = new Element("wpt", NS); wpt.setAttribute(new Attribute("lat", Double.toString(name.location.getLatitude()))); wpt.setAttribute(new Attribute("lon", Double.toString(name.location.getLongitude()))); wpt.addContent(new Element("name", NS).addContent(name.name)); wpts.add(wpt); } gpx.addContent(wpts); doc.setRootElement(gpx); FileWriter fw = null; try { fw = new FileWriter(target); XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); xout.output(doc, fw); fw.flush(); } finally { if (fw != null) fw.close(); } }
Example 7
Source File: GPXFileWriter.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
public static void writeWikiPages(List<Wikimedia.Page> pages, File target, Context context) throws IOException { Document doc = new Document(); Element gpx = new Element("gpx", NS); Namespace xsi = Namespace.getNamespace("xsi", XSI); gpx.addNamespaceDeclaration(xsi); Namespace bpt2 = Namespace.getNamespace("bpt2", BPT); gpx.addNamespaceDeclaration(bpt2); gpx.setAttribute("schemaLocation", XSD, xsi); gpx.setAttribute(new Attribute("version", "1.1")); gpx.setAttribute(new Attribute("creator", CREATOR)); Collection<Element> wpts = new ArrayList<>(); for (Wikimedia.Page page : pages) { Element wpt = new Element("wpt", NS); wpt.setAttribute(new Attribute("lat", Double.toString(page.location.getLatitude()))); wpt.setAttribute(new Attribute("lon", Double.toString(page.location.getLongitude()))); wpt.addContent(new Element("name", NS).addContent(page.title)); Element link = new Element("link", NS); link.setAttribute(new Attribute("href", page.getPageUrl())); wpt.addContent(link); wpts.add(wpt); } gpx.addContent(wpts); doc.setRootElement(gpx); FileWriter fw = null; try { fw = new FileWriter(target); XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); xout.output(doc, fw); fw.flush(); } finally { if (fw != null) fw.close(); } }
Example 8
Source File: GPXFileWriter.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
public static void writeGPXFile(File target, String trackName, boolean extensions, Cursor cTrackPoints, Cursor cWayPoints, Context context) throws IOException { Document doc = new Document(); Element gpx = new Element("gpx", NS); Namespace xsi = Namespace.getNamespace("xsi", XSI); gpx.addNamespaceDeclaration(xsi); Namespace bpt2 = Namespace.getNamespace("bpt2", BPT); gpx.addNamespaceDeclaration(bpt2); gpx.setAttribute("schemaLocation", XSD, xsi); gpx.setAttribute(new Attribute("version", "1.1")); gpx.setAttribute(new Attribute("creator", CREATOR)); gpx.addContent(getWayPoints(extensions, cWayPoints, bpt2, context)); gpx.addContent(getTrackpoints(trackName, extensions, cTrackPoints, bpt2, context)); doc.setRootElement(gpx); FileWriter fw = null; try { fw = new FileWriter(target); XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); xout.output(doc, fw); fw.flush(); } finally { if (fw != null) fw.close(); } // http://www.topografix.com/gpx/1/1/gpx.xsd // xmllint --noout --schema gpx.xsd BackPackTrack.gpx }
Example 9
Source File: YDecomposition.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public YDecomposition(String id, YSpecification specification) { _id = id; _specification = specification; _inputParameters = new HashMap<String, YParameter>(); _outputParameters = new HashMap<String, YParameter>(); _enablementParameters = new HashMap<String, YParameter>(); _outputExpressions = new HashSet<String>(); _data = new Document(); _attributes = new YAttributeMap(); _data.setRootElement(new Element(getRootDataElementName())); }
Example 10
Source File: YTask.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public void prepareDataDocsForTaskOutput() { if (null == getDecompositionPrototype()) { return; } _groupedMultiInstanceOutputData = new Document(); _groupedMultiInstanceOutputData.setRootElement( new Element(getDecompositionPrototype().getRootDataElementName())); _localVariableNameToReplaceableOutputData = new HashMap<String, Element>(); }
Example 11
Source File: TestYNetRunner.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public void setUp() throws YSchemaBuildingException, YSyntaxException, YEngineStateException, YQueryException, JDOMException, IOException, YStateException, YPersistenceException, YDataStateException { URL fileURL = getClass().getResource("YAWL_Specification2.xml"); File yawlXMLFile1 = new File(fileURL.getFile()); YSpecification specification = null; specification = (YSpecification) YMarshal. unmarshalSpecifications(StringUtil.fileToString(yawlXMLFile1.getAbsolutePath())).get(0); YEngine engine2 = YEngine.getInstance(); EngineClearer.clear(engine2); engine2.loadSpecification(specification); _id1 = engine2.startCase(specification.getSpecificationID(), null, null, null, new YLogDataItemList(), null, false); _netRunner1 = engine2._netRunnerRepository.get(_id1); _d = new Document(); _d.setRootElement(new Element("data")); }
Example 12
Source File: JDOMHandleTest.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testReadWrite() throws SAXException, IOException { // create an identifier for the database document String docId = "/example/jdom-test.xml"; // create a manager for XML database documents XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); // create a JDOM document Document writeDocument = new Document(); Element root = new Element("root"); root.setAttribute("foo", "bar"); root.addContent(new Element("child")); root.addContent("mixed"); writeDocument.setRootElement(root); // create a handle for the JDOM document JDOMHandle writeHandle = new JDOMHandle(writeDocument); // write the JDOM document to the database docMgr.write(docId, writeHandle); // create a handle to receive the database content as a JDOM document JDOMHandle readHandle = new JDOMHandle(); // read the document content from the database as a JDOM document docMgr.read(docId, readHandle); // access the document content Document readDocument = readHandle.get(); assertNotNull("Wrote null JDOM document", readDocument); assertXMLEqual("JDOM document not equal", writeHandle.toString(), readHandle.toString()); // delete the document docMgr.delete(docId); }
Example 13
Source File: AtomService.java From rome with Apache License 2.0 | 5 votes |
/** * Serialize an AtomService object into an XML document */ public Document serviceToDocument() { final AtomService service = this; final Document doc = new Document(); final Element root = new Element("service", ATOM_PROTOCOL); doc.setRootElement(root); final List<Workspace> spaces = service.getWorkspaces(); for (final Workspace space : spaces) { root.addContent(space.workspaceToElement()); } return doc; }
Example 14
Source File: KMLFileWriter.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
public static void writeKMLFile(File target, String trackName, boolean extensions, Cursor cTrackPoints, Cursor cWayPoints, Context context) throws IOException { // https://developers.google.com/kml/documentation/kmlreference Document doc = new Document(); Element kml = new Element("kml", NS); Namespace gx = Namespace.getNamespace("gx", "http://www.google.com/kml/ext/2.2"); kml.addNamespaceDeclaration(gx); Namespace atom = Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"); kml.addNamespaceDeclaration(atom); Element document = new Element("Document", NS); Element name = new Element("name", NS); name.addContent(trackName); document.addContent(name); Element author = new Element("author", atom); Element authorName = new Element("name", atom); authorName.addContent("BackPackTrackII"); author.addContent(authorName); document.addContent(author); Element style = new Element("Style", NS); style.setAttribute(new Attribute("id", "style")); Element linestyle = new Element("LineStyle", NS); Element color = new Element("color", NS); color.addContent("ffff0000"); linestyle.addContent(color); Element width = new Element("width", NS); width.addContent("5"); linestyle.addContent(width); style.addContent(linestyle); document.addContent(style); Collection<Element> placemarks = new ArrayList<>(); placemarks.add(getTrackpoints(trackName, extensions, cTrackPoints, gx, context)); placemarks.addAll(getWayPoints(extensions, cWayPoints, gx, context)); document.addContent(placemarks); kml.addContent(document); doc.setRootElement(kml); FileWriter fw = null; try { fw = new FileWriter(target); XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); xout.output(doc, fw); fw.flush(); } finally { if (fw != null) fw.close(); } // https://developers.google.com/kml/schema/kml22gx.xsd // xmllint --noout --schema kml22gx.xsd BackPackTrack.kml }
Example 15
Source File: ConvertJsonToXmlService.java From cs-actions with Apache License 2.0 | 4 votes |
private Document convertJsonStringToXmlDocument(final String json, final String rootTagName) { final JsonElement jsonElement = new JsonParser().parse(json); final Document document = new Document(); return document.setRootElement(addRootTagJsonElement(rootTagName, jsonElement)); }