Commons JXPath - Extension Functions
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的更多相关文章
- Commons JXPath - Modifying Object Graphs
JXPath 除了可以 XPath 语法访问 JavaBeans.DOM/JDOM,也可以对其属性赋值. 以下面的 JavaBeans 为例. package com.huey.jxpath; imp ...
- Commons JXPath - Object Graph Traversal
JXPath 提供了使用 Xpath 语法操纵符合 Java 类命名规范的 JavaBeans 的工具.也支持 maps.DOM 和其他对象模型.对于深层次结构的 JavaBean,使用 JXPath ...
- Commons JXPath - DOM/JDOM Document Access
除了 JavaBean,JXPath 也可以访问 DOM/JDOM. 示例 XML: <?xml version="1.0" encoding="utf-8&quo ...
- Table of Contents - Apache Commons
Apache Commons 简述 CLI Usage of CLI Option Properties Codec 常见的编码解码 Compress Configuration2 Quick sta ...
- 编写更少量的代码:使用apache commons工具类库
Commons-configuration Commons-FileUpload Commons DbUtils Commons BeanUtils Commons CLI Commo ...
- Apache Commons 工具集
一.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...
- apache commons Java包简介
更多信息,请参考:http://commons.apache.org/ 一.Commons BeanUtils说明:针对Bean的一个工具集.由于Bean往往是有一堆get和set组成,所以BeanU ...
- Apache Commons 工具集使用简介
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.我选了一些比较常用的项目做简单介绍.文中用了很多网上现成的东西,我只是做了一个汇总整理. 一.Comm ...
- Apache Commons介绍(转载)
一.Commons BeanUtils说明:针对Bean的一个工具集.由于Bean往往是有一堆get和set组成,所以BeanUtils也是在此基础上进行一些包装. 二.Commons CLI说明:这 ...
随机推荐
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- spring对数据库特殊字段的支持
1.CLOB <property name="tomdTemplateContent" type="org.springframework.orm.hibernat ...
- HttpContext讲解
http://www.cnblogs.com/scy251147/p/3549503.html http://www.360doc.com/content/14/0526/10/17655805_38 ...
- C#中的where从句
C#中的where从句 2011-07-03 13:07OrphousV | 分类:C#/.NET | 浏览8443次 能解释一下下面两段代码中where的作用吗?using System;publi ...
- python中objects的all和get方法的区别
all返回的是QuerySet: get返回的是模型对象. 想要获取查询结果的字段值: 从QuerySet中获取对象可以通过for in的形式遍历,之后通过对象获取对象的具体值: get 返回的是对象 ...
- Flex Alert.show()方法的详解
本文和大家重点讨论一下Flex Alert.show()flag详细值,Flex Alert.show()里面有多个属性,其中排在第三是flags,这个属性作用是在弹出的Alert提示框里面显示那一个 ...
- Hadoop on Mac with IntelliJ IDEA - 3 解决MRUnit - No applicable class implementing Serialization问题
本文讲述在IntelliJ IDEA中使用MRUnit 1.0.0测试Mapper派生类时因MapDriver.withInput(final K1 key, final V1 val)的key参数被 ...
- 图片攻击-BMP图片中注入恶意JS代码 <转载>
昨天看到一篇文章<hacking throung images>,里面介绍了如何在BMP格式的图片里注入JS代码,使得BMP图片既可以正常显示, 也可以运行其中的JS代码,觉得相当有趣. ...
- 套题 Codeforces Round #277 (Div. 2)
A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...
- 取消掉Transfer-Encoding:chunked
先说解决方法:::不让服务器返回Transfer-Encoding:chunked,在客户端请求的时候可以使用http 1.0的协议. 有时候,Web服务器生成HTTP Response是无法在Hea ...