List of usage examples for org.apache.commons.jxpath JXPathContext getNamespaceURI
public String getNamespaceURI(String prefix)
From source file:jp.go.nict.langrid.bpel.ProcessAnalyzer.java
/** * //from w ww .ja v a 2 s .c o m * */ static QName toQName(JXPathContext aContext, String aValue) { String[] names = aValue.split(":"); if (names.length == 2) { String uri = aContext.getNamespaceURI(names[0]); return new QName(uri, names[1], names[0]); } else if (names.length == 1) { return new QName(names[0]); } else { throw new IllegalArgumentException(String.format("%s is not valid qualified name.", aValue)); } }
From source file:org.firesoa.common.jxpath.model.dom.W3CDomFactory.java
public boolean createObject(JXPathContext context, Pointer pointer, Object parent, String name, int index) { String prefix = null;/* w w w . ja v a 2 s .c om*/ String localName = null; String namespaceURI = null; int thePosition = name.indexOf(":"); if (thePosition > 0) { prefix = name.substring(0, thePosition); localName = name.substring(thePosition + 1); namespaceURI = context.getNamespaceURI(prefix); } else { //???? localName = name; } String qualifiedName = localName; if (prefix != null && !prefix.trim().equals("")) { qualifiedName = prefix + ":" + localName; } addW3CDomElement((Node) parent, index, qualifiedName, namespaceURI); return true; }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
public NodePointer createChild(JXPathContext context, QName name, int index) { if (index == WHOLE_COLLECTION) { index = 0;/*from w w w . j av a2 s.co m*/ } boolean success = getAbstractFactory(context).createObject(context, this, node, name.toString(), index); if (success) { NodeTest nodeTest; String prefix = name.getPrefix(); String namespaceURI = prefix == null ? null : context.getNamespaceURI(prefix); nodeTest = new NodeNameTest(name, namespaceURI); NodeIterator it = childIterator(nodeTest, false, null); if (it != null && it.setPosition(index + 1)) { return it.getNodePointer(); } } throw new JXPathAbstractFactoryException("Factory could not create " + "a child node for path: " + asPath() + "/" + name + "[" + (index + 1) + "]"); }
From source file:org.xchain.framework.lifecycle.Execution.java
/** * Add all custom prefixes for the given command to the context. PrefixMappings are stored in a stack. The last prefix mapping that * is defined must be the first one undefined. Any prefixes that conflict with the command's prefixes will have their original * values saved and will be restored once the prefix mapping is undefined for the given command. * /* w ww .ja v a 2 s .com*/ * @param context The context being used. * @param command The command whose custom prefixes are to be used. */ public static void definePrefixMappings(JXPathContext context, EngineeredCommand command) { PrefixMappingContext prefixContext = null; // get the first prefix mapping. if (prefixMappingStack.get().size() > 0 && prefixMappingStack.get().getFirst().isContextFor(context, command)) { prefixContext = prefixMappingStack.get().getFirst(); prefixContext.setCallCount(prefixContext.getCallCount() + 1); } else { // create a new prefix context. prefixContext = new PrefixMappingContext(context, command); // place the prefix on the top of the prefix context stack. prefixMappingStack.get().addFirst(prefixContext); // iterate over the mappings defined in the command, storing the old values. for (Map.Entry<String, String> entry : command.getPrefixMap().entrySet()) { prefixContext.getOriginalPrefixMap().put(entry.getKey(), context.getNamespaceURI(entry.getKey())); } // set the new values into the context. for (Map.Entry<String, String> entry : command.getPrefixMap().entrySet()) { context.registerNamespace(entry.getKey(), entry.getValue()); } } }
From source file:org.xchain.framework.util.ComponentUtil.java
/** * Add the given array of prefix mappings to the context. * //from w w w .j av a 2 s .c o m * @param context The working context. * @param prefixMappings The prefix mappings to add. * * @return A prefix to namespace uri mapping of prefixes that were replaced. */ private static Map<String, String> pushPrefixMap(JXPathContext context, PrefixMapping prefixMappings[]) { Map<String, String> originalPrefixMapping = null; if (prefixMappings.length > 0) { originalPrefixMapping = new HashMap<String, String>(); // Perform prefix mappings for (PrefixMapping prefixMap : prefixMappings) { // Store the original namespace for the prefix. originalPrefixMapping.put(prefixMap.prefix(), context.getNamespaceURI(prefixMap.prefix())); // Register the new namespace. context.registerNamespace(prefixMap.prefix(), prefixMap.uri()); } } return originalPrefixMapping; }
From source file:org.xchain.framework.util.JXPathContextUtil.java
/** * Converts a string to a qName based on the mappings in the context object. *//*from w ww . j av a 2s. c o m*/ public static QName stringToQName(JXPathContext context, String value) { Matcher matcher = uriLocalNamePattern.matcher(value); if (matcher.matches()) { String uri = matcher.group(1); String localName = matcher.group(2); return new QName(uri, localName); } matcher = prefixLocalNamePattern.matcher(value); if (matcher.matches()) { String prefix = matcher.group(1); String localName = matcher.group(2); // get the uri for the prefix. String uri = context.getNamespaceURI(prefix); if (uri != null) { return new QName(uri, localName); } else { throw new RuntimeException("Could not find uri for prefix '" + prefix + "'."); } } matcher = localNamePattern.matcher(value); if (matcher.matches()) { return new QName(matcher.group(1)); } throw new RuntimeException("Could not parse the qName '" + value + "'."); }
From source file:org.xchain.javassist.CommandEngineeringTest.java
@Test public void testExtendingExecute() throws Exception { Command command = getExtendingCommand("org.xchain.javassist.SimpleCommand"); // create a context. JXPathContext context = JXPathContext.newContext(new Object()); // execute the command command.execute(context);/*from w w w .j av a 2 s . c om*/ // assert that the namespace was defined while the command executed. assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test", context.getValue("$namespace")); // assert that the namespace is no longer defined on the context. assertEquals("The namespace was still defined on the context.", (String) null, context.getNamespaceURI("test")); }
From source file:org.xchain.javassist.CommandEngineeringTest.java
@Test public void testWrappingExecute() throws Exception { Command command = getWrappingCommand("org.xchain.javassist.SimpleCommand"); // create a context. JXPathContext context = JXPathContext.newContext(new Object()); // execute the command command.execute(context);/*w w w.java 2 s. co m*/ // assert that the namespace was defined while the command executed. assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test", context.getValue("$namespace")); // assert that the namespace is no longer defined on the context. assertEquals("The namespace was still defined on the context.", (String) null, context.getNamespaceURI("test")); }
From source file:org.xchain.javassist.CommandEngineeringTest.java
@Test public void testWrappingInnerExecute() throws Exception { Command command = getWrappingInnerCommand("org.xchain.javassist.InnerClassCommand"); // create a context. JXPathContext context = JXPathContext.newContext(new Object()); // execute the command command.execute(context);//from w ww . j ava 2 s . c o m // assert that the namespace was defined while the command executed. assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test", context.getValue("$namespace")); assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test-inner", context.getValue("$inner-namespace")); assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test-static-inner", context.getValue("$static-inner-namespace")); // assert that the namespace is no longer defined on the context. assertEquals("The namespace was still defined on the context.", (String) null, context.getNamespaceURI("test")); }
From source file:org.xchain.javassist.InnerClassCommand.java
public boolean execute(JXPathContext context) throws Exception { String testNamespace = context.getNamespaceURI("test"); context.getVariables().declareVariable("namespace", testNamespace); staticInnerCommand.execute(context); innerCommand.execute(context);//from w w w . j a v a 2 s. c o m return true; }