Java Code Examples for org.springframework.util.xml.DomUtils#getChildElementsByTagName()
The following examples show how to use
org.springframework.util.xml.DomUtils#getChildElementsByTagName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanDefinitionParserDelegate.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Parse a props element. */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }
Example 2
Source File: Jaxb2MarshallerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) { String contextPath = element.getAttribute("context-path"); if (!StringUtils.hasText(contextPath)) { // Backwards compatibility with 3.x version of the xsd contextPath = element.getAttribute("contextPath"); } if (StringUtils.hasText(contextPath)) { beanDefinitionBuilder.addPropertyValue("contextPath", contextPath); } List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound"); if (!classes.isEmpty()) { ManagedList<String> classesToBeBound = new ManagedList<String>(classes.size()); for (Element classToBeBound : classes) { String className = classToBeBound.getAttribute("name"); classesToBeBound.add(className); } beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound); } }
Example 3
Source File: PersistenceUnitReader.java From spring-analysis-note with MIT License | 5 votes |
/** * Parse the {@code jar-file} XML elements. */ protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException { List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL); for (Element element : jars) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { Resource[] resources = this.resourcePatternResolver.getResources(value); boolean found = false; for (Resource resource : resources) { if (resource.exists()) { found = true; unitInfo.addJarFileUrl(resource.getURL()); } } if (!found) { // relative to the persistence unit root, according to the JPA spec URL rootUrl = unitInfo.getPersistenceUnitRootUrl(); if (rootUrl != null) { unitInfo.addJarFileUrl(new URL(rootUrl, value)); } else { logger.warn("Cannot resolve jar-file entry [" + value + "] in persistence unit '" + unitInfo.getPersistenceUnitName() + "' without root URL"); } } } } }
Example 4
Source File: DatabasePopulatorConfigUtils.java From spring-analysis-note with MIT License | 5 votes |
public static void setDatabasePopulator(Element element, BeanDefinitionBuilder builder) { List<Element> scripts = DomUtils.getChildElementsByTagName(element, "script"); if (!scripts.isEmpty()) { builder.addPropertyValue("databasePopulator", createDatabasePopulator(element, scripts, "INIT")); builder.addPropertyValue("databaseCleaner", createDatabasePopulator(element, scripts, "DESTROY")); } }
Example 5
Source File: XmlUtility.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 获取元素中指定标签的唯一元素 * * @param element * @param tag * @return */ public static Element getUniqueElement(Element element, String tag) { List<Element> elements = DomUtils.getChildElementsByTagName(element, tag); if (elements.size() != 1) { String message = StringUtility.format("指定的标签[{}]在元素[{}]中不是唯一", tag, element); logger.error(message); throw new IllegalArgumentException(message); } return elements.get(0); }
Example 6
Source File: ShardingRuleBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 5 votes |
private List<String> parseBroadcastTables(final Element element) { Element broadcastTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingRuleBeanDefinitionTag.BROADCAST_TABLE_RULES_TAG); if (null == broadcastTableRulesElement) { return Collections.emptyList(); } List<Element> broadcastTableRuleElements = DomUtils.getChildElementsByTagName(broadcastTableRulesElement, ShardingRuleBeanDefinitionTag.BROADCAST_TABLE_RULE_TAG); List<String> result = new LinkedList<>(); for (Element each : broadcastTableRuleElements) { result.add(each.getAttribute(ShardingRuleBeanDefinitionTag.TABLE_ATTRIBUTE)); } return result; }
Example 7
Source File: ScriptTemplateConfigurerBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "script"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } builder.addPropertyValue("scripts", StringUtils.toStringArray(locations)); } builder.addPropertyValue("engineName", element.getAttribute("engine-name")); if (element.hasAttribute("render-object")) { builder.addPropertyValue("renderObject", element.getAttribute("render-object")); } if (element.hasAttribute("render-function")) { builder.addPropertyValue("renderFunction", element.getAttribute("render-function")); } if (element.hasAttribute("content-type")) { builder.addPropertyValue("contentType", element.getAttribute("content-type")); } if (element.hasAttribute("charset")) { builder.addPropertyValue("charset", Charset.forName(element.getAttribute("charset"))); } if (element.hasAttribute("resource-loader-path")) { builder.addPropertyValue("resourceLoaderPath", element.getAttribute("resource-loader-path")); } if (element.hasAttribute("shared-engine")) { builder.addPropertyValue("sharedEngine", element.getAttribute("shared-engine")); } }
Example 8
Source File: FreeMarkerConfigurerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "template-loader-path"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<String>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } if (locations.isEmpty()) { locations.add("/WEB-INF/"); } builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()])); } }
Example 9
Source File: DatabasePopulatorConfigUtils.java From java-technology-stack with MIT License | 5 votes |
public static void setDatabasePopulator(Element element, BeanDefinitionBuilder builder) { List<Element> scripts = DomUtils.getChildElementsByTagName(element, "script"); if (!scripts.isEmpty()) { builder.addPropertyValue("databasePopulator", createDatabasePopulator(element, scripts, "INIT")); builder.addPropertyValue("databaseCleaner", createDatabasePopulator(element, scripts, "DESTROY")); } }
Example 10
Source File: MessageBrokerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private ManagedList<Object> extractBeanSubElements(Element parentElement, ParserContext parserContext) { ManagedList<Object> list = new ManagedList<Object>(); list.setSource(parserContext.extractSource(parentElement)); for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, "bean", "ref")) { Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null); list.add(object); } return list; }
Example 11
Source File: FreeMarkerConfigurerBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "template-loader-path"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } if (locations.isEmpty()) { locations.add("/WEB-INF/"); } builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations)); } }
Example 12
Source File: ScriptTemplateConfigurerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "script"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<String>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } builder.addPropertyValue("scripts", locations.toArray(new String[locations.size()])); } builder.addPropertyValue("engineName", element.getAttribute("engine-name")); if (element.hasAttribute("render-object")) { builder.addPropertyValue("renderObject", element.getAttribute("render-object")); } if (element.hasAttribute("render-function")) { builder.addPropertyValue("renderFunction", element.getAttribute("render-function")); } if (element.hasAttribute("content-type")) { builder.addPropertyValue("contentType", element.getAttribute("content-type")); } if (element.hasAttribute("charset")) { builder.addPropertyValue("charset", Charset.forName(element.getAttribute("charset"))); } if (element.hasAttribute("resource-loader-path")) { builder.addPropertyValue("resourceLoaderPath", element.getAttribute("resource-loader-path")); } if (element.hasAttribute("shared-engine")) { builder.addPropertyValue("sharedEngine", element.getAttribute("shared-engine")); } }
Example 13
Source File: PersistenceUnitReader.java From java-technology-stack with MIT License | 5 votes |
/** * Parse the {@code class} XML elements. */ protected void parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME); for (Element element : classes) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addManagedClassName(value); } } }
Example 14
Source File: AnnotationDrivenBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private ManagedList<Object> extractBeanSubElements(Element parentElement, ParserContext parserContext) { ManagedList<Object> list = new ManagedList<Object>(); list.setSource(parserContext.extractSource(parentElement)); for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, "bean", "ref")) { Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null); list.add(object); } return list; }
Example 15
Source File: PersistenceUnitReader.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Parse the {@code property} XML elements. */ 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); } }
Example 16
Source File: ComponentBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private static AbstractBeanDefinition parseComponentElement(Element element) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ComponentFactoryBean.class); factory.addPropertyValue("parent", parseComponent(element)); List<Element> childElements = DomUtils.getChildElementsByTagName(element, "component"); if (!CollectionUtils.isEmpty(childElements)) { parseChildComponents(childElements, factory); } return factory.getBeanDefinition(); }
Example 17
Source File: ScriptTemplateConfigurerBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "script"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } builder.addPropertyValue("scripts", StringUtils.toStringArray(locations)); } builder.addPropertyValue("engineName", element.getAttribute("engine-name")); if (element.hasAttribute("render-object")) { builder.addPropertyValue("renderObject", element.getAttribute("render-object")); } if (element.hasAttribute("render-function")) { builder.addPropertyValue("renderFunction", element.getAttribute("render-function")); } if (element.hasAttribute("content-type")) { builder.addPropertyValue("contentType", element.getAttribute("content-type")); } if (element.hasAttribute("charset")) { builder.addPropertyValue("charset", Charset.forName(element.getAttribute("charset"))); } if (element.hasAttribute("resource-loader-path")) { builder.addPropertyValue("resourceLoaderPath", element.getAttribute("resource-loader-path")); } if (element.hasAttribute("shared-engine")) { builder.addPropertyValue("sharedEngine", element.getAttribute("shared-engine")); } }
Example 18
Source File: EncryptRuleBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 5 votes |
private static Collection<BeanDefinition> parseEncryptTableRuleConfigurations(final Element element) { List<Element> encryptTableElements = DomUtils.getChildElementsByTagName(element, EncryptRuleBeanDefinitionTag.TABLE_TAG); Collection<BeanDefinition> result = new ManagedList<>(encryptTableElements.size()); for (Element each : encryptTableElements) { result.add(parseEncryptTableRuleConfiguration(each)); } return result; }
Example 19
Source File: TxAdviceBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) { List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT); ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap = new ManagedMap<>(methods.size()); transactionAttributeMap.setSource(parserContext.extractSource(attrEle)); for (Element methodEle : methods) { String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE); TypedStringValue nameHolder = new TypedStringValue(name); nameHolder.setSource(parserContext.extractSource(methodEle)); RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute(); String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE); String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE); String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE); String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE); if (StringUtils.hasText(propagation)) { attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation); } if (StringUtils.hasText(isolation)) { attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation); } if (StringUtils.hasText(timeout)) { try { attribute.setTimeout(Integer.parseInt(timeout)); } catch (NumberFormatException ex) { parserContext.getReaderContext().error("Timeout must be an integer value: [" + timeout + "]", methodEle); } } if (StringUtils.hasText(readOnly)) { attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY_ATTRIBUTE))); } List<RollbackRuleAttribute> rollbackRules = new LinkedList<>(); if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) { String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE); addRollbackRuleAttributesTo(rollbackRules,rollbackForValue); } if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) { String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE); addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue); } attribute.setRollbackRules(rollbackRules); transactionAttributeMap.put(nameHolder, attribute); } RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class); attributeSourceDefinition.setSource(parserContext.extractSource(attrEle)); attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap); return attributeSourceDefinition; }
Example 20
Source File: ConfigBeanDefinitionParser.java From java-technology-stack with MIT License | 4 votes |
private void parseAspect(Element aspectElement, ParserContext parserContext) { String aspectId = aspectElement.getAttribute(ID); String aspectName = aspectElement.getAttribute(REF); try { this.parseState.push(new AspectEntry(aspectId, aspectName)); List<BeanDefinition> beanDefinitions = new ArrayList<>(); List<BeanReference> beanReferences = new ArrayList<>(); 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(); } }