List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:fr.inria.atlanmod.collaboro.ui.views.NotationView.java
/** * Creates a splash image with the message "No item selected" * /* ww w . j a va 2s .co m*/ * @return */ protected SVGDocument createTestImage() { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.setAttributeNS(null, "width", "500px"); root.setAttributeNS(null, "height", "500px"); Element text = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "text"); text.setAttributeNS(null, "x", "10"); text.setAttributeNS(null, "y", "20"); text.setAttributeNS(null, "font-size", DEFAULT_FONT_SIZE); text.setAttributeNS(null, "font-family", DEFAULT_FONT_FAMILY); text.setAttributeNS(null, "font-weight", "bold"); text.setAttributeNS(null, "fill", "red"); text.setAttributeNS(null, "stroke", "none"); text.setTextContent("No item selected"); root.appendChild(text); return doc; }
From source file:fr.inria.atlanmod.collaboro.ui.views.NotationView.java
/** * Creates a splash image with the message "No syntax defined" * // ww w .j a v a2 s .co m * @return */ protected SVGDocument createNoSyntaxImage() { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.setAttributeNS(null, "width", "500px"); root.setAttributeNS(null, "height", "500px"); Element text = doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "text"); text.setAttributeNS(null, "x", "10"); text.setAttributeNS(null, "y", "20"); text.setAttributeNS(null, "font-size", DEFAULT_FONT_SIZE); text.setAttributeNS(null, "font-family", DEFAULT_FONT_FAMILY); text.setAttributeNS(null, "font-weight", "bold"); text.setAttributeNS(null, "fill", "red"); text.setAttributeNS(null, "stroke", "none"); text.setTextContent("No syntax defined"); root.appendChild(text); return doc; }
From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java
public Element toElement(String elementNamespace, String localElementName, Document document) { Element element = document.createElementNS(elementNamespace, localElementName); if (!StringUtils.isBlank(elementNamespace)) { String prefix = GlobalDynamicNamespacePrefixMapper.getPreferredPrefix(elementNamespace); if (!StringUtils.isBlank(prefix)) { try { element.setPrefix(prefix); } catch (DOMException e) { throw new SystemException("Error setting XML prefix '" + prefix + "' to element {" + elementNamespace + "}" + localElementName + ": " + e.getMessage(), e); }//from w w w . j a va 2 s. c o m } } element.setTextContent(getXPathWithDeclarations()); Map<String, String> namespaceMap = getNamespaceMap(); if (namespaceMap != null) { for (Entry<String, String> entry : namespaceMap.entrySet()) { DOMUtil.setNamespaceDeclaration(element, entry.getKey(), entry.getValue()); } } return element; }
From source file:org.gvnix.web.exception.handler.roo.addon.addon.WebExceptionHandlerOperationsImpl.java
/** * Update the webmvc-config.xml with the new Exception. * /*from ww w . j a v a 2 s .co m*/ * @param exceptionName Exception Name to Handle. * @return {@link String} The exceptionViewName to create the .jspx view. */ protected String updateWebMvcConfig(String exceptionName) { String webXmlPath = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), WEB_MVC_CONFIG); Validate.isTrue(fileManager.exists(webXmlPath), WEB_MVC_CONFIG_NOT_FOUND); MutableFile webXmlMutableFile = null; Document webXml; try { webXmlMutableFile = fileManager.updateFile(webXmlPath); webXml = XmlUtils.getDocumentBuilder().parse(webXmlMutableFile.getInputStream()); } catch (Exception e) { throw new IllegalStateException(e); } Element root = webXml.getDocumentElement(); Element simpleMappingException = XmlUtils .findFirstElement(RESOLVER_BEAN_MESSAGE + "/property[@name='exceptionMappings']/props", root); Element exceptionResolver = XmlUtils.findFirstElement(RESOLVER_BEAN_MESSAGE + "/property[@name='exceptionMappings']/props/prop[@key='" + exceptionName + "']", root); boolean updateMappings = false; boolean updateController = false; // View name for this Exception. String exceptionViewName; if (exceptionResolver != null) { exceptionViewName = exceptionResolver.getTextContent(); } else { updateMappings = true; exceptionViewName = getExceptionViewName(exceptionName); } Element newExceptionMapping; // Exception Mapping newExceptionMapping = webXml.createElement("prop"); newExceptionMapping.setAttribute("key", exceptionName); Validate.isTrue(exceptionViewName != null, "Can't create the view for the:\t" + exceptionName + " Exception."); newExceptionMapping.setTextContent(exceptionViewName); if (updateMappings) { simpleMappingException.appendChild(newExceptionMapping); } // Exception Controller Element newExceptionView = XmlUtils .findFirstElement("/beans/view-controller[@path='/" + exceptionViewName + "']", root); if (newExceptionView == null) { updateController = true; } newExceptionView = webXml.createElementNS("http://www.springframework.org/schema/mvc", "view-controller"); newExceptionView.setPrefix("mvc"); newExceptionView.setAttribute("path", "/" + exceptionViewName); if (updateController) { root.appendChild(newExceptionView); } if (updateMappings || updateController) { XmlUtils.writeXml(webXmlMutableFile.getOutputStream(), webXml); } return exceptionViewName; }
From source file:com.hin.hl7messaging.InvoiceSvgService.java
public Element createEndComponent(Document document, Element subG, String x, String y, String cost, String exchangeRate, String currencyCode, String discount, String interest) { int respY = Integer.parseInt(y); int respX = Integer.parseInt(x); Element path = document.createElement("path"); path.setAttribute("id", "horizontalLine"); String dString = "m " + x + "," + y + " " + 1150 + ",0"; path.setAttribute("d", dString); path.setAttribute("style", "fill:none;stroke:#0c0c0c;stroke-width:2.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); Element path1 = document.createElement("path"); path1.setAttribute("id", "horizontalLine"); String d2String = "m " + (respX + 800) + "," + (respY + 100) + " " + 350 + ",0"; path1.setAttribute("d", d2String); path1.setAttribute("style", "fill:none;stroke:#0c0c0c;stroke-width:2.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); if (!discount.isEmpty() && Float.parseFloat(discount) > 0) { Element discountText = document.createElement("text"); discountText.setAttribute("x", "223.8"); discountText.setAttribute("y", "781.76"); discountText.setAttribute("id", "legendTitle"); Element tspan = document.createElement("tspan"); tspan.setAttribute("id", "optimumTitle"); tspan.setAttribute("x", "820"); tspan.setAttribute("y", String.valueOf(respY + 60)); tspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold"); tspan.setTextContent("Discount"); discountText.appendChild(tspan); subG.appendChild(discountText);/* w w w.j a v a 2 s . com*/ Element discountTotalText = document.createElement("text"); discountTotalText.setAttribute("x", "223.8"); discountTotalText.setAttribute("y", "781.76"); discountTotalText.setAttribute("id", "legendTitle"); Element totalTspan = document.createElement("tspan"); totalTspan.setAttribute("id", "optimumTitle"); totalTspan.setAttribute("x", "1150"); totalTspan.setAttribute("y", String.valueOf(respY + 60)); totalTspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light"); totalTspan.setTextContent(discount); discountTotalText.appendChild(totalTspan); subG.appendChild(discountTotalText); respY += 100; Element discountPath = document.createElement("path"); discountPath.setAttribute("id", "horizontalLine"); String discount2String = "m " + (respX + 800) + "," + (respY + 100) + " " + 350 + ",0"; discountPath.setAttribute("d", discount2String); discountPath.setAttribute("style", "fill:none;stroke:#0c0c0c;stroke-width:2.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); x = String.valueOf(1250); String dString1 = "M " + x + "," + y + " " + x + "," + (respY + 100) + ""; Element discountVerticalPath = document.createElement("path"); discountVerticalPath.setAttribute("id", "verticalLine"); discountVerticalPath.setAttribute("d", dString1); discountVerticalPath.setAttribute("style", "#fill:none;stroke:#0c0c0c;stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); subG.appendChild(discountVerticalPath); //verticalDividerElement x = String.valueOf(900); String dString2 = "M " + x + "," + y + " " + x + "," + (respY + 100) + ""; Element discountVerticalPath2 = document.createElement("path"); discountVerticalPath2.setAttribute("id", "verticalLine"); discountVerticalPath2.setAttribute("d", dString2); discountVerticalPath2.setAttribute("style", "#fill:none;stroke:#0c0c0c;stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); subG.appendChild(discountVerticalPath2); subG.appendChild(discountPath); } if (!interest.isEmpty() && Float.parseFloat(interest) > 0) { Element interestText = document.createElement("text"); interestText.setAttribute("x", "223.8"); interestText.setAttribute("y", "781.76"); interestText.setAttribute("id", "legendTitle"); Element tspan = document.createElement("tspan"); tspan.setAttribute("id", "optimumTitle"); tspan.setAttribute("x", "820"); tspan.setAttribute("y", String.valueOf(respY + 60)); tspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold"); tspan.setTextContent("Interest"); interestText.appendChild(tspan); subG.appendChild(interestText); Element interestTotalText = document.createElement("text"); interestTotalText.setAttribute("x", "223.8"); interestTotalText.setAttribute("y", "781.76"); interestTotalText.setAttribute("id", "legendTitle"); Element totalTspan = document.createElement("tspan"); totalTspan.setAttribute("id", "optimumTitle"); totalTspan.setAttribute("x", "1150"); totalTspan.setAttribute("y", String.valueOf(respY + 60)); totalTspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light"); totalTspan.setTextContent(interest); interestTotalText.appendChild(totalTspan); subG.appendChild(interestTotalText); respY += 100; Element interestPath = document.createElement("path"); interestPath.setAttribute("id", "horizontalLine"); String interest2String = "m " + (respX + 800) + "," + (respY + 100) + " " + 350 + ",0"; interestPath.setAttribute("d", interest2String); interestPath.setAttribute("style", "fill:none;stroke:#0c0c0c;stroke-width:2.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); x = String.valueOf(1250); String dString1 = "M " + x + "," + y + " " + x + "," + (respY + 100) + ""; Element interestVerticalPath = document.createElement("path"); interestVerticalPath.setAttribute("id", "verticalLine"); interestVerticalPath.setAttribute("d", dString1); interestVerticalPath.setAttribute("style", "#fill:none;stroke:#0c0c0c;stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); subG.appendChild(interestVerticalPath); //verticalDividerElement x = String.valueOf(900); String dString2 = "M " + x + "," + y + " " + x + "," + (respY + 100) + ""; Element interestVerticalPath2 = document.createElement("path"); interestVerticalPath2.setAttribute("id", "verticalLine"); interestVerticalPath2.setAttribute("d", dString2); interestVerticalPath2.setAttribute("style", "#fill:none;stroke:#0c0c0c;stroke-width:1.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none"); subG.appendChild(interestVerticalPath2); subG.appendChild(interestPath); } Element text = document.createElement("text"); text.setAttribute("x", "223.8"); text.setAttribute("y", "781.76"); text.setAttribute("id", "legendTitle"); Element tspan = document.createElement("tspan"); tspan.setAttribute("id", "optimumTitle"); tspan.setAttribute("x", "850"); tspan.setAttribute("y", String.valueOf(respY + 60)); tspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold"); tspan.setTextContent("Total"); text.appendChild(tspan); subG.appendChild(text); Element totalText = document.createElement("text"); totalText.setAttribute("x", "223.8"); totalText.setAttribute("y", "781.76"); totalText.setAttribute("id", "legendTitle"); Element totalTspan = document.createElement("tspan"); totalTspan.setAttribute("id", "optimumTitle"); totalTspan.setAttribute("x", "1150"); totalTspan.setAttribute("y", String.valueOf(respY + 60)); totalTspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light"); totalTspan.setTextContent(cost); totalText.appendChild(totalTspan); subG.appendChild(totalText); Element convertedText = document.createElement("text"); convertedText.setAttribute("x", "223.8"); convertedText.setAttribute("y", "781.76"); convertedText.setAttribute("id", "legendTitle"); Element convertedTspan = document.createElement("tspan"); convertedTspan.setAttribute("id", "optimumTitle"); convertedTspan.setAttribute("x", "1107"); convertedTspan.setAttribute("y", String.valueOf(respY + 80)); convertedTspan.setAttribute("style", "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light"); convertedTspan.setTextContent("(" + String.valueOf(Float.parseFloat(exchangeRate) * Float.parseFloat(cost)) + " " + currencyCode + ")"); convertedText.appendChild(convertedTspan); subG.appendChild(convertedText); subG.appendChild(path); subG.appendChild(path1); return subG; }
From source file:org.gvnix.addon.datatables.addon.DatatablesOperationsImpl.java
/** * Insert a new element of type {@code nodeName} into {@code parent} with * definition declared in {@code subElementsAndValue}. * {@code subElementsAndValue} is composed in pairs of <i>nodeName</i> and * <i>textValue</i>./*from w w w. j av a 2 s.c om*/ * * @param doc * @param parent * @param nodeName * @param subElementsAndValue */ private void insertXmlElement(Document doc, Element parent, String nodeName, String... subElementsAndValue) { Validate.isTrue(subElementsAndValue.length % 2 == 0, "subElementsAndValue must be even"); Element newElement = doc.createElement(nodeName); Element subElement; for (int i = 0; i < subElementsAndValue.length - 1; i = i + 2) { subElement = doc.createElement(subElementsAndValue[i]); subElement.setTextContent(subElementsAndValue[i + 1]); newElement.appendChild(subElement); } // insert element as last element of the node type Node inserPosition = null; // Locate last node of this type List<Element> elements = XmlUtils.findElements(nodeName, parent); if (!elements.isEmpty()) { inserPosition = elements.get(elements.size() - 1).getNextSibling(); } // Add node if (inserPosition == null) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, inserPosition); } }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.XmlDynamicConfiguration.java
/** * Update the root element property values with dynamic properties. * //from w w w . ja v a2s . c o m * @param root Parent element * @param dynProps Dynamic property list */ protected void setProperties(Element root, DynPropertyList dynProps) { // Iterate all dynamic properties to update for (DynProperty dynProp : dynProps) { // Remove possible namespaces String xpath = removeNamespaces(dynProp.getKey()); // If attr prefix present, there is an attribute else an element int index; if ((index = xpath.indexOf(XPATH_ARRAY_PREFIX + XPATH_ATTRIBUTE_PREFIX)) != -1) { // Set the new attribute value through container element Element elem = XmlUtils.findFirstElement(xpath.substring(0, index), root); if (elem == null) { logger.log(Level.WARNING, "Element " + xpath + " to set attribute value not exists on file"); } else { String name = xpath.substring(index + 2, xpath.length() - 1); Attr attr = elem.getAttributeNode(name); if (attr == null) { logger.log(Level.WARNING, "Element attribute " + xpath + " to set value not exists on file"); } else { attr.setValue(dynProp.getValue()); } } } else { // Set the new element content Element elem = XmlUtils.findFirstElement(xpath, root); if (elem == null) { logger.log(Level.WARNING, "Element " + xpath + " to set text content not exists on file"); } else { elem.setTextContent(dynProp.getValue()); } } } }
From source file:ch.zhaw.ficore.p2abc.services.verification.VerificationService.java
private static Element createW3DomElement(final String elementName, final String value) { Element element; try {//from w w w. j a v a 2 s .co m element = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() .createElement(elementName); } catch (DOMException e) { throw new IllegalStateException("This should always work!", e); } catch (ParserConfigurationException e) { throw new IllegalStateException("This should always work!", e); } element.setTextContent(value); return element; }
From source file:serverTools.java
public String createServerConfig(String node, String jsonString) { String result = node + "::"; try {//ww w .ja va2s.c o m String ret; JSONObject jo = new JSONObject(jsonString); UUID uid = UUID.randomUUID(); String varName = node; String varIP = jo.get("ip").toString(); String varHyp = jo.get("hypervisor").toString(); String varVmconfigs = jo.get("vmconfigs").toString(); String varTransport = jo.get("transport").toString(); String varDesc = jo.get("description").toString(); // make sure that remote directory exist // Get the JSONArray value associated with the Result key JSONArray storageArray = jo.getJSONArray("storages"); String configDir = this.makeRelativeDirs("/" + varName + "/config"); this.makeRelativeDirs("/" + varName + "/screenshots"); this.makeRelativeDirs("/" + varName + "/vm/configs"); // Cration d'un nouveau DOM DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance(); DocumentBuilder constructeur = fabrique.newDocumentBuilder(); Document document = constructeur.newDocument(); // Proprits du DOM document.setXmlStandalone(true); // Cration de l'arborescence du DOM Element server = document.createElement("server"); document.appendChild(server); //racine.appendChild(document.createComment("Commentaire sous la racine")); Element name = document.createElement("name"); server.appendChild(name); name.setTextContent(varName); Element ip = document.createElement("ip"); server.appendChild(ip); ip.setTextContent(varIP); Element hypervisor = document.createElement("hypervisor"); server.appendChild(hypervisor); hypervisor.setTextContent(varHyp); Element transport = document.createElement("transport"); server.appendChild(transport); transport.setTextContent(varTransport); Element descEl = document.createElement("description"); server.appendChild(descEl); descEl.setTextContent(varDesc); Element vmconfigs = document.createElement("vmconfigs"); server.appendChild(vmconfigs); vmconfigs.setTextContent(varVmconfigs); JSONObject coordinatesObj = jo.getJSONObject("coordinates"); Element coordinatesEl = document.createElement("coordinates"); server.appendChild(coordinatesEl); coordinatesEl.setAttribute("building", coordinatesObj.get("building").toString()); coordinatesEl.setAttribute("street", coordinatesObj.get("street").toString()); coordinatesEl.setAttribute("city", coordinatesObj.get("city").toString()); coordinatesEl.setAttribute("latitude", coordinatesObj.get("latitude").toString()); coordinatesEl.setAttribute("longitude", coordinatesObj.get("longitude").toString()); //<storages> Element storages = document.createElement("storages"); server.appendChild(storages); int resultCount = storageArray.length(); for (int i = 0; i < resultCount; i++) { Element repository = document.createElement("repository"); storages.appendChild(repository); Element path = document.createElement("target"); repository.appendChild(path); JSONObject newStorage = storageArray.getJSONObject(i); String storageName = newStorage.get("name").toString(); String storagePath = newStorage.get("target").toString(); storageName = storageName.replaceAll(" ", "_"); storagePath = storagePath.replaceAll(" ", "_"); repository.setAttribute("type", newStorage.get("type").toString()); repository.setAttribute("name", storageName); path.setTextContent(storagePath); Element source = document.createElement("source"); repository.appendChild(source); String storageSource = newStorage.get("source").toString(); source.setTextContent(storageSource); String localStorageDir = this.makeRelativeDirs("/" + varName + "/vm/storages/" + storageName); if (localStorageDir == "Error") { return result + "Error: cannot create " + varName + "/vm/storages/" + storageName; } } //</storages> // Get network information (look for bridges) Element networks = document.createElement("networks"); server.appendChild(networks); JSONObject joAction = new JSONObject(); joAction.put("name", "add"); joAction.put("driver", varHyp); joAction.put("transport", varTransport); joAction.put("description", varDesc); ArrayList<String> optList = new ArrayList<String>(); optList.add("ip=" + varIP); String varPasswd = ""; varPasswd = jo.opt("password").toString(); if (varPasswd.length() > 0) { optList.add("exchange_keys=" + varPasswd); } joAction.put("options", optList); String msg = callOvnmanager(node, joAction.toString()); JSONObject joMsg = new JSONObject(msg); JSONObject joActionRes = joMsg.getJSONObject("action"); result += joActionRes.get("result").toString(); //write the content into xml file String pathToXml = configDir + "/" + varName + ".xml"; File xmlOutput = new File(pathToXml); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource source = new DOMSource(document); StreamResult streamRes = new StreamResult(xmlOutput); transformer.transform(source, streamRes); } catch (Exception e) { log(ERROR, "create xml file has failed", e); return result + "Error: " + e.toString(); } //ret = "done"; return result; }
From source file:org.keycloak.testsuite.adapter.servlet.AbstractSAMLServletsAdapterTest.java
@Test //KEYCLOAK-4020//from w w w. jav a 2 s . c o m public void testBooleanAttribute() throws Exception { AuthnRequestType req = SamlClient.createLoginRequestDocument("http://localhost:8081/employee2/", getAppServerSamlEndpoint(employee2ServletPage).toString(), getAuthServerSamlEndpoint(SAMLSERVLETDEMO)); Document doc = SAML2Request.convert(req); SAMLDocumentHolder res = login(bburkeUser, getAuthServerSamlEndpoint(SAMLSERVLETDEMO), doc, null, SamlClient.Binding.POST, SamlClient.Binding.POST); Document responseDoc = res.getSamlDocument(); Element attribute = responseDoc.createElement("saml:Attribute"); attribute.setAttribute("Name", "boolean-attribute"); attribute.setAttribute("NameFormat", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"); Element attributeValue = responseDoc.createElement("saml:AttributeValue"); attributeValue.setAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema"); attributeValue.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); attributeValue.setAttribute("xsi:type", "xs:boolean"); attributeValue.setTextContent("true"); attribute.appendChild(attributeValue); IOUtil.appendChildInDocument(responseDoc, "samlp:Response/saml:Assertion/saml:AttributeStatement", attribute); CloseableHttpResponse response = null; try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpClientContext context = HttpClientContext.create(); HttpUriRequest post = SamlClient.Binding.POST .createSamlUnsignedResponse(getAppServerSamlEndpoint(employee2ServletPage), null, responseDoc); response = client.execute(post, context); assertThat(response, statusCodeIsHC(Response.Status.FOUND)); response.close(); HttpGet get = new HttpGet(employee2ServletPage.toString() + "/getAttributes"); response = client.execute(get); assertThat(response, statusCodeIsHC(Response.Status.OK)); assertThat(response, bodyHC(containsString("boolean-attribute: true"))); } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (response != null) { EntityUtils.consumeQuietly(response.getEntity()); try { response.close(); } catch (IOException ex) { } } } }