List of usage examples for org.jdom2 Element addNamespaceDeclaration
public boolean addNamespaceDeclaration(final Namespace additionalNamespace)
From source file:ca.nrc.cadc.vos.TransferWriter.java
License:Open Source License
/** * Build root element for the transfer./*from w w w .ja v a 2 s . c om*/ * @param transfer * @return root element */ private Element buildRoot(Transfer transfer) { Element root = new Element("transfer", TransferReader.VOS_NS); root.addNamespaceDeclaration(TransferReader.VOS_NS); Element e = null; e = new Element("target", TransferReader.VOS_NS); e.addContent(transfer.getTarget().getURIObject().toASCIIString()); root.addContent(e); e = new Element("direction", TransferReader.VOS_NS); e.addContent(transfer.getDirection().getValue()); root.addContent(e); e = new Element("view", TransferReader.VOS_NS); if (transfer.getView() != null) { e.setAttribute("uri", transfer.getView().getURI().toString()); for (View.Parameter param : transfer.getView().getParameters()) { Element pm = new Element("param", TransferReader.VOS_NS); pm.setAttribute("uri", param.getUri().toString()); pm.setText(param.getValue()); e.addContent(pm); } root.addContent(e); } if (transfer.getProtocols() != null) { for (Protocol protocol : transfer.getProtocols()) { Element pr = new Element("protocol", TransferReader.VOS_NS); pr.setAttribute("uri", protocol.getUri()); if (protocol.getEndpoint() != null) { Element ep = new Element("endpoint", TransferReader.VOS_NS); ep.addContent(protocol.getEndpoint()); pr.addContent(ep); } root.addContent(pr); } } e = new Element("keepBytes", TransferReader.VOS_NS); e.addContent(new Boolean(transfer.isKeepBytes()).toString()); root.addContent(e); return root; }
From source file:ca.nrc.cadc.vosi.Capabilities.java
License:Open Source License
public Document toXmlDocument() { Namespace xsi = Namespace.getNamespace("xsi", VOSI.XSI_NS_URI); Namespace cap = Namespace.getNamespace("vosi", VOSI.CAPABILITIES_NS_URI); Namespace vod = Namespace.getNamespace("vod", VOSI.VODATASERVICE_NS_URI); Element eleCapabilities = new Element("capabilities", cap); eleCapabilities.addNamespaceDeclaration(xsi); eleCapabilities.addNamespaceDeclaration(cap); eleCapabilities.addNamespaceDeclaration(vod); //Attribute attSchemaLocation = new Attribute("schemaLocation", XSI_LOC, xsi); //eleCapabilities.setAttribute(attSchemaLocation); Document document = new Document(); document.addContent(eleCapabilities); for (Capability capability : this._caps) { eleCapabilities.addContent(capability.toXmlElement(xsi, cap, vod)); }// ww w . j av a2 s . c o m return document; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * Get a single Table document.//from w w w . j a v a 2 s.c o m * * @param root root element for document * @return the TapSchema as a document to be rendered as XML */ protected Document getDocument(Element root) { root.addNamespaceDeclaration(xsi); root.addNamespaceDeclaration(vod); // ivoa convention but not allowed by the VODataService schema //root.setAttribute("version", "1.1"); Document document = new Document(); document.addContent(root); return document; }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;/*w w w . j av a 2 s.c o m*/ modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }
From source file:cager.parser.test.SimpleTest3.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); //Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;/*from w w w . j av a 2 s . co m*/ modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }
From source file:com.c4om.autoconf.ulysses.extra.svinchangesetgenerator.SVINChangesetGenerator.java
License:Apache License
/** * This method generates a changeset document, which describes what nodes * must be added and replaced. It generates it from the SVRLInterpreter * report passed at constructor.//from w w w.ja v a 2 s . com * * @param pathToConfiguration path to the runtime configuration. * * @param reportDocument the report document (objective solution description). * * @return The generated changeset document. * * @throws JDOMException * If there are problems at JDOM2 XML parsings * @throws IOException * I/O problems * @throws SaxonApiException * problems with Saxon API while transforming metamodel * suggestions into partial autocomplete nodes * @throws ParserConfigurationException * problems with javax.xml APIs while transforming metamodel * suggestions into partial autocomplete nodes */ public Document getSingleChangesetDocument(String pathToConfiguration, Document reportDocument) throws JDOMException, IOException, SaxonApiException, ParserConfigurationException { Element resultRoot = new Element("changeset", AutoconfXMLConstants.NAMESPACE_SVINAPPLIER); resultRoot.addNamespaceDeclaration(NAMESPACE_AUTOCONF_METADATA); // To // prevent // several // "xmlns:*****" // attributes // to // appear // everywhere Document result = new Document(resultRoot); Element reportElement = reportDocument.getRootElement(); for (Element currentDiscrepancyElement : reportElement.getChildren()) { boolean isCreate = false; Element interestingPathsElement = currentDiscrepancyElement.getChild("interestingPaths", NAMESPACE_SVRL_INTERPETER_REPORT); String searchPathText = interestingPathsElement.getAttributeValue("search-path"); String basePathText = interestingPathsElement.getAttributeValue("base-path"); String keySubpathText = interestingPathsElement.getAttributeValue("key-subpath"); // First, we look for a path to search the element where discrepancy // took place (if it exists) String[] docAndPath; String searchPathInternal; if (searchPathText == null) { docAndPath = divideDocAndPath(basePathText); searchPathInternal = docAndPath[1] + "[" + keySubpathText + "]"; } else { docAndPath = divideDocAndPath(searchPathText); searchPathInternal = docAndPath[1]; } if (!documentCache.containsKey(docAndPath[0])) { documentCache.put(docAndPath[0], loadJDOMDocumentFromFile(new File(pathToConfiguration + "/" + docAndPath[0]))); } Document currentDoc = documentCache.get(docAndPath[0]); List<Element> discordingElementAtDocList = performJAXENXPath(searchPathInternal, currentDoc, Filters.element(), xpathNamespaces); if (discordingElementAtDocList.size() == 0) { isCreate = true; } if (isCreate) { Element nodeToCreate = currentDiscrepancyElement .getChild("suggestedPartialNode", NAMESPACE_SVRL_INTERPETER_REPORT).getChildren().get(0) .clone(); //Sometimes, svinrep namespace is declared here (it is not clear why). We must remove it. nodeToCreate.removeNamespaceDeclaration(NAMESPACE_SVRL_INTERPETER_REPORT); boolean thereAreMetamodelSuggestions = currentDiscrepancyElement .getChild("metamodelSuggestions", NAMESPACE_SVRL_INTERPETER_REPORT).getChildren() .size() > 0; if (thereAreMetamodelSuggestions) { Element metamodelSuggestionUntransformed = currentDiscrepancyElement .getChild("metamodelSuggestions", NAMESPACE_SVRL_INTERPETER_REPORT).getChildren().get(0) .clone(); Document suggestionMiniDocument = new Document(metamodelSuggestionUntransformed); Document suggestionMiniDocumentTransformed = performXSLT(suggestionMiniDocument, xsltTransformMetamodelDocument); Element metamodelSuggestion = suggestionMiniDocumentTransformed.getRootElement(); Attribute metadataAttribute = new Attribute("autogen-from", "metamodel", NAMESPACE_AUTOCONF_METADATA); mixTreesRecursive(metamodelSuggestion, nodeToCreate, metadataAttribute, NAMESPACE_AUTOCONF_METADATA.getURI()); } else { Attribute mayNeedManualCompletion = new Attribute("may-need-completion", "true", NAMESPACE_AUTOCONF_METADATA); nodeToCreate.setAttribute(mayNeedManualCompletion); } Element createNodeElement = new Element("add-node", AutoconfXMLConstants.NAMESPACE_SVINAPPLIER); final String REGEXP_TO_GET_PARENT_PATH = "(.+)(/[^\\[\\]/]+(\\[.+\\])?)$"; Pattern patternToGetParentPath = Pattern.compile(REGEXP_TO_GET_PARENT_PATH); Matcher matcherToGetParentPath = patternToGetParentPath.matcher(searchPathInternal); matcherToGetParentPath.matches(); String pathToParent = matcherToGetParentPath.group(1); Attribute pathToParentAttr = new Attribute("underParentAtPath", pathToParent); Attribute documentToChangeAttr = new Attribute("atResource", docAndPath[0]); createNodeElement.setAttribute(documentToChangeAttr); createNodeElement.setAttribute(pathToParentAttr); createNodeElement.addContent(nodeToCreate); resultRoot.addContent(createNodeElement); } else { for (int i = 0; i < discordingElementAtDocList.size(); i++) { Element nodeToModify = currentDiscrepancyElement .getChild("suggestedPartialNode", NAMESPACE_SVRL_INTERPETER_REPORT).getChildren().get(0) .clone(); //Sometimes, svinrep namespace is declared here (it is not clear why). We must remove it. nodeToModify.removeNamespaceDeclaration(NAMESPACE_SVRL_INTERPETER_REPORT); Element discordingElementAtDoc = discordingElementAtDocList.get(i); mixTreesRecursive(discordingElementAtDoc, nodeToModify, null, NAMESPACE_AUTOCONF_METADATA.getURI()); Element replaceNodeElement = new Element("replace-node", AutoconfXMLConstants.NAMESPACE_SVINAPPLIER); Attribute pathToElementAttr = new Attribute("atPath", generateAttributeBasedPath(discordingElementAtDoc)); Attribute documentToChangeAttr = new Attribute("atResource", docAndPath[0]); replaceNodeElement.setAttribute(documentToChangeAttr); replaceNodeElement.setAttribute(pathToElementAttr); replaceNodeElement.addContent(nodeToModify); resultRoot.addContent(replaceNodeElement); } } } return result; }
From source file:com.cybernostics.jsp2thymeleaf.JSP2Thymeleaf.java
private List<Content> rootContentFor(JspTree jspTree) { List<Content> contents = new ArrayList<>(); if (showBanner) { contents.add(new Comment("Created with JSP2Thymeleaf")); contents.add(new Text(NEWLINE)); }/*from w w w .j a va 2 s. c o m*/ contents.addAll(contentFor(jspTree, this)); final Optional<Content> foundHtmlElement = contents.stream().filter(JSP2Thymeleaf::isHtmlElement) .findFirst(); if (foundHtmlElement.isPresent()) { final Element htmlElement = (Element) foundHtmlElement.get(); contents.remove(htmlElement); trimTrailingWhitespace(contents); htmlElement.addContent(contents); htmlElement.setNamespace(xmlns); ActiveNamespaces.get().forEach(ns -> htmlElement.addNamespaceDeclaration(ns)); return Arrays.asList(new DocType("html", THYMELEAF_DTD), htmlElement); } else { Element thFragment = createFragmentDef(contents); return Arrays.asList(new DocType("html", THYMELEAF_DTD), thFragment); } }
From source file:com.cybernostics.jsp2thymeleaf.JSP2Thymeleaf.java
private Element createFragmentDef(List<Content> contents) { Element html = new Element("html", xmlns); ActiveNamespaces.get().forEach(ns -> html.addNamespaceDeclaration(ns)); html.addContent(NEWLINE);/*from ww w . ja v a2 s . c o m*/ Element head = new Element("head", xmlns); html.addContent(head); html.addContent(NEWLINE); Element title = new Element("title", xmlns); title.setText("Thymeleaf Fragment Definition"); head.addContent(NEWLINE); head.addContent(title); head.addContent(NEWLINE); Element body = new Element("body", xmlns); html.addContent(body); html.addContent(NEWLINE); body.addContent(contents); return html; }
From source file:com.github.cat.yum.store.util.YumUtil.java
private static void createRepoMd(String rootPath, RepoModule... repos) throws IOException { Document doc = new Document(); Element root = new Element("repomd", REPONAMESPACE); doc.addContent(root);/*from w w w. j ava 2 s . c o m*/ root.addNamespaceDeclaration(RPMNAMESPACE); long now = System.currentTimeMillis(); for (RepoModule repo : repos) { Element data = new Element("data", REPONAMESPACE); data.setAttribute("type", repo.getModule()); Element location = new Element("location", REPONAMESPACE); File xmlGzFie = getXmlGzFile(repo, repo.getXmlGzCode()); location.setAttribute("href", replacePath(FileUtils.getFileRelativePath(repo.getRootPath(), xmlGzFie))); data.addContent(location); Element checksum = new Element("checksum", REPONAMESPACE); checksum.setAttribute("type", ALGORITHM); checksum.setAttribute("pkgid", "YES"); checksum.setText(repo.getXmlGzCode()); data.addContent(checksum); Element size = new Element("size", REPONAMESPACE); size.setText(repo.getXmlGzSize() + ""); data.addContent(size); Element timestamp = new Element("timestamp", REPONAMESPACE); timestamp.setText(now + ""); data.addContent(timestamp); Element openCheckSum = new Element("open-checksum", REPONAMESPACE); openCheckSum.setAttribute("type", ALGORITHM); openCheckSum.setAttribute("pkgid", "YES"); openCheckSum.setText(repo.getXmlCode()); data.addContent(openCheckSum); Element openSize = new Element("open-size", REPONAMESPACE); openSize.setText(repo.getXmlSize() + ""); data.addContent(openSize); Element revision = new Element("revision", REPONAMESPACE); data.addContent(revision); root.addContent(data); } File repoMd = new File(rootPath + File.separator + REPOPATH + File.separator + "repomd" + ".xml"); xmlToFile(doc, repoMd); }
From source file:com.github.cat.yum.store.util.YumUtil.java
private static RepoModule createPrimary(RpmData[] rpmdatas, String rootPath) throws IOException, NoSuchAlgorithmException { RepoModule repo = new RepoModule(rootPath, "primary"); Document doc = new Document(); Element root = new Element("metadata", COMMONNAMESPACE); doc.addContent(root);/*from ww w . j a va 2 s . co m*/ root.addNamespaceDeclaration(RPMNAMESPACE); root.setAttribute("packages", rpmdatas.length + ""); for (RpmData rpmdata : rpmdatas) { RpmMetadata rpmMetadata = rpmdata.rpmMetadata; Element packAge = new Element("package", COMMONNAMESPACE); packAge.setAttribute("type", "rpm"); root.addContent(packAge); Element name = new Element("name", COMMONNAMESPACE); name.setText(rpmMetadata.name); packAge.addContent(name); Element arch = new Element("arch", COMMONNAMESPACE); arch.setText(rpmMetadata.architecture); packAge.addContent(arch); Element version = new Element("version", COMMONNAMESPACE); version.setAttribute("epoch", rpmMetadata.epoch + ""); version.setAttribute("ver", rpmMetadata.version); version.setAttribute("rel", rpmMetadata.release); packAge.addContent(version); Element checksum = new Element("checksum", COMMONNAMESPACE); checksum.setAttribute("type", ALGORITHM); checksum.setAttribute("pkgid", "YES"); checksum.setText(HashFile.getsum(rpmdata.rpm, ALGORITHM)); packAge.addContent(checksum); Element summary = new Element("summary", COMMONNAMESPACE); summary.setText(rpmMetadata.summary); packAge.addContent(summary); Element description = new Element("description", COMMONNAMESPACE); description.setText(rpmMetadata.description); packAge.addContent(description); Element packager = new Element("packager", COMMONNAMESPACE); packager.setText(rpmMetadata.packager); packAge.addContent(packager); Element url = new Element("url", COMMONNAMESPACE); url.setText(rpmMetadata.url); packAge.addContent(url); Element time = new Element("time", COMMONNAMESPACE); time.setAttribute("file", rpmdata.rpm.lastModified() / 1000 + ""); time.setAttribute("build", rpmMetadata.buildTime + ""); packAge.addContent(time); Element size = new Element("size", COMMONNAMESPACE); size.setAttribute("package", rpmdata.rpm.length() + ""); size.setAttribute("installed", rpmMetadata.installedSize + ""); size.setAttribute("archive", rpmMetadata.archiveSize + ""); packAge.addContent(size); Element location = new Element("location", COMMONNAMESPACE); location.setAttribute("href", replacePath(FileUtils.getFileRelativePath(rootPath, rpmdata.rpm))); packAge.addContent(location); Element format = new Element("format", COMMONNAMESPACE); packAge.addContent(format); Element license = new Element("license", RPMNAMESPACE); license.setText(rpmMetadata.license); format.addContent(license); Element vendor = new Element("vendor", RPMNAMESPACE); vendor.setText(rpmMetadata.vendor); format.addContent(vendor); Element group = new Element("group", RPMNAMESPACE); group.setText(rpmMetadata.group); format.addContent(group); Element buildhost = new Element("buildhost", RPMNAMESPACE); buildhost.setText(rpmMetadata.buildHost); format.addContent(buildhost); Element sourcerpm = new Element("sourcerpm", RPMNAMESPACE); sourcerpm.setText(rpmMetadata.sourceRpm); format.addContent(sourcerpm); Element headerRange = new Element("header-range", RPMNAMESPACE); headerRange.setAttribute("start", rpmMetadata.headerStart + ""); headerRange.setAttribute("end", rpmMetadata.headerEnd + ""); format.addContent(headerRange); Element provides = new Element("provides", RPMNAMESPACE); format.addContent(provides); addEntry(provides, rpmMetadata.provide, null); Element requires = new Element("requires", RPMNAMESPACE); format.addContent(requires); addEntry(requires, rpmMetadata.require, new PrivateRequireFilter()); Element conflicts = new Element("conflicts", RPMNAMESPACE); format.addContent(conflicts); addEntry(conflicts, rpmMetadata.conflict, null); Element obsoletes = new Element("obsoletes", RPMNAMESPACE); format.addContent(obsoletes); addEntry(obsoletes, rpmMetadata.obsolete, null); YumFileter fileflter = new PrivateFileFilter(); YumFileter fileDirflter = new PrivateFileDirFilter(); for (com.github.cat.yum.store.model.File file : rpmMetadata.files) { if (StringUtils.isBlank(file.type)) { if (fileflter.filter(file.path)) { continue; } } else if ("dir".equals(file.type)) { if (fileDirflter.filter(file.path)) { continue; } } Element fileElemenrt = new Element("file", COMMONNAMESPACE); fileElemenrt.setText(file.path); if (!StringUtils.isBlank(file.type)) { fileElemenrt.setAttribute("type", file.type); } format.addContent(fileElemenrt); } } yumXmlSave(doc, repo); return repo; }