`

framework freemarker / velocity

阅读更多

CMS 静态化参考

 

JAVA静态化,如何生成html问题

http://hi.csdn.net/yuezu1026/

http://topic.csdn.net/u/20080829/14/7ee4965f-f0d3-4c84-a2fa-10d44b735d63.html

 

http://hi.csdn.net/yuezu1026/

中国灯饰商贸网

www.lighting86.com.cn

中山市旅游网

http://www.86760.com/

 

 

public class Test {

    //config.getDriverName(),config.getUrl(),config.getUserName(),config.getPassword());
    public static void main(String[] args) {
        Config config = ConfigResolver.parseXML(null);
       
        String jspPage = config.getIndexFrom();//jsp文件地址
        String htmlPage = config.getIndexTo();//html文件名 
        if(jspPage!=null && htmlPage!=null ){
            createHtml(jspPage,htmlPage); //处理站点首页
        }
       
        jspPage = config.getGroupZhengquanFrom();//jsp文件地址
        htmlPage = config.getGroupZhengquanTo();//html文件名
        if(jspPage!=null && htmlPage!=null ){
            createHtml(jspPage,htmlPage); //处理证券圈子页面
        }
public static void createHtml(String jspPage,String htmlPage){
        System.out.println(jspPage+"----------------start");
        BufferedReader in = null;
        BufferedWriter out= null;
        try{
            in = new BufferedReader(new InputStreamReader(new FileInputStream(htmlPage)));
            out = getOut(htmlPage+"_old", true); //备分原文件
            copyFile(in,out); //备分原文件
        }catch(Exception e){
            e.printStackTrace();
        }       
       
        in = getIn(jspPage);
        out = getOut(htmlPage+"_back", true);
        generateHtml(in, out,jspPage);//生成静态页面
        close(in, out);
       
        try{
            in=new BufferedReader(new InputStreamReader(new FileInputStream(htmlPage+"_back")));
        }catch(Exception e){
            e.printStackTrace();
        }
        out = getOut(htmlPage, true);
        copyFile(in,out); //文件拷贝
        System.out.println(jspPage+"----------------end");
    }

    public final static void generateHtml(BufferedReader in, BufferedWriter out,String jspPage) {
        boolean flag=true;

        if (out == null)
            return;//不生成静态页面
        try {
            out.write(" <%@ page language=\"java\" %>\r\n");
            out.write(" <%@ page contentType=\"text/html; charset=GBK\"%>\r\n");
            String c;
            while ((c = in.readLine()) != null) {
//                if(c.trim().equals(" <!--portalheaderbegin-->")){           
//                    flag=false;
//                }
//                if(c.trim().equals(" <!--portalheaderend-->")){
//                    if(jspPage.indexOf("channel.jsp")!=-1){ //如果是频道页面
//                        c=" <jsp:include page='/include/portalheader.jsp?channelId="+jspPage.split("type_id=")[1]+"' />\r\n";
//                    }else if(jspPage.indexOf("zhengquan_group_act.jsp")!=-1){ //证券圈
//                        c=" <jsp:include page='/include/portalheader.jsp?groupId=43' />\r\n";
//                    }else if(jspPage.indexOf("group_general.jsp")!=-1){ //其他圈子
//                        c=" <jsp:include page='/include/portalheader.jsp?groupId="+jspPage.split("type_id=")[1]+"' />\r\n";
//                    }else if(jspPage.indexOf("group_index")!=-1){ //圈子首页
//                        c=" <jsp:include page='/include/portalheader.jsp?groupId=group' />\r\n";
//                    }else if(jspPage.indexOf("community_index")!=-1){ //社区首页
//                        c=" <jsp:include page='/include/portalheader.jsp?shequId=abc123' />\r\n";
//                    }else{
//                        c=" <jsp:include page='/include/portalheader.jsp' />\r\n";
//                    }
//                    flag=true;
//                }
               
                if(c.trim().equals(" <!--portalheaderbegin-->")){           
                    flag=false;
                }
               
                if(c.trim().equals(" <!--portalheaderend-->")){
                    if(jspPage.indexOf("channel.jsp")!=-1){ //如果是频道页面
                        //c=" <jsp:include page='/include/portalheader.jsp?channelId="+jspPage.split("type_id=")[1]+"' />\r\n";
                        c=" <jsp:include page='/permissionFilter.jsp' />\r\n";
                    }else if(jspPage.indexOf("zhengquan_group_act.jsp")!=-1){ //证券圈
                        c=" <jsp:include page='/include/portalheader.jsp?groupId=43' />\r\n";
                    }else if(jspPage.indexOf("group_general.jsp")!=-1){ //其他圈子
                        //c=" <jsp:include page='/include/portalheader.jsp?groupId="+jspPage.split("type_id=")[1]+"' />\r\n";
                        c=" <jsp:include page='/permissionFilter.jsp' />\r\n";
                    }else if(jspPage.indexOf("group_index")!=-1){ //圈子首页
                        c=" <jsp:include page='/include/portalheader.jsp?groupId=group' />\r\n";
                    }else if(jspPage.indexOf("community_index")!=-1){ //社区首页
                        c=" <jsp:include page='/include/portalheader.jsp?shequId=abc123' />\r\n";
                    }else if(jspPage.indexOf("portal/index_act.jsp")!=-1){ //首页
                        //c=" <jsp:include page='/include/portalheader.jsp?index=yes' />\r\n";
                        c=" <jsp:include page='/permissionFilter.jsp' />\r\n";
                    }else if(jspPage.indexOf("portal/blogershare_act.jsp")!=-1){ //分享页
                        c=" <jsp:include page='/permissionFilter.jsp' />\r\n";
                    }else{
                        c=" <jsp:include page='/include/portalheader.jsp' />\r\n";
                    }
                    flag=true;
                }
                if(flag&&c.length()>0){
                    out.write(c+"\r\n");
                }
            }
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public final static void copyFile(BufferedReader from, BufferedWriter to) {
        if (to == null || from == null)
            return;//不生成静态页面
        try {
            int c;
                while ((c = from.read()) != -1) {
                    to.write((char)c);
            }
            to.flush();
            close(from, to);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public final static BufferedReader getIn(String jspPage) {

        BufferedReader in = null;
        URL url = null;
        URLConnection urlConn = null;
        try {
            url = new URL(jspPage);
            urlConn = url.openConnection();//建立http连接
            in = new BufferedReader(new InputStreamReader(urlConn
                    .getInputStream(), "GBK"));//设置Encoding,必须设置,否则显示中文会有问题
        } catch (IOException e) {
            e.printStackTrace();
           
        }finally{
            urlConn=null;
            url=null;
        }
       

        return in;
    }

    public final static BufferedWriter getOut(String htmlPage, boolean flag) {

        BufferedWriter out = null;

        try {
            File htmlFile = new File(htmlPage);
            if (flag) {
                htmlFile.createNewFile();
            } else {//如果flag为false则不覆盖文件
                if (htmlFile.exists()) {//如果文件已经存在则返回null
                    return null;
                } else {//建立新文件
                    htmlFile.createNewFile();
                }
            }
            out = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(htmlFile), "GBK"));//设置Encoding
        } catch (IOException e) {
            e.printStackTrace();
        }

        return out;

    }//flag为真则覆盖原文件

    public final static void close(BufferedReader in, BufferedWriter out) {

        try {
            in.close();
            if (out != null)
                out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

 

 

public class ConfigResolver {
    private static String xmlPath = "config/config.xml";

    /**
    * 获取配置文件对象信息
    *
    * @param fileName
    * @return
    * @throws Exception
    */
    public static Config parseXML(String fileName) {
        if (null != fileName) {
            xmlPath = fileName;
        }
        Config configFile = new Config();
        try {
            XMLConfiguration parser = new XMLConfiguration();
            parser.setFile(new File(xmlPath));
            parser.load();

            //首页原
            String indexFrom = (String) parser.getProperty("indexFrom");
            configFile.setIndexFrom(indexFrom);
            //首页目标
            String indexTo = (String) parser.getProperty("indexTo");
            configFile.setIndexTo(indexTo);

            //圈子页原
            String groupZhengquanFrom = (String) parser
                    .getProperty("groupZhengquanFrom");
            configFile.setGroupZhengquanFrom(groupZhengquanFrom);
            //圈子页目标
            String groupZhengquanTo = (String) parser
                    .getProperty("groupZhengquanTo");
            configFile.setGroupZhengquanTo(groupZhengquanTo);

            //频道页原
            String channelFrom = (String) parser.getProperty("channelFrom");
            configFile.setChannelFrom(channelFrom);
            //频道页目标
            String channelTo = (String) parser.getProperty("channelTo");
            configFile.setChannelTo(channelTo);

            String channelIds = (String) parser.getProperty("channelIds");
            configFile.setChannelIds(channelIds);

            //大杂烩原
            String dazahuiFrom = (String) parser.getProperty("dazahuiFrom");
            configFile.setDazahuiFrom(dazahuiFrom);
            //大杂烩目标
            String dazahuiTo = (String) parser.getProperty("dazahuiTo");
            configFile.setDazahuiTo(dazahuiTo);

            //别人的订阅,关注原
            String anthorTakenFrom = (String) parser
                    .getProperty("anthorTakenFrom");
            configFile.setAnthorTakenFrom(anthorTakenFrom);
            //别人的订阅,关注目标
            String anthorTakenTo = (String) parser.getProperty("anthorTakenTo");
            configFile.setAnthorTakenTo(anthorTakenTo);

            //房产圈子页原
            String fangChanFrom = (String) parser
                    .getProperty("groupFangchanFrom");
            configFile.setGroupFangchanFrom(fangChanFrom);
            //房产圈子页目标
            String fangChanTo = (String) parser.getProperty("groupFangchanTo");
            configFile.setGroupFangchanTo(fangChanTo);
            String groupIds = (String) parser.getProperty("groupIds");
            configFile.setGroupIds(groupIds);

            //首页用圈子文章list原
            String quanziArticleListFrom = (String) parser.getProperty("quanziArticleListFrom");
            configFile.setQuanziArticleListFrom(quanziArticleListFrom);
            //首页用圈子文章list目标
            String quanziArticleListTo = (String) parser.getProperty("quanziArticleListTo");
            configFile.setQuanziArticleListTo(quanziArticleListTo);
           
            String quanziIds = (String) parser.getProperty("quanziIds");
            configFile.setQuanziIds(quanziIds);
           
           
            //圈子首页原
            String groupIndexFrom = (String) parser.getProperty("groupIndexFrom");
            configFile.setGroupIndexFrom(groupIndexFrom);
            //圈子首页目标
            String groupIndexTo = (String) parser.getProperty("groupIndexTo");
            configFile.setGroupIndexTo(groupIndexTo);
           
            //社区首页原
            String shequIndexFrom = (String) parser.getProperty("shequIndexFrom");
            configFile.setShequIndexFrom(shequIndexFrom);
            //社区首页目标
            String shequIndexTo = (String) parser.getProperty("shequIndexTo");
            configFile.setShequIndexTo(shequIndexTo);
           
            //热点排名周源
            String articleRankWeekFrom = (String) parser.getProperty("articleRankWeekFrom");
            configFile.setArticleRankWeekFrom(articleRankWeekFrom);
            //热点排名周目标
            String articleRankWeekTo = (String) parser.getProperty("articleRankWeekTo");
            configFile.setArticleRankWeekTo(articleRankWeekTo);
           
            //热点排名月源
            String articleRankMonthFrom = (String) parser.getProperty("articleRankMonthFrom");
            configFile.setArticleRankMonthFrom(articleRankMonthFrom);
            //热点排名月目标
            String articleRankMonthTo = (String) parser.getProperty("articleRankMonthTo");
            configFile.setArticleRankMonthTo(articleRankMonthTo);
           
            //图片首页more源
            String photoIndexMoreFrom = (String) parser.getProperty("photoIndexMoreFrom");
            configFile.setPhotoIndexMoreFrom(photoIndexMoreFrom);
            //图片首页more目标
            String photoIndexMoreTo = (String) parser.getProperty("photoIndexMoreTo");
            configFile.setPhotoIndexMoreTo(photoIndexMoreTo);
           
            //博客分享源
            String blogerShareFrom = (String) parser.getProperty("blogerShareFrom");
            configFile.setBlogerShareFrom(blogerShareFrom);
            //博客分享目标
            String blogerShareTo = (String) parser.getProperty("blogerShareTo");
            configFile.setBlogerShareTo(blogerShareTo);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return configFile;
    }
}

 

 

 

end

 

分享到:
评论

相关推荐

    spring-framework-3.0.5.RELEASE-dependencies-1

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-6

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-7

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-5

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-4

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    单点登录源码

    Velocity | 模板引擎 | [http://velocity.apache.org/](http://velocity.apache.org/) ZooKeeper | 分布式协调服务 | [http://zookeeper.apache.org/](http://zookeeper.apache.org/) Dubbo | 分布式服务框架 | ...

    spring-framework-3.0.5.RELEASE-dependencies-8

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-3

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    spring-framework-3.0.5.RELEASE-dependencies-2

    org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org....

    Apache Click User Guide

    (Note other template engines such as JSP and Freemarker are also supported) This framework uses a single servlet, called ClickServlet, to act as a request dispatcher. When a request arrives ...

    Spring Framework 5.3.6

    开发者通过策略接口将拥有对该框架的高度控制,因而该框架将适应于多种呈现(View)技术,例如JSP,FreeMarker,Velocity,Tiles,iText以及POI。值得注意的是,Spring中间层可以轻易地结合于任何基于 MVC 框架的网页...

    j2ee-framework

    页面展现这里使用Struts1、Struts2、SpringMVC(jsp视图、velocity视图、freemarker视图、pdf视图、excel视图、xml视图、json视图等)。是一个综合性的项目。 该项目后期会陆续集成一些好的框架进来比如说Spring Web...

    struts-2.5.10-all所有jar包

    api-1.0.6.jar,tiles-request-freemarker-1.0.6.jar,tiles-request-jsp-1.0.6.jar,tiles-request-servlet-1.0.6.jar,tiles-servlet-3.0.7.jar,tiles-template-3.0.7.jar,validation-api-1.1.0.Final.jar,velocity-...

    spring-webmvc5.3.6 jar包.rar

    包含国际化、标签、Theme、视图展现的FreeMarker、JasperReports、Tiles、Velocity、XSLT相关类。  当然,如果你的应用使用了独立的MVC框架,则无需这个JAR文件里的任何类。(例如: org.springframework.web....

    JFinal所需的Jar

    5:velocity-1.7.jar、velocity-1.7-dep.jar支持 Velocity 视图。 6:cos-26Dec2008.jar 支持文件上传功能。 7:mysql-connector-java-5.1.20-bin.jar 支持 mysql 数据库。 8:c3p0-0.9.1.2.jar 数据库连接池。 9:...

    springboot学习思维笔记.xmind

    Spring TestContext Framework集成测试 SpringMVC基础 Spring MVC概述 SpringMVC项目快速搭建 构建Maven项目 日志配置 演示页面 Spring MVC配置 Web配置 简单控制器 运行 Spring MVC...

    struts-2.3.30-all所有jar包

    org.apache.felix.framework-4.0.3.jar, org.apache.felix.main-4.0.3.jar, org.apache.felix.shell-1.4.3.jar, org.apache.felix.shell.tui-1.4.1.jar, org.osgi.compendium-4.0.0.jar, org.osgi.core-4.1.0.jar, ...

    restful restful所需要的jar包

    * Integration with the FreeMarker template engine * Integration with the Velocity template engine * Integration with Apache FileUpload to support multi-part forms and easily handle large file ...

    struts-2.5.2-all所有jar包

    org.apache.felix.framework-4.0.3.jar, org.apache.felix.main-4.0.3.jar, org.apache.felix.shell-1.4.3.jar, org.apache.felix.shell.tui-1.4.1.jar, org.osgi.compendium-4.0.0.jar, org.osgi.core-4.1.0.jar, ...

    struts 2.3.4.1 最新英文版API

    org.apache.struts2.views.xslt The new xslt view supports an extensible Java XML adapter framework that makes it easy to customize the XML rendering of objects and to incorporate structured XML text ...

Global site tag (gtag.js) - Google Analytics