List of usage examples for org.springframework.util.xml DomUtils getTextValue
public static String getTextValue(Element valueEle)
From source file:com.enonic.esl.xml.XMLTool.java
public static String getElementText(Element element) { if (element == null) { return null; } else {/*from w w w.j a v a 2 s. com*/ String value = DomUtils.getTextValue(element); if (value == null) { return null; } else if (value.trim().length() == 0) { return null; } else { return value; } } }
From source file:org.akaza.openclinica.ws.EventEndpoint.java
/** * Process createEvent request by creating StudyEventTransferBean from received payload. * //from w ww .j av a 2s. c o m * @param subjectElement * @return SubjectTransferBean * @throws ParseException */ private StudyEventTransferBean unMarshallToEventTransfer(Element eventElement) throws ParseException { Element eventDefinitionOidElement = DomUtils.getChildElementByTagName(eventElement, "eventDefinitionOID"); Element locationElement = DomUtils.getChildElementByTagName(eventElement, "location"); Element startDateElement = DomUtils.getChildElementByTagName(eventElement, "startDate"); Element endDateElement = DomUtils.getChildElementByTagName(eventElement, "endDate"); Element startTimeElement = DomUtils.getChildElementByTagName(eventElement, "startTime"); Element endTimeElement = DomUtils.getChildElementByTagName(eventElement, "endTime"); Element subjectRefElement = DomUtils.getChildElementByTagName(eventElement, "studySubjectRef"); Element labelElement = DomUtils.getChildElementByTagName(subjectRefElement, "label"); Element studyRefElement = DomUtils.getChildElementByTagName(eventElement, "studyRef"); Element studyIdentifierElement = DomUtils.getChildElementByTagName(studyRefElement, "identifier"); Element siteRef = DomUtils.getChildElementByTagName(studyRefElement, "siteRef"); Element siteIdentifierElement = siteRef == null ? null : DomUtils.getChildElementByTagName(siteRef, "identifier"); String studySubjectId = DomUtils.getTextValue(labelElement).trim(); String eventDefinitionOID = DomUtils.getTextValue(eventDefinitionOidElement).trim(); String studyIdentifier = DomUtils.getTextValue(studyIdentifierElement).trim(); String siteIdentifier = siteIdentifierElement == null ? null : DomUtils.getTextValue(siteIdentifierElement).trim(); String location = locationElement == null ? null : DomUtils.getTextValue(locationElement).trim(); String startDate = DomUtils.getTextValue(startDateElement).trim(); String startTime = startTimeElement == null ? null : DomUtils.getTextValue(startTimeElement).trim(); String endDate = endDateElement == null ? null : DomUtils.getTextValue(endDateElement).trim(); String endTime = endTimeElement == null ? null : DomUtils.getTextValue(endTimeElement).trim(); StudyEventTransferBean studyEventTransferBean = new StudyEventTransferBean(studySubjectId, studyIdentifier, siteIdentifier, eventDefinitionOID, location, getDate(startDate, startTime), getDate(endDate, endTime), getUserAccount()); return studyEventTransferBean; }
From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java
/** * Return a typed String value Object for the given value element. * /*from w w w.ja va 2 s .c o m*/ * @param ele element * @param defaultTypeName type class name * @return typed String value Object */ private Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(BeanDefinitionParserDelegate.TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java
/** * Parse a props element.//from ww w. ja v a 2s.c om */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new OrderedManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List propEles = DomUtils.getChildElementsByTagName(propsEle, BeanDefinitionParserDelegate.PROP_ELEMENT); for (Iterator it = propEles.iterator(); it.hasNext();) { Element propEle = (Element) it.next(); String key = propEle.getAttribute(BeanDefinitionParserDelegate.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; }
From source file:org.impalaframework.util.XMLDomUtils.java
public static String readOptionalElementText(Element element, String childName) { Element childElement = DomUtils.getChildElementByTagName(element, childName); String text = null;// ww w . ja v a2 s .com if (childElement != null) text = DomUtils.getTextValue(childElement); return text; }
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//from w w w.ja va2 s .c o m * * @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.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java
/** * Parse replaced-method sub-elements of the given bean element. */// w w w . j a v a2 s. c o m public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java
/** * Return a typed String value Object for the given value element. *///w w w .java 2 s. c o m public Object parseValueElement(Element ele, @Nullable String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java
/** * Parse a props element./* w w w .j a va2 s .com*/ */ 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; }
From source file:org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.java
/** * Parse a value, ref or collection sub-element of a property or * constructor-arg element.//from w w w .j a va 2 s .c om * @param ele subelement of property element; we don't know which yet */ protected Object parsePropertySubElement(Element ele, String beanName) throws BeanDefinitionStoreException { if (ele.getTagName().equals(BEAN_ELEMENT)) { try { return parseBeanDefinitionElement(ele, true); } catch (BeanDefinitionStoreException ex) { throw new BeanDefinitionStoreException(getResource(), beanName, "Could not parse inner bean definition", ex); } } else if (ele.getTagName().equals(REF_ELEMENT)) { // A generic reference to any name of any bean. String refName = ele.getAttribute(BEAN_REF_ATTRIBUTE); boolean toParent = false; if (!StringUtils.hasLength(refName)) { // A reference to the id of another bean in the same XML file. refName = ele.getAttribute(LOCAL_REF_ATTRIBUTE); if (!StringUtils.hasLength(refName)) { // A reference to the id of another bean in a parent context. refName = ele.getAttribute(PARENT_REF_ATTRIBUTE); toParent = true; if (!StringUtils.hasLength(refName)) { throw new BeanDefinitionStoreException(getResource(), beanName, "'bean', 'local' or 'parent' is required for <ref> element"); } } } if (!StringUtils.hasText(refName)) { throw new BeanDefinitionStoreException(getResource(), beanName, "<ref> element contains empty target attribute"); } return new RuntimeBeanReference(refName, toParent); } else if (ele.getTagName().equals(IDREF_ELEMENT)) { // A generic reference to any name of any bean. String beanRef = ele.getAttribute(BEAN_REF_ATTRIBUTE); if (!StringUtils.hasLength(beanRef)) { // A reference to the id of another bean in the same XML file. beanRef = ele.getAttribute(LOCAL_REF_ATTRIBUTE); if (!StringUtils.hasLength(beanRef)) { throw new BeanDefinitionStoreException(getResource(), beanName, "Either 'bean' or 'local' is required for <idref> element"); } } return beanRef; } else if (ele.getTagName().equals(VALUE_ELEMENT)) { // It's a literal value. String value = DomUtils.getTextValue(ele); if (ele.hasAttribute(TYPE_ATTRIBUTE)) { String typeClassName = ele.getAttribute(TYPE_ATTRIBUTE); try { Class typeClass = ClassUtils.forName(typeClassName, this.beanDefinitionReader.getBeanClassLoader()); return new TypedStringValue(value, typeClass); } catch (ClassNotFoundException ex) { throw new BeanDefinitionStoreException(getResource(), beanName, "Type class [" + typeClassName + "] not found for <value> element", ex); } } return value; } else if (ele.getTagName().equals(NULL_ELEMENT)) { // It's a distinguished null value. return null; } else if (ele.getTagName().equals(LIST_ELEMENT)) { return parseListElement(ele, beanName); } else if (ele.getTagName().equals(SET_ELEMENT)) { return parseSetElement(ele, beanName); } else if (ele.getTagName().equals(MAP_ELEMENT)) { return parseMapElement(ele, beanName); } else if (ele.getTagName().equals(PROPS_ELEMENT)) { return parsePropsElement(ele, beanName); } throw new BeanDefinitionStoreException(getResource(), beanName, "Unknown property sub-element: <" + ele.getTagName() + ">"); }