List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:com.occamlab.te.parsers.ImageParser.java
private static void processBufferedImage(BufferedImage buffimage, String formatName, NodeList nodes) throws Exception { HashMap<Object, Object> bandMap = new HashMap<Object, Object>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getLocalName().equals("subimage")) { Element e = (Element) node; int x = Integer.parseInt(e.getAttribute("x")); int y = Integer.parseInt(e.getAttribute("y")); int w = Integer.parseInt(e.getAttribute("width")); int h = Integer.parseInt(e.getAttribute("height")); processBufferedImage(buffimage.getSubimage(x, y, w, h), formatName, e.getChildNodes()); } else if (node.getLocalName().equals("checksum")) { CRC32 checksum = new CRC32(); Raster raster = buffimage.getRaster(); DataBufferByte buffer; if (node.getParentNode().getLocalName().equals("subimage")) { WritableRaster outRaster = raster.createCompatibleWritableRaster(); buffimage.copyData(outRaster); buffer = (DataBufferByte) outRaster.getDataBuffer(); } else { buffer = (DataBufferByte) raster.getDataBuffer(); }//ww w . j av a 2s . co m int numbanks = buffer.getNumBanks(); for (int j = 0; j < numbanks; j++) { checksum.update(buffer.getData(j)); } Document doc = node.getOwnerDocument(); node.appendChild(doc.createTextNode(Long.toString(checksum.getValue()))); } else if (node.getLocalName().equals("count")) { String band = ((Element) node).getAttribute("bands"); String sample = ((Element) node).getAttribute("sample"); if (sample.equals("all")) { bandMap.put(band, null); } else { HashMap<Object, Object> sampleMap = (HashMap<Object, Object>) bandMap.get(band); if (sampleMap == null) { if (!bandMap.containsKey(band)) { sampleMap = new HashMap<Object, Object>(); bandMap.put(band, sampleMap); } } sampleMap.put(Integer.decode(sample), new Integer(0)); } } else if (node.getLocalName().equals("transparentNodata")) { // 2011-08-24 // PwD String transparentNodata = checkTransparentNodata(buffimage, node); node.setTextContent(transparentNodata); } } } Iterator bandIt = bandMap.keySet().iterator(); while (bandIt.hasNext()) { String band_str = (String) bandIt.next(); int band_indexes[]; if (buffimage.getType() == BufferedImage.TYPE_BYTE_BINARY || buffimage.getType() == BufferedImage.TYPE_BYTE_GRAY) { band_indexes = new int[1]; band_indexes[0] = 0; } else { band_indexes = new int[band_str.length()]; for (int i = 0; i < band_str.length(); i++) { if (band_str.charAt(i) == 'A') band_indexes[i] = 3; if (band_str.charAt(i) == 'B') band_indexes[i] = 2; if (band_str.charAt(i) == 'G') band_indexes[i] = 1; if (band_str.charAt(i) == 'R') band_indexes[i] = 0; } } Raster raster = buffimage.getRaster(); java.util.HashMap sampleMap = (java.util.HashMap) bandMap.get(band_str); boolean addall = (sampleMap == null); if (sampleMap == null) { sampleMap = new java.util.HashMap(); bandMap.put(band_str, sampleMap); } int minx = raster.getMinX(); int maxx = minx + raster.getWidth(); int miny = raster.getMinY(); int maxy = miny + raster.getHeight(); int bands[][] = new int[band_indexes.length][raster.getWidth()]; for (int y = miny; y < maxy; y++) { for (int i = 0; i < band_indexes.length; i++) { raster.getSamples(minx, y, maxx, 1, band_indexes[i], bands[i]); } for (int x = minx; x < maxx; x++) { int sample = 0; for (int i = 0; i < band_indexes.length; i++) { sample |= bands[i][x] << ((band_indexes.length - i - 1) * 8); } Integer sampleObj = new Integer(sample); boolean add = addall; if (!addall) { add = sampleMap.containsKey(sampleObj); } if (add) { Integer count = (Integer) sampleMap.get(sampleObj); if (count == null) { count = new Integer(0); } count = new Integer(count.intValue() + 1); sampleMap.put(sampleObj, count); } } } } Node node = nodes.item(0); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getLocalName().equals("count")) { String band = ((Element) node).getAttribute("bands"); String sample = ((Element) node).getAttribute("sample"); HashMap sampleMap = (HashMap) bandMap.get(band); Document doc = node.getOwnerDocument(); if (sample.equals("all")) { Node parent = node.getParentNode(); Node prevSibling = node.getPreviousSibling(); Iterator sampleIt = sampleMap.keySet().iterator(); Element countnode = null; int digits; String prefix; switch (buffimage.getType()) { case BufferedImage.TYPE_BYTE_BINARY: digits = 1; prefix = ""; break; case BufferedImage.TYPE_BYTE_GRAY: digits = 2; prefix = "0x"; break; default: prefix = "0x"; digits = band.length() * 2; } while (sampleIt.hasNext()) { countnode = doc.createElementNS(node.getNamespaceURI(), "count"); Integer sampleInt = (Integer) sampleIt.next(); Integer count = (Integer) sampleMap.get(sampleInt); if (band.length() > 0) { countnode.setAttribute("bands", band); } countnode.setAttribute("sample", prefix + HexString(sampleInt.intValue(), digits)); Node textnode = doc.createTextNode(count.toString()); countnode.appendChild(textnode); parent.insertBefore(countnode, node); if (sampleIt.hasNext()) { if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE) { parent.insertBefore(prevSibling.cloneNode(false), node); } } } parent.removeChild(node); node = countnode; } else { Integer count = (Integer) sampleMap.get(Integer.decode(sample)); if (count == null) count = new Integer(0); Node textnode = doc.createTextNode(count.toString()); node.appendChild(textnode); } } } node = node.getNextSibling(); } }
From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java
/** * Finds a XAdES named unsigned signature property as DOM element. * <p/>//from ww w. j a va 2 s . c o m * Working DOM based is required if you want to be able to find the next * sibling at the DOM level. JAXB does not expose this properly. * * @param qualifyingPropertiesElement * the XAdES qualifying properties DOM element. * @param localName * @return * @throws XAdESValidationException */ public static Element findUnsignedSignaturePropertyElement(Element qualifyingPropertiesElement, String localName) throws XAdESValidationException { NodeList unsignedSignaturePropertiesNodeList = qualifyingPropertiesElement .getElementsByTagNameNS(XAdESUtils.XADES_132_NS_URI, "UnsignedSignatureProperties"); if (unsignedSignaturePropertiesNodeList.getLength() == 0) { throw new XAdESValidationException("UnsignedSignatureProperties node not present"); } Node unsignedSignaturePropertiesNode = unsignedSignaturePropertiesNodeList.item(0); NodeList childNodes = unsignedSignaturePropertiesNode.getChildNodes(); int childNodesCount = childNodes.getLength(); for (int idx = 0; idx < childNodesCount; idx++) { Node childNode = childNodes.item(idx); if (Node.ELEMENT_NODE != childNode.getNodeType()) { continue; } Element childElement = (Element) childNode; if (!XAdESUtils.XADES_132_NS_URI.equals(childNode.getNamespaceURI())) { continue; } String actualLocalName = childNode.getLocalName(); if (localName.equals(actualLocalName)) { return childElement; } } return null; }
From source file:eu.semaine.util.XMLTool.java
/** * Create a node iterator for the current document, which will provide exactly * the elements below root in the given namespace whose local names are in localNames. * This is independent of any namespace prefixes. * @param doc/*from ww w . java 2 s .co m*/ * @param root * @param namespaceURI * @param localNames the array of local names to be accepted. * @return */ public static NodeIterator createNodeIterator(Document doc, Node root, final String namespaceURI, final String... localNames) { NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(root, NodeFilter.SHOW_ELEMENT, new NodeFilter() { @Override public short acceptNode(Node n) { if (!isSameNamespace(n.getNamespaceURI(), namespaceURI)) { return NodeFilter.FILTER_SKIP; } for (String localName : localNames) { if (localName.equals(n.getLocalName())) { return NodeFilter.FILTER_ACCEPT; } } return NodeFilter.FILTER_SKIP; } }, false); return ni; }
From source file:com.github.xdcrafts.flower.spring.impl.xml.SyncFlowBeanDefinitionHandler.java
protected void doParse(Element element, BeanDefinitionBuilder bean) { final ManagedList<Object> actions = new ManagedList<>(); final NodeList actionNodes = element.getElementsByTagName("*"); if (actionNodes != null && actionNodes.getLength() != 0) { for (int i = 0; i < actionNodes.getLength(); i++) { final Node node = actionNodes.item(i); final String type = node.getLocalName(); if (type.equalsIgnoreCase("method")) { actions.add(node.getTextContent()); } else if (type.equalsIgnoreCase("action")) { actions.add(new RuntimeBeanReference(node.getTextContent())); } else { throw new IllegalArgumentException("Unknown element type: " + type); }/*ww w . j av a 2 s .co m*/ } } bean.addPropertyValue("actions", actions); }
From source file:com.microsoft.tfs.util.xml.DOMUtils.java
/** * Tests whether the given {@link Node} matches the specified name. No * <code>null</code> checking is done of the <code>node</code> argument. * * @param node// w w w. j av a 2 s . c o m * the {@link Node} to test (must not be <code>null</code>) * @param useNamespaces * <code>true</code> for namespaces mode * @param namespaceURI * the namespace URI to match, <code>null</code> to match no * namespace, <code>*</code> to match any namespace (ignored if * <code>useNamespaces</code> is <code>false</code>) * @param localName * <code>null</code> or <code>*</code> to match any node, matches the * node name if <code>useNamespaces</code> is <code>false</code>, * matches the local name if <code>useNamespaces</code> is * <code>true</code> * @return <code>true</code> if the {@link Node} matches the criteria */ private static boolean matches(final Node node, final boolean useNamespaces, final String namespaceURI, final String localName) { if (useNamespaces) { if (namespaceURI == null && node.getNamespaceURI() != null) { return false; } if (namespaceURI != null && !namespaceURI.equals("*") && !namespaceURI.equals(node.getNamespaceURI())) //$NON-NLS-1$ { return false; } } if (localName == null || localName.equals("*")) //$NON-NLS-1$ { return true; } if (useNamespaces) { return localName.equals(node.getLocalName()); } return localName.equals(node.getNodeName()); }
From source file:fi.vrk.xroad.catalog.lister.WsdlCdataInterceptor.java
@Override public boolean handleResponse(MessageContext messageContext, Object o) throws Exception { WebServiceMessage response = messageContext.getResponse(); SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response; SOAPMessage soapMessage = saajSoapMessage.getSaajMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); Iterator responses = body// w w w .j a v a 2s. c o m .getChildElements(new QName("http://xroad.vrk.fi/xroad-catalog-lister", "GetWsdlResponse")); while (responses.hasNext()) { Node wsdlResponse = (Node) responses.next(); NodeList children = wsdlResponse.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getLocalName().equals("wsdl")) { CDATASection cdat = soapPart.createCDATASection(child.getFirstChild().getNodeValue()); child.removeChild(child.getFirstChild()); child.appendChild(cdat); } } } return true; }
From source file:eu.apenet.dpt.utils.util.extendxsl.EdmQualityCheckerCall.java
@Override public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException { NodeInfo nodeInfo = (NodeInfo) sequences[0].head(); NodeOverNodeInfo nodeOverNodeInfo = NodeOverNodeInfo.wrap(nodeInfo); boolean hasNoIdentifier; //get dc:identifier information from edm:ProvidedCHO String identifier = ""; NodeList childNodes = nodeOverNodeInfo.getChildNodes(); //if dc:identifier exists, set variable, else increment counter hasNoIdentifier = true;/* www . j a v a 2 s . com*/ for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getLocalName() != null && node.getLocalName().equals("identifier") && node.getTextContent() != null && StringUtils.isNotBlank(node.getTextContent())) { hasNoIdentifier = false; identifier = node.getTextContent(); } } if (hasNoIdentifier) { counterNoUnitid++; } //collect all dc:identifier values in Map for detection of duplicates if (StringUtils.isNotBlank(identifier)) { Integer numOccurrence = identifiers.get(identifier); if (numOccurrence == null) { //first count identifiers.put(identifier, 1); } else { identifiers.put(identifier, numOccurrence + 1); } } return StringValue.makeStringValue(""); }
From source file:org.carewebframework.shell.BaseXmlParser.java
/** * Returns the node name. First tries local name. If this is null, returns instead the full node * name.//from ww w .j a v a 2 s .co m * * @param node DOM node to examine. * @return Name of the node. */ protected String getNodeName(Node node) { String result = node.getLocalName(); return result == null ? node.getNodeName() : result; }
From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java
@SuppressWarnings("unchecked") @Override/* www . j a v a 2 s .co m*/ public boolean handleMessage(SOAPMessageContext context) { try { Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); logger.debug("LicenseHandler:{}", out); if (!out) { SOAPMessage message = context.getMessage(); logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message)); SOAPEnvelope enve = message.getSOAPPart().getEnvelope(); SOAPHeader header = enve.getHeader(); SOAPBody body = enve.getBody(); Node bn = body.getChildNodes().item(0); String partname = bn.getLocalName(); if ("getUser".equals(partname)) { if (header == null) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements(); if (!iterator.hasNext()) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } while (iterator.hasNext()) { SOAPHeaderElement ele = iterator.next(); System.out.println(ele.getTextContent()); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
From source file:org.hdiv.config.xml.ValidationBeanDefinitionParser.java
protected void doParse(Element element, BeanDefinitionBuilder bean) { String componentType = element.getAttribute("componentType"); if (StringUtils.hasText(componentType)) { bean.addPropertyValue("componentType", componentType); }// ww w . ja v a2 s. c o m NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getLocalName().equalsIgnoreCase("acceptedPattern")) { String value = node.getTextContent(); if (StringUtils.hasText(value)) { bean.addPropertyValue("acceptedPattern", value); } } if (node.getLocalName().equalsIgnoreCase("rejectedPattern")) { String value = node.getTextContent(); if (StringUtils.hasText(value)) { bean.addPropertyValue("rejectedPattern", value); } } } } }