Example usage for org.springframework.util.xml DomUtils getChildElementValueByTagName

List of usage examples for org.springframework.util.xml DomUtils getChildElementValueByTagName

Introduction

In this page you can find the example usage for org.springframework.util.xml DomUtils getChildElementValueByTagName.

Prototype

@Nullable
public static String getChildElementValueByTagName(Element ele, String childEleName) 

Source Link

Document

Utility method that returns the first child element value identified by its name.

Usage

From source file:org.jdal.beans.CustomBeanDefinitionParser.java

/**
 * Parse bean like a real bean definition.
 * @param ele element/*from   ww  w  . j  ava 2 s  . c  om*/
 * @param parserContext parserContext
 * @param builder builder
 */
protected void parseBeanDefinition(Element ele, ParserContext parserContext, BeanDefinitionBuilder builder) {
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
    AbstractBeanDefinition bd = builder.getRawBeanDefinition();
    XmlReaderContext reader = parserContext.getReaderContext();

    try {
        delegate.parseBeanDefinitionAttributes(ele, beanName, null, bd);
        bd.setDescription(DomUtils.getChildElementValueByTagName(ele, "description"));

        delegate.parseMetaElements(ele, bd);
        delegate.parseLookupOverrideSubElements(ele, bd.getMethodOverrides());
        delegate.parseReplacedMethodSubElements(ele, bd.getMethodOverrides());

        delegate.parseConstructorArgElements(ele, bd);
        delegate.parsePropertyElements(ele, bd);
        delegate.parseQualifierElements(ele, bd);

    } catch (NoClassDefFoundError err) {
        reader.error("Class that bean class [" + this.beanClass + "] depends on not found", ele, err);
    } catch (Throwable ex) {
        reader.error("Unexpected failure during bean definition parsing", ele, ex);
    }

}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java

/**
 * Returns the <tt>groupId</tt> setting in a <tt>pom.xml</tt> file.
 * /*from ww w .ja  v a 2s.  com*/
 * @return a <tt>pom.xml</tt> <tt>groupId</tt>.
 */
String getGroupIdFromPom(Resource pomXml) {
    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(pomXml.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        String groupId = DomUtils.getChildElementValueByTagName(document.getDocumentElement(), GROUP_ID_ELEM);
        // no groupId specified, try the parent definition
        if (groupId == null) {
            if (log.isTraceEnabled())
                log.trace("No groupId defined; checking for the parent definition");
            Element parent = DomUtils.getChildElementByTagName(document.getDocumentElement(), "parent");
            if (parent != null)
                return DomUtils.getChildElementValueByTagName(parent, GROUP_ID_ELEM);
        } else {
            return groupId;
        }
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + pomXml).initCause(ex));
    }

    throw new IllegalArgumentException(
            "no groupId or parent/groupId defined by resource [" + pomXml.getDescription() + "]");

}

From source file:org.eobjects.datacleaner.monitor.pentaho.PentahoCarteClient.java

public List<PentahoTransformation> getAvailableTransformations() throws PentahoJobException {
    final String statusUrl = getUrl("status", null, null);

    final HttpGet request = new HttpGet(statusUrl);
    try {//w  ww  .  j ava2s .c om
        final HttpResponse response = execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            final List<PentahoTransformation> result = new ArrayList<PentahoTransformation>();
            final Document doc = parse(response.getEntity());
            final Element serverstatusElement = doc.getDocumentElement();
            final Element transstatuslistElement = DomUtils.getChildElementByTagName(serverstatusElement,
                    "transstatuslist");
            final List<Element> transstatusElements = DomUtils.getChildElements(transstatuslistElement);
            for (Element transstatusElement : transstatusElements) {
                final String transId = DomUtils.getChildElementValueByTagName(transstatusElement, "id");
                final String transName = DomUtils.getChildElementValueByTagName(transstatusElement,
                        "transname");
                final PentahoTransformation transformation = new PentahoTransformation(transId, transName);
                result.add(transformation);
            }
            return result;
        } else {
            throw new PentahoJobException(
                    "Unexpected response status when updating transformation status: " + statusCode);
        }
    } finally {
        request.releaseConnection();
    }
}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.LocalFileSystemMavenRepository.java

/**
 * Returns the <code>localRepository</code> settings as indicated by the
 * <code>settings.xml</code> file.
 * /*w ww.  j  a  va 2s  .  com*/
 * @return local repository as indicated by a Maven settings.xml file
 */
