public void testWrite() throws Exception { Car car = new Car(); car.numberOfDoors = 2; car.milesPerGallon = 30; car.model = "Grand Am"; car.manufacturer = "Pontiac"; car.topSpeed = 220; Document carDocument = marshaller.objectToXML(car); Element root = (Element) carDocument.getElementsByTagNameNS("mynamespaceuri", "vehicle").item(0); Attr elem = root.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); String carType = elem.getNodeValue(); assertTrue( "The type field was written incorrectly for the subclass", carType.equals("prefix:car-type")); Vehicle vehicle = new Vehicle(); vehicle.model = "Blah Blah"; vehicle.manufacturer = "Some Place"; vehicle.topSpeed = 10000; Document vehicleDocument = marshaller.objectToXML(vehicle); root = (Element) vehicleDocument.getElementsByTagNameNS("mynamespaceuri", "vehicle").item(0); elem = root.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); String vehicleType = elem.getNodeValue(); assertTrue( "The type field was written incorrectly for the superclass", vehicleType.equals("prefix:vehicle-type")); }
public void testSetNamedItemNS3() throws Throwable { Document doc; Document docAlt; NamedNodeMap attributes; NamedNodeMap attributesAlt; NodeList elementList; NodeList elementListAlt; Element element; Element elementAlt; Attr attr; String nullNS = null; doc = (Document) load("staffNS", builder); elementList = doc.getElementsByTagNameNS("*", "address"); element = (Element) elementList.item(1); attributes = element.getAttributes(); docAlt = (Document) load("staffNS", builder); elementListAlt = docAlt.getElementsByTagNameNS("*", "address"); elementAlt = (Element) elementListAlt.item(1); attributesAlt = elementAlt.getAttributes(); attr = (Attr) attributesAlt.getNamedItemNS(nullNS, "street"); attributesAlt.removeNamedItemNS(nullNS, "street"); { boolean success = false; try { attributes.setNamedItemNS(attr); } catch (DOMException ex) { success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); } assertTrue("throw_WRONG_DOCUMENT_ERR", success); } }
public void testPropertyIsNotEqualToEncode() throws Exception { PropertyIsNotEqualTo equalTo = FilterMockData.propertyIsNotEqualTo(); Document dom = encode(equalTo, OGC.PropertyIsNotEqualTo); assertEquals( 1, dom.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart()).getLength()); assertEquals( 1, dom.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart()).getLength()); }
public boolean hasValidityIntervalIndication(ConversationID id) { Document document = getSAMLDocument(id); if (null == document) { return false; } NodeList saml1AssertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion"); if (0 != saml1AssertionNodeList.getLength()) { Element assertionElement = (Element) saml1AssertionNodeList.item(0); NodeList conditionsNodeList = assertionElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:1.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } NodeList saml2AssertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion"); if (0 != saml2AssertionNodeList.getLength()) { Element assertionElement = (Element) saml2AssertionNodeList.item(0); NodeList conditionsNodeList = assertionElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } NodeList saml2AuthnRequestNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest"); if (0 != saml2AuthnRequestNodeList.getLength()) { Element authnRequestElement = (Element) saml2AuthnRequestNodeList.item(0); NodeList conditionsNodeList = authnRequestElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } return false; }
/** * Get an element from the document given its {@link QName} * * <p>First an attempt to get the element based on its namespace is made, failing which an element * with the localpart ignoring any namespace is returned. * * @param doc * @param elementQName * @return */ public static Element getElement(Document doc, QName elementQName) { NodeList nl = doc.getElementsByTagNameNS(elementQName.getNamespaceURI(), elementQName.getLocalPart()); if (nl.getLength() == 0) { nl = doc.getElementsByTagNameNS("*", elementQName.getLocalPart()); if (nl.getLength() == 0) nl = doc.getElementsByTagName(elementQName.getPrefix() + ":" + elementQName.getLocalPart()); if (nl.getLength() == 0) return null; } return (Element) nl.item(0); }
@Test public void adRoundtrip() throws JAXBException, InvalidModelException, IOException, XMLStreamException, MissingRspecElementException, DeprecatedRspecVersionException, InvalidRspecValueException { final String filename = "/geni/ciscogeni/cisco-10vm-1lan.rspec"; final String inputRspec = AbstractConverter.toString(filename); // System.out.println("Converting this input from '" + filename + "':"); // System.out.println("==============================="); // System.out.println(inputRspec); // System.out.println("==============================="); final String outputRspec = RSpecValidation.completeRoundtrip(inputRspec); // PrintWriter outFile = new PrintWriter("filename.txt"); // outFile.println(outputRspec); // outFile.close(); // System.out.println("Generated this rspec:"); // System.out.println("==============================="); // System.out.println(outputRspec); // System.out.println("==============================="); Assert.assertTrue("type", outputRspec.contains("type=\"request\"")); System.out.println("==============================="); System.out.println("Diffs:"); int[] diffsNodes = RSpecValidation.getDiffsNodes(inputRspec); Document xmlDoc = RSpecValidation.loadXMLFromString(outputRspec); // check that output has one rspec element NodeList rspec = xmlDoc.getElementsByTagNameNS("http://www.geni.net/resources/rspec/3", "rspec"); Assert.assertTrue(rspec.getLength() == 1); NodeList nodes = xmlDoc.getElementsByTagNameNS("http://www.geni.net/resources/rspec/3", "node"); Assert.assertTrue(nodes.getLength() == 10); NodeList links = xmlDoc.getElementsByTagNameNS("http://www.geni.net/resources/rspec/3", "link"); Assert.assertTrue(links.getLength() == 1); String linkClientId = links.item(0).getAttributes().getNamedItem("client_id").getNodeValue(); Assert.assertTrue(linkClientId.equals("Lan")); // TODO: Currently returns a high number of errors, although translation // appears to be correct. // Assert.assertTrue("No differences between input and output files", // diffsNodes[0] == 0); }
// TODO : stitch extension @Test public void requestRoundtrip() throws JAXBException, InvalidModelException, IOException, XMLStreamException, MissingRspecElementException, DeprecatedRspecVersionException, InvalidRspecValueException { final String filename = "/geni/request/request_ion.xml"; final String inputRspec = AbstractConverter.toString(filename); // System.out.println("Converting this input from '" + filename + "':"); // System.out.println("==============================="); // System.out.println(inputRspec); // System.out.println("==============================="); final String outputRspec = RSpecValidation.completeRoundtrip(inputRspec); // System.out.println("Generated this rspec:"); // System.out.println("==============================="); // System.out.println(outputRspec); // System.out.println("==============================="); // System.out.println("Get number of diffs and nodes:"); // System.out.println("==============================="); // int[] diffsNodes = RSpecValidation.getDiffsNodes(inputRspec); Assert.assertTrue("type", outputRspec.contains("type=\"request\"")); Assert.assertTrue("client id", outputRspec.contains("client_id=\"pg1\"")); Document xmlDoc = RSpecValidation.loadXMLFromString(outputRspec); // check that output has one rspec element NodeList rspec = xmlDoc.getElementsByTagNameNS("http://www.geni.net/resources/rspec/3", "rspec"); Assert.assertTrue(rspec.getLength() == 1); NodeList nodes = xmlDoc.getElementsByTagNameNS("http://www.geni.net/resources/rspec/3", "node"); Assert.assertTrue(nodes.getLength() == 2); NodeList stitching = xmlDoc.getElementsByTagNameNS( "http://www.geni.net/resources/rspec/ext/stitch/2/", "stitching"); Assert.assertTrue(stitching.getLength() == 1); String sliverName = stitching.item(0).getAttributes().getNamedItem("lastUpdateTime").getNodeValue(); Assert.assertTrue(sliverName.equals("20120815:09:30:00")); // TODO: This test does not consistently return 0, only sometimes. Need // to debug. // Assert.assertTrue("No differences between input and output files", // diffsNodes[0] == 0); }
public void testEncode() throws Exception { Geometry geometry = GML3MockData.multiGeometry(); GML3EncodingUtils.setID(geometry, "geometry"); Document dom = encode(geometry, GML.MultiGeometry); // print(dom); assertEquals("geometry", getID(dom.getDocumentElement())); assertEquals(3, dom.getElementsByTagNameNS(GML.NAMESPACE, "geometryMember").getLength()); // geometry.1 is not encoded on the gml:Point because user data is already being used for // srsDimension and srsName; not going to support the use of these inside a multigeometry // and combined with gml:id assertEquals( "geometry.2", getID(dom.getElementsByTagNameNS(GML.NAMESPACE, "LineString").item(0))); assertEquals("geometry.3", getID(dom.getElementsByTagNameNS(GML.NAMESPACE, "Polygon").item(0))); }
/** * Add Token to a specific jaxb object. * * @param string the serialized JaxbObject * @param token the token * @return * @throws SoapFault */ public static final String getToken(final Document doc) throws SoapFault { NodeList nodes = doc.getElementsByTagNameNS("http://ist_phosphorus.eu/nsp/webservice/reservation", "Token"); if (nodes == null || nodes.getLength() == 0) { nodes = doc.getElementsByTagNameNS( "http://ist_phosphorus.eu/nsp/webservice/reservation", "Token"); } if (nodes != null && nodes.getLength() > 0) { String tokenRet = nodes.item(0).getTextContent(); return tokenRet; } return null; }
public static List getFontFaces(Document doc, BridgeContext ctx) { // check fontFamilyMap to see if we have already created an // FontFamily that matches Map fontFamilyMap = ctx.getFontFamilyMap(); List ret = (List) fontFamilyMap.get(doc); if (ret != null) return ret; ret = new LinkedList(); NodeList fontFaceElements = doc.getElementsByTagNameNS(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG); SVGFontFaceElementBridge fontFaceBridge; fontFaceBridge = (SVGFontFaceElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG); for (int i = 0; i < fontFaceElements.getLength(); i++) { Element fontFaceElement = (Element) fontFaceElements.item(i); ret.add(fontFaceBridge.createFontFace(ctx, fontFaceElement)); } CSSEngine engine = ((SVGOMDocument) doc).getCSSEngine(); List sms = engine.getFontFaces(); Iterator iter = sms.iterator(); while (iter.hasNext()) { FontFaceRule ffr = (FontFaceRule) iter.next(); ret.add(CSSFontFace.createCSSFontFace(engine, ffr)); } return ret; }
public static void main(String args[]) throws Exception { if (args.length < 2) { usage(); System.exit(1); } // load the encrypted file into a Document Document document = loadEncryptedFile(args[0]); // get the encrypted data element String namespaceURI = EncryptionConstants.EncryptionSpecNS; String localName = EncryptionConstants._TAG_ENCRYPTEDDATA; Element encryptedDataElement = (Element) document.getElementsByTagNameNS(namespaceURI, localName).item(0); // Load the key encryption key. Key keyEncryptKey = loadKeyEncryptionKey(); // initialize cipher XMLCipher xmlCipher = XMLCipher.getInstance(); xmlCipher.init(XMLCipher.DECRYPT_MODE, null); xmlCipher.setKEK(keyEncryptKey); // do the actual decryption xmlCipher.doFinal(document, encryptedDataElement); // write the results to a file writeDecryptedDocToFile(document, args[1]); // wyciagnij z xml binarny plik saveBinaryFromXmlToFile(args[1]); }
public void testSetNamedItemNS8() throws Throwable { Document doc; NamedNodeMap attributes; NodeList elementList; Element element; Attr attr; doc = (Document) load("staffNS", builder); elementList = doc.getElementsByTagNameNS("*", "address"); element = (Element) elementList.item(0); attributes = element.getAttributes(); attr = (Attr) attributes.getNamedItemNS("http://www.usa.com", "domestic"); element = (Element) elementList.item(1); attributes = element.getAttributes(); { boolean success = false; try { attributes.setNamedItemNS(attr); } catch (DOMException ex) { success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR); } assertTrue("namednodemapsetnameditemns08", success); } }
/** Test the generateSaxFragment method. */ public void testGenerateSaxFragment() throws Exception { List beans = new ArrayList(2); beans.add(new TestBean("1", "One")); beans.add(new TestBean("2", "Two")); Map flowContextObject = new HashMap(); flowContextObject.put("beans", beans); Request request = new MockRequest(); Map objectModel = new HashMap(); FlowHelper.setContextObject(objectModel, flowContextObject); objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request); Map contextObjectModel = new HashMap(); contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel); Context context = new DefaultContext(contextObjectModel); Source sampleSource = new ResourceSource( "resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml"); Document sample = parser.parse(sampleSource.getInputStream()); Element datatypeElement = (Element) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "datatype").item(0); Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); FlowJXPathSelectionList list = new FlowJXPathSelectionList( context, "beans", "key", "value", datatype, null, false, null, false); DOMBuilder dest = new DOMBuilder(); list.generateSaxFragment(dest, Locale.ENGLISH); Source expectedSource = new ResourceSource( "resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml"); Document expected = parser.parse(expectedSource.getInputStream()); assertEqual("Test if generated list matches expected", expected, dest.getDocument()); }
@Override public List<FeedItem> parseFeed(Feed feed) { try { List<FeedItem> feedItems = new ArrayList<FeedItem>(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new URL(feed.getUrl()).openStream()); NodeList items = doc.getElementsByTagNameNS(ATOM, "entry"); for (int i = 0; i < items.getLength() && i < max; i++) { Node item = items.item(i); Builder feedItem = new FeedItem.Builder(feed); feedItem.setTitle(getTextValueOf(item, "title")); feedItem.setUrl(getTextValueOfAttribute(item, "link", "href")); feedItem.setDate(parseDate(getTextValueOf(item, "updated"))); feedItems.add(feedItem.build()); } if (log != null) { log.log( LogService.LOG_INFO, feedItems.size() + " atom feed items parsed from " + feed.getUrl()); } return feedItems; } catch (Exception e) { if (log != null) { log.log(LogService.LOG_WARNING, "Problem parsing feed " + e); } return null; } }
public void testSetNamedItemNS4() throws Throwable { Document doc; DOMImplementation domImpl; Document docAlt; DocumentType docType = null; NamedNodeMap attributes; NodeList elementList; Element element; Attr attrAlt; String nullNS = null; doc = (Document) load("staffNS", builder); elementList = doc.getElementsByTagNameNS("*", "address"); element = (Element) elementList.item(1); attributes = element.getAttributes(); domImpl = doc.getImplementation(); docAlt = domImpl.createDocument(nullNS, "newDoc", docType); attrAlt = docAlt.createAttributeNS(nullNS, "street"); { boolean success = false; try { attributes.setNamedItemNS(attrAlt); } catch (DOMException ex) { success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); } assertTrue("throw_WRONG_DOCUMENT_ERR", success); } }
private Node getUsername(Document doc, Element header) { Element e = doc.createElement("username"); e.appendChild( doc.createTextNode( ((Element) doc.getElementsByTagNameNS(COM_NS, "userName").item(0)).getTextContent())); e.setAttributeNS(XSI_NS, "xsi:type", "xsd:string"); return e; }
public static Document replaceTokenValue(Document dom, String tokenValue) { NodeList listNode = dom.getElementsByTagNameNS("http://ist_phosphorus.eu/nsp/webservice/reservation", "Token"); if (listNode == null || listNode.getLength() == 0) { listNode = dom.getElementsByTagNameNS( "http://ist_phosphorus.eu/nsp/webservice/reservation", "Token"); } if (listNode != null && listNode.getLength() > 0) { TokenHelper.log.info("Getting Token..."); TokenHelper.log.info(listNode.item(0).getTextContent()); listNode.item(0).setTextContent(tokenValue); return dom; } return null; }
// Simulates a stream based processor or producer (e.g., file EP) public SOAPMessage invokeStream(InputStream in) { SOAPMessage response = null; try { Document doc = StaxUtils.read(in); if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(), sayHi.getLocalPart()).getLength() == 1) { response = sayHiResponse; } else if (doc.getElementsByTagNameNS(greetMe.getNamespaceURI(), greetMe.getLocalPart()) .getLength() == 1) { response = greetMeResponse; } } catch (Exception ex) { ex.printStackTrace(); } return response; }
public void replace(String namespaceURI, String localName, String value) { NodeList nodes = domDocument.getElementsByTagNameNS(namespaceURI, localName); Node node; for (int i = 0; i < nodes.getLength(); i++) { node = nodes.item(i); setNodeText(domDocument, node, value); } }
@Test public void testSetingExistingElementAtLevelZero() { xmlContentHandler.setValue("text-1", "text1"); NodeList text1Nodes = document.getElementsByTagNameNS(NS_ODATA, "text-1"); assertEquals(1, text1Nodes.getLength()); Node text1Node1 = text1Nodes.item(0); assertEquals("text1", text1Node1.getTextContent()); assertEquals(0, text1Node1.getAttributes().getLength()); }
/** * Check whether a node belongs to a document * * @param doc * @param node * @return */ public static boolean containsNode(Document doc, Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element elem = (Element) node; NodeList nl = doc.getElementsByTagNameNS(elem.getNamespaceURI(), elem.getLocalName()); if (nl != null && nl.getLength() > 0) return true; else return false; } throw new UnsupportedOperationException(); }
private Node getSingleNodeFromXml(String xml, String tagName) throws IOException, SAXException, ParserConfigurationException { Document d = parseXml(xml); NodeList nl = d.getElementsByTagNameNS("*", tagName); log.debug("nodes: " + nl + ", size=" + nl.getLength()); assertTrue(nl.getLength() == 1); return nl.item(0); }
private NodeList parseXMLOptionsFile() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); f.setNamespaceAware(true); DocumentBuilder db = f.newDocumentBuilder(); db.setErrorHandler(new DefaultHandler()); Document d = db.parse(optionsFile); return d.getElementsByTagNameNS("", "taxonomy"); }
public List<NamedValue> getSAMLAttributes(ConversationID id) { List<NamedValue> samlAttributes = new ArrayList<NamedValue>(); Document document = getSAMLDocument(id); if (null == document) { return samlAttributes; } NodeList attributeNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Attribute"); for (int idx = 0; idx < attributeNodeList.getLength(); idx++) { Element attributeElement = (Element) attributeNodeList.item(idx); String attributeName = attributeElement.getAttribute("AttributeName"); NodeList attributeValueNodeList = attributeElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:1.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } NodeList attribute2NodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int idx = 0; idx < attribute2NodeList.getLength(); idx++) { Element attributeElement = (Element) attribute2NodeList.item(idx); String attributeName = attributeElement.getAttribute("Name"); NodeList attributeValueNodeList = attributeElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } return samlAttributes; }
/** * Add Token to a specific jaxb object. * * @param string the serialized JaxbObject * @param token the token * @return * @throws SoapFault */ public static final Document addTokenCreate(final Document doc, final String token) throws SoapFault { NodeList nodes = doc.getElementsByTagNameNS("http://ist_phosphorus.eu/nsp/webservice/reservation", "Token"); if (nodes != null && nodes.getLength() > 0) { nodes.item(0).setTextContent(token); } return doc; }
public List getDecryptedAttributes(ConversationID id, String hexKey) throws Exception { List samlAttributes = new ArrayList(); /* * We create a new DOM tree as XMLCipher will change the tree. */ String encodedSamlMessage = getEncodedSAMLMessage(id); String decodedSamlMessage = getDecodedSAMLMessage(encodedSamlMessage); ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedSamlMessage.getBytes()); Document document = this.builder.parse(inputStream); byte[] keyBytes = Hex.decode(hexKey); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128); xmlCipher.init(XMLCipher.DECRYPT_MODE, secretKeySpec); NodeList encryptedAttributeNodeList = document.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "EncryptedAttribute"); for (int encryptedAttributeIdx = 0; encryptedAttributeIdx < encryptedAttributeNodeList.getLength(); encryptedAttributeIdx++) { Element encryptedAttributeElement = (Element) encryptedAttributeNodeList.item(encryptedAttributeIdx); NodeList encryptedDataNodeList = encryptedAttributeElement.getElementsByTagNameNS( "http://www.w3.org/2001/04/xmlenc#", "EncryptedData"); if (1 != encryptedDataNodeList.getLength()) { continue; } Element encryptedDataElement = (Element) encryptedDataNodeList.item(0); xmlCipher.doFinal(document, encryptedDataElement); NodeList attributeNodeList = encryptedAttributeElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); if (1 != attributeNodeList.getLength()) { continue; } Element attributeElement = (Element) attributeNodeList.item(0); String attributeName = attributeElement.getAttribute("Name"); NodeList attributeValueNodeList = attributeElement.getElementsByTagNameNS( "urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } return samlAttributes; }
// take the first one // return "" if not found public static String getStudyInstanceUID(Document document) { if (document == null) { return ""; } NodeList imageStudyNodes = document.getElementsByTagNameNS(AIM_NS, "ImageStudy"); if (imageStudyNodes.getLength() > 0) { return ((Element) imageStudyNodes.item(0)).getAttribute("instanceUID"); } return ""; }
public Node getNextSiblingOfIssuer(Document doc) { // Find the sibling of Issuer NodeList nl = doc.getElementsByTagNameNS( JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()); if (nl.getLength() > 0) { Node issuer = nl.item(0); return issuer.getNextSibling(); } return null; }
/* * Util method similar to DOM getElementById() method, but it works without an id attribute being specified. Deep * searches all children in this container's DOM for the first child with the given id. The element retrieved must * have the passed local name. Note that in an XHTML file (aka DOM) elements should have a unique id within the * scope of a document. We use local name because this allows for finding intro anchors, includes and dynamic * content element regardless of whether or not an xmlns was used in the xml. */ public static Element getElementById(Document dom, String id, String localElementName) { NodeList children = dom.getElementsByTagNameNS("*", localElementName); // $NON-NLS-1$ for (int i = 0; i < children.getLength(); i++) { Element element = (Element) children.item(i); if (element.getAttribute("id").equals(id)) { return element; } } // non found. return null; }
// take the first one // return "" if not found public static String getSeriesInstanceUID(Document document) { if (document == null) { return ""; } NodeList imageSeriesNodes = document.getElementsByTagNameNS(AIM_NS, "ImageSeries"); System.out.println("found nodes:" + imageSeriesNodes.getLength()); if (imageSeriesNodes.getLength() > 0) { return ((Element) imageSeriesNodes.item(0)).getAttribute("instanceUID"); } return ""; }