List of usage examples for org.springframework.util.xml DomUtils getChildElementsByTagName
public static List<Element> getChildElementsByTagName(Element ele, String childEleName)
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Finds the attribute type of the schema being used by the element. * * @param tag - The tag to check.//from w w w . j ava 2 s. c o m * @return The schema attribute type. */ protected BeanTagAttribute.AttributeType findBeanType(Element tag) { int numberChildren = 0; // Checks if the user overrides the default attribute type of the schema. String overrideType = tag.getAttribute("overrideBeanType"); if (!StringUtils.isEmpty(overrideType)) { if (overrideType.toLowerCase().compareTo("singlebean") == 0) { return BeanTagAttribute.AttributeType.SINGLEBEAN; } if (overrideType.toLowerCase().compareTo("singlevalue") == 0) { return BeanTagAttribute.AttributeType.SINGLEVALUE; } if (overrideType.toLowerCase().compareTo("listbean") == 0) { return BeanTagAttribute.AttributeType.LISTBEAN; } if (overrideType.toLowerCase().compareTo("listvalue") == 0) { return BeanTagAttribute.AttributeType.LISTVALUE; } if (overrideType.toLowerCase().compareTo("mapbean") == 0) { return BeanTagAttribute.AttributeType.MAPBEAN; } if (overrideType.toLowerCase().compareTo("mapvalue") == 0) { return BeanTagAttribute.AttributeType.MAPVALUE; } if (overrideType.toLowerCase().compareTo("setbean") == 0) { return BeanTagAttribute.AttributeType.SETBEAN; } if (overrideType.toLowerCase().compareTo("setvalue") == 0) { return BeanTagAttribute.AttributeType.SETVALUE; } } // Checks if the element is a list composed of standard types numberChildren = DomUtils.getChildElementsByTagName(tag, "value").size(); if (numberChildren > 0) { return BeanTagAttribute.AttributeType.LISTVALUE; } numberChildren = DomUtils.getChildElementsByTagName(tag, "spring:list").size(); if (numberChildren > 0) { return BeanTagAttribute.AttributeType.LISTBEAN; } numberChildren = DomUtils.getChildElementsByTagName(tag, "spring:set").size(); if (numberChildren > 0) { return BeanTagAttribute.AttributeType.SETBEAN; } // Checks if the element is a map numberChildren = DomUtils.getChildElementsByTagName(tag, "entry").size(); if (numberChildren > 0) { return BeanTagAttribute.AttributeType.MAPVALUE; } numberChildren = DomUtils.getChildElementsByTagName(tag, "map").size(); if (numberChildren > 0) { return BeanTagAttribute.AttributeType.MAPBEAN; } // Checks if the element is a list of beans numberChildren = DomUtils.getChildElements(tag).size(); if (numberChildren > 1) { return BeanTagAttribute.AttributeType.LISTBEAN; } // Defaults to return the element as a single bean. return BeanTagAttribute.AttributeType.SINGLEBEAN; }
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/* w w w. j a va 2s . c o m*/ * 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()); }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseImportsAndIfs(Element profileElement, ParserContext parserContext) { List<Element> importElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_IMPORT); for (Element singleImportElement : importElements) { IMPORT_BEAN_DEFINITION_PARSER.parse(singleImportElement, parserContext); }/*from ww w . j a v a2 s.c o m*/ List<Element> ifElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_IF); for (Element ifElement : ifElements) { IF_BEAN_DEFINITION_PARSER.parse(ifElement, parserContext); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseAndRegisterCapabilityDefinitions(Element profileElement, File origin, BeanDefinitionRegistry registry, ParserContext parserContext) { List<Element> capabilityDefinitionElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_CAPABILITY_DEF);/*www .j a va2 s.c om*/ for (Element capabilityDefElement : capabilityDefinitionElements) { parseAndRegisterSingleCapabilityDefinition(capabilityDefElement, origin, parserContext, registry); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private List<CapabilityDefinitionReference> parseInheritDefinitionElements(Element capabilityDefElement, BeanDefinitionRegistry registry) { Set<CapabilityDefinitionReference> distinctAncestors = new HashSet<>(); List<Element> inheritElements = DomUtils.getChildElementsByTagName(capabilityDefElement, ELEMENT_INHERIT_DEF);// w ww . java 2 s. co m for (Element inheritElement : inheritElements) { String referencedCapabilityId = inheritElement.getAttribute(ATTRIBUTE_CAPABILITY_DEFINITION_REF); String prefix = parseString(inheritElement, ATTRIBUTE_PREFIX, null, registry); CapabilityDefinitionReference capRef = new CapabilityDefinitionReference(referencedCapabilityId, prefix); distinctAncestors.add(capRef); } List<CapabilityDefinitionReference> ancestors = new ArrayList<>(distinctAncestors.size()); ancestors.addAll(distinctAncestors); return ancestors; }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private ManagedList<AttributeKey> parseAttributeKeyElements(Element capabilityDefElement, ParserContext parserContext) {//from w w w. j av a 2s .c o m Set<AttributeKey> attributeKeys = new HashSet<>(); List<Element> attributeKeyElements = DomUtils.getChildElementsByTagName(capabilityDefElement, ELEMENT_ATTRIBUTE_KEY); for (Element attributeKey : attributeKeyElements) { String key = attributeKey.getAttribute(ATTRIBUTE_ATTRIBUTE_KEY_KEY); File origin = determineOrigin(key, parserContext); String description = extractDescription(attributeKey, parserContext.getRegistry()); String defaultValue = parseString(attributeKey, ATTRIBUTE_KEY_DEFAULT, null, parserContext.getRegistry()); boolean optional = Boolean.valueOf(attributeKey.getAttribute(ATTRIBUTE_KEY_OPTIONAL)); if (StringUtils.isNotBlank(key)) { attributeKeys.add(new AttributeKey(key, origin, description, optional, defaultValue)); } } ManagedList<AttributeKey> attributeKeysList = new ManagedList<>(attributeKeys.size()); attributeKeysList.addAll(attributeKeys); return attributeKeysList; }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseAndRegisterUnits(Element profileElement, File origin, BeanDefinitionRegistry registry, ParserContext parserContext) {//from ww w .j av a2s. c o m List<Element> unitElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_UNIT); for (Element unitElement : unitElements) { // first retrieve all XML attributes of the Unit element String unitId = extractMandatoryIdAttributeFromElement(unitElement, "Unit", registry); // TODO: currently not used as there is nowhere to set this on a ConfigurationUnit @SuppressWarnings("unused") String unitType = unitElement.getAttribute(ATTRIBUTE_UNIT_TYPE); boolean unitIsAbstract = Boolean.valueOf(unitElement.getAttribute(ATTRIBUTE_UNIT_ABSTRACT)); String unitExtends = parseString(unitElement, ATTRIBUTE_UNIT_EXTENDS, null, registry); ManagedList<AbstractBeanDefinition> requiredCapabilityReferences = parseRequiredCapabilities( unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> providedCapabilityReferences = parseProvidedCapabilities( unitElement, unitId, registry); ManagedList<Attribute> attributes = parseAttributesElement(unitElement, parserContext); ManagedList<AbstractBeanDefinition> mappings = parseMappingsElement(unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> commands = parseCommands(unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> asserts = parseAsserts(unitElement, registry); BeanDefinitionBuilder unitBeanDefBuilder = null; if (StringUtils.isNotBlank(unitExtends)) { unitBeanDefBuilder = BeanDefinitionBuilder.childBeanDefinition(unitExtends); unitBeanDefBuilder.getRawBeanDefinition().setBeanClass(ConfigurationUnit.class); requiredCapabilityReferences.setMergeEnabled(true); providedCapabilityReferences.setMergeEnabled(true); attributes.setMergeEnabled(true); mappings.setMergeEnabled(true); commands.setMergeEnabled(true); asserts.setMergeEnabled(true); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_PARENT_ID, unitExtends); } else { unitBeanDefBuilder = BeanDefinitionBuilder.rootBeanDefinition(ConfigurationUnit.class); } String description = extractDescription(unitElement, registry); unitBeanDefBuilder.setAbstract(false); unitBeanDefBuilder.addPropertyValue(PROPERTY_ORIGIN, origin); unitBeanDefBuilder.addPropertyValue(PROPERTY_DESCRIPTION, description); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ABSTRACT, unitIsAbstract); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_PROVIDED_CAPABILITIES, providedCapabilityReferences); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_REQUIRED_CAPABILITIES, requiredCapabilityReferences); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ATTRIBUTES, attributes); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_MAPPINGS, mappings); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_COMMANDS, commands); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ASSERTS, asserts); unitBeanDefBuilder.addConstructorArgValue(unitId); RuntimeBeanReference unitBeanRef = new RuntimeBeanReference(unitId); unitBeanRef.setSource(parserContext.getReaderContext().extractSource(unitElement)); registry.registerBeanDefinition(unitId, unitBeanDefBuilder.getBeanDefinition()); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private ManagedList<AbstractBeanDefinition> parseAsserts(Element parentElement, BeanDefinitionRegistry registry) { final ManagedList<AbstractBeanDefinition> asserts = new ManagedList<>(); final List<Element> assertsElements = DomUtils.getChildElementsByTagName(parentElement, ELEMENT_ASSERTS); for (Element assertsElement : assertsElements) { parseUniqueAsserts(asserts, assertsElement, registry); parsePrerequisitesAsserts(asserts, assertsElement, registry); parseIsTrueAsserts(asserts, assertsElement, registry); }/*from w w w .j av a 2 s. c o m*/ return asserts; }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parsePrerequisitesAsserts(final ManagedList<AbstractBeanDefinition> asserts, Element assertsElement, BeanDefinitionRegistry registry) { final List<Element> uniqueAsserts = DomUtils.getChildElementsByTagName(assertsElement, "prerequisite"); for (Element uniqueAssert : uniqueAsserts) { final BeanDefinitionBuilder assertBeanDefBuilder = BeanDefinitionBuilder .genericBeanDefinition(PrerequisiteAssert.class); assertBeanDefBuilder.addConstructorArgValue(uniqueAssert.getAttribute("key")); assertBeanDefBuilder.addConstructorArgValue(parseString(uniqueAssert, "value", null, registry)); asserts.add(assertBeanDefBuilder.getBeanDefinition()); }/* www . jav a 2 s.c o m*/ }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseUniqueAsserts(final ManagedList<AbstractBeanDefinition> asserts, Element assertsElement, BeanDefinitionRegistry registry) { final List<Element> uniqueAsserts = DomUtils.getChildElementsByTagName(assertsElement, "unique"); for (Element uniqueAssert : uniqueAsserts) { final BeanDefinitionBuilder assertBeanDefBuilder = BeanDefinitionBuilder .genericBeanDefinition(UniqueAssert.class); assertBeanDefBuilder.addConstructorArgValue(parseString(uniqueAssert, "value", null, registry)); assertBeanDefBuilder.addConstructorArgValue(parseString(uniqueAssert, "enabled", null, registry)); assertBeanDefBuilder.addConstructorArgValue(parseString(uniqueAssert, "message", null, registry)); asserts.add(assertBeanDefBuilder.getBeanDefinition()); }/*from w w w .j a v a2s . co m*/ }