List of usage examples for org.w3c.dom Document createElementNS
public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;
From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java
private static void addOriginSigsRels(final String signatureZipEntryName, final ZipOutputStream zipOutputStream) throws ParserConfigurationException, IOException, TransformerException { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); final Document originSignRelsDocument = documentBuilderFactory.newDocumentBuilder().newDocument(); final Element relationshipsElement = originSignRelsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationships"); //$NON-NLS-1$ relationshipsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", RELATIONSHIPS_SCHEMA); //$NON-NLS-1$ originSignRelsDocument.appendChild(relationshipsElement); final Element relationshipElement = originSignRelsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationship"); //$NON-NLS-1$ final String relationshipId = "rel-" + UUID.randomUUID().toString(); //$NON-NLS-1$ relationshipElement.setAttribute("Id", relationshipId); //$NON-NLS-1$ relationshipElement.setAttribute("Type", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature"); //$NON-NLS-1$ relationshipElement.setAttribute("Target", FilenameUtils.getName(signatureZipEntryName)); //$NON-NLS-1$ relationshipsElement.appendChild(relationshipElement); zipOutputStream.putNextEntry(new ZipEntry("_xmlsignatures/_rels/origin.sigs.rels")); //$NON-NLS-1$ writeDocumentNoClosing(originSignRelsDocument, zipOutputStream, false); }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addElement(Document relevantDocument, Node instanceNode) { Element relevantElement;//from w w w . java 2 s.c om if (instanceNode.getNamespaceURI() == null) { relevantElement = relevantDocument.createElement(instanceNode.getNodeName()); } else { relevantElement = relevantDocument.createElementNS(instanceNode.getNamespaceURI(), instanceNode.getNodeName()); } relevantDocument.appendChild(relevantElement); addAttributes(relevantElement, instanceNode); addChildren(relevantElement, instanceNode); }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addElement(Element relevantParent, Node instanceNode) { Document relevantDocument = relevantParent.getOwnerDocument(); Element relevantElement;//from www .java 2 s .c o m if (instanceNode.getNamespaceURI() == null) { relevantElement = relevantDocument.createElement(instanceNode.getNodeName()); } else { relevantElement = relevantDocument.createElementNS(instanceNode.getNamespaceURI(), instanceNode.getNodeName()); } // needed in instance serializer ... relevantElement.setUserData("", instanceNode.getUserData(""), null); relevantParent.appendChild(relevantElement); addAttributes(relevantElement, instanceNode); addChildren(relevantElement, instanceNode); }
From source file:Main.java
/** * Copy elements from one document to another attaching at the specified * element and translating the namespace. * * @param from copy the children of this element (exclusive) * @param to where to attach the copied elements * @param newNamespace destination namespace * * @since 8.4/* w ww . j av a 2 s .c o m*/ */ public static void copyDocument(Element from, Element to, String newNamespace) { Document doc = to.getOwnerDocument(); NodeList nl = from.getChildNodes(); int length = nl.getLength(); for (int i = 0; i < length; i++) { Node node = nl.item(i); Node newNode = null; if (Node.ELEMENT_NODE == node.getNodeType()) { Element oldElement = (Element) node; newNode = doc.createElementNS(newNamespace, oldElement.getTagName()); NamedNodeMap m = oldElement.getAttributes(); Element newElement = (Element) newNode; for (int index = 0; index < m.getLength(); index++) { Node attr = m.item(index); newElement.setAttribute(attr.getNodeName(), attr.getNodeValue()); } copyDocument(oldElement, newElement, newNamespace); } else { newNode = node.cloneNode(true); newNode = to.getOwnerDocument().importNode(newNode, true); } if (newNode != null) { to.appendChild(newNode); } } }
From source file:com.msopentech.odatajclient.engine.data.json.GeospatialJSONHandler.java
private static Element deserializePoint(final Document document, final Iterator<JsonNode> itor) { final Element point = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POINT); final Element ppos = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POS); point.appendChild(ppos);// w w w.ja v a 2 s . co m if (itor.hasNext()) { ppos.appendChild(document.createTextNode(itor.next().asText() + " " + itor.next().asText())); } return point; }
From source file:com.msopentech.odatajclient.engine.data.json.GeospatialJSONHandler.java
private static Element deserializeLineString(final Document document, final Iterator<JsonNode> itor) { final Element lineString = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_LINESTRING); if (!itor.hasNext()) { lineString.appendChild(document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POSLIST)); }// ww w. ja v a 2s. c o m appendPoses(lineString, document, itor); return lineString; }
From source file:com.msopentech.odatajclient.engine.data.json.GeospatialJSONHandler.java
private static Element deserializePolygon(final Document document, final Iterator<JsonNode> itor) { final Element polygon = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POLYGON); if (itor.hasNext()) { final Iterator<JsonNode> extItor = itor.next().elements(); final Element exterior = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POLYGON_EXTERIOR); polygon.appendChild(exterior);/*from ww w . ja va 2s . c o m*/ final Element extLR = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POLYGON_LINEARRING); exterior.appendChild(extLR); appendPoses(extLR, document, extItor); } if (itor.hasNext()) { final Iterator<JsonNode> intItor = itor.next().elements(); final Element interior = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POLYGON_INTERIOR); polygon.appendChild(interior); final Element intLR = document.createElementNS(ODataConstants.NS_GML, ODataConstants.ELEM_POLYGON_LINEARRING); interior.appendChild(intLR); appendPoses(intLR, document, intItor); } return polygon; }
From source file:at.gv.egovernment.moa.id.util.client.mis.simple.MISSimpleClient.java
public static List<MISMandate> sendGetMandatesRequest(String webServiceURL, String sessionId, SSLSocketFactory sSLSocketFactory) throws MISSimpleClientException { if (webServiceURL == null) { throw new NullPointerException("Argument webServiceURL must not be null."); }//from ww w . ja va2 s .c o m if (sessionId == null) { throw new NullPointerException("Argument sessionId must not be null."); } // ssl settings if (sSLSocketFactory != null) { SZRGWSecureSocketFactory fac = new SZRGWSecureSocketFactory(sSLSocketFactory); Protocol.registerProtocol("https", new Protocol("https", fac, 443)); } try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element mirElement = doc.createElementNS(MIS_NS, "MandateIssueRequest"); Element sessionIdElement = doc.createElementNS(MIS_NS, "SessionID"); sessionIdElement.appendChild(doc.createTextNode(sessionId)); mirElement.appendChild(sessionIdElement); // send soap request Element mandateIssueResponseElement = sendSOAPRequest(webServiceURL, mirElement); // check for error checkForError(mandateIssueResponseElement); // check for session id NodeList mandateElements = XPathAPI.selectNodeList(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:Mandates/mis:Mandate", NS_NODE); if (mandateElements == null || mandateElements.getLength() == 0) { throw new MISSimpleClientException("No mandates found in response."); } ArrayList<MISMandate> foundMandates = new ArrayList<MISMandate>(); for (int i = 0; i < mandateElements.getLength(); i++) { Element mandate = (Element) mandateElements.item(i); MISMandate misMandate = new MISMandate(); if (mandate.hasAttribute("ProfessionalRepresentative")) { // System.out.println("OID: " + mandate.getAttribute("ProfessionalRepresentative")); misMandate.setProfRep(mandate.getAttribute("ProfessionalRepresentative")); } if (mandate.hasAttribute("OWbPK")) { misMandate.setOWbPK(mandate.getAttribute("OWbPK")); // System.out.println("OWBPK: " + mandate.getAttribute("OWbPK")); } //misMandate.setMandate(Base64.decodeBase64(DOMUtils.getText(mandate))); misMandate.setMandate(Base64.decodeBase64(DOMUtils.getText(mandate).getBytes())); misMandate.setFullMandateIncluded(true); foundMandates.add(misMandate); } return foundMandates; } catch (ParserConfigurationException e) { throw new MISSimpleClientException("service.06", e); } catch (DOMException e) { throw new MISSimpleClientException("service.06", e); } catch (TransformerException e) { throw new MISSimpleClientException("service.06", e); } }
From source file:Main.java
/** * Creates a new Element having the specified qualified name. The element * must be {@link Document#adoptNode(Node) adopted} when inserted into * another Document.//from ww w .j a va2s. c o m * * @param qName * A QName object. * @return An Element node (with a Document owner but no parent). */ public static Element createElement(QName qName) { Document doc = null; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } StringBuilder nodeName = new StringBuilder(); if (qName.getPrefix().isEmpty()) { nodeName.append(qName.getLocalPart()); } else { nodeName.append(qName.getPrefix()).append(':').append(qName.getLocalPart()); } Element elem = doc.createElementNS(qName.getNamespaceURI(), nodeName.toString()); return elem; }
From source file:at.gv.egovernment.moa.id.util.client.mis.simple.MISSimpleClient.java
public static MISSessionId sendSessionIdRequest(String webServiceURL, byte[] idl, byte[] cert, String oaFriendlyName, String redirectURL, String referenceValue, List<String> mandateIdentifier, String targetType, byte[] authBlock, SSLSocketFactory sSLSocketFactory) throws MISSimpleClientException { if (webServiceURL == null) { throw new MISSimpleClientException("service.04"); }//from ww w.j a v a 2s . c om if (idl == null) { throw new NullPointerException("Argument idl must not be null."); } if (redirectURL == null) { throw new NullPointerException("Argument redirectURL must not be null."); } // ssl settings if (sSLSocketFactory != null) { SZRGWSecureSocketFactory fac = new SZRGWSecureSocketFactory(sSLSocketFactory); Protocol.registerProtocol("https", new Protocol("https", fac, 443)); } try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element mirElement = doc.createElementNS(MIS_NS, "MandateIssueRequest"); Element idlElement = doc.createElementNS(MIS_NS, "IdentityLink"); idlElement.appendChild(doc.createTextNode(new String(Base64.encodeBase64(idl)))); mirElement.appendChild(idlElement); if (cert != null && cert.length > 0) { Element certElement = doc.createElementNS(MIS_NS, "X509SignatureCertificate"); certElement.appendChild(doc.createTextNode(new String(Base64.encodeBase64(cert)))); //certElement.appendChild(doc.createTextNode(Base64.encodeBase64(cert))); // certElement.appendChild(doc.createTextNode(new String(Base64.encodeBase64(cert)))); mirElement.appendChild(certElement); } if (!StringUtils.isEmpty(oaFriendlyName)) { Element oaFriendlyNameElement = doc.createElementNS(MIS_NS, "OAFriendlyName"); oaFriendlyNameElement.appendChild(doc.createTextNode(oaFriendlyName)); mirElement.appendChild(oaFriendlyNameElement); } Element redirectElement = doc.createElementNS(MIS_NS, "RedirectURL"); redirectElement.appendChild(doc.createTextNode(redirectURL)); mirElement.appendChild(redirectElement); Element referenceValueElement = doc.createElementNS(MIS_NS, "ReferenceValue"); referenceValueElement.appendChild(doc.createTextNode(referenceValue)); mirElement.appendChild(referenceValueElement); if (mandateIdentifier != null && mandateIdentifier.size() > 0) { Element filtersElement = doc.createElementNS(MIS_NS, "Filters"); Element mandateIdentifiersElement = doc.createElementNS(MIS_NS, "MandateIdentifiers"); for (int i = 0; i < mandateIdentifier.size(); i++) { Element mandateIdentifierElement = doc.createElementNS(MIS_NS, "MandateIdentifier"); mandateIdentifierElement.appendChild(doc.createTextNode(mandateIdentifier.get(i))); mandateIdentifiersElement.appendChild(mandateIdentifierElement); } filtersElement.appendChild(mandateIdentifiersElement); mirElement.appendChild(filtersElement); } //add Target element Element targetElement = doc.createElementNS(MIS_NS, "Target"); Element targetTypeElement = doc.createElementNS(MIS_NS, "Type"); targetTypeElement.appendChild(doc.createTextNode(targetType)); targetElement.appendChild(targetTypeElement); mirElement.appendChild(targetElement); //add AuthBlock element Element authBlockElement = doc.createElementNS(MIS_NS, "authBlock"); authBlockElement.appendChild(doc.createTextNode(new String(Base64.encodeBase64(authBlock)))); mirElement.appendChild(authBlockElement); // send soap request Element mandateIssueResponseElement = sendSOAPRequest(webServiceURL, mirElement); // check for error checkForError(mandateIssueResponseElement); // check for session id //String sessionId = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "/mis:MandateIssueResponse/mis:SessionID/text()", NS_NODE)).getNodeValue(); Node sessionIdNode = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:SessionID/text()", NS_NODE)); if (sessionIdNode == null) { throw new MISSimpleClientException("SessionId not found in response."); } String sessionId = sessionIdNode.getNodeValue(); Node guiRedirectURLNode = ((Node) XPathAPI.selectSingleNode(mandateIssueResponseElement, "//mis:MandateIssueResponse/mis:GuiRedirectURL/text()", NS_NODE)); if (guiRedirectURLNode == null) { throw new MISSimpleClientException("GuiRedirectURL not found in response."); } String guiRedirectURL = guiRedirectURLNode.getNodeValue(); // create return object MISSessionId msid = new MISSessionId(); msid.setSessiondId(sessionId); msid.setRedirectURL(guiRedirectURL); return msid; } catch (ParserConfigurationException e) { throw new MISSimpleClientException("service.06", e); } catch (DOMException e) { throw new MISSimpleClientException("service.06", e); } catch (TransformerException e) { throw new MISSimpleClientException("service.06", e); } }