本文整理汇总了Java中org.springframework.util.xml.SimpleNamespaceContext类的典型用法代码示例。如果您正苦于以下问题:Java SimpleNamespaceContext类的具体用法?Java SimpleNamespaceContext怎么用?Java SimpleNamespaceContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleNamespaceContext类属于org.springframework.util.xml包,在下文中一共展示了SimpleNamespaceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: naConstructie
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
/**
* Zet xpath namespace ctx & initialiseer database met afnemervoorbeeld schema.
*/
@PostConstruct
//heeft shutdown hook
//
public void naConstructie() {
final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext.bindNamespaceUri("brp", "http://www.bzk.nl/brp/brp0200");
xPath.setNamespaceContext(nsContext);
LOGGER.warn("Berichten opslaan in database: {}", isDatabasePersistent);
if (isDatabasePersistent) {
final ClassPathXmlApplicationContext cp = new ClassPathXmlApplicationContext("afnemervoorbeeld-databasepersist-context.xml");
cp.registerShutdownHook();
jdbcTemplate = (JdbcTemplate) cp.getBean("jdbcTemplate");
}
}
示例2: createXPathExpression
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
public static XPathExpression createXPathExpression(String expression) {
SimpleNamespaceContext namespaces = new SimpleNamespaceContext();
// NOTE: These are the internal prefixes used in XPath expression
namespaces.bindNamespaceUri("wfs", NS_URL_WFS);
namespaces.bindNamespaceUri("xlink", NS_URL_XLINK);
namespaces.bindNamespaceUri("gml", NS_URL_GML);
namespaces.bindNamespaceUri("ogc", NS_URL_OGC);
namespaces.bindNamespaceUri("ktjkiiwfs", NS_URL_KTJ_KIINTEISTO);
namespaces.bindDefaultNamespaceUri(NS_URL_KTJ_KIINTEISTO);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(namespaces);
try {
return xpath.compile(expression);
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}
示例3: getTargetLanguage
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
/**
* Gets the target language of the XLIFF by looking at the first "file"
* element.
*
* @param xliffContent xliff content from which to extract the target language
* @return the target language or {@code null} if not found
*/
public String getTargetLanguage(String xliffContent) {
String targetLanguage = null;
InputSource inputSource = new InputSource(new StringReader(xliffContent));
XPath xPath = XPathFactory.newInstance().newXPath();
SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
simpleNamespaceContext.bindNamespaceUri("xlf", "urn:oasis:names:tc:xliff:document:1.2");
xPath.setNamespaceContext(simpleNamespaceContext);
try {
Node node = (Node) xPath.evaluate("/xlf:xliff/xlf:file[1]/@target-language", inputSource, XPathConstants.NODE);
if(node != null) {
targetLanguage = node.getTextContent();
}
} catch (XPathExpressionException xpee) {
logger.debug("Can't extract target language from xliff", xpee);
}
return targetLanguage;
}
示例4: selectNodes
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
/**
* Select all nodes that are selected by this XPath expression. If multiple nodes match,
* multiple nodes will be returned. Nodes will be returned in document-order,
* @param path
* @param node
* @param namespaces Namespaces that need to be available in the xpath, where the key is the
* prefix and the value the namespace URI
* @return
*/
public static NodeList selectNodes(String path, Object node, Map<String, String> namespaces) {
try {
XPathFactory factory = XPathFactory.newInstance();
javax.xml.xpath.XPath xpath = factory.newXPath();
if (namespaces != null) {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
bindUnboundedNamespaces(nsContext, namespaces);
xpath.setNamespaceContext(nsContext);
}
return (NodeList) xpath.evaluate(path, node, XPathConstants.NODESET);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: selectNode
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
public static Node selectNode(String path, Object node, Map<String, String> namespaces) {
try {
XPathFactory factory = XPathFactory.newInstance();
javax.xml.xpath.XPath xpath = factory.newXPath();
if (namespaces != null) {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
bindUnboundedNamespaces(nsContext, namespaces);
xpath.setNamespaceContext(nsContext);
}
return (Node) xpath.evaluate(path, node, XPathConstants.NODE);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: selectText
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
/**
* Return the text of a node, or the value of an attribute
* @param path the XPath to execute
* @param node the node, node-set or Context object for evaluation. This value can be null.
*/
public static String selectText(String path, Object node, Map<String, String> namespaces) {
try {
XPathFactory factory = XPathFactory.newInstance();
javax.xml.xpath.XPath xpath = factory.newXPath();
if (namespaces != null) {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
bindUnboundedNamespaces(nsContext, namespaces);
xpath.setNamespaceContext(nsContext);
}
return (String) xpath.evaluate(path, node, XPathConstants.STRING);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: parseToUrlList
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
protected List<String> parseToUrlList(String responseBody) throws ParseUrlException {
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
SimpleNamespaceContext namespaces = new SimpleNamespaceContext();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("x", "http://openrosa.org/xforms/xformsList");
namespaces.setBindings(namespaceMap);
xPath.setNamespaceContext(namespaces);
InputSource inputSource = new InputSource(new ByteArrayInputStream(responseBody.getBytes()));
NodeList nodeList = (NodeList) xPath.compile("/x:xforms/x:xform/x:downloadUrl").evaluate(inputSource, XPathConstants.NODESET);
List<String> urls = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i).getFirstChild();
urls.add(node.getNodeValue());
}
return urls;
} catch (XPathExpressionException e) {
throw new ParseUrlException(e);
}
}
示例8: translate
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
@Override
public <T> T translate(Node node, T value, TestContext context) {
for (Map.Entry<String, String> expressionEntry : mappings.entrySet()) {
String expression = expressionEntry.getKey();
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
namespaceContext.setBindings(context.getNamespaceContextBuilder().getNamespaceMappings());
NodeList findings = (NodeList) XPathUtils.evaluateExpression(node.getOwnerDocument(), expression, namespaceContext, XPathConstants.NODESET);
if (findings != null && containsNode(findings, node)) {
return convertIfNecessary(context.replaceDynamicContentInString(expressionEntry.getValue()), value);
}
}
return value;
}
示例9: transform
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
private static XPathRoot transform(TransformationBuilder builder) {
StreamResult result;
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
try {
TransformerFactory transformerFactory = (TransformerFactory)
Class.forName(XsltTransformer.PREFERRED_TRANSFORMER_FACTORY).newInstance();
Transformer transformer = transformerFactory.newTransformer(
new StreamSource(XmlTransformationTestUtil.class.getResourceAsStream(builder.stylesheet)));
for (Map.Entry<String, Object> mapEntry : builder.parameterMap.entrySet()) {
transformer.setParameter(mapEntry.getKey(), mapEntry.getValue());
}
result = new StreamResult(new StringWriter());
transformer.transform(new StreamSource(XmlTransformationTestUtil.class.getResourceAsStream(builder.source)), result);
} catch (Exception e) {
throw new GreenbirdTestException(e);
}
for (String key : builder.namespaceMap.keySet()) {
namespaceContext.bindNamespaceUri(key, builder.namespaceMap.get(key));
}
return XPathRoot.forString(result.getWriter().toString()).withNamespaceContext(namespaceContext);
}
示例10: initializeXPath
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
private static XPath initializeXPath() {
final Map<String, String> mappings = new HashMap<>();
mappings.put(BRP_NAMESPACE_PREFIX.replace(":", ""), BRP_NAMESPACE_URI);
final SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
simpleNamespaceContext.setBindings(mappings);
final XPathFactory xPathFactory = XPathFactory.newInstance();
final XPath xpath = xPathFactory.newXPath();
xpath.setNamespaceContext(simpleNamespaceContext);
return xpath;
}
示例11: compileXpathExpression
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
private XPathExpression compileXpathExpression(String expression, Map<String, String> namespaces)
throws XPathExpressionException {
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
namespaceContext.setBindings((namespaces != null) ? namespaces : Collections.<String, String> emptyMap());
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(namespaceContext);
return xpath.compile(expression);
}
示例12: getModules
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
/**
* Get the Citrus modules for this project based on the build dependencies.
* @return
*/
public List<Module> getModules() {
List<Module> modules = new ArrayList<>();
Collection<String> allModules = new SpringBeanNamespacePrefixMapper().getNamespaceMappings().values();
if (project.isMavenProject()) {
try {
String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile()));
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext.bindNamespaceUri("mvn", "http://maven.apache.org/POM/4.0.0");
Document pomDoc = XMLUtils.parseMessagePayload(pomXml);
NodeList dependencies = XPathUtils.evaluateAsNodeList(pomDoc, "/mvn:project/mvn:dependencies/mvn:dependency/mvn:artifactId[starts-with(., 'citrus-')]", nsContext);
for (int i = 0; i < dependencies.getLength(); i++) {
String moduleName = DomUtils.getTextValue((Element) dependencies.item(i));
if (moduleName.equals("citrus-core")) {
allModules.remove("citrus");
} else {
allModules.remove(moduleName);
}
modules.add(new Module(moduleName.substring("citrus-".length()), getActiveProject().getVersion(), true));
}
} catch (IOException e) {
throw new ApplicationRuntimeException("Unable to open Maven pom.xml file", e);
}
}
allModules.stream()
.filter(name -> !name.equals("citrus-test"))
.map(name -> name.equals("citrus") ? "citrus-core" : name)
.map(name -> new Module(name.substring("citrus-".length()), getActiveProject().getVersion(), false))
.forEach(modules::add);
return modules;
}
示例13: bindUnboundedNamespaces
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
private static void bindUnboundedNamespaces(SimpleNamespaceContext nsContext, Map<String, String> namespaces) {
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
//making sure that namespace is not already bound. Otherwise UnsupportedException happens
if(nsContext.getPrefix(entry.getValue()) == null) {
nsContext.bindNamespaceUri(entry.getKey(), entry.getValue());
}
}
}
示例14: XformParserODK
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
public XformParserODK() {
XPathFactory xPathFactory = XPathFactory.newInstance();
this.xPath = xPathFactory.newXPath();
SimpleNamespaceContext namespaces = new SimpleNamespaceContext();
namespaces.setBindings(NAMESPACE_MAP);
this.xPath.setNamespaceContext(namespaces);
}
示例15: XPathHelper
import org.springframework.util.xml.SimpleNamespaceContext; //导入依赖的package包/类
public XPathHelper() {
xpath = XPathFactory
.newInstance()
.newXPath();
namespaceContext = new SimpleNamespaceContext();
xpath.setNamespaceContext(namespaceContext);
}