List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:de.qucosa.webapi.v1.DocumentResource.java
private FileUpdateOperation updateFileNodeWith(Element target, Element update) throws FedoraClientException, IOException, XPathExpressionException { FileUpdateOperation fupo = new FileUpdateOperation(); NodeList updateNodes = update.getChildNodes(); for (int i = 0; i < updateNodes.getLength(); i++) { if (updateNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element updateField = (Element) updateNodes.item(i); String updateFieldLocalName = updateField.getLocalName(); Element targetElement = (Element) target.getElementsByTagName(updateFieldLocalName).item(0); if (targetElement == null) { targetElement = target.getOwnerDocument().createElement(updateFieldLocalName); target.appendChild(targetElement); targetElement.appendChild(target.getOwnerDocument().createTextNode("")); }/*from w w w. ja v a 2 s. c o m*/ String oldVal = targetElement.getTextContent(); String newVal = updateField.getTextContent(); if (!oldVal.equals(newVal)) { switch (updateFieldLocalName) { case "PathName": if (!newVal.isEmpty()) fupo.rename(oldVal, newVal); break; case "Label": fupo.newLabel(updateField.getTextContent()); break; case "FrontdoorVisible": fupo.newState(determineDatastreamState(update)); break; } targetElement.setTextContent(updateField.getTextContent()); } } } return fupo; }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImpl.java
private void validateToken(Element tokenElement, String expectedAudience, IdentityProviderConfiguration identityProviderConfiguration) throws Exception { List<X509Certificate> certificateChain = identityProviderConfiguration.getIdentityCertificateChain(); if (certificateChain.isEmpty()) { throw new SecurityException("no eID IdP service identity configured"); }//from w ww . j a va 2 s. com Element nsElement = tokenElement.getOwnerDocument().createElement("nsElement"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:saml2", "urn:oasis:names:tc:SAML:2.0:assertion"); LOG.debug("token element: " + tokenElement.getLocalName()); LOG.debug("token element namespace: " + tokenElement.getNamespaceURI()); LOG.debug("token: " + toString(tokenElement)); // fix for recent versions of Apache xmlsec. tokenElement.setIdAttribute("ID", true); Element signatureElement = (Element) XPathAPI.selectSingleNode(tokenElement, "ds:Signature", nsElement); if (null == signatureElement) { throw new SecurityException("missing XML signature"); } XMLSignature xmlSignature = new XMLSignature(signatureElement, ""); KeyInfo keyInfo = xmlSignature.getKeyInfo(); X509Certificate actualCertificate = keyInfo.getX509Certificate(); boolean signatureResult = xmlSignature.checkSignatureValue(actualCertificate); if (false == signatureResult) { throw new SecurityException("invalid XML signature"); } LOG.debug("XML signature OK"); X509Certificate serviceCertificate = certificateChain.get(0); if (false == Arrays.equals(serviceCertificate.getEncoded(), actualCertificate.getEncoded())) { throw new SecurityException("SAML signing certificate different from eID IdP service identity"); } LOG.debug("SAML signer OK"); String actualIssuer = XPathAPI.selectSingleNode(tokenElement, "saml2:Issuer/text()", nsElement) .getNodeValue(); String serviceIssuer = identityProviderConfiguration.getDefaultIssuer(); if (false == actualIssuer.equals(serviceIssuer)) { LOG.debug("actual issuer: " + actualIssuer); LOG.debug("service issuer: " + serviceIssuer); throw new SecurityException("wrong SAML issuer"); } LOG.debug("SAML issuer OK"); if (null != expectedAudience) { String audience = XPathAPI .selectSingleNode(tokenElement, "saml2:Conditions/saml2:AudienceRestriction/saml2:Audience/text()", nsElement) .getNodeValue(); if (false == expectedAudience.equals(audience)) { LOG.debug("expected audience: " + expectedAudience); LOG.debug("actual audience: " + audience); throw new SecurityException("incorrect SAML audience"); } LOG.debug("SAML Audience OK"); } else { LOG.warn("SAML audience restriction not checked"); } String authnContextClassRef = XPathAPI .selectSingleNode(tokenElement, "saml2:AuthnStatement/saml2:AuthnContext/saml2:AuthnContextClassRef/text()", nsElement) .getNodeValue(); LOG.debug("AuthnContextClassRef: " + authnContextClassRef); SamlAuthenticationPolicy samlAuthenticationPolicy = SamlAuthenticationPolicy .getAuthenticationPolicy(authnContextClassRef); if (SamlAuthenticationPolicy.AUTHENTICATION != samlAuthenticationPolicy && SamlAuthenticationPolicy.AUTHENTICATION_WITH_IDENTIFICATION != samlAuthenticationPolicy) { throw new SecurityException("wrong SAML authentication policy: " + samlAuthenticationPolicy); } String notBeforeStr = XPathAPI.selectSingleNode(tokenElement, "saml2:Conditions/@NotBefore", nsElement) .getNodeValue(); String notOnOrAfterStr = XPathAPI .selectSingleNode(tokenElement, "saml2:Conditions/@NotOnOrAfter", nsElement).getNodeValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime notBefore = dateTimeFormatter.parseDateTime(notBeforeStr); DateTime notOnOrAfter = dateTimeFormatter.parseDateTime(notOnOrAfterStr); DateTime now = new DateTime(); if (now.isBefore(notBefore)) { throw new SecurityException("SAML assertion in future"); } if (now.isAfter(notOnOrAfter)) { throw new SecurityException("SAML assertion expired"); } LOG.debug("SAML timestamp OK"); }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind brush element// ww w . ja va 2 s . com * * @param element brush element * @return brush data object * @throws InkMLException */ protected Brush getBrush(final Element element) throws InkMLException { final String id = element.getAttribute("id"); final Brush brush = new Brush(id); final String brushRef = element.getAttribute("brushRef"); if (!"".equals(brushRef)) { brush.setBrushRef(brushRef); } // Process the child <annotation>, <annotationXML> elements final NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { final Node node = list.item(i); if (!(node instanceof Element)) { continue; } final Element childElement = (Element) node; final String tagName = childElement.getLocalName(); if ("annotationXML".equalsIgnoreCase(tagName)) { final AnnotationXML aXml = this.getAnnotationXML(childElement); brush.setAnnotationXML(aXml); } else if ("annotation".equalsIgnoreCase(tagName)) { final Annotation annotation = this.getAnnotation(childElement); brush.setAnnotation(annotation); } } return brush; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind TraceGroup element/*w ww. j ava 2s. c o m*/ * * @param element the TraceGroup element * @return TraceGroup data object * @throws InkMLException */ protected TraceGroup getTraceGroup(final Element element) throws InkMLException { final TraceGroup traceGroup = new TraceGroup(); // bind attribute final String id = element.getAttribute("id"); final String contextref = element.getAttribute("contextRef"); final String brushRef = element.getAttribute("brushRef"); if (!"".equals(id)) { traceGroup.setId(id); } if (!"".equals(contextref)) { traceGroup.setContextRef(contextref); } if (!"".equals(brushRef)) { traceGroup.setBrushRef(brushRef); } // bind child element final NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { final Node node = list.item(i); if (!(node instanceof Element)) { continue; } final Element child = (Element) node; final String tagName = child.getLocalName(); if ("trace".equals(tagName)) { final Trace trace = this.getTrace(child); trace.setParentTraceGroup(traceGroup); traceGroup.addToTraceData(trace); } else if ("traceGroup".equals(tagName)) { final TraceGroup childTG = this.getTraceGroup(child); childTG.setParentTraceGroup(traceGroup); traceGroup.addToTraceData(childTG); } } return traceGroup; }
From source file:org.apache.cxf.systest.jaxrs.JAXRSClientServerSpringBookTest.java
private void checkSchemas(String address, String schemaSegment, String includedSchema, String refAttrName) throws Exception { WebClient client = WebClient.create(address + schemaSegment); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000L); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); Element root = doc.getDocumentElement(); assertEquals(Constants.URI_2001_SCHEMA_XSD, root.getNamespaceURI()); assertEquals("schema", root.getLocalName()); if (includedSchema != null) { List<Element> includeEls = DOMUtils.getChildrenWithName(root, Constants.URI_2001_SCHEMA_XSD, refAttrName);/*from w w w.j a va2s . co m*/ assertEquals(1, includeEls.size()); String href = includeEls.get(0).getAttribute("schemaLocation"); assertEquals(address + includedSchema, href); } }
From source file:org.apache.cxf.systest.jaxrs.JAXRSClientServerSpringBookTest.java
private void checkWadlResourcesType(String baseURI, String requestTypeURI, String schemaRef) throws Exception { WebClient client = WebClient.create(requestTypeURI); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); Element root = doc.getDocumentElement(); assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI()); assertEquals("application", root.getLocalName()); List<Element> grammarEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size());/* www . j a v a2 s . c om*/ List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0), WadlGenerator.WADL_NS, "include"); assertEquals(1, includeEls.size()); String href = includeEls.get(0).getAttribute("href"); assertEquals(baseURI + schemaRef, href); List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resources"); assertEquals(0, resourcesEls.size()); List<Element> resourceTypeEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resource_type"); assertEquals(1, resourceTypeEls.size()); }
From source file:org.apache.cxf.systest.jaxrs.JAXRSClientServerSpringBookTest.java
private List<Element> checkWadlResourcesInfo(Document doc, String baseURI, String schemaRef, int size) throws Exception { Element root = doc.getDocumentElement(); assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI()); assertEquals("application", root.getLocalName()); List<Element> grammarEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size());//w ww . j av a2 s.c om List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0), WadlGenerator.WADL_NS, "include"); assertEquals(1, includeEls.size()); String href = includeEls.get(0).getAttribute("href"); assertEquals(baseURI + schemaRef, href); List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resources"); assertEquals(1, resourcesEls.size()); Element resourcesEl = resourcesEls.get(0); assertEquals(baseURI, resourcesEl.getAttribute("base")); List<Element> resourceEls = DOMUtils.getChildrenWithName(resourcesEl, WadlGenerator.WADL_NS, "resource"); assertEquals(size, resourceEls.size()); return resourceEls; }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
/**************************************************************************** * DOCUMENTATION//from www.j a va 2s . c o m ****************************************************************************/ private Element getDocumentationElement() { Element documentation = null; ArrayList<Element> list = new ArrayList<Element>(); list.addAll(annotation.getUserInformation()); for (Iterator<Element> iter = list.iterator(); iter.hasNext();) { Element ann = iter.next(); String name = ann.getLocalName(); if ("documentation".equals(name.toLowerCase())) {//$NON-NLS-1$ documentation = ann; break; } } return documentation; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind the children of Definitions element * /*from www . j a v a 2 s . com*/ * @param elements the Definitions child element * @param definitions the definitions data object to resolve the reference attributes * @throws InkMLException */ protected void addToDefinitions(final NodeList elements, final Definitions definitions) throws InkMLException { for (int i = 0; i < elements.getLength(); i++) { final Node node = elements.item(i); if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final String tagName = element.getLocalName(); final String id = element.getAttribute("id"); if ("".equals(id)) { throw new InkMLException("Elements within a <definitions> block must have an 'id' attribute. A " + tagName + " element do not have 'id' attribute."); } InkElement inkElement = null; // when the object of child elements created, the elements having a non empty id are added to definitions. // This is done in the constructors of all the child elements of Definitions if ("brush".equalsIgnoreCase(tagName)) { inkElement = this.getBrush(element); } else if ("traceFormat".equalsIgnoreCase(tagName)) { inkElement = this.getTraceFormat(element, definitions); } else if ("context".equalsIgnoreCase(tagName)) { final Context context = this.getContext(element, definitions); // resolve implicit references for contextual elements to their counterpart in the "DefaultContext" context.resolveImplicitReferenceWithDefaultContext(); inkElement = context; } else if ("inkSource".equalsIgnoreCase(tagName)) { inkElement = this.getInkSource(element, definitions); } else if ("trace".equalsIgnoreCase(tagName)) { inkElement = this.getTrace(element); } else if ("traceGroup".equalsIgnoreCase(tagName)) { inkElement = this.getTraceGroup(element); } else if ("traceView".equalsIgnoreCase(tagName)) { inkElement = this.getTraceView(element, definitions); } else if ("canvas".equalsIgnoreCase(tagName)) { inkElement = this.getCanvas(element, definitions); } else if ("canvasTransform".equalsIgnoreCase(tagName)) { inkElement = this.getCanvasTransform(element); } else if ("timestamp".equalsIgnoreCase(tagName)) { inkElement = this.getTimestamp(element); } else if ("mapping".equalsIgnoreCase(tagName)) { inkElement = this.getMapping(element); } else { throw new InkMLException("Parse Error: The element " + tagName + "should not be a child to <definitions> element.\n"); } definitions.addToDirectChildrenMap(inkElement); } }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
private LinkedHashMap<String, String> getAppInfos(String regex) { LinkedHashMap<String, String> appInfos = new LinkedHashMap<String, String>(); ArrayList<Element> list = new ArrayList<Element>(); // list.addAll(annotation.getUserInformation()); list.addAll(annotation.getApplicationInformation()); int i = 0;/*from w w w. j a v a2s. com*/ for (Iterator<Element> iter = list.iterator(); iter.hasNext();) { Element ann = iter.next(); String name = ann.getLocalName(); if ("appinfo".equals(name.toLowerCase())) {//$NON-NLS-1$ name = ann.getAttribute("source");//$NON-NLS-1$ if (name.equals(regex)) { appInfos.put(name + "_" + i, ann.getFirstChild().getNodeValue());//$NON-NLS-1$ i++; } else if (name.matches(regex)) { appInfos.put(name, ann.getFirstChild().getNodeValue()); } } } return appInfos; }