Example usage for org.w3c.dom Element hasAttribute

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

Introduction

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

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java

/**
 * Parse the validation element and register the resulting bean definitions
 *
 * @param element        element that is to be parsed into one or more
 *                       <tt>BeanDefinitions</tt>
 * @param parserContext  the object encapsulating the current state of the
 *                       parsing process
 * //from  w  w w  .  j  a va  2s  .c  o  m
 * @return the primary <tt>BeanDefinition</tt>
 */
public BeanDefinition parse(Element element, ParserContext parserContext) {
    if (!element.hasAttribute("id")) {
        throw new IllegalStateException("Top-level validator element must have an 'id' attribute defined.");
    }
    return parseAndRegisterValidator(element, parserContext);
}

From source file:com.consol.citrus.admin.service.report.TestNGTestReportService.java

@Override
public TestReport getLatest(Project activeProject) {
    TestReport report = new TestReport();

    if (hasTestResults(activeProject)) {
        try {/*from w w  w. j  a  v a  2  s  .  c  om*/
            Document testResults = XMLUtils.parseMessagePayload(getTestResultsAsString(activeProject));
            report.setProjectName(activeProject.getName());
            report.setSuiteName(
                    XPathUtils.evaluateAsString(testResults, "/testng-results/suite[1]/@name", null));
            report.setDuration(Long.valueOf(
                    XPathUtils.evaluateAsString(testResults, "/testng-results/suite[1]/@duration-ms", null)));

            try {
                report.setExecutionDate(dateFormat.parse(XPathUtils.evaluateAsString(testResults,
                        "/testng-results/suite[1]/@started-at", null)));
            } catch (ParseException e) {
                log.warn("Unable to read test execution time", e);
            }

            report.setPassed(
                    Long.valueOf(XPathUtils.evaluateAsString(testResults, "/testng-results/@passed", null)));
            report.setFailed(
                    Long.valueOf(XPathUtils.evaluateAsString(testResults, "/testng-results/@failed", null)));
            report.setSkipped(
                    Long.valueOf(XPathUtils.evaluateAsString(testResults, "/testng-results/@skipped", null)));
            report.setTotal(
                    Long.valueOf(XPathUtils.evaluateAsString(testResults, "/testng-results/@total", null)));

            NodeList testClasses = XPathUtils.evaluateAsNodeList(testResults,
                    "testng-results/suite[1]/test/class", null);
            for (int i = 0; i < testClasses.getLength(); i++) {
                Element testClass = (Element) testClasses.item(i);

                List<Element> testMethods = DomUtils.getChildElementsByTagName(testClass, "test-method");
                for (Element testMethod : testMethods) {
                    if (!testMethod.hasAttribute("is-config")
                            || testMethod.getAttribute("is-config").equals("false")) {
                        TestResult result = new TestResult();
                        Test test = new Test();

                        test.setClassName(testClass.getAttribute("name"));
                        test.setMethodName(testMethod.getAttribute("name"));
                        test.setPackageName(
                                test.getClassName().substring(0, test.getClassName().lastIndexOf('.')));
                        test.setName(test.getClassName().substring(test.getClassName().lastIndexOf('.') + 1)
                                + "." + test.getMethodName());
                        test.setType(TestType.JAVA);

                        result.setTest(test);
                        result.setSuccess(testMethod.getAttribute("status").equals("PASS"));
                        report.getResults().add(result);
                    }
                }
            }

        } catch (IOException e) {
            log.error("Failed to read test results file", e);
        }
    }

    return report;
}

From source file:com.opengamma.web.bundle.BundleParser.java

private boolean hasValidId(Element element) {
    if (element.hasAttribute(ID_ATTR) && StringUtils.isNotBlank(element.getAttribute(ID_ATTR))) {
        return true;
    }/*from   w ww . j a  va 2 s  .  c  om*/
    throw new OpenGammaRuntimeException("parsing bundle XML : bundle element needs id attribute");
}

From source file:org.romaz.spring.scripting.ext.ExtScriptBeanDefinitionParser.java

/**
 * Resolves the script source from either the '<code>script-source</code>' attribute or
 * the '<code>inline-script</code>' element. Logs and {@link XmlReaderContext#error} and
 * returns <code>null</code> if neither or both of these values are specified.
 *///  www .  jav  a2 s.  com
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
    boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
    if (hasScriptSource && !elements.isEmpty()) {
        readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
        return null;
    } else if (hasScriptSource) {
        return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    } else if (!elements.isEmpty()) {
        Element inlineElement = (Element) elements.get(0);
        return "inline:" + DomUtils.getTextValue(inlineElement);
    } else {
        readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
        return null;
    }
}

From source file:com.predic8.membrane.core.config.spring.AbstractParser.java

