List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:com.marklogic.entityservices.tests.TestInstanceConverterGenerator.java
@Test public void testEnvelopeFunction() throws TestEvalException { for (String entityType : converters.keySet()) { String functionCall = moduleImport(entityType) + "let $p := map:map()" + "let $_ := map:put($p, '$type', 'Order')" + "let $_ := map:put($p, 'prop', 'val')" + "let $_ := map:put($p, '$attachments', element source { 'bah' })" + "return conv:instance-to-envelope( $p )"; DOMHandle handle = evalOneResult(functionCall, new DOMHandle()); Document document = handle.get(); Element docElement = document.getDocumentElement(); assertEquals("envelope function verification", "envelope", docElement.getLocalName()); NodeList nl = docElement.getChildNodes(); assertEquals("Envelope must have two children.", 2, nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { logger.debug("Checking node name " + n.getLocalName()); Element e = (Element) n; assertTrue(e.getLocalName().equals("instance") || e.getLocalName().equals("attachments")); }// w w w .j a v a2s.c o m } } }
From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}/*from w w w.j a v a 2 s . c om*/ */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String tableBeanName = name + TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS; String tableClass = DEFAULT_TABLE_CLASS; if (element.hasAttribute(DATA_SOURCE)) dataSource = element.getAttribute(DATA_SOURCE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); if (element.hasAttribute(PAGEABLE_TABLE_CLASS)) pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS); if (element.hasAttribute(TABLE_CLASS)) tableClass = element.getAttribute(TABLE_CLASS); // create PageableTable BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass); bdb.setScope(scope); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyValue(NAME, pageableTableBeanName); bdb.addPropertyReference(TABLE, tableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyValue(ENTITY_CLASS, entity); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null, bdb.getBeanDefinition()); BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName); // Test Decorators like aop:scoped-proxy NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName())) continue; NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(n.getNamespaceURI()); if (handler != null) { holder = handler.decorate(n, holder, parserContext); } } parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // create ConfigurableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT); if (element.hasAttribute(SELECTABLE)) { bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE)); } else { // set selectable by default bdb.addPropertyValue(SELECTABLE, true); } // parse columns NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:chat.viska.xmpp.plugins.webrtc.WebRtcPlugin.java
private void consumeIq(@Nonnull final Stanza iq) { final Element webrtcElement = (Element) iq.getXml().getDocumentElement().getFirstChild(); final String id = webrtcElement.getAttribute("id"); try {// ww w. j av a2 s .c o m if (StringUtils.isBlank(id)) { throw new StanzaErrorException(iq, StanzaErrorException.Condition.BAD_REQUEST, StanzaErrorException.Type.MODIFY, "No session id found.", null, null, null); } final String actionAttribute = webrtcElement.getAttribute("action"); if ("close".equals(actionAttribute)) { this.eventStream.onNext(new SessionClosingEvent(id)); } else { final boolean creating = "create".equals(actionAttribute); for (Node node : DomUtils.convertToList(webrtcElement.getChildNodes())) { if ("sdp".equals(node.getLocalName())) { final SessionDescription.Type type; try { type = SessionDescription.Type.fromCanonicalForm(((Element) node).getAttribute("type")); } catch (Exception ex) { throw new StanzaErrorException(iq, StanzaErrorException.Condition.BAD_REQUEST, StanzaErrorException.Type.MODIFY, "SDP type unknown.", null, null, null); } this.eventStream.onNext( new SdpReceivedEvent(new SessionDescription(type, convertSdpElementsToString(node)), id, iq.getSender(), creating)); } else if ("ice-candidate".equals(node.getLocalName())) { consumeIceCandidate((Element) node, id, creating); } } } } catch (StanzaErrorException ex) { this.context.sendError(ex); } }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
@SuppressWarnings("unchecked") private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException { XTeeHeader pais = new XTeeHeader(); if (paringMessage.getSOAPHeader() == null) { return pais; }/*from ww w . ja v a 2 s. c om*/ SOAPHeader header = paringMessage.getSOAPHeader(); for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) { Node headerElement = headerElemendid.next(); if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) { String localName = headerElement.getLocalName(); String value = headerElement.getFirstChild().getNodeValue(); pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value); } } return pais; }
From source file:org.apache.taverna.activities.wsdl.T2WSDLSOAPInvoker.java
@Override protected void addSoapHeader(SOAPEnvelope envelope) throws SOAPException { if (wsrfEndpointReference != null) { // Extract elements // Add WSA-stuff // Add elements Document wsrfDoc;//from ww w . ja v a2 s. co m try { wsrfDoc = parseWsrfEndpointReference(wsrfEndpointReference); } catch (Exception e) { logger.warn("Could not parse endpoint reference, ignoring:\n" + wsrfEndpointReference, e); return; } Element wsrfRoot = wsrfDoc.getDocumentElement(); Element endpointRefElem = null; if (!wsrfRoot.getNamespaceURI().equals(WSA200403NS) || !wsrfRoot.getLocalName().equals(ENDPOINT_REFERENCE)) { // Only look for child if the parent is not an EPR NodeList nodes = wsrfRoot.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(ENDPOINT_REFERENCE) && node.getNamespaceURI().equals(WSA200403NS)) { // Support wrapped endpoint reference for backward compatibility // and convenience (T2-677) endpointRefElem = (Element) node; break; } } } if (endpointRefElem == null) { logger.warn("Unexpected element name for endpoint reference, but inserting anyway: " + wsrfRoot.getTagName()); endpointRefElem = wsrfRoot; } Element refPropsElem = null; NodeList nodes = endpointRefElem.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(REFERENCE_PROPERTIES) && node.getNamespaceURI().equals(WSA200403NS)) { refPropsElem = (Element) node; break; } } if (refPropsElem == null) { logger.warn("Could not find " + REFERENCE_PROPERTIES); return; } SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } NodeList refProps = refPropsElem.getChildNodes(); for (int i = 0, n = refProps.getLength(); i < n; i++) { Node node = refProps.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) { SOAPElement soapElement = SOAPFactory.newInstance().createElement((Element) node); header.addChildElement(soapElement); Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements(); while (headers.hasNext()) { SOAPHeaderElement headerElement = headers.next(); if (headerElement.getElementQName().equals(soapElement.getElementQName())) { headerElement.setMustUnderstand(false); headerElement.setActor(null); } } } } } }
From source file:org.solmix.runtime.support.spring.AbstractRootBeanDefinitionParser.java
protected void parseArguments(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) {//from w ww. j a v a 2 s .c o m if (nodeList != null && nodeList.getLength() > 0) { ManagedList arguments = null; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element element = (Element) node; if ("argument".equals(node.getNodeName()) || "argument".equals(node.getLocalName())) { String argumentIndex = element.getAttribute("index"); if (arguments == null) { arguments = new ManagedList(); } BeanDefinition argumentBeanDefinition = parse(((Element) node), parserContext, /*ArgumentConfig.class*/null); String name = id + "." + argumentIndex; BeanDefinitionHolder argumentBeanDefinitionHolder = new BeanDefinitionHolder( argumentBeanDefinition, name); arguments.add(argumentBeanDefinitionHolder); } } } if (arguments != null) { beanDefinition.getPropertyValues().addPropertyValue("arguments", arguments); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.xml.XmlReaderXPath.java
/** * Add the text in current node to document text buffer, create and add to index a Field * annotation out of the text. This usually processes a document. *//*from w w w . j a v a 2 s . c o m*/ private void processNode(CAS cas, Node node, StringBuilder documentText) { if (node.hasChildNodes()) { if (docIdTag != null) { ensureIdValidity(node); } NodeList docFields = node.getChildNodes(); for (int i = 0; i < docFields.getLength(); i++) { Node field = docFields.item(i); int begin = documentText.length(); String nodeTag = field.getLocalName(); if (nodeTag != null && isIncluded(nodeTag)) { String nodeText = field.getTextContent(); documentText = documentText.append(nodeText); int end = documentText.length(); documentText = documentText.append("\n"); // Substitue tag if specified if (useSubstitution && substitution.containsKey(nodeTag)) { nodeTag = substitution.get(nodeTag); } createFieldAnnotation(cas, nodeTag, begin, end); } } } }
From source file:hudson.plugins.plot.XMLSeries.java
/** * Load the series from a properties file. *///from ww w . j a va 2s. co m @Override public List<PlotPoint> loadSeries(FilePath workspaceRootDir, int buildNumber, PrintStream logger) { InputStream in = null; InputSource inputSource = null; try { List<PlotPoint> ret = new ArrayList<PlotPoint>(); FilePath[] seriesFiles = null; try { seriesFiles = workspaceRootDir.list(getFile()); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception trying to retrieve series files", e); return null; } if (ArrayUtils.isEmpty(seriesFiles)) { LOGGER.info("No plot data file found: " + getFile()); return null; } try { if (LOGGER.isLoggable(defaultLogLevel)) LOGGER.log(defaultLogLevel, "Loading plot series data from: " + getFile()); in = seriesFiles[0].read(); // load existing plot file inputSource = new InputSource(in); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Exception reading plot series data from " + seriesFiles[0], e); return null; } if (LOGGER.isLoggable(defaultLogLevel)) LOGGER.log(defaultLogLevel, "NodeType " + nodeTypeString + " : " + nodeType); if (LOGGER.isLoggable(defaultLogLevel)) LOGGER.log(defaultLogLevel, "Loaded XML Plot file: " + getFile()); XPath xpath = XPathFactory.newInstance().newXPath(); Object xmlObject = xpath.evaluate(xpathString, inputSource, nodeType); /* * If we have a nodeset, we need multiples, otherwise we just need * one value, and can do a toString() to set it. */ if (nodeType.equals(XPathConstants.NODESET)) { NodeList nl = (NodeList) xmlObject; if (LOGGER.isLoggable(defaultLogLevel)) LOGGER.log(defaultLogLevel, "Number of nodes: " + nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (!new Scanner(node.getTextContent().trim()).hasNextDouble()) { return coalesceTextnodesAsLabelsStrategy(nl, buildNumber); } } return mapNodeNameAsLabelTextContentAsValueStrategy(nl, buildNumber); } else if (nodeType.equals(XPathConstants.NODE)) { addNodeToList(ret, (Node) xmlObject, buildNumber); } else { // otherwise we have a single type and can do a toString on it. if (xmlObject instanceof NodeList) { NodeList nl = (NodeList) xmlObject; if (LOGGER.isLoggable(defaultLogLevel)) LOGGER.log(defaultLogLevel, "Number of nodes: " + nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n != null && n.getLocalName() != null && n.getTextContent() != null) { addValueToList(ret, label, xmlObject, buildNumber); } } } else { addValueToList(ret, label, xmlObject, buildNumber); } } return ret; } catch (XPathExpressionException e) { LOGGER.log(Level.SEVERE, "XPathExpressionException for XPath '" + getXpath() + "'", e); } finally { IOUtils.closeQuietly(in); } return null; }
From source file:de.betterform.xml.xforms.ui.Item.java
private Element findElement(NodeList nodes, String namespace, String localName) { for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); if (child instanceof Element) { if (child.getNamespaceURI().equals(namespace) && child.getLocalName().equals(localName)) { return (Element) child; }//from w ww.ja va2 s . c o m } } return null; }