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

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

Introduction

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

Prototype

public static List<Element> getChildElementsByTagName(Element ele, String childEleName) 

Source Link

Document

Retrieves all child elements of the given DOM element that match the given element name.

Usage

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

private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
    Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
    if (null == bindingTableRulesElement) {
        return Collections.emptyList();
    }//  ww w.ja v  a 2 s  .  c  o m
    List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
    BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder
            .rootBeanDefinition(BindingTableRuleConfig.class);
    List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
    for (Element bindingTableRuleElement : bindingTableRuleElements) {
        bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement
                .getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
        result.add(bindingTableRuleFactory.getBeanDefinition());
    }
    return result;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.general.GeneralConfigConverter.java

private void convertJmxListener(Document document, Element server, JmxListener from,
        Properties catalinaProperties) {
    Element jmxListener = null;/*from   w  w w  . ja v  a  2  s  .  co  m*/
    boolean foundJmxListener = false;
    for (Element listener : DomUtils.getChildElementsByTagName(server, TAG_NAME_LISTENER)) {
        if ("com.springsource.tcserver.serviceability.rmi.JmxSocketListener"
                .equals(listener.getAttribute(ATTRIBUTE_CLASS_NAME))) {
            foundJmxListener = true;
            jmxListener = listener;
            if (!from.getEnabled()) {
                server.removeChild(jmxListener);
            }
        }
    }
    if (from.getEnabled()) {
        if (!foundJmxListener) {
            jmxListener = document.createElement(TAG_NAME_LISTENER);
            jmxListener.setAttribute(ATTRIBUTE_CLASS_NAME,
                    "com.springsource.tcserver.serviceability.rmi.JmxSocketListener");
        }
        setAttribute(jmxListener, ACCESS_FILE, from.getAccessFile(), catalinaProperties, true);
        if (from.getAuthenticate() != null) {
            setAttribute(jmxListener, AUTHENTICATE, from.getAuthenticate(), catalinaProperties, true);
        }
        setAttribute(jmxListener, BIND, from.getBind(), catalinaProperties, true);
        setAttribute(jmxListener, CIPHER_SUITES, from.getCipherSuites(), catalinaProperties, true);
        if (from.getClientAuth() != null) {
            setAttribute(jmxListener, CLIENT_AUTH, from.getClientAuth(), catalinaProperties, true);
        }
        setAttribute(jmxListener, KEYSTORE_FILE, from.getKeystoreFile(), catalinaProperties, true);
        setAttribute(jmxListener, KEYSTORE_PASS, from.getKeystorePass(), catalinaProperties, true);
        setAttribute(jmxListener, PASSOWRD_FILE, from.getPasswordFile(), catalinaProperties, true);
        if (from.getPort() != null) {
            setAttribute(jmxListener, JMX_PORT, from.getPort(), catalinaProperties, true);
        }
        setAttribute(jmxListener, PROTOCOLS, from.getProtocols(), catalinaProperties, true);
        setAttribute(jmxListener, TRUSTSTORE_FILE, from.getTruststoreFile(), catalinaProperties, true);
        setAttribute(jmxListener, TRUSTSTORE_PASS, from.getTruststorePass(), catalinaProperties, true);
        if (from.getUseJdkClientFactory() != null) {
            setAttribute(jmxListener, USE_JDK_CLIENT_FACTORY, from.getUseJdkClientFactory(), catalinaProperties,
                    true);
        }
        if (from.getUseSSL() != null) {
            setAttribute(jmxListener, USE_SSL, from.getUseSSL(), catalinaProperties, true);
        }
        if (!foundJmxListener) {
            server.appendChild(jmxListener);
        }
    }
}

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.
 *///  w  ww .  j  av a  2s  . co m
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:org.springmodules.cache.config.AbstractCacheSetupStrategyParser.java

/**
 * Parses the given XML element containing references to the caching listeners
 * to be added to the caching setup strategy.
 * /* w w  w  .  ja v a  2 s . c o  m*/
 * @param element
 *          the XML element to parse
 * @param parserContext
 *          the parser context
 * @return a list containing references to caching listeners already
 *         registered in the given register
 * @throws IllegalStateException
 *           if any of the given ids reference a caching listener that does
 *           not exist in the registry
 * @throws IllegalStateException
 *           if the given id references a caching listener that is not an
 *           instance of <code>CachingListener</code>
 * @throws IllegalStateException
 *           if the caching listener elements does not contain a reference to
 *           an existing caching listener and does not contain an inner
 *           definition of a caching listener
 */
private List parseCachingListeners(Element element, ParserContext parserContext) throws IllegalStateException {

    List listenersElements = DomUtils.getChildElementsByTagName(element, "cachingListeners");

    if (CollectionUtils.isEmpty(listenersElements)) {
        return null;
    }

    Element listenersElement = (Element) listenersElements.get(0);
    List listenerElements = DomUtils.getChildElementsByTagName(listenersElement, "cachingListener");

    ManagedList listeners = new ManagedList();
    boolean registerCachingListener = true;
    int listenerCount = listenerElements.size();

    for (int i = 0; i < listenerCount; i++) {
        Element listenerElement = (Element) listenerElements.get(i);

        Object cachingListener = beanReferenceParser.parse(listenerElement, parserContext,
                registerCachingListener);
        cachingListenerValidator.validate(cachingListener, i, parserContext);
        listeners.add(cachingListener);
    }

    return listeners;
}

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