protected void setPropertyIfSet(String xmlPropertyName, String springPropertyName, Element e,
        BeanDefinitionBuilder builder, boolean flexibleEnum) {
    if (e.hasAttribute(xmlPropertyName))
        setProperty(xmlPropertyName, springPropertyName, e, builder, flexibleEnum);
}

From source file:de.itsvs.cwtrpc.controller.config.CacheControlConfigBeanDefinitionParser.java

@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
        throws BeanDefinitionStoreException {
    if (element.hasAttribute(ID_ATTRIBUTE)) {
        return super.resolveId(element, definition, parserContext);
    }/*from w w w . j av  a2s . c  o  m*/
    return CacheControlConfig.DEFAULT_BEAN_ID;
}

From source file:org.xmatthew.spy2servers.component.web.config.ServerPaser.java

private Handler parseHandler(Element element) {
    WebAppContext webAppContext = new WebAppContext();
    if (element.hasAttribute(CONTEXT_PATH_PROPERTY)) {
        webAppContext.setContextPath(element.getAttribute(CONTEXT_PATH_PROPERTY));
    } else {/*from   w ww.j  av  a2  s . c  o  m*/
        throw new RuntimeException("sub property " + CONTEXT_PATH_PROPERTY + " must exsit");
    }
    if (element.hasAttribute(RESOURCE_BASE_PROPERTY)) {
        webAppContext.setResourceBase(element.getAttribute(RESOURCE_BASE_PROPERTY));
    } else {
        throw new RuntimeException("sub property " + RESOURCE_BASE_PROPERTY + " must exsit");
    }
    if (element.hasAttribute(lOGURL_ON_START_PROPERTY)) {
        boolean logUrlOnStart = Boolean.valueOf(element.getAttribute(lOGURL_ON_START_PROPERTY));
        webAppContext.setLogUrlOnStart(logUrlOnStart);
    }
    return webAppContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParser.java

protected BeanReference getSerializationPolicyProviderBeanRef(Element element, ParserContext parserContext) {
    final String serializationPolicyProviderName;

    if (element.hasAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR)
            && !ExtendedSerializationPolicyProvider.DEFAULT_BEAN_ID
                    .equals(element.getAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR))) {
        serializationPolicyProviderName = element.getAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR);
    } else {/*from ww  w .  j  a v  a 2  s . c o m*/
        serializationPolicyProviderName = ExtendedSerializationPolicyProvider.DEFAULT_BEAN_ID;
        if (!parserContext.getRegistry().containsBeanDefinition(serializationPolicyProviderName)) {
            final RootBeanDefinition bd;

            if (log.isInfoEnabled()) {
                log.info("Registering default serialization policy provider with name '"
                        + serializationPolicyProviderName + "'");
            }
            bd = new RootBeanDefinition(DefaultExtendedSerializationPolicyProvider.class);
            bd.setSource(parserContext.extractSource(element));
            if (parserContext.isDefaultLazyInit()) {
                bd.setLazyInit(true);
            }
            parserContext
                    .registerBeanComponent(new BeanComponentDefinition(bd, serializationPolicyProviderName));
        }
    }

    return new RuntimeBeanReference(serializationPolicyProviderName);
}

From source file:com.pavelvlasov.uml.xmi.ElementImpl.java

ElementImpl(ModelImpl model, Element holder) {
    this.model = model;
    this.holder = holder;
    if (holder.hasAttribute(ConstantsXML.xmiType)) {
        if (holder.getAttribute(ConstantsXML.xmiType).equals(ConstantsXML.umlDotDot + Constants.PACKAGE)) {
            setType(AuxiliaryFunctionsXML.filterType(holder.getAttribute(ConstantsXML.xmiType)));
        }//from www .  ja v a2s .  co  m
    }
    NodeList nodeList = holder.getElementsByTagName("type");
    if (nodeList.getLength() > 0) {
        setType(AuxiliaryFunctionsXML.filterAttributeType(nodeList.item(0).getAttributes().item(0).toString()));
    } else {
        setType(holder.getAttribute(ConstantsXML.TYPE_ONLY));
    }
}

From source file:com.predic8.membrane.core.config.spring.AbstractParser.java

protected void setIdIfNeeded(Element element, ParserContext parserContext, String defaultId) {
    if (!isInlined() && !element.hasAttribute("id")) {
        Set<String> names = Sets.newHashSet(parserContext.getRegistry().getBeanDefinitionNames());
        for (int i = 0;; i++) {
            String id = defaultId + (i == 0 ? "" : i);
            if (!names.contains(id)) {
                element.setAttribute("id", id);
                return;
            }//www. j  a v  a  2 s . c o  m
        }
    }
}