zoukankan      html  css  js  c++  java
  • Commons JXPath

    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')");
  • 相关阅读:
    二极管常用
    金属化孔与非金属化孔
    电容~3.钽电容
    电感~2.电路分析
    交流整流之后
    电容~2.电路分许
    三极管~3常见电路
    三极管~2.电路分析
    名词解释
    硬件设计
  • 原文地址:https://www.cnblogs.com/huey/p/4703383.html
Copyright © 2011-2022 走看看