Standard Extension Functions

创建新的对象

JXPathContext context = JXPathContext.newContext(null);
Book book = (Book) context.getValue("com.huey.jxpath.Book.new()");
Author author = (Author) context.getValue("com.huey.jxpath.Author.new('Eric', 'Freeman', 'F', java.util.Date.new())");

调用静态方法

JXPathContext context = JXPathContext.newContext(null);
Book bestBook = (Book) context.getValue("com.huey.jxpath.Book.getBestBook()");

调用普通方法

the target of the method is specified as the first parameter of the function.

JXPathContext context = JXPathContext.newContext(null);
context.getVariables().declareVariable("book", book);
String title = (String) context.getValue("getTitle($book)");

Custom Extension Functions

定义一个格式化类:

package com.huey.jxpath;

import java.text.SimpleDateFormat;
import java.util.Date; public class MyFormats {
public static String dateToStr(Date d, String pattern){
return new SimpleDateFormat(pattern).format(d);
}
}

将格式化类注册到 JXPathContext:

JXPathContext context = JXPathContext.newContext(null);
context.setFunctions(new ClassFunctions(MyFormats.class, "formats"));
context.getVariables().declareVariable("today", new Date());
String today = (String) context.getValue("formats:dateToStr($today, 'yyyy-MM-dd')");

Commons JXPath - Extension Functions的更多相关文章

  1. Commons JXPath - Modifying Object Graphs

    JXPath 除了可以 XPath 语法访问 JavaBeans.DOM/JDOM,也可以对其属性赋值. 以下面的 JavaBeans 为例. package com.huey.jxpath; imp ...

  2. Commons JXPath - Object Graph Traversal

    JXPath 提供了使用 Xpath 语法操纵符合 Java 类命名规范的 JavaBeans 的工具.也支持 maps.DOM 和其他对象模型.对于深层次结构的 JavaBean,使用 JXPath ...

  3. Commons JXPath - DOM/JDOM Document Access

    除了 JavaBean,JXPath 也可以访问 DOM/JDOM. 示例 XML: <?xml version="1.0" encoding="utf-8&quo ...

  4. Table of Contents - Apache Commons

    Apache Commons 简述 CLI Usage of CLI Option Properties Codec 常见的编码解码 Compress Configuration2 Quick sta ...

  5. 编写更少量的代码:使用apache commons工具类库

    Commons-configuration   Commons-FileUpload   Commons DbUtils   Commons BeanUtils  Commons CLI  Commo ...

  6. Apache Commons 工具集

    一.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...

  7. apache commons Java包简介

    更多信息,请参考:http://commons.apache.org/ 一.Commons BeanUtils说明:针对Bean的一个工具集.由于Bean往往是有一堆get和set组成,所以BeanU ...

  8. Apache Commons 工具集使用简介

    Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.我选了一些比较常用的项目做简单介绍.文中用了很多网上现成的东西,我只是做了一个汇总整理. 一.Comm ...

  9. Apache Commons介绍(转载)

    一.Commons BeanUtils说明:针对Bean的一个工具集.由于Bean往往是有一堆get和set组成,所以BeanUtils也是在此基础上进行一些包装. 二.Commons CLI说明:这 ...

随机推荐

  1. android中的Cursor类

    转载: 使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生,如果你是搞.net 开发你大可以把Cursor理解成 Ado.net 中的数据集合相当于dataReader.今天特地将它单独拿 ...

  2. 几道 SQL 语句面试题

    --S (sno,sname)学生关系,sno为学号 sname为姓名 --C(cno,cname,Cteacher)课程关系 cno为课程号,cname为课程名,cteacher 为任课教师 --S ...

  3. php and web service with wsdl

    Following are the links: Developing Web Services Using PHP PHP Web Services with WSDL Creating Web S ...

  4. cocos2d-x CCTableView

    转自:http://www.cnblogs.com/dcxing/archive/2013/01/16/2862068.html CCTableView在游戏中一般用在背包这样场景或层中,当然也不止这 ...

  5. LFI漏洞利用总结(转载)

    主要涉及到的函数include(),require().include_once(),require_once()magic_quotes_gpc().allow_url_fopen().allow_ ...

  6. Swift学习笔记三

    协议和扩展 在Objective-C中,协议是很常见也非常重要的一个特性,Swift中也保留了协议,语法略有变化. 用protocol关键字声明一个协议: protocol ExampleProtoc ...

  7. delphi 添加节点

      //在选中的节点中上添加1个节点 procedure TForm1.Button1Click(Sender: TObject); begin     with TreeView1 do     b ...

  8. CircleDisplay

    https://github.com/PhilJay/CircleDisplay

  9. 【v2.x OGE教程 19】 引擎状态控制

    1.手机button监听 OGE中提供了在BaseGameLauncher(GameLauncher的父类)和IScene(Scene实现的接口)中定义了onKeyUp和onKeyDown的方法.使得 ...

  10. 优秀js插件收藏

    1. 滚动视差效果,类似锤子主页等效果实现 https://github.com/hahnzhu/parallax.js 2. jQuery全屏滚动插件 http://www.dowebok.com/ ...