String getMavenSettingsLocalRepository(Resource m2Settings) {
    // no file found, return null to continue the discovery process
    if (!m2Settings.exists())
        return null;

    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(m2Settings.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        return (DomUtils.getChildElementValueByTagName(document.getDocumentElement(), LOCAL_REPOSITORY_ELEM));
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + m2Settings).initCause(ex));
    }
}

From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse the unit info DOM element.//from w  ww . j a v  a 2  s  .  c o m
 */
protected MySpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version)
        throws IOException { // JC: Changed
    MySpringPersistenceUnitInfo unitInfo = new MySpringPersistenceUnitInfo();

    // set JPA version (1.0 or 2.0)
    unitInfo.setPersistenceXMLSchemaVersion(version);

    // set unit name
    unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

    // set transaction type
    String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
    if (StringUtils.hasText(txType)) {
        unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
    }

    // data-source
    String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
    if (StringUtils.hasText(jtaDataSource)) {
        unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
    }

    String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
    if (StringUtils.hasText(nonJtaDataSource)) {
        unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
    }

    // provider
    String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
    if (StringUtils.hasText(provider)) {
        unitInfo.setPersistenceProviderClassName(provider.trim());
    }

    // exclude unlisted classes
    Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit,
            EXCLUDE_UNLISTED_CLASSES);
    if (excludeUnlistedClasses != null) {
        unitInfo.setExcludeUnlistedClasses(true);
    }

    // set JPA 2.0 shared cache mode
    String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
    if (StringUtils.hasText(cacheMode)) {
        unitInfo.setSharedCacheModeName(cacheMode);
    }

    // set JPA 2.0 validation mode
    String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
    if (StringUtils.hasText(validationMode)) {
        unitInfo.setValidationModeName(validationMode);
    }

    parseMappingFiles(persistenceUnit, unitInfo);
    parseJarFiles(persistenceUnit, unitInfo);
    parseClass(persistenceUnit, unitInfo);
    parseProperty(persistenceUnit, unitInfo);

    return unitInfo;
}

From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java

/**
 * Parse the unit info DOM element./*w  w  w .  ja va2  s  .co  m*/
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version,
        URL rootUrl) throws IOException {

    SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

    // set JPA version (1.0 or 2.0)
    unitInfo.setPersistenceXMLSchemaVersion(version);

    // set persistence unit root URL
    unitInfo.setPersistenceUnitRootUrl(rootUrl);

    // set unit name
    unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

    // set transaction type
    String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
    if (StringUtils.hasText(txType)) {
        unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
    }

    // data-source
    String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
    if (StringUtils.hasText(jtaDataSource)) {
        unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
    }

    String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
    if (StringUtils.hasText(nonJtaDataSource)) {
        unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
    }

    // provider
    String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
    if (StringUtils.hasText(provider)) {
        unitInfo.setPersistenceProviderClassName(provider.trim());
    }

    // exclude unlisted classes
    Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit,
            EXCLUDE_UNLISTED_CLASSES);
    if (excludeUnlistedClasses != null) {
        unitInfo.setExcludeUnlistedClasses(true);
    }

    // set JPA 2.0 shared cache mode
    String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
    if (StringUtils.hasText(cacheMode)) {
        unitInfo.setSharedCacheModeName(cacheMode);
    }

    // set JPA 2.0 validation mode
    String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
    if (StringUtils.hasText(validationMode)) {
        unitInfo.setValidationModeName(validationMode);
    }

    parseProperties(persistenceUnit, unitInfo);
    parseManagedClasses(persistenceUnit, unitInfo);
    parseMappingFiles(persistenceUnit, unitInfo);
    parseJarFiles(persistenceUnit, unitInfo);

    return unitInfo;
}

From source file:com.apdplat.platform.spring.APDPlatPersistenceUnitReader.java