/**
 * Parse the validated document and add entries to the given unit info list.
 *///from  w ww  .  j a  v  a2  s  .c  om
protected List<SpringPersistenceUnitInfo> parseDocument(Resource resource, Document document,
        List<SpringPersistenceUnitInfo> infos) throws IOException {

    Element persistence = document.getDocumentElement();
    String version = persistence.getAttribute(PERSISTENCE_VERSION);
    URL unitRootURL = determinePersistenceUnitRootUrl(resource);
    List<Element> units = DomUtils.getChildElementsByTagName(persistence, PERSISTENCE_UNIT);
    for (Element unit : units) {
        SpringPersistenceUnitInfo info = parsePersistenceUnitInfo(unit, version);
        info.setPersistenceUnitRootUrl(unitRootURL);
        infos.add(info);
    }

    return infos;
}

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();/*from  w  ww.j  av  a  2s.  c  o  m*/
        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:org.springmodules.cache.config.AbstractCacheSetupStrategyParser.java

/**
 * Parses the given XML element which sub-elements containing the properties
 * of the caching models to create./* w ww  .  j  a v a 2 s. c  om*/
 * 
 * @param element
 *          the XML element to parse
 * @return a map containing the parsed caching models.The key of each element
 *         is the value of the XML attribute <code>target</code> (a String)
 *         and the value is the caching model (an instance of
 *         <code>CachingModel</code>)
 */
private Map parseCachingModels(Element element) {
    List modelElements = DomUtils.getChildElementsByTagName(element, "caching");
    if (CollectionUtils.isEmpty(modelElements)) {
        return null;
    }

    String cacheModelKey = getCacheModelKey();
    Map models = new HashMap();
    int modelElementCount = modelElements.size();

    for (int i = 0; i < modelElementCount; i++) {
        Element modelElement = (Element) modelElements.get(i);
        String key = modelElement.getAttribute(cacheModelKey);

        CachingModel model = cacheModelParser.parseCachingModel(modelElement);
        models.put(key, model);
    }

    return models;
}

From source file:eap.config.ConfigBeanDefinitionParser.java

private void parseAspect(Element aspectElement, ParserContext parserContext) {
    String aspectId = aspectElement.getAttribute(ID);
    String aspectName = aspectElement.getAttribute(REF);

    try {/*from  w ww . j a  v a  2s  . c  o  m*/
        this.parseState.push(new AspectEntry(aspectId, aspectName));
        List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>();
        List<BeanReference> beanReferences = new ArrayList<BeanReference>();

        List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS);
        for (int i = METHOD_INDEX; i < declareParents.size(); i++) {
            Element declareParentsElement = declareParents.get(i);
            beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext));
        }

        // We have to parse "advice" and all the advice kinds in one loop, to get the
        // ordering semantics right.
        NodeList nodeList = aspectElement.getChildNodes();
        boolean adviceFoundAlready = false;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (isAdviceNode(node, parserContext)) {
                if (!adviceFoundAlready) {
                    adviceFoundAlready = true;
                    if (!StringUtils.hasText(aspectName)) {
                        parserContext.getReaderContext().error(
                                "<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.",
                                aspectElement, this.parseState.snapshot());
                        return;
                    }
                    beanReferences.add(new RuntimeBeanReference(aspectName));
                }
                AbstractBeanDefinition advisorDefinition = parseAdvice(aspectName, i, aspectElement,
                        (Element) node, parserContext, beanDefinitions, beanReferences);
                beanDefinitions.add(advisorDefinition);
            }
        }

        AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition(aspectElement,
                aspectId, beanDefinitions, beanReferences, parserContext);
        parserContext.pushContainingComponent(aspectComponentDefinition);

        List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT);
        for (Element pointcutElement : pointcuts) {
            parsePointcut(pointcutElement, parserContext);
        }

        parserContext.popAndRegisterContainingComponent();
    } finally {
        this.parseState.pop();
    }
}

From source file:org.springmodules.cache.config.AbstractCacheSetupStrategyParser.java

/**
 * Parses the given XML element which sub-elements containing the properties
 * of the flushing models to create./* w w  w.  ja  v  a 2 s .com*/
 * 
 * @param element
 *          the XML element to parse
 * @return a map containing the parsed flushing models.The key of each element
 *         is the value of the XML attribute <code>target</code> (a String) *
 *         and the value is the flushing model (an instance of
 *         <code>FlushingModel</code>)
 */
private Map parseFlushingModels(Element element) {
    List modelElements = DomUtils.getChildElementsByTagName(element, "flushing");
    if (CollectionUtils.isEmpty(modelElements)) {
        return null;
    }

    String cacheModelKey = getCacheModelKey();
    Map models = new HashMap();
    int modelElementCount = modelElements.size();

    for (int i = 0; i < modelElementCount; i++) {
        Element modelElement = (Element) modelElements.get(i);
        String key = modelElement.getAttribute(cacheModelKey);

        FlushingModel model = cacheModelParser.parseFlushingModel(modelElement);
        models.put(key, model);
    }

    return models;
}

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();//w w w. jav  a2  s .  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!");
    }
}