Java Code Examples for org.jdom2.Element#addNamespaceDeclaration()
The following examples show how to use
org.jdom2.Element#addNamespaceDeclaration() .
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: CatalogXmlWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Element writeMetadata(ThreddsMetadata.MetadataOther mdata) { Element mdataElem = new Element("metadata", Catalog.defNS); if (mdata.getType() != null) mdataElem.setAttribute("metadataType", mdata.getType()); if (mdata.isInherited()) mdataElem.setAttribute("inherited", "true"); String ns = mdata.getNamespaceURI(); if ((ns != null) && !ns.equals(Catalog.CATALOG_NAMESPACE_10)) { Namespace mdataNS = Namespace.getNamespace(mdata.getPrefix(), ns); mdataElem.addNamespaceDeclaration(mdataNS); } if (mdata.getXlinkHref() != null) { mdataElem.setAttribute("href", mdata.getXlinkHref(), Catalog.xlinkNS); if (mdata.getTitle() != null) mdataElem.setAttribute("title", mdata.getTitle(), Catalog.xlinkNS); } else if (mdata.getContentObject() != null && mdata.getContentObject() instanceof Element) { Element content = (Element) mdata.getContentObject(); mdataElem.setContent(content); } return mdataElem; }
Example 2
Source File: NcMLWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Element makeNetcdfElement(NetcdfFile ncFile, String location) { Element rootElem = makeGroupElement(ncFile.getRootGroup()); // rootElem isn't just like any other group element; we must undo some of the changes made to it in writeGroup(). rootElem.setName("netcdf"); // Was "group". rootElem.removeAttribute("name"); // This attribute is not defined on the root "netcdf" element. rootElem.addNamespaceDeclaration(namespace); if (null == location) location = ncFile.getLocation(); if (null != location) { rootElem.setAttribute("location", URLnaming.canonicalizeWrite(location)); } if (null != ncFile.getId()) rootElem.setAttribute("id", ncFile.getId()); if (null != ncFile.getTitle()) rootElem.setAttribute("title", ncFile.getTitle()); return rootElem; }
Example 3
Source File: NcmlWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Element makeNetcdfElement(NetcdfFile ncFile, @Nullable String location) { Element rootElem = makeGroupElement(ncFile.getRootGroup()); // rootElem isn't just like any other group element; we must undo some of the changes made to it in writeGroup(). rootElem.setName("netcdf"); // Was "group". rootElem.removeAttribute("name"); // This attribute is not defined on the root "netcdf" element. rootElem.addNamespaceDeclaration(namespace); if (null == location) location = ncFile.getLocation(); if (null != location) { rootElem.setAttribute("location", URLnaming.canonicalizeWrite(location)); } if (null != ncFile.getId()) rootElem.setAttribute("id", ncFile.getId()); if (null != ncFile.getTitle()) rootElem.setAttribute("title", ncFile.getTitle()); return rootElem; }
Example 4
Source File: ExceptionReport.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
public ExceptionReport(List<WcsException> exceptions) { Element rootElem = new Element("ServiceExceptionReport", ogcNS); rootElem.addNamespaceDeclaration(ogcNS); rootElem.setAttribute("version", "1.2.0"); if (exceptions != null) for (WcsException curException : exceptions) { Element exceptionElem = new Element("ServiceException", ogcNS); if (curException.getCode() != null && !curException.getCode().equals(WcsException.Code.UNKNOWN)) exceptionElem.setAttribute("code", curException.getCode().toString()); if (curException.getLocator() != null && !curException.getLocator().equals("")) exceptionElem.setAttribute("locator", curException.getLocator()); if (curException.getTextMessages() != null) { for (String curMessage : curException.getTextMessages()) { // ToDo - somehow seperate multiple text messages. exceptionElem.addContent(curMessage); } } rootElem.addContent(exceptionElem); } exceptionReport = new Document(rootElem); }
Example 5
Source File: MCRGoogleSitemapCommon.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * The method call the database and build the sitemap_google.xml JDOM document. * * @param number * number of this file - '1' = sitemap_google.xml - '> 1' sitemap_google_xxx.xml * @return The sitemap.xml as JDOM document */ protected Document buildPartSitemap(int number) throws Exception { LOGGER.debug("Build Google URL sitemap list number {}", Integer.toString(number)); // build document frame Element urlset = new Element("urlset", NS); urlset.addNamespaceDeclaration(XSI_NAMESPACE); urlset.setAttribute("schemaLocation", SITEMAP_SCHEMA, XSI_NAMESPACE); Document jdom = new Document(urlset); // build over all types int start = numberOfURLs * (number); int stop = numberOfURLs * (number + 1); if (stop > objidlist.size()) { stop = objidlist.size(); } LOGGER.debug("Build Google URL in range from {} to {}.", Integer.toString(start), Integer.toString(stop - 1)); for (int i = start; i < stop; i++) { MCRObjectIDDate objectIDDate = objidlist.get(i); urlset.addContent(buildURLElement(objectIDDate)); } return jdom; }
Example 6
Source File: RSS090Generator.java From rome with Apache License 2.0 | 5 votes |
protected Element createRootElement(final Channel channel) { final Element root = new Element("RDF", getRDFNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); root.addNamespaceDeclaration(getRDFNamespace()); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root); return root; }
Example 7
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 8
Source File: ConvertJsonToXmlService.java From cs-actions with Apache License 2.0 | 5 votes |
private Element createElement(final String tagName) { final String[] tagNames = tagName.split(NAMESPACE_DELIMITER); final Element result = tagNames.length == 1 ? new Element(tagName) : new Element(tagNames[1], namespaces.get(tagNames[0])); for (Namespace namespace : namespaces.values()) { result.addNamespaceDeclaration(namespace); } return result; }
Example 9
Source File: MCRBase.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * This method create a XML stream for all object data. * * @exception MCRException * if the content of this class is not valid * @return a JDOM Document with the XML data of the object as byte array */ public Document createXML() throws MCRException { validate(); Element elm = new Element(getRootTagName()); Document doc = new Document(elm); elm.addNamespaceDeclaration(XSI_NAMESPACE); elm.addNamespaceDeclaration(XLINK_NAMESPACE); elm.setAttribute("noNamespaceSchemaLocation", mcrSchema, XSI_NAMESPACE); elm.setAttribute("ID", mcrId.toString()); if (mcrLabel != null) { elm.setAttribute("label", mcrLabel); } elm.setAttribute("version", mcrVersion); return doc; }
Example 10
Source File: MCREditorOutValidator.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * @throws IOException * @throws JDOMException * */ private void checkObject() throws JDOMException, IOException { // add the namespaces (this is a workaround) Element root = input.getRootElement(); root.addNamespaceDeclaration(XLINK_NAMESPACE); root.addNamespaceDeclaration(XSI_NAMESPACE); // set the schema String mcrSchema = "datamodel-" + id.getTypeId() + ".xsd"; root.setAttribute("noNamespaceSchemaLocation", mcrSchema, XSI_NAMESPACE); // check the label String label = MCRUtils.filterTrimmedNotEmpty(root.getAttributeValue("label")) .orElse(null); if (label == null) { root.setAttribute("label", id.toString()); } // remove the path elements from the incoming Element pathes = root.getChild("pathes"); if (pathes != null) { root.removeChildren("pathes"); } Element structure = root.getChild("structure"); if (structure == null) { root.addContent(new Element("structure")); } else { checkObjectStructure(structure); } Element metadata = root.getChild("metadata"); checkObjectMetadata(metadata); Element service = root.getChild("service"); checkObjectService(root, service); }
Example 11
Source File: MCRAccessCommands.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * This method just export the permissions to a file * * @param filename * the file written to */ @MCRCommand(syntax = "export all permissions to file {0}", help = "Export all permissions from the Access Control System to the file {0}.", order = 50) public static void exportAllPermissionsToFile(String filename) throws Exception { MCRAccessInterface accessImpl = MCRAccessManager.getAccessImpl(); Element mcrpermissions = new Element("mcrpermissions"); mcrpermissions.addNamespaceDeclaration(XSI_NAMESPACE); mcrpermissions.addNamespaceDeclaration(XLINK_NAMESPACE); mcrpermissions.setAttribute("noNamespaceSchemaLocation", "MCRPermissions.xsd", XSI_NAMESPACE); Document doc = new Document(mcrpermissions); Collection<String> permissions = accessImpl.getPermissions(); for (String permission : permissions) { Element mcrpermission = new Element("mcrpermission"); mcrpermission.setAttribute("name", permission); String ruleDescription = accessImpl.getRuleDescription(permission); if (!ruleDescription.equals("")) { mcrpermission.setAttribute("ruledescription", ruleDescription); } Element rule = accessImpl.getRule(permission); mcrpermission.addContent(rule); mcrpermissions.addContent(mcrpermission); } File file = new File(filename); if (file.exists()) { LOGGER.warn("File {} yet exists, overwrite.", filename); } FileOutputStream fos = new FileOutputStream(file); LOGGER.info("Writing to file {} ...", filename); String mcrEncoding = MCRConfiguration2.getString("MCR.Metadata.DefaultEncoding").orElse(DEFAULT_ENCODING); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding(mcrEncoding)); out.output(doc, fos); }
Example 12
Source File: MCRUpdateDerivateServlet.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Updates derivate xml in the persistence backend * @param editorSubmission * MyCoRe derivate as XML * @return * MCRObjectID of the MyCoRe object * @throws SAXParseException * @throws MCRAccessException */ private MCRObjectID updateDerivateXML(Document editorSubmission) throws SAXParseException, IOException, MCRAccessException { Element root = editorSubmission.getRootElement(); root.setAttribute("noNamespaceSchemaLocation", "datamodel-derivate.xsd", XSI_NAMESPACE); root.addNamespaceDeclaration(XLINK_NAMESPACE); root.addNamespaceDeclaration(XSI_NAMESPACE); byte[] xml = new MCRJDOMContent(editorSubmission).asByteArray(); MCRDerivate der = new MCRDerivate(xml, true); MCRMetadataManager.update(der); return der.getOwnerID(); }
Example 13
Source File: Atom03Generator.java From rome with Apache License 2.0 | 5 votes |
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); generateModuleNamespaceDefs(root); return root; }
Example 14
Source File: PersisterJdomUtil.java From n2o-framework with Apache License 2.0 | 5 votes |
public static void installPrefix(Element element, Element rootElement) { if (element == null) return; if (rootElement.getNamespace() == null) return; if (element.getNamespacePrefix() == null) return; if (element.getNamespace() == null) return; if (element.getNamespace().getURI().equals(rootElement.getNamespace().getURI())) return; if (element.getNamespace().getURI().isEmpty()) return; if (rootElement.getAdditionalNamespaces().contains(element.getNamespace())) return; Namespace additional = element.getNamespace(); rootElement.addNamespaceDeclaration(additional); }
Example 15
Source File: DescribeCoverage.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
Document generateDescribeCoverageDoc() { // CoverageDescription (wcs) [1] Element coverageDescriptionsElem = new Element("CoverageDescription", wcsNS); coverageDescriptionsElem.addNamespaceDeclaration(gmlNS); coverageDescriptionsElem.addNamespaceDeclaration(xlinkNS); coverageDescriptionsElem.setAttribute("version", this.getVersion()); // ToDo Consider dealing with "updateSequence" // coverageDescriptionsElem.setAttribute( "updateSequence", this.getCurrentUpdateSequence() ); for (String curCoverageId : this.coverages) coverageDescriptionsElem.addContent(genCoverageOfferingElem(curCoverageId)); return new Document(coverageDescriptionsElem); }
Example 16
Source File: RSS091UserlandGenerator.java From rome with Apache License 2.0 | 5 votes |
@Override protected Element createRootElement(final Channel channel) { final Element root = new Element("rss", getFeedNamespace()); final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root); return root; }
Example 17
Source File: ConfigElementImplementationRegistry.java From gocd with Apache License 2.0 | 4 votes |
public void registerNamespacesInto(Element element) { for (PluginNamespace namespace : xsdsFor.values()) { element.addNamespaceDeclaration(Namespace.getNamespace(namespace.prefix, namespace.uri)); } }
Example 18
Source File: CatalogXmlWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Document writeCatalog(Catalog cat) { Element rootElem = new Element("catalog", Catalog.defNS); Document doc = new Document(rootElem); // attributes if (cat.getName() != null) rootElem.setAttribute("name", cat.getName()); rootElem.setAttribute("version", version); rootElem.addNamespaceDeclaration(Catalog.xlinkNS); if (cat.getExpires() != null) rootElem.setAttribute("expires", cat.getExpires().toString()); // services Iterator iter = cat.getServices().iterator(); while (iter.hasNext()) { Service service = (Service) iter.next(); rootElem.addContent(writeService(service)); } /* * dataset roots * if (raw) { * iter = cat.getDatasetRoots().iterator(); * while (iter.hasNext()) { * Property p = (Property) iter.next(); * rootElem.addContent(writeDatasetRoot(p)); * } * } */ // properties iter = cat.getProperties().iterator(); while (iter.hasNext()) { Property p = (Property) iter.next(); rootElem.addContent(writeProperty(p)); } // datasets iter = cat.getDatasetsLocal().iterator(); while (iter.hasNext()) { Dataset ds = (Dataset) iter.next(); if (ds instanceof CatalogRef) rootElem.addContent(writeCatalogRef((CatalogRef) ds)); else rootElem.addContent(writeDataset(ds)); } return doc; }
Example 19
Source File: MCREpicurLite.java From mycore with GNU General Public License v3.0 | 4 votes |
/** * Creates the epicur lite xml. */ public Document toXML() { //TODO support multiple url elements Element epicurLite = newEpicureElement("epicurlite"); epicurLite.addNamespaceDeclaration(XSI_NAMESPACE); epicurLite.setAttribute("schemaLocation", "http://nbn-resolving.org/epicurlite http://nbn-resolving.org/schemas/epicurlite/1.0/epicurlite.xsd", XSI_NAMESPACE); Document epicurLiteDoc = new Document(epicurLite); // authentication information if (credentials != null) { Element login = newEpicureElement("login"); Element password = newEpicureElement("password"); login.setText(credentials.getUserName()); password.setText(credentials.getPassword()); epicurLite.addContent(login); epicurLite.addContent(password); } // urn element Element identifier = newEpicureElement("identifier"); Element value = newEpicureElement("value"); value.setText(urn.getIdentifier()); epicurLite.addContent(identifier.addContent(value)); // resource Element Element resource = newEpicureElement("resource"); Element urlElem = newEpicureElement("url"); urlElem.setText(url.toString()); Element primary = newEpicureElement("primary"); primary.setText(String.valueOf(isPrimary)); Element frontpage = newEpicureElement("frontpage"); frontpage.setText(String.valueOf(isFrontpage)); resource.addContent(urlElem); resource.addContent(primary); resource.addContent(frontpage); epicurLite.addContent(resource); return epicurLiteDoc; }
Example 20
Source File: BaseWireFeedGenerator.java From rome with Apache License 2.0 | 4 votes |
protected void generateModuleNamespaceDefs(final Element root) { for (final Namespace allModuleNamespace : allModuleNamespaces) { root.addNamespaceDeclaration(allModuleNamespace); } }