List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.mrgeo.resources.tms.TileMapServiceResource.java
protected static Document mrsPyramidToTileMapServiceXml(final String url, final List<String> pyramidNames) throws ParserConfigurationException, DOMException, UnsupportedEncodingException { /*//from w w w . j a va 2 s . c o m * String tileMapService = "<?xml version='1.0' encoding='UTF-8' ?>" + * "<TileMapService version='1.0.0' services='http://localhost/mrgeo-services/api/tms/'>" + * " <Title>Example Tile Map Service</Title>" + * " <Abstract>This is a longer description of the example tiling map service.</Abstract>" + * " <TileMaps>" + " <TileMap " + " title='AfPk Elevation V2' " + * " srs='EPSG:4326' " + " profile='global-geodetic' " + * " href='http:///localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2' />" + * " </TileMaps>" + "</TileMapService>"; */ final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements final Document doc = docBuilder.newDocument(); final Element rootElement = doc.createElement("TileMapService"); doc.appendChild(rootElement); final Attr v = doc.createAttribute("version"); v.setValue(VERSION); rootElement.setAttributeNode(v); final Attr service = doc.createAttribute("services"); service.setValue(normalizeUrl(normalizeUrl(url).replace(VERSION, ""))); rootElement.setAttributeNode(service); // child elements final Element title = doc.createElement("Title"); title.setTextContent("Tile Map Service"); rootElement.appendChild(title); final Element abst = doc.createElement("Abstract"); abst.setTextContent("MrGeo MrsPyramid rasters available as TMS"); rootElement.appendChild(abst); final Element tilesets = doc.createElement("TileMaps"); rootElement.appendChild(tilesets); Collections.sort(pyramidNames); for (final String p : pyramidNames) { final Element tileset = doc.createElement("TileMap"); tilesets.appendChild(tileset); final Attr href = doc.createAttribute("href"); href.setValue(normalizeUrl(url) + "/" + URLEncoder.encode(p, "UTF-8")); tileset.setAttributeNode(href); final Attr maptitle = doc.createAttribute("title"); maptitle.setValue(p); tileset.setAttributeNode(maptitle); final Attr srs = doc.createAttribute("srs"); srs.setValue(SRS); tileset.setAttributeNode(srs); final Attr profile = doc.createAttribute("profile"); profile.setValue("global-geodetic"); tileset.setAttributeNode(profile); } return doc; }
From source file:org.mycore.common.xml.MCRXMLFunctions.java
/** * Returns a list of link targets of a given MCR object type. The structure * is <em>link</em>. If no links are found an empty NodeList is returned. * //from w ww. j ava 2 s . c om * @param mcrid * MCRObjectID as String as the link source * @param destinationType * MCR object type * @return a NodeList with <em>link</em> elements */ public static NodeList getLinkDestinations(String mcrid, String destinationType) { DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked(); try { Document document = documentBuilder.newDocument(); Element rootElement = document.createElement("linklist"); document.appendChild(rootElement); MCRLinkTableManager ltm = MCRLinkTableManager.instance(); for (String id : ltm.getDestinationOf(mcrid, destinationType)) { Element link = document.createElement("link"); link.setTextContent(id); rootElement.appendChild(link); } return rootElement.getChildNodes(); } finally { MCRDOMUtils.releaseDocumentBuilder(documentBuilder); } }
From source file:org.mycore.common.xml.MCRXMLFunctions.java
/** * Returns a list of link sources of a given MCR object type. The structure * is <em>link</em>. If no links are found an empty NodeList is returned. * * @param mcrid/*from www . ja v a2 s .c o m*/ * MCRObjectID as String as the link target * @param sourceType * MCR object type * @return a NodeList with <em>link</em> elements */ public static NodeList getLinkSources(String mcrid, String sourceType) { DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked(); try { Document document = documentBuilder.newDocument(); Element rootElement = document.createElement("linklist"); document.appendChild(rootElement); MCRLinkTableManager ltm = MCRLinkTableManager.instance(); for (String id : ltm.getSourceOf(mcrid)) { if (sourceType == null || MCRObjectID.getIDParts(id)[1].equals(sourceType)) { Element link = document.createElement("link"); link.setTextContent(id); rootElement.appendChild(link); } } return rootElement.getChildNodes(); } finally { MCRDOMUtils.releaseDocumentBuilder(documentBuilder); } }
From source file:org.nuxeo.runtime.model.impl.ComponentRegistrySerializer.java
public static Document toDocument() { ComponentManagerImpl mgr = (ComponentManagerImpl) Framework.getRuntime().getComponentManager(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc;/*from w ww . j a v a 2s . c om*/ try { doc = factory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Element root = doc.createElement("components"); doc.appendChild(root); for (RegistrationInfo ri : mgr.getRegistrations()) { ComponentName name = ri.getName(); if (name == null) { log.error("BUG: Found component with null name"); continue; } Element comp = doc.createElement("component"); comp.setAttribute("name", name.getName()); String impl = ri.getImplementation(); if (impl != null && impl.length() > 0) { comp.setAttribute("class", impl); } String bundle = ri.getBundle(); if (bundle == null) { bundle = ri.getContext().getBundle().getSymbolicName(); } if (bundle != null) { comp.setAttribute("bundle", bundle); } Version v = ri.getVersion(); if (v != null) { comp.setAttribute("version", v.toString()); } root.appendChild(comp); // write source if known String src = getComponentSrc(ri); if (src != null) { comp.setAttribute("src", src); } // write documentation String docText = ri.getDocumentation(); if (docText != null) { docText = docText.trim(); Element docu = doc.createElement("documentation"); docu.setTextContent(docText); comp.appendChild(docu); } // write services String[] services = ri.getProvidedServiceNames(); if (services != null && services.length > 0) { Element svcsEl = doc.createElement("services"); for (String service : services) { Element svcEl = doc.createElement("service"); svcEl.setAttribute("class", service); svcsEl.appendChild(svcEl); } comp.appendChild(svcsEl); } // write extension points ExtensionPoint[] xps = ri.getExtensionPoints(); if (xps != null && xps.length > 0) { Element xpsEl = doc.createElement("extension-points"); for (ExtensionPoint xp : xps) { Element xpEl = doc.createElement("extension-point"); xpEl.setAttribute("name", xp.getName()); docText = xp.getDocumentation(); if (docText != null) { xpEl.setTextContent(docText.trim()); } xpsEl.appendChild(xpEl); } comp.appendChild(xpsEl); } } return doc; }
From source file:org.obm.caldav.server.propertyHandler.impl.GetETag.java
@Override public void appendCalendarMultiGetPropertyValue(Element prop, IBackend proxy, CalendarResourceICS ics) throws AppendPropertyException { Element val = appendElement(prop, "getetag", NameSpaceConstant.DAV_NAMESPACE_PREFIX); val.setTextContent(ics.getETag()); }
From source file:org.obm.caldav.server.propertyHandler.impl.GetETag.java
@Override public void appendPropertyValue(Element prop, CalDavToken t, DavRequest req, IBackend proxy, DavComponent comp) {//from www . ja v a 2 s . c o m Element val = appendElement(prop, "getetag", NameSpaceConstant.DAV_NAMESPACE_PREFIX); val.setTextContent(comp.getETag()); }
From source file:org.ojbc.adapters.identifier.MessageUtils.java
public static SoapHeader makeSoapHeader(Document doc, String namespace, String localName, String value) { Element messageId = doc.createElementNS(namespace, localName); messageId.setTextContent(value); SoapHeader soapHeader = new SoapHeader(new QName(namespace, localName), messageId); return soapHeader; }
From source file:org.ojbc.adapters.identifier.processor.IdentifierRequestProcessor.java
public Document returnIdentifierResponse(@Header("personNode") Node personNode) throws Exception { Document document = documentBuilder.newDocument(); Element rootElement = appendRootElement(document); Element identification = XmlUtils.appendElement(rootElement, NS_NC_30, "Identification"); Element identificationId = XmlUtils.appendElement(identification, NS_NC_30, "IdentificationID"); String personIdentifier = getPersonIdentifier(personNode); identificationId.setTextContent(personIdentifier); return document; }
From source file:org.ojbc.adapters.rapbackdatastore.processor.AbstractIdentificationResultsQueryProcessor.java
protected void appendDocumentElement(Element parentElement, QueryResponseElementName elementName, String documentId, byte[] binaryData) { Element element = XmlUtils.appendElement(parentElement, NS_ORGANIZATION_IDENTIFICATION_INITIAL_RESULTS_QUERY_RESULTS_EXT, elementName.name()); XmlUtils.addAttribute(element, NS_STRUCTURES_30, "id", documentId); Element documentBinary = XmlUtils.appendElement(element, NS_NC_30, QueryResponseElementName.DocumentBinary.name()); Element base64BinaryObject = XmlUtils.appendElement(documentBinary, NS_ORGANIZATION_IDENTIFICATION_INITIAL_RESULTS_QUERY_RESULTS_EXT, QueryResponseElementName.Base64BinaryObject.name()); base64BinaryObject.setTextContent(Base64.encodeBase64String(binaryData)); }