List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, String attributeName, QName attributeValue) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttribute(attributeName); setQNameAttribute(element, attr, attributeValue, element); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setNamespaceDeclaration(Element element, String prefix, String namespaceUri) { Document doc = element.getOwnerDocument(); NamedNodeMap attributes = element.getAttributes(); Attr attr;//from w ww . j a v a 2 s . c om if (prefix == null || prefix.isEmpty()) { // default namespace attr = doc.createAttributeNS(W3C_XML_SCHEMA_XMLNS_URI, W3C_XML_SCHEMA_XMLNS_PREFIX); } else { attr = doc.createAttributeNS(W3C_XML_SCHEMA_XMLNS_URI, W3C_XML_SCHEMA_XMLNS_PREFIX + ":" + prefix); } checkValidXmlChars(namespaceUri); attr.setValue(namespaceUri); attributes.setNamedItem(attr); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix);/*from w w w. j a v a2 s . c o m*/ setQNameAttribute(element, attr, attributeValue, element); }
From source file:com.aipo.container.gadgets.render.AipoRenderingGadgetRewriter.java
@Override public void rewrite(Gadget gadget, MutableContent mutableContent) throws RewritingException { // Don't touch sanitized gadgets. if (gadget.sanitizeOutput()) { return;/*from ww w . j a va 2s .co m*/ } try { Document document = mutableContent.getDocument(); Element head = (Element) DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head"); // Insert new content before any of the existing children of the head // element Node firstHeadChild = head.getFirstChild(); Element contentLanguage = document.createElement("meta"); contentLanguage.setAttribute("http-equiv", "Content-Language"); contentLanguage.setAttribute("content", "ja"); head.insertBefore(contentLanguage, firstHeadChild); Element contentType = document.createElement("meta"); contentType.setAttribute("http-equiv", "Content-Type"); contentType.setAttribute("content", "text/html; charset=UTF-8"); head.insertBefore(contentType, firstHeadChild); Element contentStyleType = document.createElement("meta"); contentStyleType.setAttribute("http-equiv", "Content-Style-Type"); contentStyleType.setAttribute("content", "text/css"); head.insertBefore(contentStyleType, firstHeadChild); Element contentScriptType = document.createElement("meta"); contentScriptType.setAttribute("http-equiv", "Content-Script-Type"); contentScriptType.setAttribute("content", "text/javascript"); head.insertBefore(contentScriptType, firstHeadChild); // Only inject default styles if no doctype was specified. // if (document.getDoctype() == null) { boolean isAipoStyle = gadget.getAllFeatures().contains("aipostyle") && gadget.getSpec().getModulePrefs().getFeatures().keySet().contains("aipostyle"); Element defaultStyle = document.createElement("style"); defaultStyle.setAttribute("type", "text/css"); head.insertBefore(defaultStyle, firstHeadChild); defaultStyle.appendChild( defaultStyle.getOwnerDocument().createTextNode(isAipoStyle ? aipoStyleCss : DEFAULT_CSS)); // } injectBaseTag(gadget, head); injectGadgetBeacon(gadget, head, firstHeadChild); injectFeatureLibraries(gadget, head, firstHeadChild); // This can be one script block. Element mainScriptTag = document.createElement("script"); GadgetContext context = gadget.getContext(); MessageBundle bundle = messageBundleFactory.getBundle(gadget.getSpec(), context.getLocale(), context.getIgnoreCache(), context.getContainer()); injectMessageBundles(bundle, mainScriptTag); injectDefaultPrefs(gadget, mainScriptTag); injectPreloads(gadget, mainScriptTag); // We need to inject our script before any developer scripts. head.insertBefore(mainScriptTag, firstHeadChild); Element body = (Element) DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "body"); body.setAttribute("dir", bundle.getLanguageDirection()); injectOnLoadHandlers(body); mutableContent.documentChanged(); } catch (GadgetException e) { throw new RewritingException(e.getLocalizedMessage(), e, e.getHttpStatusCode()); } }
From source file:com.enonic.esl.xml.XMLTool.java
public static Element renameElement(Element elem, String newName) { Document doc = elem.getOwnerDocument(); // Create an element with the new name Element elem2 = doc.createElement(newName); // Copy the attributes to the new element NamedNodeMap attrs = elem.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr2 = (Attr) doc.importNode(attrs.item(i), true); elem2.getAttributes().setNamedItem(attr2); }// w w w. ja v a2 s. c o m // Move all the children while (elem.hasChildNodes()) { elem2.appendChild(elem.getFirstChild()); } // Replace the old node with the new node elem.getParentNode().replaceChild(elem2, elem); return elem2; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void createComment(Element element, String text) { if (text != null) { Comment commentNode = element.getOwnerDocument().createComment(replaceInvalidXmlChars(text)); element.appendChild(commentNode); }/* w w w. j av a 2 s .c o m*/ }
From source file:es.itecban.deployment.security.client.ws.LogonWS.java
/** * //from ww w . j a v a 2 s . com * @param username * @param password * @return the security token obtained by invoking ITECBAN's security * service or ANONYMOUSTOKEN if security is disabled */ public String logon(String username, String password) throws Exception { // Get the request element and document if (!isEnableSecurity()) return "ANONYMOUSTOKEN"; Element requestElement = this.getRequestElement(LogonWS.LOGON_PREFIX + ":" + LogonWS.LOGON_OPERATION); Document requestDoc = requestElement.getOwnerDocument(); // Add main element Node logon = addChildNode(requestElement, LogonWS.LOGON_PARAM); Node ptecnica = addChildNode((Element) logon, LogonWS.PARTE_TECNICA); Node dtecnicos = addChildNode((Element) ptecnica, LogonWS.DATOS_TECNICOS); addTextNode((Element) dtecnicos, LogonWS.COD_SERVICIO, LogonWS.COD_SERVICIO_VALUE); addTextNode((Element) dtecnicos, LogonWS.COD_APP_CANAL, LogonWS.COD_APP_CANAL_VALUE); addTextNode((Element) dtecnicos, LogonWS.CANAL_DIST, LogonWS.CANAL_DIST_VALUE); addTextNode((Element) dtecnicos, LogonWS.VER_SERV, LogonWS.VER_SERV_VALUE); // FIXME Change these values for real ones obtained using "capa tecnica" // classes addTextNode((Element) dtecnicos, LogonWS.ID_MENSAJE, LogonWS.ID_MENSAJE_VALUE); addTextNode((Element) dtecnicos, LogonWS.MOMENTO_EJEC, LogonWS.MOMENTO_EJEC_VALUE); Node pespecifica = addChildNode((Element) logon, LogonWS.PARTE_ESPECIFICA); addTextNode((Element) pespecifica, LogonWS.ID_ORIGIN, LogonWS.ID_ORIGIN_VALUE); addTextNode((Element) pespecifica, LogonWS.PASSWORD, password); addTextNode((Element) pespecifica, LogonWS.USERNAME, username); Source requestSource = new DOMSource(requestDoc); // printMessage(requestSource); Document responseDoc = this.getResponseDocument(requestSource); // Get the operation result (security token) and return it NodeList token = responseDoc.getElementsByTagName(LogonWS.TOKEN); if (token == null) throw new Exception("Logon reject for user:" + username); return token.item(0).getTextContent(); }
From source file:org.coronastreet.gpxconverter.Converter.java
private void dumpNode(Element e) { Document document = e.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); String str = serializer.writeToString(e); log("XML::: " + str); }
From source file:be.agiv.security.handler.WSSecurityHandler.java
private void addToken(SOAPMessageContext context, Element securityElement) { if (null != this.token) { LOG.debug("adding WS-Security token"); securityElement.appendChild(securityElement.getOwnerDocument().importNode(this.token, true)); }/*from ww w . j a va2 s . c om*/ }
From source file:at.gv.egovernment.moa.id.auth.validator.parep.client.szrgw.SZRGWClient.java
/** * Creates a mandate./* w w w .j av a 2 s . co m*/ * * @param reqElem the request. * @return a SZR-gateway response containing the result * @throws SZRGWException when an error occurs creating the mandate. */ public CreateMandateResponse createMandateResponse(Element reqElem) throws SZRGWClientException { //Logger.info("Connecting to SZR-gateway."); try { if (address == null) { throw new NullPointerException("Address (SZR-gateway ServiceURL) must not be null."); } HttpClient client = HttpClientWithProxySupport.getHttpClient(); PostMethod method = new PostMethod(address); method.setRequestHeader("SOAPAction", ""); // ssl settings if (sSLSocketFactory != null) { SZRGWSecureSocketFactory fac = new SZRGWSecureSocketFactory(sSLSocketFactory); Protocol.registerProtocol("https", new Protocol("https", fac, 443)); } // create soap body Element soapBody = getSOAPBody(); Document doc = soapBody.getOwnerDocument(); soapBody.appendChild(doc.importNode(reqElem, true)); Element requestElement = soapBody.getOwnerDocument().getDocumentElement(); //ParepUtils.saveElementToFile(requestElement, new File("c:/temp/szrRequest.xml")); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ParepUtils.serializeElementAsDocument(requestElement, bos); method.setRequestBody(new ByteArrayInputStream(bos.toByteArray())); client.executeMethod(method); CreateMandateResponse response = new CreateMandateResponse(); bos = new ByteArrayOutputStream(); doc = ParepUtils.readDocFromIs(method.getResponseBodyAsStream()); //ParepUtils.saveElementToFile(doc.getDocumentElement(), new File("c:/temp/szrResponse.xml")); response.parse(doc.getDocumentElement()); return response; } catch (Exception e) { //e.printStackTrace(); throw new SZRGWClientException(e); } }