/**
 * Parse the unit info DOM element.//from  w  ww.j a v a 2s.c  o  m
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version)
        throws IOException { // JC: Changed
    SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

    // set JPA version (1.0 or 2.0)
    unitInfo.setPersistenceXMLSchemaVersion(version);

    // set unit name
    logger.info(
            "apdplatspring jpa1(1. Start to execute custom modifications  of APDPlat for Spring JPA )");
    String unitName = persistenceUnit.getAttribute(UNIT_NAME).trim();
    logger.info("??(Content of placeholder is): " + unitName);
    //${}??
    unitName = PropertyHolder.getProperty(unitName.substring(2, unitName.length() - 1));
    logger.info("???(Content of config file related to placeholder is): "
            + unitName);
    unitInfo.setPersistenceUnitName(unitName);

    // set transaction type
    String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
    if (StringUtils.hasText(txType)) {
        unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
    }

    // data-source
    String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
    if (StringUtils.hasText(jtaDataSource)) {
        unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
    }

    String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
    if (StringUtils.hasText(nonJtaDataSource)) {
        unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
    }

    // provider
    String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
    if (StringUtils.hasText(provider)) {
        unitInfo.setPersistenceProviderClassName(provider.trim());
    }

    // exclude unlisted classes
    Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit,
            EXCLUDE_UNLISTED_CLASSES);
    if (excludeUnlistedClasses != null) {
        unitInfo.setExcludeUnlistedClasses(true);
    }

    // set JPA 2.0 shared cache mode
    String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
    if (StringUtils.hasText(cacheMode)) {
        unitInfo.setSharedCacheModeName(cacheMode);
    }

    // set JPA 2.0 validation mode
    String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
    if (StringUtils.hasText(validationMode)) {
        unitInfo.setValidationModeName(validationMode);
    }

    parseMappingFiles(persistenceUnit, unitInfo);
    parseJarFiles(persistenceUnit, unitInfo);
    parseClass(persistenceUnit, unitInfo);
    parseProperty(persistenceUnit, unitInfo);

    return unitInfo;
}

From source file:org.eobjects.datacleaner.monitor.pentaho.PentahoJobEngine.java

/**
 * Logs the progress of a job in Carte based on the XML response of a
 * 'transUpdate' call./*from  w ww . java2s. c  o  m*/
 * 
 * @param statusType
 *            the type of status update - expecting a word to put into an
 *            update sentence like 'progress' or 'finished'.
 * @param pentahoJobType
 * @param executionLogger
 * @param document
 */
