⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pageutil.java

📁 AJAX的一个好东西哦,国人的一个AJAX的实现不错的东西
💻 JAVA
字号:
/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * $Id: PageUtil.java 30 2005-11-23 02:17:04Z michael $
 */ 
package net.buffalo.demo.page;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.commons.lang.StringUtils;

/**
 * @author michael
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PageUtil {
    
    public static String extractScript(String source) {        
        String value = "";
        if (source.indexOf("</script>") != -1) {
            value = StringUtils.substringBetween(source,"<script language=\"javascript\">", "</script>");
        } else {
            value = null;
        }
        return value;
    }
    
    public static String extractHtml(String source) {
        if (source.indexOf("</script>") != -1) {
            return StringUtils.substringAfter(source, "</script>");
        } else {
            return source;
        }
    } 
    
    public static String loadFile(String filePath) throws IOException {
        File f = new File(filePath);
        
        byte buffer[] = new byte[256];
        int len = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream(f)); 
        while((len = bis.read(buffer, 0, 256)) != -1) {
            baos.write(buffer, 0, len);
        }
        
        String totalPage = baos.toString();
        
        return totalPage;
    }
    
    public static void main(String[] args) throws IOException {
        String str = loadFile("D:/Work/BuffaloFramework/war/pages/home.jsp");
        //String str = "aa<SCRIPT>aaa\nbbb\r\naaaccc</script>bbb";
        System.out.println(extractScript(str));
        
        //System.out.println(extractHtml(str));
    }
    
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -