Example usage for org.w3c.dom Element getNodeName

List of usage examples for org.w3c.dom Element getNodeName

Introduction

In this page you can find the example usage for org.w3c.dom Element getNodeName.

Prototype

public String getNodeName();

Source Link

Document

The name of this node, depending on its type; see the table above.

Usage

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleDefaultsTimeSource(Configuration configuration, Element parentElement) {
    DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("time-source-type")) {
            String valueText = getRequiredAttribute(subElement, "value");
            if (valueText == null) {
                throw new ConfigurationException("No value attribute supplied for time-source element");
            }/*from   w w w.j a v a  2s .c o m*/
            ConfigurationEngineDefaults.TimeSourceType timeSourceType;
            if (valueText.toUpperCase().trim().equals("NANO")) {
                timeSourceType = ConfigurationEngineDefaults.TimeSourceType.NANO;
            } else if (valueText.toUpperCase().trim().equals("MILLI")) {
                timeSourceType = ConfigurationEngineDefaults.TimeSourceType.MILLI;
            } else {
                throw new ConfigurationException("Value attribute for time-source element invalid, "
                        + "expected one of the following keywords: nano, milli");
            }
            configuration.getEngineDefaults().getTimeSource().setTimeSourceType(timeSourceType);
        }
    }
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handlePlugInMultiFunctionAggregation(Configuration configuration, Element element) {
    String functionNames = getRequiredAttribute(element, "function-names");
    String factoryClassName = getOptionalAttribute(element, "factory-class");

    DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes());
    Map<String, Object> additionalProps = null;
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("init-arg")) {
            String name = getRequiredAttribute(subElement, "name");
            String value = getRequiredAttribute(subElement, "value");
            if (additionalProps == null) {
                additionalProps = new HashMap<String, Object>();
            }// w  w  w  .  ja  va 2 s  . c o  m
            additionalProps.put(name, value);
        }
    }

    ConfigurationPlugInAggregationMultiFunction config = new ConfigurationPlugInAggregationMultiFunction(
            functionNames.split(","), factoryClassName);
    config.setAdditionalConfiguredProperties(additionalProps);
    configuration.addPlugInAggregationMultiFunction(config);
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleMethodReference(Configuration configuration, Element element) {
    String className = getRequiredAttribute(element, "class-name");
    ConfigurationMethodRef configMethodRef = new ConfigurationMethodRef();
    configuration.addMethodRef(className, configMethodRef);

    DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("expiry-time-cache")) {
            String maxAge = getRequiredAttribute(subElement, "max-age-seconds");
            String purgeInterval = getRequiredAttribute(subElement, "purge-interval-seconds");
            ConfigurationCacheReferenceType refTypeEnum = ConfigurationCacheReferenceType.getDefault();
            if (subElement.getAttributes().getNamedItem("ref-type") != null) {
                String refType = subElement.getAttributes().getNamedItem("ref-type").getTextContent();
                refTypeEnum = ConfigurationCacheReferenceType.valueOf(refType.toUpperCase());
            }//from ww  w.  ja  v  a  2s .co  m
            configMethodRef.setExpiryTimeCache(Double.parseDouble(maxAge), Double.parseDouble(purgeInterval),
                    refTypeEnum);
        } else if (subElement.getNodeName().equals("lru-cache")) {
            String size = getRequiredAttribute(subElement, "size");
            configMethodRef.setLRUCache(Integer.parseInt(size));
        }
    }
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleDefaultsStreamSelection(Configuration configuration, Element parentElement) {
    DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("stream-selector")) {
            String valueText = getRequiredAttribute(subElement, "value");
            if (valueText == null) {
                throw new ConfigurationException("No value attribute supplied for stream-selector element");
            }//from w ww .jav a 2 s  .c  o  m
            StreamSelector defaultSelector;
            if (valueText.toUpperCase().trim().equals("ISTREAM")) {
                defaultSelector = StreamSelector.ISTREAM_ONLY;
            } else if (valueText.toUpperCase().trim().equals("RSTREAM")) {
                defaultSelector = StreamSelector.RSTREAM_ONLY;
            } else if (valueText.toUpperCase().trim().equals("IRSTREAM")) {
                defaultSelector = StreamSelector.RSTREAM_ISTREAM_BOTH;
            } else {
                throw new ConfigurationException("Value attribute for stream-selector element invalid, "
                        + "expected one of the following keywords: istream, irstream, rstream");
            }
            configuration.getEngineDefaults().getStreamSelection().setDefaultStreamSelector(defaultSelector);
        }
    }
}

From source file:com.itdhq.contentLoader.ContentLoaderComponent.java

/**
 * Usual node parser/*w w w.  j  av  a 2s . co m*/
 *
 * @param parent
 * @param node
 */
private void parseNode(NodeRef parent, Node node) {
    logger.debug("parseNode");
    if (Node.ELEMENT_NODE == node.getNodeType() && node.getNodeName().equals("node")) {
        Element tmpEl = (Element) node;
        logger.debug(tmpEl.getNodeName() + "; name: " + tmpEl.getAttribute("name") + "; object: "
                + tmpEl.getAttribute("object") + "; count: " + tmpEl.getAttribute("count"));
        int count = Integer.parseInt(tmpEl.getAttribute("count"));
        if (count > 0) {
            logger.debug(Integer.toString(count) + " - number.");
            NodeRef tmp1 = this.createDocument(parent, tmpEl.getAttribute("name"),
                    objects.get(tmpEl.getAttribute("object")));
            logger.debug(nodeService.getProperty(tmp1, ContentModel.PROP_NAME));
            NodeList nodes = tmpEl.getChildNodes();
            for (int i = 0; i < nodes.getLength(); ++i) {
                parseNode(tmp1, nodes.item(i));
            }
            for (int j = 1; j < count; ++j) {
                NodeRef tmp = this.createDocument(parent,
                        tmpEl.getAttribute("name") + " " + Integer.toString(j),
                        objects.get(tmpEl.getAttribute("object")));
                logger.debug(nodeService.getProperty(tmp, ContentModel.PROP_NAME));
                nodes = tmpEl.getChildNodes();
                for (int i = 0; i < nodes.getLength(); ++i) {
                    parseNode(tmp, nodes.item(i));
                }
            }
        }
    }
}

From source file:immf.growl.GrowlApiClient.java

private GrowlApiResult analyzeResponse(HttpResponse res) {

    GrowlApiResult result = GrowlApiResult.ERROR;

    if (res == null) {
        GrowlNotifier.log.info("HttpResponse is null");
        this.incrementInternalServerErrorCount();
        return GrowlApiResult.ERROR;
    } else {/*from w  w w  . ja  v a2 s. c om*/
        decrementCallsRemaining();
        int status = res.getStatusLine().getStatusCode();
        switch (status) {
        case 200:
            log.info("Api call is success.");
            result = GrowlApiResult.SUCCESS;
            break;
        case 400:
            log.error("The data supplied is in the wrong format, invalid length or null.");
            result = GrowlApiResult.INVALID;
            break;
        case 401:
            log.error("The 'apikey' provided is not valid.");
            result = GrowlApiResult.INVALID;
            break;
        case 402:
        case 406:
            log.error("Maximum number of API calls exceeded.");
            result = GrowlApiResult.EXCEEDED;
            break;
        case 500:
            log.error("Internal server error.");
            this.incrementInternalServerErrorCount();
            result = GrowlApiResult.ERROR;
            break;
        default:
            ;
        }

        if (status == 200 || status == 402 || status == 406) {
            HttpEntity entity = res.getEntity();
            try {
                final InputStream in = entity.getContent();
                final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                final Document resDoc = builder.parse(in);

                // ??
                Element rootNode = resDoc.getDocumentElement();
                if (rootNode != null && this.topLevelTag.equals(rootNode.getNodeName())) {
                    NodeList rootChildren = rootNode.getChildNodes();
                    for (int i = 0, max = rootChildren.getLength(); i < max; i++) {
                        Node node = rootChildren.item(i);
                        if (TAG_ERROR.equals(node.getNodeName()) || TAG_SUCCESS.equals(node.getNodeName())) {
                            NamedNodeMap attrs = node.getAttributes();
                            if (attrs != null) {
                                Node attrNode = attrs.getNamedItem(ATTR_RESETTIMER);
                                if (attrNode != null && attrNode.getNodeValue().length() > 0) {
                                    setResetTimer(Integer.parseInt(attrNode.getNodeValue()));
                                }
                                attrNode = attrs.getNamedItem(ATTR_RESETDATE);
                                if (attrNode != null && attrNode.getNodeValue().length() > 0) {
                                    setResetDate(Integer.parseInt(attrNode.getNodeValue()));
                                }
                                attrNode = attrs.getNamedItem(ATTR_REMAINING);
                                if (attrNode != null && attrNode.getNodeValue().length() > 0) {
                                    int remaining = Integer.parseInt(attrNode.getNodeValue());
                                    setCallsRemaining(remaining);
                                }
                            }
                        }
                    }
                }
            } catch (IllegalStateException e) {
                log.error(e.getMessage());
            } catch (IOException e) {
                log.error(e.getMessage());
            } catch (ParserConfigurationException e) {
                log.error(e.getMessage());
            } catch (SAXException e) {
                log.error(e.getMessage());
            }
        }

        return result;

    }
}

From source file:com.athena.chameleon.engine.core.analyzer.parser.PomXMLParser.java

/**
 * <pre>/*from   w w  w . j a v a2s  . c  om*/
 * 
 * </pre>
 * @param model
 * @param path
 * @return
 * @throws IOException 
 * @throws JAXBException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 */
private Object checkDependency(Object model, String path)
        throws JAXBException, IOException, IllegalAccessException, InvocationTargetException {
    Dependencies dependencies = ((Model) model).getDependencies();
    List<Dependency> dependencyList = dependencies.getDependency();

    boolean isChanged = false;
    MavenDependency mavenDependency = null;
    for (Dependency dependency : dependencyList) {
        mavenDependency = new MavenDependency();
        BeanUtils.copyProperties(mavenDependency, dependency);

        if (mavenDependency.getVersion().startsWith("${") && mavenDependency.getVersion().endsWith("}")) {
            List<Element> elementList = ((Model) model).getProperties().getAny();

            for (Element element : elementList) {
                if (StringUtils.equals(
                        mavenDependency.getVersion().substring(2, mavenDependency.getVersion().length() - 1),
                        element.getNodeName())) {
                    mavenDependency.setVersion(element.getTextContent());
                    break;
                }
            }
        }

        analyzeDefinition.getMavenDependencyList().add(mavenDependency);

        if (dependency.getGroupId().equals("xerces") && dependency.getArtifactId().equals("xercesImpl")
                && !StringUtils.equals(dependency.getScope(), "provided")) {
            isChanged = true;
            dependency.setScope("provided");

            mavenDependency = new MavenDependency();
            BeanUtils.copyProperties(mavenDependency, dependency);
            analyzeDefinition.getModifiedMavenDependencyList().add(mavenDependency);
        } else if (dependency.getGroupId().equals("xml-apis") && dependency.getArtifactId().equals("xml-apis")
                && !StringUtils.equals(dependency.getScope(), "provided")) {
            isChanged = true;
            dependency.setScope("provided");

            mavenDependency = new MavenDependency();
            BeanUtils.copyProperties(mavenDependency, dependency);
            analyzeDefinition.getModifiedMavenDependencyList().add(mavenDependency);
        } else if (dependency.getGroupId().equals("xalan") && dependency.getArtifactId().equals("xalan")
                && !StringUtils.equals(dependency.getScope(), "provided")) {
            isChanged = true;
            dependency.setScope("provided");

            mavenDependency = new MavenDependency();
            BeanUtils.copyProperties(mavenDependency, dependency);
            analyzeDefinition.getModifiedMavenDependencyList().add(mavenDependency);
        }
    }

    if (isChanged) {
        // pom.xml 
        String xmlData = JaxbUtils.marshal(Model.class.getPackage().getName(), model,
                new String[] {
                        "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" },
                true);
        rewrite(new File(path, "pom.xml"), xmlData);
        logger.debug("pom.xml has been modified.\n{}", xmlData);

        CommonAnalyze commonAnalyze = null;
        commonAnalyze = new CommonAnalyze();
        commonAnalyze.setItem(analyzeDefinition.getMavenProjectList().get(0).getItem());
        commonAnalyze.setLocation(analyzeDefinition.getMavenProjectList().get(0).getLocation());
        commonAnalyze.setContents(xmlData);

        analyzeDefinition.getMavenProjectList().add(commonAnalyze);
    }

    return model;
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleVariantStream(Configuration configuration, Element element) {
    ConfigurationVariantStream variantStream = new ConfigurationVariantStream();
    String varianceName = getRequiredAttribute(element, "name");

    if (element.getAttributes().getNamedItem("type-variance") != null) {
        String typeVar = element.getAttributes().getNamedItem("type-variance").getTextContent();
        ConfigurationVariantStream.TypeVariance typeVarianceEnum;
        try {/*from  w  w w.  ja  v a 2  s  . c  o  m*/
            typeVarianceEnum = ConfigurationVariantStream.TypeVariance.valueOf(typeVar.trim().toUpperCase());
            variantStream.setTypeVariance(typeVarianceEnum);
        } catch (RuntimeException ex) {
            throw new ConfigurationException(
                    "Invalid enumeration value for type-variance attribute '" + typeVar + "'");
        }
    }

    DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("variant-event-type")) {
            String name = subElement.getAttributes().getNamedItem("name").getTextContent();
            variantStream.addEventTypeName(name);
        }
    }

    configuration.addVariantStream(varianceName, variantStream);
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleMetricsReportingPatterns(ConfigurationMetricsReporting.StmtGroupMetrics groupDef,
        Element parentElement) {/*from   w  ww  . j av  a  2s .  c o m*/
    DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("include-regex")) {
            String text = subElement.getChildNodes().item(0).getTextContent();
            groupDef.getPatterns()
                    .add(new Pair<StringPatternSet, Boolean>(new StringPatternSetRegex(text), true));
        }
        if (subElement.getNodeName().equals("exclude-regex")) {
            String text = subElement.getChildNodes().item(0).getTextContent();
            groupDef.getPatterns()
                    .add(new Pair<StringPatternSet, Boolean>(new StringPatternSetRegex(text), false));
        }
        if (subElement.getNodeName().equals("include-like")) {
            String text = subElement.getChildNodes().item(0).getTextContent();
            groupDef.getPatterns()
                    .add(new Pair<StringPatternSet, Boolean>(new StringPatternSetLike(text), true));
        }
        if (subElement.getNodeName().equals("exclude-like")) {
            String text = subElement.getChildNodes().item(0).getTextContent();
            groupDef.getPatterns()
                    .add(new Pair<StringPatternSet, Boolean>(new StringPatternSetLike(text), false));
        }
    }
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleDefaultsLogging(Configuration configuration, Element parentElement) {
    DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("execution-path")) {
            String valueText = getRequiredAttribute(subElement, "enabled");
            Boolean value = Boolean.parseBoolean(valueText);
            configuration.getEngineDefaults().getLogging().setEnableExecutionDebug(value);
        }//  w  ww .j a v a2s .c o m
        if (subElement.getNodeName().equals("timer-debug")) {
            String valueText = getRequiredAttribute(subElement, "enabled");
            Boolean value = Boolean.parseBoolean(valueText);
            configuration.getEngineDefaults().getLogging().setEnableTimerDebug(value);
        }
        if (subElement.getNodeName().equals("query-plan")) {
            String valueText = getRequiredAttribute(subElement, "enabled");
            Boolean value = Boolean.parseBoolean(valueText);
            configuration.getEngineDefaults().getLogging().setEnableQueryPlan(value);
        }
        if (subElement.getNodeName().equals("jdbc")) {
            String valueText = getRequiredAttribute(subElement, "enabled");
            Boolean value = Boolean.parseBoolean(valueText);
            configuration.getEngineDefaults().getLogging().setEnableJDBC(value);
        }
        if (subElement.getNodeName().equals("audit")) {
            configuration.getEngineDefaults().getLogging()
                    .setAuditPattern(getOptionalAttribute(subElement, "pattern"));
        }
    }
}