欢迎光临
我们一直在努力

利用JDK1.4中的Templates实现xslt转换的缓存-JSP教程,资料/其它

建站超值云服务器,限时71元/月

javax.xml.transform.templates是一个编译过的xsl, 线程安全, 可以从其中得到transformer. 在server端做xslt转换的bs架构中可以明显提高效率.

    //模板缓存
    static private hashtable templates = new hashtable();

    public static transformer gettransformer(source xslsource)
    throws exception
    {
        transformer transformer = null;
        string id = xslsource.getsystemid();
        if (null != id){
            synchronized(templates){
                templates temp = (templates)templates.get(id);
                if (null != temp){
//                    system.out.println("use cache: "+id);
                    return temp.newtransformer();
                }
            }
        }
        transformerfactory factory = transformerfactory.newinstance();
        templates temp = factory.newtemplates(xslsource);
        if (null != id)
            synchronized(templates){
                templates.put(id,temp);
            }
        transformer = factory.newtransformer(xslsource);
        return transformer;
    }

    public static void transform(source xmlsource, source xslsource, writer result, string encoding)
    throws exception
    {
        if (xmlsource == null || xslsource == null || result == null)
            throw new nullpointerexception("null xslt input");

        transformer transformer = this.gettransformer(xslsource);
        transformer.setoutputproperty("encoding", encoding);

//        system.out.println("xfmr: "+transformer);

        streamresult transformresult = new streamresult(result);
        transformer.transform(xmlsource, transformresult);
    }

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用JDK1.4中的Templates实现xslt转换的缓存-JSP教程,资料/其它
分享到: 更多 (0)