List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * This method sets the namespace which will determinate the {@code XPathQueryHolder} to use. The content of the Transform element is ignored. * * @param element//from ww w . j a v a 2 s .com */ public void recursiveNamespaceBrowser(final Element element) { for (int ii = 0; ii < element.getChildNodes().getLength(); ii++) { final Node node = element.getChildNodes().item(ii); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element childElement = (Element) node; final String namespaceURI = childElement.getNamespaceURI(); // final String tagName = childElement.getTagName(); final String localName = childElement.getLocalName(); // final String nodeName = childElement.getNodeName(); // System.out.println(tagName + "-->" + namespaceURI); if (XPathQueryHolder.XMLE_TRANSFORM.equals(localName) && javax.xml.crypto.dsig.XMLSignature.XMLNS.equals(namespaceURI)) { continue; } else if (XPathQueryHolder.XMLE_QUALIFYING_PROPERTIES.equals(localName)) { setXPathQueryHolder(namespaceURI); return; } recursiveNamespaceBrowser(childElement); } } }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * This method returns the last timestamp validation data for an archive timestamp. * * @return/*from w w w. j a v a2 s .c o m*/ */ public Element getLastTimestampValidationData() { final List<TimestampToken> archiveTimestamps = getArchiveTimestamps(); TimestampToken mostRecentTimestamp = null; for (final TimestampToken archiveTimestamp : archiveTimestamps) { if (mostRecentTimestamp == null) { mostRecentTimestamp = archiveTimestamp; continue; } final Date generationTime = archiveTimestamp.getGenerationTime(); final Date mostRecentGenerationTime = mostRecentTimestamp.getGenerationTime(); if (generationTime.after(mostRecentGenerationTime)) { mostRecentTimestamp = archiveTimestamp; } } final int timestampHashCode = mostRecentTimestamp.getHashCode(); final NodeList nodeList = DSSXMLUtils.getNodeList(signatureElement, xPathQueryHolder.XPATH_UNSIGNED_SIGNATURE_PROPERTIES + "/*"); boolean found = false; for (int ii = 0; ii < nodeList.getLength(); ii++) { final Element unsignedSignatureElement = (Element) nodeList.item(ii); final int nodeHashCode = unsignedSignatureElement.hashCode(); if (nodeHashCode == timestampHashCode) { found = true; } else if (found) { final String nodeName = unsignedSignatureElement.getLocalName(); if ("TimeStampValidationData".equals(nodeName)) { return unsignedSignatureElement; } } } return null; }
From source file:com.wfreitas.camelsoap.SoapClient.java
/** * Expand the message to accommodate data collections. * <p/>/*from w ww. j a va 2 s.co m*/ * It basically just clones the message where appropriate. * * @param element The element to be processed. * @param params The message params. Uses the message params to * decide whether or not cloning is required. */ private void expandMessage(Element element, Map params) { // If this element is not a cloned element, check does it need to be cloned... if (!element.hasAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, IS_CLONE_ATTRIB)) { String ognl = OGNLUtils.getOGNLExpression(element); Element clonePoint = getClonePoint(element); if (clonePoint != null) { int collectionSize; collectionSize = calculateCollectionSize(ognl, params); if (collectionSize == -1) { // It's a collection, but has no entries that match the OGNL expression for this element... if (clonePoint == element) { // If the clonePoint is the element itself, we remove it... we're done with it... clonePoint.getParentNode().removeChild(clonePoint); } else { // If the clonePoint is not the element itself (it's a child element), leave it // and check it again when we get to it... resetClonePoint(clonePoint); } } else if (collectionSize == 0) { // It's a collection, but has no entries, remove it... clonePoint.getParentNode().removeChild(clonePoint); } else if (collectionSize == 1) { // It's a collection, but no need to clone coz we // already have an entry for it... clonePoint.setAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, OGNLUtils.JBOSSESB_SOAP_NS_PREFIX + OGNLUtils.OGNL_ATTRIB, ognl + "[0]"); } else { // It's a collection and we need to do some cloning if (clonePoint != null) { // We already have one, so decrement by one... cloneCollectionTemplateElement(clonePoint, (collectionSize - 1), ognl); } else { LOGGER.warn("Collection/array template element <" + element.getLocalName() + "> would appear to be invalid. It doesn't contain any child elements."); } } } } // Now do the same for the child elements... List<Node> children = DOMUtil.copyNodeList(element.getChildNodes()); for (Node node : children) { if (node.getNodeType() == Node.ELEMENT_NODE) { expandMessage((Element) node, params); } } }
From source file:com.amalto.workbench.utils.Util.java
/** * return {fk,fk info,fk filter} element *///from w ww . j av a 2 s.c o m public static Object[] getAllForeignKeyRelatedInfos(Object elem, List<Object> objList, IStructuredContentProvider provider, final Set<Object> visited) { if (elem == null || objList == null || visited == null || provider == null) { return null; } visited.add(elem); Object[] elems = provider.getElements(elem); if (elems != null && elems.length > 0) { for (Object obj : elems) { if (obj == null) { continue; } if (obj instanceof Element) { Element e = (Element) obj; if (e.getLocalName().equals("appinfo")) {//$NON-NLS-1$ String source = e.getAttribute("source");//$NON-NLS-1$ if (source != null && !objList.contains(e)) { if (source.equals("X_ForeignKey") || source.equals("X_ForeignKeyInfo") //$NON-NLS-1$ //$NON-NLS-2$ || source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$ objList.add(e); } } } } else { if (!visited.contains(obj)) { getAllForeignKeyRelatedInfos(obj, objList, provider, visited); } } } } return objList.toArray(); }
From source file:com.amalto.workbench.editors.DataModelMainPage.java
public boolean hasVisibleRule(XSDElementDeclaration xsdEl) { XSDAnnotation annotation = xsdEl.getAnnotation(); List<Element> informations = annotation.getApplicationInformation(); for (Element el : informations) { String name = el.getLocalName(); if ("appinfo".equals(name.toLowerCase())) {//$NON-NLS-1$ name = el.getAttribute("source");//$NON-NLS-1$ if (name.matches("X_Visible_Rule")) { //$NON-NLS-1$ return true; }/*from w ww. jav a 2 s. c om*/ } } return false; }
From source file:de.betterform.connector.serializer.FormDataSerializer.java
protected void serializeElement(PrintWriter writer, Element element, String boundary, String charset) throws Exception { /* The specs http://www.w3.org/TR/2003/REC-xforms-20031014/slice11.html#serialize-form-data *//from w w w . j a v a 2s .c om * Each element node is visited in document order. * * Each element that has exactly one text node child is selected * for inclusion. * * Element nodes selected for inclusion are as encoded as * Content-Disposition: form-data MIME parts as defined in * [RFC 2387], with the name parameter being the element local name. * * Element nodes of any datatype populated by upload are serialized * as the specified content and additionally have a * Content-Disposition filename parameter, if available. * * The Content-Type must be text/plain except for xsd:base64Binary, * xsd:hexBinary, and derived types, in which case the header * represents the media type of the attachment if known, otherwise * application/octet-stream. If a character set is applicable, the * Content-Type may have a charset parameter. * */ String nodeValue = null; boolean isCDATASection = false; boolean includeTextNode = true; NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); switch (n.getNodeType()) { /* CDATA sections are not mentioned ... ignore for now case Node.CDATA_SECTION_NODE: isCDATASection = true; */ case Node.TEXT_NODE: if (includeTextNode) { if (nodeValue != null) { /* only one text node allowed by specs */ includeTextNode = false; } else { nodeValue = n.getNodeValue(); } } break; /* Real ambiguity in specs, what if there's one text node and * n elements ? Let's assume if there is an element, ignore the * text nodes */ case Node.ELEMENT_NODE: includeTextNode = false; serializeElement(writer, (Element) n, boundary, charset); break; default: // ignore comments and other nodes... } } if (nodeValue != null && includeTextNode) { Object object = element.getUserData(""); if (object != null && !(object instanceof ModelItem)) { throw new XFormsException("Unknown instance data format."); } ModelItem item = (ModelItem) object; writer.print("\r\n--" + boundary); String name = element.getLocalName(); if (name == null) { name = element.getNodeName(); } // mediatype tells about file upload if (item != null && item.getMediatype() != null) { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); if (item.getFilename() != null) { File file = new File(item.getFilename()); writer.print(" filename=\"" + file.getName() + "\";"); } writer.print("\r\nContent-Type: " + item.getMediatype()); } else { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); writer.print("\r\nContent-Type: text/plain; charset=\"" + charset + "\";"); } String encoding = "8bit"; if (item != null && "base64Binary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { encoding = "base64"; } else if (item != null && "hexBinary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { // recode to base64 because of MIME nodeValue = new String(Base64.encodeBase64(Hex.decodeHex(nodeValue.toCharArray()), true)); encoding = "base64"; } writer.print("\r\nContent-Transfer-Encoding: " + encoding); writer.print("\r\n\r\n" + nodeValue); } writer.flush(); }
From source file:com.amalto.workbench.editors.DataModelMainPage.java
private int getElementType(Object decl) { if (Util.getParent(decl) == decl) { if (Util.checkConcept((XSDElementDeclaration) decl)) { return 0; }/*from w w w . j a v a2 s .c o m*/ return 1; } if (decl instanceof XSDComplexTypeDefinition) { return 2; } if (decl instanceof XSDIdentityConstraintDefinition) { return 3; } if (decl instanceof XSDXPathDefinition) { return 4; } if (decl instanceof XSDSimpleTypeDefinition) { return 5; } if (decl instanceof XSDAnnotation) { return 6; } if (decl instanceof XSDParticle) { return 7; } if (decl instanceof XSDModelGroup) { return 8; } if (decl instanceof XSDWhiteSpaceFacet) { return 201; } if (decl instanceof XSDLengthFacet) { return 202; } if (decl instanceof XSDMinLengthFacet) { return 203; } if (decl instanceof XSDMaxLengthFacet) { return 204; } if (decl instanceof XSDTotalDigitsFacet) { return 205; } if (decl instanceof XSDFractionDigitsFacet) { return 206; } if (decl instanceof XSDMaxInclusiveFacet) { return 207; } if (decl instanceof XSDMaxExclusiveFacet) { return 208; } if (decl instanceof XSDMinInclusiveFacet) { return 209; } if (decl instanceof XSDMinExclusiveFacet) { return 210; } if (decl instanceof XSDPatternFacet) { return 211; } if (decl instanceof XSDEnumerationFacet) { return 212; } if (decl instanceof Element) { Element e = (Element) decl; if (e.getLocalName().equals("appinfo")) {//$NON-NLS-1$ } String source = e.getAttribute("source");//$NON-NLS-1$ if (source != null) { if (source.startsWith("X_Label_")) {//$NON-NLS-1$ return 101; } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$ return 102; } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$ return 103; } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$ return 104; } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$ return 105; } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$ return 106; } else if (source.equals("X_Write")) {//$NON-NLS-1$ return 107; } else if (source.equals("X_Hide")) {//$NON-NLS-1$ return 108; } else if (source.equals("X_Schematron")) {//$NON-NLS-1$ return 109; } else if (source.startsWith("X_Facet_")) {//$NON-NLS-1$ return 110; } else if (source.startsWith("X_Workflow")) {//$NON-NLS-1$ return 111; } else if (source.startsWith("X_ForeignKey_Filter")) {//$NON-NLS-1$ return 112; } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$ return 113; } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$ return 114; } else if (source.equals("X_PrimaryKeyInfo")) {//$NON-NLS-1$ return 115; } else if (source.equals("X_Visible_Rule")) {//$NON-NLS-1$ return 116; } else if (source.equals("X_Default_Value_Rule")) {//$NON-NLS-1$ return 117; } else if (source.equals("X_Deny_Create")) {//$NON-NLS-1$ return 118; } else if (source.equals("X_Deny_PhysicalDelete")) {//$NON-NLS-1$ return 119; } else if (source.equals("X_Deny_LogicalDelete")) {//$NON-NLS-1$ return 120; } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$ return 121; } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$ return 122; } else if (source.equals("X_ForeignKeyInfoFormat")) {//$NON-NLS-1$ return 123; } } } return -1; }
From source file:com.amalto.core.plugin.base.xslt.XSLTTransformerPluginBean.java
/** * Process the mappings after xsl transformation * // w ww . jav a 2s. c om * @param xrefElement * @return the processed Element */ private Element processMappings(Element xrefElement) throws XtentisException { try { String xrefcluster = xrefElement.getAttribute("xrefCluster"); //$NON-NLS-1$ String xrefIn = xrefElement.getAttribute("xrefIn"); //$NON-NLS-1$ String xrefOut = xrefElement.getAttribute("xrefOut"); //$NON-NLS-1$ String xrefIgnore = xrefElement.getAttribute("xrefIgnore"); //$NON-NLS-1$ String xrefDefault = xrefElement.getAttribute("xrefDefault"); //$NON-NLS-1$ Logger.getLogger(XSLTTransformerPluginBean.class) .debug("\n xrefIgnore=" + xrefIgnore + "\n xrefDefault=" + xrefDefault); //$NON-NLS-1$ //$NON-NLS-2$ // parse xrefbein dockey1:xrefkey1,dockey2:xrefkey2 String[] mappings = xrefIn.split(","); //$NON-NLS-1$ HashMap<String, String> itemvals = new HashMap<String, String>(); for (int j = 0; j < mappings.length; j++) { String[] relations = mappings[j].split("="); //$NON-NLS-1$ String docpath = relations[0]; String xrefpath = relations[1]; String itemval = ""; //$NON-NLS-1$ try { if (docpath.startsWith("[")) // hardcoded value //$NON-NLS-1$ itemval = docpath.substring(1, docpath.length() - 1); else itemval = Util.getFirstTextNode(xrefElement, docpath); } catch (Exception x) { throw new XtentisException( "Value for business element '" + xrefElement.getNodeName() + '/' + docpath //$NON-NLS-1$ + "' cannot be found!"); //$NON-NLS-1$ } if (itemval == null) itemval = ""; //$NON-NLS-1$ String content = stripeOuterBracket(itemval); if (content.split(",").length >= mappings.length) //$NON-NLS-1$ itemvals.put(xrefpath, content.split(",")[j]); //$NON-NLS-1$ else itemvals.put(xrefpath, ""); //$NON-NLS-1$ } WhereAnd wAnd = new WhereAnd(); Collection<Map.Entry<String, String>> c = itemvals.entrySet(); int i = 0; for (Iterator<Map.Entry<String, String>> iter = c.iterator(); iter.hasNext();) { i++; Map.Entry<String, String> entry = iter.next(); wAnd.add(new WhereCondition(entry.getKey(), WhereCondition.EQUALS, entry.getValue(), WhereCondition.PRE_NONE, false)); } ArrayList<String> resList = Util.getItemCtrl2Local().xPathsSearch(new DataClusterPOJOPK(xrefcluster), null, new ArrayList<String>(Arrays.asList(new String[] { xrefOut })), wAnd, -1, // spell 0, // start 1, // limit false); String val = ""; //$NON-NLS-1$ if ((resList == null) || (resList.size() == 0)) { if (xrefIgnore.equals("true") || xrefIgnore.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$ if (xrefDefault != null) val = xrefDefault; else val = ""; //$NON-NLS-1$ } else { String ks = ""; //$NON-NLS-1$ c = itemvals.entrySet(); for (Iterator<Map.Entry<String, String>> iter = c.iterator(); iter.hasNext();) { Map.Entry<String, String> entry = iter.next(); ks += " " + entry.getKey() + "=\"" + entry.getValue() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } throw new XtentisException("Foreign keys values not found for: " + ks); //$NON-NLS-1$ } } else { // read result Pattern p = Pattern.compile("<.*?>(.*?)</.*>", Pattern.DOTALL); //$NON-NLS-1$ Matcher m = p.matcher(resList.iterator().next()); if (m.matches()) val = StringEscapeUtils.unescapeXml(m.group(1)); else { Pattern p2 = Pattern.compile("<.*?/>", Pattern.DOTALL); //$NON-NLS-1$ Matcher m2 = p2.matcher(resList.iterator().next()); if (!m2.matches() && !(xrefIgnore.equals("true") || xrefIgnore.equals("1"))) { //$NON-NLS-1$ //$NON-NLS-2$ throw new XtentisException("Result values were not understood for crossref element"); //$NON-NLS-1$ } } } NodeList l = xrefElement.getChildNodes(); for (int j = 0; j < l.getLength(); j++) { switch (l.item(j).getNodeType()) { case Node.TEXT_NODE: l.item(j).setNodeValue(val); break; case Node.ELEMENT_NODE: xrefElement.removeChild(l.item(j)); break; default: } } xrefElement.removeAttribute("xrefCluster"); //$NON-NLS-1$ xrefElement.removeAttribute("xrefIgnore"); //$NON-NLS-1$ xrefElement.removeAttribute("xrefDefault"); //$NON-NLS-1$ xrefElement.removeAttribute("xrefIn"); //$NON-NLS-1$ xrefElement.removeAttribute("xrefOut"); //$NON-NLS-1$ return xrefElement; } catch (Exception e) { String err = "Unable to process the mappings for the element '" + xrefElement.getLocalName() + "'"; //$NON-NLS-1$ //$NON-NLS-2$ LOG.error(err, e); throw new XtentisException(err); } }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Parse a content.// w w w.ja va2 s. co m * @param xml content's raw XML. * @param jid optional reply-to XMPP address. * @return content. * @throws Exception parsing problem, most likely invalid XML. */ private CapptainReachContent parseContent(String xml, String jid) throws Exception { /* Check root element, drop it if invalid XML or invalid namespace */ Element root = XmlUtil.parseContent(xml); String rootNS = root.getNamespaceURI(); if (!REACH_NAMESPACE.equals(rootNS)) throw new IllegalArgumentException("Unknown namespace: " + rootNS); /* If this is an announcement */ String rootTagName = root.getLocalName(); if ("announcement".equals(rootTagName)) /* Parse the announcement */ return new CapptainAnnouncement(jid, xml, root, mInjectedParams); /* If this is a poll */ else if ("poll".equals(rootTagName)) /* Parse the poll */ return new CapptainPoll(jid, xml, root); /* If this is a notification announcement */ else if ("notifAnnouncement".equals(rootTagName)) /* Parse the notification announcement */ return new CapptainNotifAnnouncement(jid, xml, root, mInjectedParams); /* If this is a data push */ else if ("datapush".equals(rootTagName)) /* Parse the datapush */ return new CapptainDataPush(jid, xml, root, mInjectedParams); /* XML/Namespace valid but content is not recognized */ throw new IllegalArgumentException("Unknown root tag: " + rootTagName); }
From source file:nl.b3p.ogc.utils.OgcWfsClient.java
/** Haal de elementen uit de describefeaturetype request */// w w w . j a v a2 s . co m public static ArrayList getDescribeFeatureElements(Element el) throws Exception { //Haal eerst de complexTypes type elementen op en de prefix. String namespaceUri = el.getNamespaceURI(); NodeList childs = el.getChildNodes(); String prefix = ""; for (int i = 0; i < childs.getLength() && prefix.length() == 0; i++) { Node n = childs.item(i); if (n instanceof DeferredElementNSImpl) { Element e = (Element) n; if (e.getLocalName().equalsIgnoreCase("element")) { if (e.getAttribute("type") != null && e.getAttribute("type").contains(":")) { prefix = e.getAttribute("type").split(":")[0]; } } } } String featureNameSpace = null; if (prefix.length() > 0) { featureNameSpace = el.getAttribute("xmlns:" + prefix); } String s = elementToString(el); if (el == null) { return null; } NodeList nlist = el.getElementsByTagNameNS(namespaceUri, "complexType"); if (!(nlist.getLength() > 0)) { log.error("no complexType element found"); return null; } ArrayList returnValue = new ArrayList(); for (int i = 0; i < nlist.getLength(); i++) { Element e = (Element) nlist.item(i); NodeList nl = e.getElementsByTagNameNS(namespaceUri, "element"); for (int b = 0; b < nl.getLength(); b++) { Element element = (Element) nl.item(b); if (featureNameSpace != null && featureNameSpace.length() > 0) { element.setAttribute("name", "{" + featureNameSpace + "}" + element.getAttribute("name")); } returnValue.add(element); } } return returnValue; }