List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:com.itdhq.contentLoader.ContentLoaderComponent.java
/** * Init parsing method. Should be totally refactored. * * @param file - path to config//from w ww . j a v a2s .co m */ public void parseRootNode(String file) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); File dataStructFile = new File(getClass().getClassLoader().getResource(file).getFile()); Document dataStructConfig = dBuilder.parse(dataStructFile); dataStructConfig.getDocumentElement().normalize(); Node root = dataStructConfig.getDocumentElement(); NodeRef root_folder = null; if (Node.ELEMENT_NODE == root.getNodeType() && root.getNodeName().equals("data")) { Element tmpEl = (Element) root; if ("data" == tmpEl.getNodeName()) { // TODO add correct regexp checker and refactor!!!! logger.debug(tmpEl.getAttribute("store") + "/" + tmpEl.getAttribute("path")); StoreRef spaces = this.getStoreRefByName(tmpEl.getAttribute("store")); List<String> path = Arrays.asList(tmpEl.getAttribute("path").split("/")); root_folder = nodeService.getRootNode(spaces); logger.debug(nodeService.getProperty(root_folder, ContentModel.PROP_NAME)); for (String i : path) { logger.debug("cm:Name " + i); // TODO: it will not work, if the first path component is missing. // Children of store root node should created with nodeService, not fileFolderService // since store root requires custom association type for children. root_folder = this.createDocument(root_folder, i, objects.get("root")); logger.debug(nodeService.getProperty(root_folder, ContentModel.PROP_NAME)); } } else { logger.debug("Not root!"); } NodeList nodes = tmpEl.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { parseNode(root_folder, nodes.item(i)); } } }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handlePluginLoaders(Configuration configuration, Element element) { String loaderName = getRequiredAttribute(element, "name"); String className = getRequiredAttribute(element, "class-name"); Properties properties = new Properties(); String configXML = null;/*from www . j a v a 2s.c o m*/ DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes()); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("init-arg")) { String name = getRequiredAttribute(subElement, "name"); String value = getRequiredAttribute(subElement, "value"); properties.put(name, value); } if (subElement.getNodeName().equals("config-xml")) { DOMElementIterator nodeIter = new DOMElementIterator(subElement.getChildNodes()); if (!nodeIter.hasNext()) { throw new ConfigurationException("Error handling config-xml for plug-in loader '" + loaderName + "', no child node found under initializer element, expecting an element node"); } StringWriter output = new StringWriter(); try { TransformerFactory.newInstance().newTransformer().transform(new DOMSource(nodeIter.next()), new StreamResult(output)); } catch (TransformerException e) { throw new ConfigurationException( "Error handling config-xml for plug-in loader '" + loaderName + "' :" + e.getMessage(), e); } configXML = output.toString(); } } configuration.addPluginLoader(loaderName, className, properties, configXML); }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handlePlugInEventRepresentation(Configuration configuration, Element element) { DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes()); String uri = getRequiredAttribute(element, "uri"); String className = getRequiredAttribute(element, "class-name"); String initializer = null;/* www .java 2s . c o m*/ while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("initializer")) { DOMElementIterator nodeIter = new DOMElementIterator(subElement.getChildNodes()); if (!nodeIter.hasNext()) { throw new ConfigurationException("Error handling initializer for plug-in event representation '" + uri + "', no child node found under initializer element, expecting an element node"); } StringWriter output = new StringWriter(); try { TransformerFactory.newInstance().newTransformer().transform(new DOMSource(nodeIter.next()), new StreamResult(output)); } catch (TransformerException e) { throw new ConfigurationException("Error handling initializer for plug-in event representation '" + uri + "' :" + e.getMessage(), e); } initializer = output.toString(); } } URI uriParsed; try { uriParsed = new URI(uri); } catch (URISyntaxException ex) { throw new ConfigurationException( "Error parsing URI '" + uri + "' as a valid java.net.URI string:" + ex.getMessage(), ex); } configuration.addPlugInEventRepresentation(uriParsed, className, initializer); }
From source file:org.freeeed.search.web.solr.SolrSearchService.java
/** * Parse the given DOM to SolrResult object. * //from w w w .j a va 2s . co m * @param query * @param solrDoc * @return */ private SolrResult buildResult(Document solrDoc) { SolrResult result = new SolrResult(); NodeList responseList = solrDoc.getElementsByTagName("result"); Element responseEl = (Element) responseList.item(0); int totalSize = Integer.parseInt(responseEl.getAttribute("numFound")); result.setTotalSize(totalSize); NodeList documentsList = responseEl.getElementsByTagName("doc"); Map<String, SolrDocument> solrDocuments = new HashMap<String, SolrDocument>(); for (int i = 0; i < documentsList.getLength(); i++) { Element documentEl = (Element) documentsList.item(i); Map<String, List<String>> data = new HashMap<String, List<String>>(); NodeList fieldsList = documentEl.getChildNodes(); for (int j = 0; j < fieldsList.getLength(); j++) { Element field = (Element) fieldsList.item(j); String name = field.getAttribute("name"); List<String> value = new ArrayList<String>(); //multivalues if (field.getNodeName().equals("arr")) { NodeList strList = field.getChildNodes(); for (int k = 0; k < strList.getLength(); k++) { Node strNode = strList.item(k); value.add(strNode.getTextContent()); } } else { value.add(field.getTextContent()); } data.put(name, value); } SolrDocument doc = solrDocumentParser.createSolrDocument(data); solrDocuments.put(doc.getDocumentId(), doc); } result.setDocuments(solrDocuments); return result; }
From source file:com.cloud.agent.api.storage.OVFHelper.java
public void rewriteOVFFile(final String origOvfFilePath, final String newOvfFilePath, final String diskName) { try {// ww w . jav a2 s. c o m final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new File(origOvfFilePath)); NodeList disks = doc.getElementsByTagName("Disk"); NodeList files = doc.getElementsByTagName("File"); NodeList items = doc.getElementsByTagName("Item"); String keepfile = null; List<Element> toremove = new ArrayList<Element>(); for (int j = 0; j < files.getLength(); j++) { Element file = (Element) files.item(j); String href = file.getAttribute("ovf:href"); if (diskName.equals(href)) { keepfile = file.getAttribute("ovf:id"); } else { toremove.add(file); } } String keepdisk = null; for (int i = 0; i < disks.getLength(); i++) { Element disk = (Element) disks.item(i); String fileRef = disk.getAttribute("ovf:fileRef"); if (keepfile == null) { s_logger.info("FATAL: OVA format error"); } else if (keepfile.equals(fileRef)) { keepdisk = disk.getAttribute("ovf:diskId"); } else { toremove.add(disk); } } for (int k = 0; k < items.getLength(); k++) { Element item = (Element) items.item(k); NodeList cn = item.getChildNodes(); for (int l = 0; l < cn.getLength(); l++) { if (cn.item(l) instanceof Element) { Element el = (Element) cn.item(l); if ("rasd:HostResource".equals(el.getNodeName()) && !(el.getTextContent().contains("ovf:/file/" + keepdisk) || el.getTextContent().contains("ovf:/disk/" + keepdisk))) { toremove.add(item); break; } } } } for (Element rme : toremove) { if (rme.getParentNode() != null) { rme.getParentNode().removeChild(rme); } } final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); final DOMSource domSource = new DOMSource(doc); transformer.transform(domSource, result); PrintWriter outfile = new PrintWriter(newOvfFilePath); outfile.write(writer.toString()); outfile.close(); } catch (SAXException | IOException | ParserConfigurationException | TransformerException e) { s_logger.info("Unexpected exception caught while removing network elements from OVF:" + e.getMessage(), e); throw new CloudRuntimeException(e); } }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handlePlugInEventType(Configuration configuration, Element element) { DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes()); List<URI> uris = new ArrayList<URI>(); String name = getRequiredAttribute(element, "name"); String initializer = null;/*from ww w. j a va2 s.c om*/ while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("resolution-uri")) { String uriValue = getRequiredAttribute(subElement, "value"); URI uri; try { uri = new URI(uriValue); } catch (URISyntaxException ex) { throw new ConfigurationException("Error parsing URI '" + uriValue + "' as a valid java.net.URI string:" + ex.getMessage(), ex); } uris.add(uri); } if (subElement.getNodeName().equals("initializer")) { DOMElementIterator nodeIter = new DOMElementIterator(subElement.getChildNodes()); if (!nodeIter.hasNext()) { throw new ConfigurationException("Error handling initializer for plug-in event type '" + name + "', no child node found under initializer element, expecting an element node"); } StringWriter output = new StringWriter(); try { TransformerFactory.newInstance().newTransformer().transform(new DOMSource(nodeIter.next()), new StreamResult(output)); } catch (TransformerException e) { throw new ConfigurationException( "Error handling initializer for plug-in event type '" + name + "' :" + e.getMessage(), e); } initializer = output.toString(); } } configuration.addPlugInEventType(name, uris.toArray(new URI[uris.size()]), initializer); }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleRevisionEventType(Configuration configuration, Element element) { ConfigurationRevisionEventType revEventType = new ConfigurationRevisionEventType(); String revTypeName = getRequiredAttribute(element, "name"); if (element.getAttributes().getNamedItem("property-revision") != null) { String propertyRevision = element.getAttributes().getNamedItem("property-revision").getTextContent(); ConfigurationRevisionEventType.PropertyRevision propertyRevisionEnum; try {//w w w . j a va 2s.c o m propertyRevisionEnum = ConfigurationRevisionEventType.PropertyRevision .valueOf(propertyRevision.trim().toUpperCase()); revEventType.setPropertyRevision(propertyRevisionEnum); } catch (RuntimeException ex) { throw new ConfigurationException( "Invalid enumeration value for property-revision attribute '" + propertyRevision + "'"); } } DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes()); Set<String> keyProperties = new HashSet<String>(); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("base-event-type")) { String name = getRequiredAttribute(subElement, "name"); revEventType.addNameBaseEventType(name); } if (subElement.getNodeName().equals("delta-event-type")) { String name = getRequiredAttribute(subElement, "name"); revEventType.addNameDeltaEventType(name); } if (subElement.getNodeName().equals("key-property")) { String name = getRequiredAttribute(subElement, "name"); keyProperties.add(name); } } String[] keyProps = keyProperties.toArray(new String[keyProperties.size()]); revEventType.setKeyPropertyNames(keyProps); configuration.addRevisionEventType(revTypeName, revEventType); }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleDefaultsEventMeta(Configuration configuration, Element parentElement) { DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes()); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("class-property-resolution")) { Node styleNode = subElement.getAttributes().getNamedItem("style"); if (styleNode != null) { String styleText = styleNode.getTextContent(); Configuration.PropertyResolutionStyle value = Configuration.PropertyResolutionStyle .valueOf(styleText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setClassPropertyResolutionStyle(value); }//from w w w. jav a 2 s.com Node accessorStyleNode = subElement.getAttributes().getNamedItem("accessor-style"); if (accessorStyleNode != null) { String accessorStyleText = accessorStyleNode.getTextContent(); ConfigurationEventTypeLegacy.AccessorStyle value = ConfigurationEventTypeLegacy.AccessorStyle .valueOf(accessorStyleText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setDefaultAccessorStyle(value); } } if (subElement.getNodeName().equals("event-representation")) { Node typeNode = subElement.getAttributes().getNamedItem("type"); if (typeNode != null) { String typeText = typeNode.getTextContent(); Configuration.EventRepresentation value = Configuration.EventRepresentation .valueOf(typeText.toUpperCase()); configuration.getEngineDefaults().getEventMeta().setDefaultEventRepresentation(value); } } if (subElement.getNodeName().equals("anonymous-cache")) { Node sizeNode = subElement.getAttributes().getNamedItem("size"); if (sizeNode != null) { configuration.getEngineDefaults().getEventMeta() .setAnonymousCacheSize(Integer.parseInt(sizeNode.getTextContent())); } } } }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleEventTypeDef(String name, String optionalClassName, Configuration configuration, Node parentNode) {/*from w w w. j a va2 s.c o m*/ DOMElementIterator eventTypeNodeIterator = new DOMElementIterator(parentNode.getChildNodes()); while (eventTypeNodeIterator.hasNext()) { Element eventTypeElement = eventTypeNodeIterator.next(); String nodeName = eventTypeElement.getNodeName(); if (nodeName.equals("xml-dom")) { handleXMLDOM(name, configuration, eventTypeElement); } else if (nodeName.equals("java-util-map")) { handleMap(name, configuration, eventTypeElement); } else if (nodeName.equals("objectarray")) { handleObjectArray(name, configuration, eventTypeElement); } else if (nodeName.equals("legacy-type")) { handleLegacy(name, optionalClassName, configuration, eventTypeElement); } } }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleEngineSettingsDefaults(Configuration configuration, Element parentElement) { DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes()); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("threading")) { handleDefaultsThreading(configuration, subElement); }//from w ww . j av a 2s .com if (subElement.getNodeName().equals("event-meta")) { handleDefaultsEventMeta(configuration, subElement); } if (subElement.getNodeName().equals("view-resources")) { handleDefaultsViewResources(configuration, subElement); } if (subElement.getNodeName().equals("logging")) { handleDefaultsLogging(configuration, subElement); } if (subElement.getNodeName().equals("variables")) { handleDefaultsVariables(configuration, subElement); } if (subElement.getNodeName().equals("patterns")) { handleDefaultsPatterns(configuration, subElement); } if (subElement.getNodeName().equals("stream-selection")) { handleDefaultsStreamSelection(configuration, subElement); } if (subElement.getNodeName().equals("time-source")) { handleDefaultsTimeSource(configuration, subElement); } if (subElement.getNodeName().equals("metrics-reporting")) { handleMetricsReporting(configuration, subElement); } if (subElement.getNodeName().equals("language")) { handleLanguage(configuration, subElement); } if (subElement.getNodeName().equals("expression")) { handleExpression(configuration, subElement); } if (subElement.getNodeName().equals("execution")) { handleExecution(configuration, subElement); } if (subElement.getNodeName().equals("exceptionHandling")) { configuration.getEngineDefaults().getExceptionHandling() .addClasses(getHandlerFactories(subElement)); } if (subElement.getNodeName().equals("conditionHandling")) { configuration.getEngineDefaults().getConditionHandling() .addClasses(getHandlerFactories(subElement)); } if (subElement.getNodeName().equals("scripts")) { handleDefaultScriptConfig(configuration, subElement); } } }