本文整理汇总了Java中org.apache.commons.jxpath.JXPathContext.setFunctions方法的典型用法代码示例。如果您正苦于以下问题:Java JXPathContext.setFunctions方法的具体用法?Java JXPathContext.setFunctions怎么用?Java JXPathContext.setFunctions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.jxpath.JXPathContext
的用法示例。
在下文中一共展示了JXPathContext.setFunctions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public String format(final Object obj) {
final JXPathContext context = JXPathContext.newContext(obj);
context.setFunctions(new ClassFunctions(JXPathFormatExtension.class, "format"));
for(final Map.Entry<String,String> entry : this.namespaces.entrySet()) {
context.registerNamespace(entry.getKey(), entry.getValue());
}
if(this.locale != null) {
context.setLocale(this.locale);
context.setDecimalFormatSymbols(null, new DecimalFormatSymbols(this.locale));
}
if(this.expression == null) {
this.expression = context.compilePath(this.expressionString);
}
final Object val = this.expression.getValue(context);
return val == null ? null : val.toString();
}
示例2: setXpathFunctions
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
private void setXpathFunctions(JXPathContext xpathContext) {
Functions existing = xpathContext.getFunctions();
final FunctionLibrary funcLib;
if (existing == null) {
funcLib = new FunctionLibrary();
} else if (existing instanceof FunctionLibrary) {
funcLib = (FunctionLibrary) existing;
} else {
funcLib = new FunctionLibrary();
funcLib.addFunctions(existing);
}
for (ITagLibrary lib : getPaxml().getParser().getTagLibraries()) {
for (String name : lib.getUtilFunctionsFactoryNames()) {
Class<? extends IUtilFunctionsFactory> clazz = lib.getUtilFunctionsFactory(name);
Class<?> xpathFunClass = ReflectUtils.createObject(clazz).getXpathUtilFunctions(this);
if (xpathFunClass == null) {
// skip this one
continue;
}
Util util = ReflectUtils.getAnnotation(clazz, Util.class);
if (util == null) {
throw new PaxmlRuntimeException("Internal error: util function factory is not annotated: " + clazz.getName());
}
funcLib.addFunctions(new ClassFunctions(xpathFunClass, util.value()));
}
}
xpathContext.setFunctions(funcLib);
}