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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.dangdang.ddframe.rdb.sharding.spring.namespace.parser.ShardingJdbcDataSourceBeanDefinitionParser.java

private BeanDefinition parseDefaultStrategyConfig(final Element element, final String attr) {
    Element strategyElement = DomUtils.getChildElementByTagName(element, attr);
    return null == strategyElement ? null
            : ShardingJdbcStrategyBeanDefinition.getBeanDefinitionByElement(strategyElement);
}

From source file:com.dangdang.ddframe.rdb.sharding.spring.namespace.parser.ShardingJdbcDataSourceBeanDefinitionParser.java

private Properties parseProperties(final Element element, final ParserContext parserContext) {
    Element propsElement = DomUtils.getChildElementByTagName(element,
            ShardingJdbcDataSourceBeanDefinitionParserTag.PROPS_TAG);
    return null == propsElement ? new Properties()
            : parserContext.getDelegate().parsePropsElement(propsElement);
}

From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java

@SuppressWarnings("unchecked")
private void parseCrawlerConfigurations(Element element, BeanDefinitionBuilder factory) {
    List<Element> targetSites = DomUtils.getChildElementsByTagName(element, TARGET_SITE);
    List<CrawlerConfiguration> crawlerConfigurations = new ManagedList(targetSites.size());
    for (Element targetSiteEle : targetSites) {
        String hostName = DomUtils.getChildElementByTagName(targetSiteEle, HOST_NAME).getTextContent();
        String startLink = DomUtils.getChildElementByTagName(targetSiteEle, START_LINK).getTextContent();
        String maxConcurrentDownloads = DomUtils
                .getChildElementByTagName(targetSiteEle, MAX_CONCURRENT_DOWNLOADS).getTextContent();
        String maxVisitedLinks = DomUtils.getChildElementByTagName(targetSiteEle, MAX_VISITED_LINKS)
                .getTextContent();//  www . j  a  v  a2 s  .c om
        CrawlerConfiguration crawlerConfiguration = new CrawlerConfiguration();
        crawlerConfiguration.setHostName(hostName);
        crawlerConfiguration.setStartLink(startLink);
        crawlerConfiguration.setMaxConcurrentDownloads(new Integer(maxConcurrentDownloads).intValue());
        crawlerConfiguration.setMaxVisitedLinks(new Integer(maxVisitedLinks).intValue());
        crawlerConfigurations.add(crawlerConfiguration);
    }
    factory.addPropertyValue(CRAWLER_CONFIGURATIONS_BEAN_PROPERTY, crawlerConfigurations);
}

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

/**
 * Parse the unit info DOM element.// ww w .j  a  v  a  2 s.  c om
 */
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 ww .  ja v a  2 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:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java

@SuppressWarnings("unchecked")
private void parseTasksConfiguration(Element tasksElement, BeanDefinitionBuilder beanDefinitionBuilder)
        throws NumberFormatException, MadStoreConfigurationException, DOMException {
    List<Element> taskElements = DomUtils.getChildElementsByTagName(tasksElement, TASK_TAG);
    Map<String, SimpleTriggerConfiguration> triggerTasks = new ManagedMap();
    for (Element task : taskElements) {
        String key = task.getAttribute(TASK_NAME);
        Element simpleTriggerConfigurationElement = DomUtils.getChildElementByTagName(task,
                SIMPLE_TRIGGER_CONFIGURATION_TAG);
        String startDelaySt = DomUtils.getChildElementByTagName(simpleTriggerConfigurationElement, START_DELAY)
                .getTextContent();/*from  w w  w .  j ava  2s .  c o  m*/
        String repeatIntervalSt = DomUtils
                .getChildElementByTagName(simpleTriggerConfigurationElement, REPEAT_INTERVAL).getTextContent();
        if ("".equals(startDelaySt) || "".equals(repeatIntervalSt)) {
            throw new MadStoreConfigurationException("Parameters startDelay and repeatInterval in "
                    + SIMPLE_TRIGGER_CONFIGURATION_TAG + " tag cannot be empty.");
        }
        SimpleTriggerConfiguration simpleTriggerConfiguration = new SimpleTriggerConfiguration();
        simpleTriggerConfiguration.setStartDelay(new Integer(startDelaySt).intValue());
        simpleTriggerConfiguration.setRepeatInterval(new Integer(repeatIntervalSt).intValue());
        triggerTasks.put(key, simpleTriggerConfiguration);
    }
    beanDefinitionBuilder.addPropertyValue(TASKS_CONFIGURATION_BEAN_PROPERTY, triggerTasks);

    List<CrawlerConfiguration> crawlerConfigurations = (List<CrawlerConfiguration>) beanDefinitionBuilder
            .getBeanDefinition().getPropertyValues().getPropertyValue(CRAWLER_CONFIGURATIONS_BEAN_PROPERTY)
            .getValue();

    if (triggerTasks.keySet().contains(CRAWLER_TASK) && crawlerConfigurations.size() == 0) {
        throw new MadStoreConfigurationException("Crawler task cannot exist without crawler tag definition!");
    }
}

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  www. jav a  2s.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:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse the <code>property</code> XML elements.
 *///  w w  w . java2 s  .  c om
@SuppressWarnings("unchecked")
protected void parseProperty(Element persistenceUnit, MySpringPersistenceUnitInfo unitInfo) {
    Element propRoot = DomUtils.getChildElementByTagName(persistenceUnit, PROPERTIES);
    if (propRoot == null) {
        return;
    }
    List<Element> properties = DomUtils.getChildElementsByTagName(propRoot, "property");
    for (Element property : properties) {
        String name = property.getAttribute("name");
        String value = property.getAttribute("value");
        unitInfo.addProperty(name, value);
    }
}

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

/**
 * Parse the <code>property</code> XML elements.
 *///w  w  w.ja  v  a2s.com
@SuppressWarnings("unchecked")
protected void parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) {
    Element propRoot = DomUtils.getChildElementByTagName(persistenceUnit, PROPERTIES);
    if (propRoot == null) {
        return;
    }
    List<Element> properties = DomUtils.getChildElementsByTagName(propRoot, "property");
    for (Element property : properties) {
        String name = property.getAttribute("name");
        String value = property.getAttribute("value");
        unitInfo.addProperty(name, value);
    }
}

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

/**
 * Parse the unit info DOM element.//  www  .  j a v  a 2  s.  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;
}