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. UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)

    题意:一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师.每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两个老 ...

  2. MSSQL导入数据时,出现“无法截断表 因为表正由Foreign key引用”错误

    * 错误 0xc002f210: 准备 SQL 任务: 执行查询“TRUNCATE TABLE [dsc100552_db].[dbo].[ALV_SalesBigClass] ”失败,错误如下:“无 ...

  3. Objective-C: NSFileManager 的使用

    在Objective-C 中的 Foundation 框架中,文件操作是由NSFileManager 类来实现的. 下面通过例子来说明如何创建一个文件,并向文件中写内容,以及如何读出文件中的内容: - ...

  4. 在Android Eclipse 开发如何 使用 (*.aar)文件

    http://www.cnblogs.com/shortboy/p/4424944.html 开场白:其实这篇文章有点白费心机. 详细说明是:http://blog.csdn.net/qiujuer/ ...

  5. Ping批量函数

    function pingm ($file){ $ips = gc $file foreach ($ip in $ips) { $cmdline +="ping " + $ip + ...

  6. 搭建Nginx图片服务器

    搭建Nginx图片服务器 Part-I 安装Nginx 安装PCRE 下载 ngx_cache_purge 并解压,用来清除缓存 下载Nginx并解压 cd nginx-1.7.7 编译,--pref ...

  7. springMVC中的Controller里面定义全局变量

    转自:http://notebookdong.iteye.com/blog/1869852 使用SpringMVC的时候,如果想要在Controller中定义一个全局变量,并且实现在不同用户访问程序的 ...

  8. 自己动手写CPU之第九阶段(8)——MIPS32中的LL、SC指令说明

    将陆续上传新书<自己动手写CPU>,今天是第47篇. 9.7 ll.sc指令实现思路 9.7.1 实现思路 这2条指令都涉及到訪问链接状态位LLbit,能够将LLbit当做寄存器处理,ll ...

  9. 目录操作函数opendir、readdir和closedir

    首先,明确一个类型DIR的含义: #include <dirent.h> DIR    A type representing a directory stream. DIR是在目录项格式 ...

  10. 真机下, 如何在File Explorer里看data下的数据?

    首先手机得Root , 你如果想单个单个的看, root explorer可以设置Permission Other下的两个权限点上就ok了. 如果想看到所有的, 即子目录也可以看到, 只需要adb r ...