List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
/** * Reads in all the url patterns to exclude from decoration. */// w ww. j av a 2 s.c om private void loadExcludeUrls(NodeList nodes) { clearExcludeUrls(); for (int i = 0; i < nodes.getLength(); i++) { if (nodes.item(i) instanceof Element) { Element p = (Element) nodes.item(i); if ("pattern".equalsIgnoreCase(p.getTagName()) || "url-pattern".equalsIgnoreCase(p.getTagName())) { Text patternText = (Text) p.getFirstChild(); if (patternText != null) { String pattern = patternText.getData().trim(); if (pattern != null) { addExcludeUrl(pattern); } } } } } }
From source file:org.commonjava.maven.galley.maven.model.view.AbstractMavenElementView.java
protected final List<Element> getElements(final String path) { if (path.contains("/")) { final List<Node> nodes = getNodes(path); if (nodes != null) { final List<Element> elements = new ArrayList<>(); for (final Node node : nodes) { elements.add((Element) node); }/* w ww. j a v a2 s . c o m*/ return elements; } } else { final NodeList nl = getCollapsedElement().getChildNodes(); final List<Element> elements = new ArrayList<>(); for (int i = 0; i < nl.getLength(); i++) { final Node node = nl.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element e = (Element) node; if ("*".equals(path) || e.getTagName().equals(path)) { elements.add((Element) node); } } } return elements; } return null; }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
/** * @see org.commonreality.sensors.xml.processor.IXMLProcessor#process(org.w3c.dom.Element, * org.commonreality.identifier.IIdentifier, * org.commonreality.sensors.xml.XMLSensor) */// ww w .j a v a2 s. co m public Collection<IMessage> process(Element element, IIdentifier agentID, XMLSensor sensor) { Collection<IMessage> rtn = new ArrayList<IMessage>(); Collection<IObjectDelta> added = new ArrayList<IObjectDelta>(); Collection<IIdentifier> addedIds = new ArrayList<IIdentifier>(); Collection<IObjectDelta> updated = new ArrayList<IObjectDelta>(); Collection<IIdentifier> updatedIds = new ArrayList<IIdentifier>(); Collection<IIdentifier> removedIds = new ArrayList<IIdentifier>(); Collection<NodeList> nodeLists = new ArrayList<NodeList>(); nodeLists.add(element.getElementsByTagName("add")); nodeLists.add(element.getElementsByTagName("update")); nodeLists.add(element.getElementsByTagName("remove")); for (NodeList nl : nodeLists) for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); if (!(child instanceof Element)) continue; Element childElement = (Element) child; String tagName = childElement.getTagName(); /** * remove all that match a pattern */ if (tagName.equalsIgnoreCase("remove") && childElement.hasAttribute("pattern") && _aliases.containsKey(agentID)) { Pattern pattern = Pattern.compile(childElement.getAttribute("pattern")); Collection<String> aliases = new ArrayList<String>(_aliases.get(agentID).keySet()); for (String alias : aliases) if (pattern.matcher(alias).matches()) { IIdentifier objectId = getIdentifier(alias, agentID); if (objectId != null) { removeIdentifier(alias, agentID); removedIds.add(objectId); } } } else if (shouldProcess(childElement, agentID) && childElement.hasAttribute("alias")) if (tagName.equalsIgnoreCase("add")) { IObjectDelta delta = add(childElement, agentID, sensor); if (delta != null) { added.add(delta); addedIds.add(delta.getIdentifier()); } } else if (tagName.equalsIgnoreCase("update")) { IObjectDelta delta = update(childElement, agentID, sensor); if (delta != null) { updated.add(delta); updatedIds.add(delta.getIdentifier()); } } else if (tagName.equalsIgnoreCase("remove")) { IIdentifier id = remove(childElement, agentID, sensor); if (id != null) removedIds.add(id); } } IIdentifier sId = sensor.getIdentifier(); /* * handle all the adds, updates and removes send the data first.. */ if (added.size() != 0) { rtn.add(new ObjectDataRequest(sId, agentID, added)); rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.ADDED, addedIds)); } if (updated.size() != 0) { rtn.add(new ObjectDataRequest(sId, agentID, updated)); rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.UPDATED, updatedIds)); } if (removedIds.size() != 0) rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.REMOVED, removedIds)); return rtn; }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processContent(IMutableObject realObject, Node content) { if (!(content instanceof Element)) return;/*w w w .ja v a 2 s. c o m*/ Element element = (Element) content; String tagName = element.getTagName(); if (tagName.equalsIgnoreCase("double")) processDouble(realObject, element); else if (tagName.equalsIgnoreCase("doubles")) processDoubles(realObject, element); else if (tagName.equalsIgnoreCase("string")) processString(realObject, element); else if (tagName.equalsIgnoreCase("strings")) processStrings(realObject, element); else if (tagName.equalsIgnoreCase("boolean")) processBoolean(realObject, element); else if (tagName.equalsIgnoreCase("int")) processInt(realObject, element); else if (tagName.equalsIgnoreCase("ints")) processInts(realObject, element); else { /* * process children */ NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) processContent(realObject, nl.item(i)); } }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processDouble(IMutableObject realObject, Element element) { String name = element.getAttribute("name"); String str = element.getAttribute("value"); try {//from ww w.j a va 2 s . co m realObject.setProperty(name, Double.valueOf(str)); } catch (NumberFormatException nfe) { LOGGER.warn(element.getTagName() + "." + name + " not properly formatted : " + str); } }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processDoubles(IMutableObject realObject, Element element) { String name = element.getAttribute("name"); Collection<Double> doubles = new ArrayList<Double>(); String[] strings = getStrings(element); for (String element2 : strings) try {//from w w w .j a v a2s . co m doubles.add(Double.valueOf(element2)); } catch (NumberFormatException nfe) { LOGGER.warn(element.getTagName() + "." + name + " not properly formatted : " + element2); } double[] dbls = new double[doubles.size()]; int i = 0; for (Double d : doubles) dbls[i++] = d; realObject.setProperty(name, dbls); }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processBoolean(IMutableObject realObject, Element element) { String name = element.getAttribute("name"); try {/*from w w w. jav a 2 s. com*/ realObject.setProperty(name, Boolean.valueOf(element.getAttribute("value"))); } catch (Exception e) { LOGGER.warn(element.getTagName() + "." + name + " not properly formatted : " + element.getAttribute("value")); } }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processInt(IMutableObject realObject, Element element) { String name = element.getAttribute("name"); String str = element.getAttribute("value"); try {/*from w w w. ja v a 2 s . co m*/ realObject.setProperty(name, Integer.valueOf(str)); } catch (NumberFormatException nfe) { LOGGER.warn(element.getTagName() + "." + name + " not properly formatted : " + str); } }
From source file:org.commonreality.sensors.xml.processor.AbstractProcessor.java
protected void processInts(IMutableObject realObject, Element element) { String name = element.getAttribute("name"); Collection<Integer> integers = new ArrayList<Integer>(); String[] strings = getStrings(element); for (String element2 : strings) try {/*w w w. ja v a2s . c o m*/ integers.add(Integer.valueOf(element2)); } catch (NumberFormatException nfe) { LOGGER.warn(element.getTagName() + "." + name + " not properly formatted : " + element2); } int[] ints = new int[integers.size()]; int i = 0; for (Integer d : integers) ints[i++] = d; realObject.setProperty(name, ints); }
From source file:org.commonreality.sensors.xml2.processor.AbstractProcessor.java
/** * @see org.commonreality.sensors.xml.processor.IXMLProcessor#process(org.w3c.dom.Element, * org.commonreality.identifier.IIdentifier, * org.commonreality.sensors.xml.XMLSensor) *//*from w w w . j av a 2 s . com*/ public Collection<IMessage> process(Element element, IIdentifier agentID, XMLSensor sensor) { Collection<IMessage> rtn = new ArrayList<IMessage>(); Collection<IObjectDelta> added = new ArrayList<IObjectDelta>(); Collection<IIdentifier> addedIds = new ArrayList<IIdentifier>(); Collection<IObjectDelta> updated = new ArrayList<IObjectDelta>(); Collection<IIdentifier> updatedIds = new ArrayList<IIdentifier>(); Collection<IIdentifier> removedIds = new ArrayList<IIdentifier>(); Collection<NodeList> nodeLists = new ArrayList<NodeList>(); nodeLists.add(element.getElementsByTagName("add")); nodeLists.add(element.getElementsByTagName("update")); nodeLists.add(element.getElementsByTagName("remove")); for (NodeList nl : nodeLists) for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); if (!(child instanceof Element)) continue; Element childElement = (Element) child; String tagName = childElement.getTagName(); String forWhichAgent = childElement.getAttribute("for"); if (forWhichAgent != null && forWhichAgent.length() > 0) { IAgentObject ao = sensor.getAgentObjectManager().get(agentID); String agentName = (String) ao.getProperty("name"); if (agentName == null) LOGGER.error("Agent name was not set for " + agentID); else if (!agentName.equals(forWhichAgent)) { if (LOGGER.isDebugEnabled()) LOGGER.debug( String.format("agentId %s does not match targeted name %s, skipping processing", agentName, forWhichAgent)); continue; } } /** * remove all that match a pattern */ if (tagName.equalsIgnoreCase("remove") && childElement.hasAttribute("pattern") && _aliases.containsKey(agentID)) { Pattern pattern = Pattern.compile(childElement.getAttribute("pattern")); Collection<String> aliases = new ArrayList<String>(_aliases.get(agentID).keySet()); for (String alias : aliases) if (pattern.matcher(alias).matches()) { IIdentifier objectId = getIdentifier(alias, agentID); if (objectId != null) { removeIdentifier(alias, agentID); removedIds.add(objectId); } } } else if (shouldProcess(childElement, agentID) && childElement.hasAttribute("alias")) if (tagName.equalsIgnoreCase("add")) { IObjectDelta delta = add(childElement, agentID, sensor); if (delta != null) { added.add(delta); addedIds.add(delta.getIdentifier()); } } else if (tagName.equalsIgnoreCase("update")) { IObjectDelta delta = update(childElement, agentID, sensor); if (delta != null) { updated.add(delta); updatedIds.add(delta.getIdentifier()); } } else if (tagName.equalsIgnoreCase("remove")) { IIdentifier id = remove(childElement, agentID, sensor); if (id != null) removedIds.add(id); } } IIdentifier sId = sensor.getIdentifier(); /* * handle all the adds, updates and removes send the data first.. */ if (added.size() != 0) { rtn.add(new ObjectDataRequest(sId, agentID, added)); rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.ADDED, addedIds)); } if (updated.size() != 0) { rtn.add(new ObjectDataRequest(sId, agentID, updated)); rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.UPDATED, updatedIds)); } if (removedIds.size() != 0) rtn.add(new ObjectCommandRequest(sId, agentID, IObjectCommand.Type.REMOVED, removedIds)); return rtn; }