List of usage examples for org.w3c.dom Document createElementNS
public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;
From source file:be.fedict.eid.applet.service.signer.odf.OpenOfficeSignatureFacet.java
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("pre sign"); Element dateElement = document.createElementNS("", "dc:date"); dateElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:dc", "http://purl.org/dc/elements/1.1/"); DateTime dateTime = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String now = fmt.print(dateTime); now = now.substring(0, now.indexOf("Z")); LOG.debug("now: " + now); dateElement.setTextContent(now);/* w ww . j a v a 2s . c om*/ String signaturePropertyId = "sign-prop-" + UUID.randomUUID().toString(); List<XMLStructure> signaturePropertyContent = new LinkedList<XMLStructure>(); signaturePropertyContent.add(new DOMStructure(dateElement)); SignatureProperty signatureProperty = signatureFactory.newSignatureProperty(signaturePropertyContent, "#" + signatureId, signaturePropertyId); List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); List<SignatureProperty> signaturePropertiesContent = new LinkedList<SignatureProperty>(); signaturePropertiesContent.add(signatureProperty); SignatureProperties signatureProperties = signatureFactory .newSignatureProperties(signaturePropertiesContent, null); objectContent.add(signatureProperties); objects.add(signatureFactory.newXMLObject(objectContent, null, null, null)); DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); Reference reference = signatureFactory.newReference("#" + signaturePropertyId, digestMethod); references.add(reference); }
From source file:fr.ortolang.diffusion.seo.SeoServiceBean.java
private Element buildSiteMapEntry(String loc, String lastmod, ChangeFrequency changefreq, String priority, Document doc) throws SeoServiceException { Element url = doc.createElementNS(SITEMAP_NS_URI, "url"); if (loc == null || loc.length() == 0) { throw new SeoServiceException("Cannot generate site map entry: 'loc' is mandatory"); }/*from ww w . j ava2s .c om*/ Element locElement = doc.createElementNS(SITEMAP_NS_URI, "loc"); locElement.appendChild(doc.createTextNode(loc)); url.appendChild(locElement); if (lastmod != null) { Element lastmodElement = doc.createElementNS(SITEMAP_NS_URI, "lastmod"); lastmodElement.appendChild(doc.createTextNode(lastmod)); url.appendChild(lastmodElement); } if (changefreq != null) { Element changefreqElement = doc.createElementNS(SITEMAP_NS_URI, "changefreq"); changefreqElement.appendChild(doc.createTextNode(changefreq.name().toLowerCase())); url.appendChild(changefreqElement); } if (priority != null) { Element priorityElement = doc.createElementNS(SITEMAP_NS_URI, "priority"); priorityElement.appendChild(doc.createTextNode(priority)); url.appendChild(priorityElement); } return url; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static Element getOrCreateAsFirstElement(Element parentElement, QName elementQName) { Element element = getChildElement(parentElement, elementQName); if (element != null) { return element; }/*w w w .ja va2s .com*/ Document doc = parentElement.getOwnerDocument(); element = doc.createElementNS(elementQName.getNamespaceURI(), elementQName.getLocalPart()); parentElement.insertBefore(element, getFirstChildElement(parentElement)); return element; }
From source file:erwins.util.repack.xml.XMLBuilder.java
/** * Construct a builder for new XML document with a default namespace. * The document will be created with the given root element, and the builder * returned by this method will serve as the starting-point for any further * document additions.//from w w w .ja v a2 s . c o m * * @param name * the name of the document's root element. * @param namespaceURI * default namespace URI for document, ignored if null or empty. * @return * a builder node that can be used to add more nodes to the XML document. * * @throws FactoryConfigurationError * @throws ParserConfigurationException */ public static XMLBuilder create(String name, String namespaceURI) throws ParserConfigurationException, FactoryConfigurationError { // Init DOM builder and Document. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(isNamespaceAware); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element rootElement = null; if (namespaceURI != null && namespaceURI.length() > 0) { rootElement = document.createElementNS(namespaceURI, name); } else { rootElement = document.createElement(name); } document.appendChild(rootElement); return new XMLBuilder(document); }
From source file:de.ingrid.interfaces.csw.server.cswt.impl.GenericServerCSWT.java
private Document createSummaryResponse(CSWTransactionResult result) throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true);//from w w w.j a v a2s. com DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DOMImplementation domImpl = docBuilder.getDOMImplementation(); Document doc = domImpl.createDocument(RESPONSE_NAMESPACE, "csw:TransactionResponse", null); // create summary Element summary = doc.createElementNS(RESPONSE_NAMESPACE, "csw:TransactionSummary"); summary.setAttribute("requestId", result.getRequestId()); doc.getDocumentElement().appendChild(summary); int inserts = result.getNumberOfInserts(); summary.appendChild(doc.createElementNS(RESPONSE_NAMESPACE, "totalInserted")) .appendChild(doc.createTextNode(String.valueOf(inserts))); int updates = result.getNumberOfUpdates(); summary.appendChild(doc.createElementNS(RESPONSE_NAMESPACE, "totalUpdated")) .appendChild(doc.createTextNode(String.valueOf(updates))); int deletes = result.getNumberOfDeletes(); summary.appendChild(doc.createElementNS(RESPONSE_NAMESPACE, "totalDeleted")) .appendChild(doc.createTextNode(String.valueOf(deletes))); // add insert results // if (inserts > 0) { // Element insertResult = doc.createElementNS(RESPONSE_NAMESPACE, "csw:InsertResult"); // doc.getDocumentElement().appendChild(insertResult); // for (ActionResult curResult : result.getInsertResults()) { // List<CSWRecord> records = curResult.getRecords(); // if (records.size() > 0) { // Node recordNode = records.get(0).getDocument().getFirstChild(); // Action action = curResult.getAction(); // String handle = action.getHandle(); // if (handle != null && recordNode instanceof Element) { // ((Element)recordNode).setAttribute("handle", handle); // } // doc.adoptNode(recordNode); // insertResult.appendChild(recordNode); // } // } // } return doc; }
From source file:be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java
private void addOriginSigsRels(String signatureZipEntryName, ZipOutputStream zipOutputStream) throws ParserConfigurationException, IOException, TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document originSignRelsDocument = documentBuilder.newDocument(); Element relationshipsElement = originSignRelsDocument .createElementNS("http://schemas.openxmlformats.org/package/2006/relationships", "Relationships"); relationshipsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", "http://schemas.openxmlformats.org/package/2006/relationships"); originSignRelsDocument.appendChild(relationshipsElement); Element relationshipElement = originSignRelsDocument .createElementNS("http://schemas.openxmlformats.org/package/2006/relationships", "Relationship"); String relationshipId = "rel-" + UUID.randomUUID().toString(); relationshipElement.setAttribute("Id", relationshipId); relationshipElement.setAttribute("Type", "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature"); String target = FilenameUtils.getName(signatureZipEntryName); LOG.debug("target: " + target); relationshipElement.setAttribute("Target", target); relationshipsElement.appendChild(relationshipElement); zipOutputStream.putNextEntry(new ZipEntry("_xmlsignatures/_rels/origin.sigs.rels")); writeDocumentNoClosing(originSignRelsDocument, zipOutputStream, false); }
From source file:com.nortal.jroad.wsdl.XTeeSoapProvider.java
@Override protected void populatePort(Definition definition, Port port) throws WSDLException { super.populatePort(definition, port); ExtensionRegistry extensionRegistry = definition.getExtensionRegistry(); extensionRegistry.mapExtensionTypes(Port.class, new QName(XTeeWsdlDefinition.XROAD_NAMESPACE, "address", XTeeWsdlDefinition.XROAD_PREFIX), UnknownExtensibilityElement.class); UnknownExtensibilityElement element = (UnknownExtensibilityElement) extensionRegistry.createExtension( Port.class, new QName(XTeeWsdlDefinition.XROAD_NAMESPACE, "address", XTeeWsdlDefinition.XROAD_NAMESPACE)); Document doc; try {/* w w w . ja v a 2 s .c om*/ doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Element xRoadAddr = doc.createElementNS(XTeeWsdlDefinition.XROAD_NAMESPACE, "address"); xRoadAddr.setPrefix(XTeeWsdlDefinition.XROAD_PREFIX); xRoadAddr.setAttribute("producer", xRoadDatabase); element.setElement(xRoadAddr); port.addExtensibilityElement(element); }
From source file:es.itecban.deployment.security.client.ws.LogonWS.java
private Element getRequestElement(String operationName) { // Create the DOM document Document doc = documentBuilder.newDocument(); doc.setDocumentURI(NAMESPACE_URI); // Create the root element Element requestElement = doc.createElementNS(NAMESPACE_URI, operationName); // Element requestElement = doc.createElement(operationName); doc.appendChild(requestElement);/* w w w.jav a 2 s .co m*/ // Return it return requestElement; }
From source file:com.marklogic.dom.ElementImpl.java
protected Node cloneNode(Document doc, boolean deep) { Element elem = doc.createElementNS(getNamespaceURI(), getTagName()); elem.setPrefix(getPrefix());//www.j a v a2s. c om for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (attr instanceof AttrImpl) { elem.setAttributeNode((Attr) ((AttrImpl) attr).cloneNode(doc, deep)); } else { // ns decl, stored as Java DOM Attr // uri of xmlns is "http://www.w3.org/2000/xmlns/" Attr clonedAttr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", attr.getName()); clonedAttr.setValue(attr.getValue()); elem.setAttributeNode(clonedAttr); } } if (deep) { // clone children NodeList list = getChildNodes(); for (int i = 0; i < list.getLength(); i++) { NodeImpl n = (NodeImpl) list.item(i); Node c = n.cloneNode(doc, true); elem.appendChild(c); } } return elem; }
From source file:org.callimachusproject.xproc.Pipeline.java
private XdmNode parse(String systemId, InputStream source, String media, XProcConfiguration config) throws IOException, SAXException, ParserConfigurationException { if (source == null && media == null) return null; try {//w w w . j a v a 2 s. c om FluidType type = new FluidType(InputStream.class, media); if (type.isXML()) return resolver.parse(systemId, source); Document doc = DocumentFactory.newInstance().newDocument(); if (systemId != null) { doc.setDocumentURI(systemId); } Element data = doc.createElementNS(XPROC_STEP, DATA); data.setAttribute("content-type", media); if (type.isText()) { Charset charset = type.getCharset(); if (charset == null) { charset = Charset.forName("UTF-8"); } if (source != null) { appendText(new InputStreamReader(source, charset), doc, data); } } else if (source != null) { data.setAttribute("encoding", "base64"); appendBase64(source, doc, data); } doc.appendChild(data); return config.getProcessor().newDocumentBuilder().wrap(doc); } finally { if (source != null) { source.close(); } } }