List of usage examples for org.springframework.util.xml DomUtils getChildElements
public static List<Element> getChildElements(Element ele)
From source file:com.joyveb.dbpimpl.cass.prepare.config.xml.CassandraSessionParser.java
private ManagedList<Object> parseTablesAttributes(Element element) { List<Element> subElements = DomUtils.getChildElements(element); ManagedList<Object> tables = new ManagedList<Object>(subElements.size()); // parse nested elements for (Element subElement : subElements) { String name = subElement.getLocalName(); if ("table".equals(name)) { tables.add(parseTable(subElement)); }/* w w w . jav a 2 s. co m*/ } return tables; }
From source file:org.sarons.spring4me.web.page.config.xml.XmlPageConfigFactory.java
private WidgetConfig parseWidget(Element widgetEle, GroupConfig groupConfig) { String id = widgetEle.getAttribute("id"); String name = widgetEle.getAttribute("name"); String path = widgetEle.getAttribute("path"); String cacheStr = widgetEle.getAttribute("cache"); String disabled = widgetEle.getAttribute("disabled"); ///*w w w.j a va 2 s . co m*/ int cache = -1; if (StringUtils.hasText(cacheStr)) { cache = Integer.valueOf(cacheStr); } // WidgetConfig widgetConfig = new WidgetConfig(groupConfig); widgetConfig.setId(id); widgetConfig.setName(name); widgetConfig.setPath(path); widgetConfig.setCache(cache); widgetConfig.setDisabled("true".equals(disabled)); // Element titleEle = DomUtils.getChildElementByTagName(widgetEle, "title"); if (titleEle != null) { String title = titleEle.getTextContent(); widgetConfig.setTitle(title); } // Element descEle = DomUtils.getChildElementByTagName(widgetEle, "description"); if (descEle != null) { String description = descEle.getTextContent(); widgetConfig.setDescription(description); } // Map<String, String> events = new HashMap<String, String>(); Element eventsEle = DomUtils.getChildElementByTagName(widgetEle, "events"); if (eventsEle != null) { List<Element> eventEles = DomUtils.getChildElements(eventsEle); for (Element eventEle : eventEles) { String on = eventEle.getAttribute("on"); String to = eventEle.getAttribute("to"); events.put(on, to); } widgetConfig.getGroupConfig().getPageConfig().setEvents(events); } // Map<String, String> preferences = new HashMap<String, String>(); Element prefEle = DomUtils.getChildElementByTagName(widgetEle, "preference"); if (prefEle != null) { List<Element> keyValueEles = DomUtils.getChildElements(prefEle); for (Element keyValueEle : keyValueEles) { String key = keyValueEle.getTagName(); String value = keyValueEle.getTextContent(); preferences.put(key, value); } widgetConfig.setPreferences(preferences); } // return widgetConfig; }
From source file:eap.config.ConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); configureAutoProxyCreator(parserContext, element); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { String localName = parserContext.getDelegate().getLocalName(elt); if (POINTCUT.equals(localName)) { parsePointcut(elt, parserContext); } else if (ADVISOR.equals(localName)) { parseAdvisor(elt, parserContext); } else if (ASPECT.equals(localName)) { parseAspect(elt, parserContext); }// ww w.j a v a2s. c o m } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:org.focusns.common.web.page.config.xml.XmlPageFactory.java
private PageConfig parsePageConfigFile(Element pageEle) { //// w w w. ja va 2 s .co m String path = pageEle.getAttribute("path"); String layout = pageEle.getAttribute("layout"); String authority = pageEle.getAttribute("authority"); Map<String, String> parameters = getParameters(pageEle); // PageConfig pageConfig = new PageConfig(path, layout); pageConfig.setAuthority(authority); pageConfig.setParameters(parameters); List<Element> positionEles = DomUtils.getChildElementsByTagName(pageEle, "position"); for (Element positionEle : positionEles) { // String position = positionEle.getAttribute("name"); PositionConfig positionConfig = new PositionConfig(pageConfig); positionConfig.setName(position); List<Element> widgetEles = DomUtils.getChildElementsByTagName(positionEle, "widget"); for (Element widgetEle : widgetEles) { // String styleId = widgetEle.getAttribute("styleId"); String styleClass = widgetEle.getAttribute("styleClass"); // String context = widgetEle.getAttribute("context"); String target = widgetEle.getAttribute("target"); String mode = widgetEle.getAttribute("mode"); String cache = widgetEle.getAttribute("cache"); String order = widgetEle.getAttribute("order"); // WidgetConfig widgetConfig = new WidgetConfig(positionConfig); widgetConfig.setStyleId(styleId); widgetConfig.setStyleClass(styleClass); widgetConfig.setContext(context); widgetConfig.setTarget(target); widgetConfig.setMode(mode); widgetConfig.setCache("".equals(cache) ? 0 : Integer.parseInt(cache)); widgetConfig.setOrder("".equals(order) ? 0 : Integer.parseInt(order)); // preference element Element preferenceEle = DomUtils.getChildElementByTagName(widgetEle, "preference"); if (preferenceEle != null) { for (Element prefEle : DomUtils.getChildElements(preferenceEle)) { String name = prefEle.getAttribute("name"); String value = DomUtils.getTextValue(prefEle); widgetConfig.getPreferences().put(name, value); } } // navigation Element navigationEle = DomUtils.getChildElementByTagName(widgetEle, "navigation"); if (navigationEle != null) { Map<String, String> navigationMap = new HashMap<String, String>(); List<Element> eventEles = DomUtils.getChildElementsByTagName(navigationEle, "event"); for (Element eventEle : eventEles) { String eventOn = eventEle.getAttribute("on"); String eventTo = DomUtils.getTextValue(eventEle); navigationMap.put(eventOn, eventTo); } widgetConfig.setNavigationMap(navigationMap); } // validation Element validationEle = DomUtils.getChildElementByTagName(widgetEle, "validation"); if (validationEle != null) { widgetConfig.setValidationForm(validationEle.getAttribute("formId")); Element targetEle = DomUtils.getChildElementByTagName(validationEle, "target"); if (targetEle != null) { widgetConfig.setValidationTarget(DomUtils.getTextValue(targetEle).trim()); } Element groupsEle = DomUtils.getChildElementByTagName(validationEle, "groups"); if (groupsEle != null) { List<String> validationGroups = new ArrayList<String>(); List<Element> groupEles = DomUtils.getChildElementsByTagName(groupsEle, "group"); for (Element groupEle : groupEles) { validationGroups.add(DomUtils.getTextValue(groupEle).trim()); } widgetConfig.setValidationGroups(validationGroups); } } // positionConfig.addWidgetConfig(widgetConfig); // pageConfig.addWidgetConfig(position, widgetConfig); } pageConfig.addPositionConfig(positionConfig); } // return pageConfig; }
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.//w ww .j a v a 2s .c om * * @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.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses the xml bean into a standard bean definition format and fills the information in the passed in definition * builder/* w ww .j a v a2s . c om*/ * * @param element - The xml bean being parsed. * @param parserContext - Provided information and functionality regarding current bean set. * @param bean - A definition builder used to build a new spring bean from the information it is filled with. */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) { // Retrieve custom schema information build from the annotations Map<String, Map<String, BeanTagAttributeInfo>> attributeProperties = CustomTagAnnotations .getAttributeProperties(); Map<String, BeanTagAttributeInfo> entries = attributeProperties.get(element.getLocalName()); // Log error if there are no attributes found for the bean tag if (entries == null) { LOG.error("Bean Tag not found " + element.getLocalName()); } if (element.getTagName().equals(INC_TAG)) { String parentId = element.getAttribute("compId"); bean.setParentName(parentId); return; } if (element.getTagName().equals("content")) { bean.setParentName("Uif-Content"); String markup = nodesToString(element.getChildNodes()); bean.addPropertyValue("markup", markup); return; } // Retrieve the information for the new bean tag and fill in the default parent if needed BeanTagInfo tagInfo = CustomTagAnnotations.getBeanTags().get(element.getLocalName()); String elementParent = element.getAttribute("parent"); if (StringUtils.isNotBlank(elementParent) && !StringUtils.equals(elementParent, tagInfo.getParent())) { bean.setParentName(elementParent); } else if (StringUtils.isNotBlank(tagInfo.getParent())) { bean.setParentName(tagInfo.getParent()); } // Create the map for the attributes found in the tag and process them in to the definition builder. NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { processSingleValue(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue(), entries, bean); } ArrayList<Element> children = (ArrayList<Element>) DomUtils.getChildElements(element); // Process the children found in the xml tag for (int i = 0; i < children.size(); i++) { String tag = children.get(i).getLocalName(); BeanTagAttributeInfo info = entries.get(tag); if (children.get(i).getTagName().equals("spring:property") || children.get(i).getTagName().equals("property")) { BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); delegate.parsePropertyElement(children.get(i), bean.getBeanDefinition()); continue; } // Sets the property name to be used when adding the property value String propertyName; BeanTagAttribute.AttributeType type = null; if (info == null) { propertyName = CustomTagAnnotations.findPropertyByType(element.getLocalName(), tag); if (StringUtils.isNotBlank(propertyName)) { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); continue; } else { // If the tag is not in the schema map let spring handle the value by forwarding the tag as the // propertyName propertyName = tag; type = findBeanType(children.get(i)); } } else { // If the tag is found in the schema map use the connected name stored in the attribute information propertyName = info.getPropertyName(); type = info.getType(); } // Process the information stored in the child bean ArrayList<Element> grandChildren = (ArrayList<Element>) DomUtils.getChildElements(children.get(i)); if (type == BeanTagAttribute.AttributeType.SINGLEVALUE) { String propertyValue = DomUtils.getTextValue(children.get(i)); bean.addPropertyValue(propertyName, propertyValue); } else if (type == BeanTagAttribute.AttributeType.ANY) { String propertyValue = nodesToString(children.get(i).getChildNodes()); bean.addPropertyValue(propertyName, propertyValue); } else if ((type == BeanTagAttribute.AttributeType.DIRECT) || (type == BeanTagAttribute.AttributeType.DIRECTORBYTYPE)) { boolean isPropertyTag = false; if ((children.get(i).getAttributes().getLength() == 0) && (grandChildren.size() == 1)) { String grandChildTag = grandChildren.get(0).getLocalName(); Class<?> valueClass = info.getValueType(); if (valueClass.isInterface()) { try { valueClass = Class.forName(valueClass.getName() + "Base"); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find impl class for interface", e); } } Set<String> validTagNames = CustomTagAnnotations.getBeanTagsByClass(valueClass); if (validTagNames.contains(grandChildTag)) { isPropertyTag = true; } } if (isPropertyTag) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); } } else if ((type == BeanTagAttribute.AttributeType.SINGLEBEAN) || (type == BeanTagAttribute.AttributeType.BYTYPE)) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTBEAN) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTVALUE) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPVALUE) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPBEAN) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETVALUE) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETBEAN) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } } }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Finds the key of a map entry in the custom schema. * * @param grandchild - The map entry.//from w w w. ja v a 2 s .c om * @return The object (bean or value) entry key */ protected Object findKey(Element grandchild, BeanDefinitionBuilder parent, ParserContext parserContext) { String key = grandchild.getAttribute("key"); if (!key.isEmpty()) { return key; } Element keyTag = DomUtils.getChildElementByTagName(grandchild, "key"); if (keyTag != null) { if (DomUtils.getChildElements(keyTag).isEmpty()) { return keyTag.getTextContent(); } else { return parseBean(DomUtils.getChildElements(keyTag).get(0), parent, parserContext); } } return null; }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Finds the value of a map entry in the custom schema. * * @param grandchild - The map entry./* w w w . j a v a 2 s. c o m*/ * @return The object (bean or value) entry value */ protected Object findValue(Element grandchild, BeanDefinitionBuilder parent, ParserContext parserContext) { String value = grandchild.getAttribute("value"); if (!value.isEmpty()) { return value; } Element valueTag = DomUtils.getChildElementByTagName(grandchild, "value"); if (valueTag != null) { if (DomUtils.getChildElements(valueTag).isEmpty()) { return valueTag.getTextContent(); } else { return parseBean(DomUtils.getChildElements(valueTag).get(0), parent, parserContext); } } return null; }
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 a va2 s.com * @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.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private Element profileTypeElement(Element profileElement) { Element profileTypeElement = DomUtils.getChildElementByTagName(profileElement, ELEMENT_TYPE); if (profileTypeElement != null) { Element concreteTypeElement = DomUtils.getChildElements(profileTypeElement).get(0); return concreteTypeElement; }/*from ww w . j a va2 s . c o m*/ return null; }