List of usage examples for org.springframework.util.xml DomUtils getTextValue
public static String getTextValue(Element valueEle)
From source file:org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.java
/** * Parse a props element.//from w w w . j a va 2 s . com */ protected Properties parsePropsElement(Element propsEle, String beanName) throws BeanDefinitionStoreException { Properties props = new Properties(); List propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Iterator it = propEles.iterator(); it.hasNext();) { Element propEle = (Element) it.next(); 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(); props.setProperty(key, value); } return props; }
From source file:org.springframework.ide.eclipse.osgi.blueprint.internal.BlueprintParser.java
/** * Parse a props element./*from w ww . j ava 2s .com*/ */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new OrderedManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, BeanDefinitionParserDelegate.PROP_ELEMENT); for (Iterator<Element> it = propEles.iterator(); it.hasNext();) { Element propEle = 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.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the unit info DOM element./*from w w w. j a va 2s . c o m*/ */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the {@code class} XML elements. *//*from www . jav a 2 s. c o m*/ 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); } }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the {@code mapping-file} XML elements. *///from w ww. j a v a 2 s.c o m protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME); for (Element element : files) { String value = DomUtils.getTextValue(element).trim(); if (StringUtils.hasText(value)) { unitInfo.addMappingFileName(value); } } }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the {@code jar-file} XML elements. *//*w w w . jav a 2s . co m*/ 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"); } } } } }
From source file:org.springmodules.remoting.xmlrpc.dom.AbstractDomXmlRpcParser.java
/** * Parses the given XML element that contains a member of a XML-RPC complex * structure./*from www . jav a2s.co m*/ * * @param memberElement * the XML element to parse. * @return the created member of a XML-RPC complex structure. * @throws XmlRpcInvalidPayloadException * if the element contains a child with an unknown name. Only one * element with name "name" and one element with name "value" are * allowed inside an "member" element. * @throws XmlRpcInvalidPayloadException * if the name of the parsed struct member is empty. * @see #parseValueElement(Element) */ protected final XmlRpcMember parseMemberElement(Element memberElement) { String name = null; XmlRpcElement value = null; NodeList children = memberElement.getChildNodes(); int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node child = children.item(i); if (child instanceof Element) { String childName = child.getNodeName(); if (XmlRpcElementNames.NAME.equals(childName)) { Element nameElement = (Element) child; name = DomUtils.getTextValue(nameElement); } else if (XmlRpcElementNames.VALUE.equals(childName)) { Element valueElement = (Element) child; value = parseValueElement(valueElement); } else { XmlRpcParsingUtils.handleUnexpectedElementFound(childName); } } } if (!StringUtils.hasText(name)) { throw new XmlRpcInvalidPayloadException("The struct member should have a name"); } return new XmlRpcMember(name, value); }
From source file:org.springmodules.remoting.xmlrpc.dom.AbstractDomXmlRpcParser.java
/** * Parses the given XML element that contains the value of a parameter, a * struct member or an element of an array. * /*from w w w . j a va2s . c o m*/ * @param valueElement * the XML element to parse. * @return the created value. * @throws XmlRpcInvalidPayloadException * if there are invalid XML elements. * @see #parseArrayElement(Element) * @see #parseStructElement(Element) */ protected final XmlRpcElement parseValueElement(Element valueElement) { NodeList children = valueElement.getChildNodes(); int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node child = children.item(i); if (child instanceof Element) { String childName = child.getNodeName(); Element xmlElement = (Element) child; if (XmlRpcElementNames.ARRAY.equals(childName)) { return parseArrayElement(xmlElement); } else if (XmlRpcElementNames.BASE_64.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcBase64(source); } else if (XmlRpcElementNames.BOOLEAN.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcBoolean(source); } else if (XmlRpcElementNames.DATE_TIME.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcDateTime(source); } else if (XmlRpcElementNames.DOUBLE.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcDouble(source); } else if (XmlRpcElementNames.I4.equals(childName) || XmlRpcElementNames.INT.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcInteger(source); } else if (XmlRpcElementNames.STRING.equals(childName)) { String source = DomUtils.getTextValue(xmlElement); return new XmlRpcString(source); } else if (XmlRpcElementNames.STRUCT.equals(childName)) { return parseStructElement(xmlElement); } else { XmlRpcParsingUtils.handleUnexpectedElementFound(childName); } } else if (child instanceof Text) { String source = DomUtils.getTextValue(valueElement); return new XmlRpcString(source); } } // we should not reach this point. return null; }