本文整理汇总了Java中javax.xml.xpath.XPathFunction类的典型用法代码示例。如果您正苦于以下问题:Java XPathFunction类的具体用法?Java XPathFunction怎么用?Java XPathFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathFunction类属于javax.xml.xpath包,在下文中一共展示了XPathFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: functionAvailable
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
/**
* Is the extension function available?
*/
public boolean functionAvailable(String ns, String funcName)
throws javax.xml.transform.TransformerException {
try {
if ( funcName == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"Function Name"} );
throw new NullPointerException ( fmsg );
}
//Find the XPathFunction corresponding to namespace and funcName
javax.xml.namespace.QName myQName = new QName( ns, funcName );
javax.xml.xpath.XPathFunction xpathFunction =
resolver.resolveFunction ( myQName, 0 );
if ( xpathFunction == null ) {
return false;
}
return true;
} catch ( Exception e ) {
return false;
}
}
示例2: createPropertiesFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
private XPathFunction createPropertiesFunction() {
return new XPathFunction() {
@SuppressWarnings("rawtypes")
public Object evaluate(List list) throws XPathFunctionException {
if (!list.isEmpty()) {
Object value = list.get(0);
if (value != null) {
String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
try {
// use the property placeholder resolver to lookup the property for us
Object answer = exchange.get().getContext().resolvePropertyPlaceholders("{{" + text + "}}");
return answer;
} catch (Exception e) {
throw new XPathFunctionException(e);
}
}
}
return null;
}
};
}
示例3: createSimpleFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
private XPathFunction createSimpleFunction() {
return new XPathFunction() {
@SuppressWarnings("rawtypes")
public Object evaluate(List list) throws XPathFunctionException {
if (!list.isEmpty()) {
Object value = list.get(0);
if (value != null) {
String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
Language simple = exchange.get().getContext().resolveLanguage("simple");
Expression exp = simple.createExpression(text);
Object answer = exp.evaluate(exchange.get(), Object.class);
return answer;
}
}
return null;
}
};
}
示例4: endFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
@Override
public void endFunction() throws SAXPathException{
ArrayDeque params = popFrame();
javax.xml.namespace.QName name = (javax.xml.namespace.QName)params.pollFirst();
if(name.getNamespaceURI().length()==0)
push(createFunction(name.getLocalPart(), params).simplify());
else{
int noOfParams = params.size();
XPathFunction function = functionResolver.resolveFunction(name, noOfParams);
if(function==null)
throw new SAXPathException("Unknown Function: "+name);
FunctionCall functionCall = new FunctionCall(new Functions.UserFunction(name.getNamespaceURI(), name.getLocalPart(), function), noOfParams);
for(int i=0; i<noOfParams; i++)
functionCall.addMember(params.pollFirst(), i);
push(functionCall);
}
}
示例5: functionAvailable
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
/**
* Is the extension function available?
*/
public boolean functionAvailable(String ns, String funcName)
throws javax.xml.transform.TransformerException {
try {
if ( funcName == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"Function Name"} );
throw new NullPointerException ( fmsg );
}
//Find the XPathFunction corresponding to namespace and funcName
javax.xml.namespace.QName myQName = new QName( ns, funcName );
javax.xml.xpath.XPathFunction xpathFunction =
resolver.resolveFunction ( myQName, 0 );
if ( xpathFunction == null ) {
return false;
}
return true;
} catch ( Exception e ) {
return false;
}
}
示例6: findFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
/**
* Look for a function in the registered XPathFunctionResolvers.
* @param iri The URI of the function to find.
* @return The requested XPathFunction, or <code>null</code> if not found.
*/
private XPathFunction findFunction(IRI iri, int argCount) {
String label = iri.toString() + "/" + argCount;
XPathFunction result = fnCache.get(label);
if (result == null) {
QName fnName = iri.getQName();
if (fnName == null) return null;
for (XPathFunctionResolver resolver: FunctionResolverRegistry.getFunctionResolverRegistry()) {
try {
result = resolver.resolveFunction(fnName, argCount);
if (result != null) {
fnCache.put(label, result);
break;
}
} catch (Exception e) {
// this resolver is unable to handle the given QName
result = null;
}
}
}
return result;
}
示例7: init
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
public void init(Node ctx, final Map<String, Object> properties,
final ReferenceResolver referenceResolver){
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
xpath.setXPathVariableResolver(new XPathVariableResolver(){
@Override
public Object resolveVariable(QName variableName) {
return properties.get(variableName.getLocalPart());
}
});
xpath.setXPathFunctionResolver(new XPathFunctionResolver(){
@Override
public XPathFunction resolveFunction(QName name, int arity) {
if (FUNC_RANDOM.equals(name.getLocalPart())){
return new XPathFunctionRandom();
}
if (FUNC_EVALUATE.equals(name.getLocalPart())){
return new XPathFunctionEvaluate(referenceResolver);
}
return null;
}
});
this.ctx=ctx;
}
示例8: resolveFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
@Override
public XPathFunction resolveFunction(QName functionName, int arity) {
if (functionName == null) {
throw new NullPointerException("function name cannot be null");
}
if (XmlNamespace.Signavio.getUri().equals(functionName.getNamespaceURI())) {
if (FUNCTION_IS_EMPTY.equals(functionName.getLocalPart())) {
return new SignavioIsEmptyFunction();
// } else if (<your function here>.equals(functionName.getLocalPart())) {
}
}
return null;
}
示例9: resolveFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
@Override
public XPathFunction resolveFunction(final QName functionName, final int arity)
{
if (functionMap.containsKey(functionName))
{
return new XPathFunction()
{
@Override
public Object evaluate(List args) throws XPathFunctionException
{
return functionMap.get(functionName).evaluate(args);
}
};
}
return originalResolver.resolveFunction(functionName, arity);
}
示例10: resolveFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
@Override
public XPathFunction resolveFunction(QName functionQName, int arity) {
boolean enableDebug = false;
String namespace = functionQName.getNamespaceURI();
if (StringUtils.isEmpty(namespace)) {
namespace = MidPointConstants.NS_FUNC_BASIC;
enableDebug = true;
} else if (namespace.equals(MidPointConstants.NS_FUNC_BASIC)) {
enableDebug = true;
}
FunctionLibrary lib = findLibrary(namespace);
if (lib == null) {
LOGGER.trace("Unknown namespace for function {} function with {} arguments", functionQName, arity);
return null;
}
Object functionObject = null;
if (lib.getXmlFunctions() != null) {
functionObject = lib.getXmlFunctions();
} else {
functionObject = lib.getGenericFunctions();
}
String functionName = functionQName.getLocalPart();
LOGGER.trace("Resolving to {} function with {} arguments", functionName, arity);
ReflectionXPathFunctionWrapper xPathFunction = new ReflectionXPathFunctionWrapper(functionObject, functionName,
arity, enableDebug);
return xPathFunction;
}
示例11: resolveFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public XPathFunction resolveFunction (QName name, int arity)
{
// Search up the view hierarchy for a matching function
for (View view = View.this; view != null; view = view.parent) {
Function function = view.functions.get (name);
if (function != null) return (function.getInstance ());
}
return (null);
}
示例12: resolveFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
public XPathFunction resolveFunction(QName name, int arity)
{
String uri = name.getNamespaceURI();
if (XSL_NS.equals(uri) || uri == null || uri.length() == 0)
{
String localName = name.getLocalPart();
if ("document".equals(localName) && (arity == 1 || arity == 2))
{
if (current == null)
throw new RuntimeException("current is null");
return new DocumentFunction(getRootStylesheet(), current);
}
else if ("key".equals(localName) && (arity == 2))
return new KeyFunction(getRootStylesheet());
else if ("format-number".equals(localName) &&
(arity == 2 || arity == 3))
return new FormatNumberFunction(getRootStylesheet());
else if ("current".equals(localName) && (arity == 0))
return new CurrentFunction(getRootStylesheet());
else if ("unparsed-entity-uri".equals(localName) && (arity == 1))
return new UnparsedEntityUriFunction();
else if ("generate-id".equals(localName) &&
(arity == 1 || arity == 0))
return new GenerateIdFunction();
else if ("system-property".equals(localName) && (arity == 1))
return new SystemPropertyFunction();
else if ("element-available".equals(localName) && (arity == 1))
return new ElementAvailableFunction(new NamespaceProxy(current));
else if ("function-available".equals(localName) && (arity == 1))
return new FunctionAvailableFunction(new NamespaceProxy(current));
}
return null;
}
示例13: createBodyFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
private XPathFunction createBodyFunction() {
return new XPathFunction() {
@SuppressWarnings("rawtypes")
public Object evaluate(List list) throws XPathFunctionException {
return exchange.get().getIn().getBody();
}
};
}
示例14: createHeaderFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
private XPathFunction createHeaderFunction() {
return new XPathFunction() {
@SuppressWarnings("rawtypes")
public Object evaluate(List list) throws XPathFunctionException {
if (!list.isEmpty()) {
Object value = list.get(0);
if (value != null) {
String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
return exchange.get().getIn().getHeader(text);
}
}
return null;
}
};
}
示例15: createOutBodyFunction
import javax.xml.xpath.XPathFunction; //导入依赖的package包/类
private XPathFunction createOutBodyFunction() {
return new XPathFunction() {
@SuppressWarnings("rawtypes")
public Object evaluate(List list) throws XPathFunctionException {
if (exchange.get() != null && exchange.get().hasOut()) {
return exchange.get().getOut().getBody();
}
return null;
}
};
}