List of usage examples for org.jdom2 Element setNamespace
public Element setNamespace(Namespace namespace)
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata for al list of processes as a single file to a given stream. * //from w ww . j a v a 2s . c o m * @param processList * @param outputStream * @param xslt */ public void startExport(List<Process> processList, OutputStream outputStream, String xslt) { Document answer = new Document(); Element root = new Element("processes"); answer.setRootElement(root); Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addNamespaceDeclaration(xsi); root.setNamespace(xmlns); Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi); root.setAttribute(attSchema); for (Process p : processList) { Document doc = createDocument(p, false); Element processRoot = doc.getRootElement(); processRoot.detach(); root.addContent(processRoot); } XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); try { outp.output(answer, outputStream); } catch (IOException e) { } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { outputStream = null; } } } }
From source file:org.jumpmind.metl.core.runtime.component.AbstractXMLComponentRuntime.java
License:Open Source License
protected Map<Element, Namespace> removeNamespaces(Document document) { Map<Element, Namespace> namespaces = new HashMap<Element, Namespace>(); if (ignoreNamespace && document.hasRootElement()) { namespaces.put(document.getRootElement(), document.getRootElement().getNamespace()); document.getRootElement().setNamespace(null); for (Element el : document.getRootElement().getDescendants(new ElementFilter())) { Namespace nsp = el.getNamespace(); if (nsp != null) { el.setNamespace(null); namespaces.put(el, nsp); }//from w w w . ja v a 2s . co m } } return namespaces; }
From source file:org.jumpmind.metl.core.runtime.component.AbstractXMLComponentRuntime.java
License:Open Source License
protected void restoreNamespaces(Document document, Map<Element, Namespace> namespaces) { if (ignoreNamespace) { Set<Element> elements = namespaces.keySet(); for (Element element : elements) { element.setNamespace(namespaces.get(element)); }/*from www.j a v a 2s .c o m*/ } }
From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata for al list of processes as a * single file to a given stream.// w w w.j a v a 2 s. c om * * @param docketDataList * a list of Docket data * @param outputStream * The output stream, to write the docket to. */ void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) { Document answer = new Document(); Element root = new Element("processes"); answer.setRootElement(root); Namespace xmlns = Namespace.getNamespace(NAMESPACE); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addNamespaceDeclaration(xsi); root.setNamespace(xmlns); Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi); root.setAttribute(attSchema); for (DocketData docketData : docketDataList) { Document doc = createDocument(docketData, false); Element processRoot = doc.getRootElement(); processRoot.detach(); root.addContent(processRoot); } XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat()); try { outp.output(answer, outputStream); } catch (IOException e) { logger.error("Generating XML Output failed.", e); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error("Closing the output stream failed.", e); } } } }
From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method creates a new xml document with process metadata. * * @param docketData/*w w w . java2 s .co m*/ * the docketData to export * @return a new xml document */ private Document createDocument(DocketData docketData, boolean addNamespace) { Element processElm = new Element("process"); final Document doc = new Document(processElm); processElm.setAttribute("processID", String.valueOf(docketData.getProcessId())); Namespace xmlns = Namespace.getNamespace(NAMESPACE); processElm.setNamespace(xmlns); // namespace declaration if (addNamespace) { Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); processElm.addNamespaceDeclaration(xsi); Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi); processElm.setAttribute(attSchema); } // process information ArrayList<Element> processElements = new ArrayList<>(); Element processTitle = new Element("title", xmlns); processTitle.setText(docketData.getProcessName()); processElements.add(processTitle); Element project = new Element("project", xmlns); project.setText(docketData.getProjectName()); processElements.add(project); Element date = new Element("time", xmlns); date.setAttribute("type", "creation date"); date.setText(String.valueOf(docketData.getCreationDate())); processElements.add(date); Element ruleset = new Element("ruleset", xmlns); ruleset.setText(docketData.getRulesetName()); processElements.add(ruleset); Element comment = new Element("comment", xmlns); comment.setText(docketData.getComment()); processElements.add(comment); List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns); if (!processProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(processProperties); processElements.add(properties); } // template information ArrayList<Element> templateElements = new ArrayList<>(); Element template = new Element("original", xmlns); ArrayList<Element> templateProperties = new ArrayList<>(); if (docketData.getTemplateProperties() != null) { for (Property prop : docketData.getTemplateProperties()) { Element property = new Element(PROPERTY, xmlns); property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle()); if (prop.getValue() != null) { property.setAttribute(VALUE, replacer(prop.getValue())); } else { property.setAttribute(VALUE, ""); } Element label = new Element(LABEL, xmlns); label.setText(prop.getTitle()); property.addContent(label); templateProperties.add(property); if (prop.getTitle().equals("Signatur")) { Element secondProperty = new Element(PROPERTY, xmlns); secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded"); if (prop.getValue() != null) { secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue())); Element secondLabel = new Element(LABEL, xmlns); secondLabel.setText(prop.getTitle()); secondProperty.addContent(secondLabel); templateProperties.add(secondProperty); } } } } if (!templateProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(templateProperties); template.addContent(properties); } templateElements.add(template); Element templates = new Element("originals", xmlns); templates.addContent(templateElements); processElements.add(templates); // digital document information ArrayList<Element> docElements = new ArrayList<>(); Element dd = new Element("digitalDocument", xmlns); List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns); if (!docProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(docProperties); dd.addContent(properties); } docElements.add(dd); Element digdoc = new Element("digitalDocuments", xmlns); digdoc.addContent(docElements); processElements.add(digdoc); processElm.setContent(processElements); return doc; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildModelFromPackageNames(Model model) { Element modelElem = new Element("Model"); modelElem.setNamespace(umlNs); this.xmiElem.addContent(modelElem); modelElem.setAttribute(new Attribute("id", model.getId(), xmiNs)); modelElem.setAttribute(new Attribute("name", model.getName())); modelElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(model.getId(), modelElem); if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(modelElem, model.getId(), doc.getBody().getValue()); }/*from w w w . j av a2 s . com*/ // Only a root (model) package // tag the model w/a SDO namespace streotype, else tag the // last package descendant below if (model.getPackages().size() == 0) { Element modelStereotype = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(modelStereotype); modelStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); modelStereotype.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, model.getId())); modelStereotype.setAttribute(new Attribute(SDONamespace.URI, model.getUri())); if (model.getAlias() != null) addAlias(model.getAlias(), model.getId()); } for (Package pkg : model.getPackages()) { Element pkgElem = new Element("packagedElement"); modelElem.addContent(pkgElem); // add package child pkgElem.setAttribute(new Attribute("type", "uml:Package", xmiNs)); pkgElem.setAttribute(new Attribute("id", pkg.getId(), xmiNs)); pkgElem.setAttribute(new Attribute("name", pkg.getName())); pkgElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(pkg.getId(), pkgElem); if (pkg.getAlias() != null) addAlias(pkg.getAlias(), pkg.getId()); Element pkgStereotypeElem = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(pkgStereotypeElem); pkgStereotypeElem.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, pkg.getId())); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.URI, pkg.getUri())); if (pkg.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(pkgElem, pkg.getId(), doc.getBody().getValue()); } } return modelElem; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildModelFromURITokens(Model model) { Element rootPackageElem = null; String[] packageNames = ConfigUtils.toPackageTokens(model.getUri()); Element modelElem = new Element("Model"); modelElem.setNamespace(umlNs); this.xmiElem.addContent(modelElem); modelElem.setAttribute(new Attribute("id", model.getId(), xmiNs)); modelElem.setAttribute(new Attribute("name", packageNames[0])); modelElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(model.getId(), modelElem); // FIXME: duplicating model level docs at package // descendant level if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(modelElem, model.getId(), doc.getBody().getValue()); }//from w w w . ja v a 2 s . c om // tag the model w/a SDO namespace streotype, else tag the // last package descendant below if (packageNames.length == 1) { Element modelStereotype = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(modelStereotype); modelStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); modelStereotype.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, model.getId())); modelStereotype.setAttribute(new Attribute(SDONamespace.URI, this.destNamespaceURI)); } rootPackageElem = modelElem; for (int i = 1; i < packageNames.length; i++) { Element pkgElem = new Element("packagedElement"); rootPackageElem.addContent(pkgElem); String id = UUID.randomUUID().toString(); pkgElem.setAttribute(new Attribute("type", "uml:Package", xmiNs)); pkgElem.setAttribute(new Attribute("id", id, xmiNs)); pkgElem.setAttribute(new Attribute("name", packageNames[i])); pkgElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(id, pkgElem); if (i == packageNames.length - 1) { Element pkgStereotypeElem = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(pkgStereotypeElem); pkgStereotypeElem.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, id)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.URI, this.destNamespaceURI)); // FIXME: no packages or package-level docs in provisioning model // use model-level docs here if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(pkgElem, id, doc.getBody().getValue()); } } rootPackageElem = pkgElem; } return rootPackageElem; }
From source file:org.shaman.rpg.editor.project.elements.JdomElement.java
private void setChildText(String child, String text) { org.jdom2.Element e = data.getChild(child, JdomElements.NAMESPACE); if (text == null) { if (e != null) { e.detach();/*from w w w .java 2 s . co m*/ } return; } if (e == null) { e = new org.jdom2.Element(child); e.setNamespace(JdomElements.NAMESPACE); data.addContent(e); } e.setText(text); }
From source file:org.shaman.rpg.editor.project.elements.JdomElements.java
private JdomGroup newDoc() { //create new file org.jdom2.Element e = new org.jdom2.Element(ROOT_NAME); e.setNamespace(NAMESPACE); //e.setAttribute("xmlns", ROOT_NAMESPACE); doc = new Document(e); JdomGroup r = new JdomGroup(null, this, e, 0); return r;//from ww w .j a va 2s .com }
From source file:org.xcri.util.lax.Lax.java
License:Open Source License
/** * Get specified child elements as generously as possible * /*from ww w.ja v a 2s . c om*/ * @param parentElement * @param childElementName * @param preferredNamespace * @return * @throws WrongNamespaceException * @throws ElementNameFormattingException */ @SuppressWarnings("unchecked") private static List<Element> getAllChildren(Element parentElement, String childElementName, Namespace preferredNamespace) throws LaxException { boolean misspelled = false; boolean wrongNamespace = false; LinkedList<Element> list = new LinkedList<Element>(); List<Element> allChildren = parentElement.getChildren(); Iterator<Element> iter = allChildren.iterator(); while (iter.hasNext()) { Element nextElement = iter.next(); if (nextElement.getName().equals(childElementName)) { // // Add elements that use the wrong namespace, but correct it // here so when its exported its correct // list.add(nextElement); if (nextElement.getNamespace() != preferredNamespace) { nextElement.setNamespace(preferredNamespace); wrongNamespace = true; } } else if (nextElement.getName().compareToIgnoreCase(childElementName) == 0) { // // Add elements that use incorrect case, but correct it here // so when its exported its done correctly // nextElement.setName(childElementName); list.add(nextElement); misspelled = true; } } if (misspelled || wrongNamespace) { LaxException ex = new LaxException(list); ex.setMisspelled(misspelled); ex.setIncorrectNamespace(wrongNamespace); throw ex; } return list; }