private void logTransStatus(String statusType, PentahoJobType pentahoJobType, ExecutionLogger executionLogger,
        Document document) {
    final Element transstatusElement = document.getDocumentElement();
    final Element stepstatuslistElement = DomUtils.getChildElementByTagName(transstatusElement,
            "stepstatuslist");
    final List<Element> stepstatusElements = DomUtils.getChildElements(stepstatuslistElement);
    for (Element stepstatusElement : stepstatusElements) {
        final String stepName = DomUtils.getChildElementValueByTagName(stepstatusElement, "stepname");
        final String linesInput = DomUtils.getChildElementValueByTagName(stepstatusElement, "linesInput");
        final String linesOutput = DomUtils.getChildElementValueByTagName(stepstatusElement, "linesOutput");
        final String linesRead = DomUtils.getChildElementValueByTagName(stepstatusElement, "linesRead");
        final String linesWritten = DomUtils.getChildElementValueByTagName(stepstatusElement, "linesWritten");
        final String statusDescription = DomUtils.getChildElementValueByTagName(stepstatusElement,
                "statusDescription");

        final StringBuilder update = new StringBuilder();
        update.append("Step '");
        update.append(stepName);
        update.append("' ");
        update.append(statusType);
        update.append(": status='");
        update.append(statusDescription);
        update.append("'");

        if (!"0".equals(linesRead)) {
            update.append(", linesRead=");
            update.append(linesRead);
        }
        if (!"0".equals(linesWritten)) {
            update.append(", linesWritten=");
            update.append(linesWritten);
        }
        if (!"0".equals(linesInput)) {
            update.append(", linesInput=");
            update.append(linesInput);
        }
        if (!"0".equals(linesOutput)) {
            update.append(", linesOutput=");
            update.append(linesOutput);
        }

        executionLogger.log(update.toString());
    }
    executionLogger.flushLog();
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parse the bean definition itself, without regard to name or aliases. May return <code>null</code> if problems
 * occurred during the parse of the bean definition.
 *///w ww.ja v a 2 s  . c  om
private AbstractBeanDefinition parseBeanDefinitionElement(Element ele, String beanName,
        BeanDefinition containingBean) {

    this.parseState.push(new BeanEntry(beanName));

    String className = null;
    if (ele.hasAttribute(BeanDefinitionParserDelegate.CLASS_ATTRIBUTE)) {
        className = ele.getAttribute(BeanDefinitionParserDelegate.CLASS_ATTRIBUTE).trim();
    }

    try {
        AbstractBeanDefinition beanDefinition = BeanDefinitionReaderUtils.createBeanDefinition(null, className,
                parserContext.getReaderContext().getBeanClassLoader());

        // some early validation
        String activation = ele.getAttribute(LAZY_INIT_ATTR);
        String scope = ele.getAttribute(BeanDefinitionParserDelegate.SCOPE_ATTRIBUTE);

        if (EAGER_INIT_VALUE.equals(activation) && BeanDefinition.SCOPE_PROTOTYPE.equals(scope)) {
            error("Prototype beans cannot be eagerly activated", ele);
        }

        // add marker to indicate that the scope was present
        if (StringUtils.hasText(scope)) {
            beanDefinition.setAttribute(DECLARED_SCOPE, Boolean.TRUE);
        }

        // parse attributes
        parseAttributes(ele, beanName, beanDefinition);

        // inner beans get a predefined scope in RFC 124
        if (containingBean != null) {
            beanDefinition.setLazyInit(true);
            beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
        }

        // parse description
        beanDefinition.setDescription(
                DomUtils.getChildElementValueByTagName(ele, BeanDefinitionParserDelegate.DESCRIPTION_ELEMENT));

        parseConstructorArgElements(ele, beanDefinition);
        parsePropertyElements(ele, beanDefinition);

        beanDefinition.setResource(parserContext.getReaderContext().getResource());
        beanDefinition.setSource(extractSource(ele));

        return beanDefinition;
    } catch (ClassNotFoundException ex) {
        error("Bean class [" + className + "] not found", ele, ex);
    } catch (NoClassDefFoundError err) {
        error("Class that bean class [" + className + "] depends on not found", ele, err);
    } catch (Throwable ex) {
        error("Unexpected failure during bean definition parsing", ele, ex);
    } finally {
        this.parseState.pop();
    }

    return null;
}

From source file:org.ligoj.app.plugin.build.jenkins.JenkinsPluginResource.java

/**
 * Search the Jenkin's jobs matching to the given criteria. Name, display name and description are considered.
 *
 * @param node// www . j a va2s .com
 *            the node to be tested with given parameters.
 * @param criteria
 *            the search criteria.
 * @param view
 *            The optional view URL.
 * @return job names matching the criteria.
 */
private List<Job> findAllByName(final String node, final String criteria, final String view)
        throws SAXException, IOException, ParserConfigurationException {

    // Prepare the context, an ordered set of jobs
    final Format format = new NormalizeFormat();
    final String formatCriteria = format.format(criteria);
    final Map<String, String> parameters = pvResource.getNodeParameters(node);

    // Get the jobs and parse them
    final String url = StringUtils.trimToEmpty(view) + "api/xml?tree=jobs[name,displayName,description,color]";
    final String jobsAsXml = StringUtils.defaultString(getResource(parameters, url), "<a/>");
    final InputStream jobsAsInput = IOUtils.toInputStream(jobsAsXml, StandardCharsets.UTF_8);
    final Element hudson = (Element) xml.parse(jobsAsInput).getFirstChild();
    final Map<String, Job> result = new TreeMap<>();
    for (final Element jobNode : DomUtils.getChildElementsByTagName(hudson, "job")) {

        // Extract string data from this job
        final String name = StringUtils.trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "name"));
        final String displayName = StringUtils
                .trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "displayName"));
        final String description = StringUtils
                .trimToEmpty(DomUtils.getChildElementValueByTagName(jobNode, "description"));

        // Check the values of this job
        if (format.format(name).contains(formatCriteria) || format.format(displayName).contains(formatCriteria)
                || format.format(description).contains(formatCriteria)) {

            // Retrieve description and display name
            final Job job = new Job();
            job.setName(StringUtils.trimToNull(displayName));
            job.setDescription(StringUtils.trimToNull(description));
            job.setId(name);
            job.setStatus(toStatus(DomUtils.getChildElementValueByTagName(jobNode, "color")));
            result.put(format.format(ObjectUtils.defaultIfNull(job.getName(), job.getId())), job);
        }
    }
    return new ArrayList<>(result.values());
}