抓取OA考勤记录

<%@ page language="java" import="java.util.*,com.lxp.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>国人通信 买房快线 罗平 考勤记录</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="国人通信 买房快线 罗平 考勤记录">
	<meta http-equiv="description" content="国人通信 买房快线 罗平 考勤记录">
	<link rel="shortcut icon" href="favicon.ico" />
  </head>
  
  <body>
  <font color=red>
    当前时间:<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date())%>&nbsp;<%=WeekDay.getWeekDay(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()))%><br />
  </font>
  <br />
  <a href="index_1.jsp">[考勤记录]查询</a>
  <br /><br />
  <a href="index_2.jsp">中文分词</a>
  <br /><br /><br />
    <%--<%
        String[][] result=com.lxp.Attendance.getAttendance();
        for(int i=0;i<result.length;i++)
        {
          if(i<4)
            out.print(result[i][0]+"<br />");
          else
            out.print(result[result.length-1+4-i][0]+"<br />");
        }
    %>--%>
  </body>
</html>

<%@ page language="java" import="java.util.*,com.lxp.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>国人通信 买房快线 考勤记录 查询</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="国人通信 买房快线 考勤记录 查询">
	<meta http-equiv="description" content="国人通信 买房快线 考勤记录 查询">
	<link rel="shortcut icon" href="favicon.ico" />
  </head>
  
  <body>
  <font color=red>
    当前时间:<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date())%>&nbsp;<%=WeekDay.getWeekDay(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()))%><br />
  </font>
	<form method="post" action="result_1.jsp">
	<br />用户名:<input type=text name=username><br />
	<br />密&nbsp;&nbsp;码:<input type=password name=password><br />
	<br /><input type=submit value=submit>
	</form>
  </body>
</html>

<%@ page language="java" import="java.util.*,com.lxp.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>国人通信 买房快线 罗平 考勤记录</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="国人通信 买房快线 罗平 考勤记录">
	<meta http-equiv="description" content="国人通信 买房快线 罗平 考勤记录">
	<link rel="shortcut icon" href="favicon.ico" />
  </head>
  
  <body>
  <font color=red>
    当前时间:<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date())%>&nbsp;<%=WeekDay.getWeekDay(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()))%><br />
  </font>
  <br />
    <%
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        String[][] result=com.lxp.Attendance_1.getAttendance(username,password);
        for(int i=0;i<result.length;i++)
        {
          if(i<4)
            out.print(result[i][0]+"<br />");
          else
            out.print(result[result.length-1+4-i][0]+"<br />");
        }
    %>
  </body>
</html>

package com.lxp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.HostConfiguration;
import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.filters.*;
import org.htmlparser.tags.*;
import org.htmlparser.util.NodeList;

public class Attendance_1 {

	public static void main(String[] args) throws HttpException, IOException {

	}

	public static String[][] getAttendance(String username,String password) throws HttpException, IOException {
		String viewState = "/wEPDwUKMTUwNjAxMzkyNw9kFgICAw9kFhICAw8WAh4EVGV4dAUS5ZGY5bel6Ieq5Yqp5bmz5Y+wZAIFDw9kFgIeCU9ua2V5ZG93bgU0aWYgKHdpbmRvdy5ldmVudC5rZXlDb2RlPT0xMykgd2luZG93LmV2ZW50LmtleUNvZGU9OWQCBw8PZBYCHwEFNGlmICh3aW5kb3cuZXZlbnQua2V5Q29kZT09MTMpIHdpbmRvdy5ldmVudC5rZXlDb2RlPTlkAgkPDxYEHhFVc2VTdWJtaXRCZWhhdmlvcmgeDU9uQ2xpZW50Q2xpY2sFFXRoaXMuZGlzYWJsZWQgPSB0cnVlO2RkAg0PDxYCHgtOYXZpZ2F0ZVVybAUcc2lwOnl1YW5xaWFvbGluZ0Bwb3dlcmNuLmNvbWRkAhEPDxYCHwQFH21haWx0bzp5dWFucWlhb2xpbmdAcG93ZXJjbi5jb21kZAITDxYCHwAFHua3seWcs+WbveS6uumAmuS/oeaciemZkOWFrOWPuGQCFQ8WAh8ABQ/kv6Hmga/nrqHnkIbpg6hkAhcPFgIfAAUoQ29weXJpZ2h0wqkyMDExIHBvd2VyY24uY29tIOeJiOadg+aJgOaciWRksb9gomZPhlpfVev+cyZJhs2ycvU=";
		String eventValidation = "";
		String ctl00_ContentPlaceHolder1_grd_CallbackState = "";
		String str_page_count = "";
		String str_all_count = "";
		String str_temp = "";

		Parser parser = null;
		HttpConnectionManager connMan = null;
		connMan = new MultiThreadedHttpConnectionManager();
		HttpConnectionManagerParams par = new HttpConnectionManagerParams();
		connMan.setParams(par);
		HttpClient client = new HttpClient(connMan);
		byte[] buffer = null;
		PostMethod post = null;
		Charset charset = Charset.forName("utf8");
		CharsetDecoder decoder = charset.newDecoder();

		Protocol easyhttps = new Protocol("https",
				new EasySSLProtocolSocketFactory(), 443);
		Protocol.registerProtocol("https", easyhttps);
		HttpClient httpClient = new HttpClient();
		httpClient.getParams().setContentCharset("UTF-8");
		HostConfiguration hc = new HostConfiguration();
		hc.setHost("hr.com", 80, easyhttps);

		// 模拟登录页面
		post = new PostMethod(
				"https://hr.com/UserLogin.aspx?ReturnUrl=%2fIndex.aspx");
		NameValuePair name = new NameValuePair("edtLoginName", username);
		NameValuePair pass = new NameValuePair("edtPassword", password);
		NameValuePair __LASTFOCUS = new NameValuePair("__LASTFOCUS", "");
		NameValuePair __EVENTTARGET = new NameValuePair("__EVENTTARGET",
				"btnOk");
		NameValuePair __EVENTARGUMENT = new NameValuePair("__EVENTARGUMENT", "");
		NameValuePair __VIEWSTATE = new NameValuePair("__VIEWSTATE", viewState);
		NameValuePair __EVENTVALIDATION = new NameValuePair(
				"__EVENTVALIDATION",
				"/wEWBALP3KqKDwKZj97jDwKl+MKYBAL9kpmPASjYeHEdXCJmCxZHftM3nE0pzPXu");
		post
				.setRequestBody(new NameValuePair[] { name, pass, __LASTFOCUS,
						__EVENTTARGET, __EVENTARGUMENT, __VIEWSTATE,
						__EVENTVALIDATION });
		client.executeMethod(post);
		post.releaseConnection();
		// 查看cookie信息
		Cookie[] cookies = client.getState().getCookies();
		client.getState().addCookies(cookies);
		if (cookies.length == 0) {
			System.out.println("None");
		} else {
			for (int i = 0; i < cookies.length; i++) {
				System.out.println(cookies[i].toString());
			}
		}

		try {
			post = new PostMethod(
					"https://hr.com/WorkingTime/CardRecord.aspx");
			// post.addParameter("__CALLBACKID",
			// "ctl00$ContentPlaceHolder1$grd");
			// post.addParameter("__CALLBACKPARAM",
			// "c0:GB|20;12|PAGERONCLICK3|PN0;");
			// post.addParameter("__EVENTVALIDATION", eventValidation);
			// post.addParameter("ctl00$ContentPlaceHolder1$grd$CallbackState",
			// ctl00_ContentPlaceHolder1_grd_CallbackState);
			// post.addParameter("__VIEWSTATE", viewState);
			client.executeMethod(post);
			InputStream in = post.getResponseBodyAsStream();
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			byte[] buf = new byte[2048];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			buffer = out.toByteArray();
			ByteBuffer bbuf = ByteBuffer.allocate(buffer.length);
			bbuf.put(buffer);
			bbuf.flip();
			CharBuffer charBuf = decoder.decode(bbuf);
			parser = new Parser();
			parser.setInputHTML(charBuf.toString());
			parser.setEncoding("utf8");

			HasAttributeFilter attrfilter = new HasAttributeFilter("class",
					"dxpSummary");
			NodeList nodeList = parser.extractAllNodesThatMatch(attrfilter);
			str_temp = nodeList.elementAt(1).toPlainTextString();
			str_all_count = str_temp.substring(str_temp.indexOf("(") + 1,
					str_temp.indexOf("items)")).trim();
			str_page_count = str_temp.substring(str_temp.indexOf("of") + 2,
					str_temp.indexOf("(")).trim();
			System.out.println(str_all_count);
			System.out.println(str_page_count);

			parser.reset();
			HasAttributeFilter attrfilter_1 = new HasAttributeFilter("id",
					"__VIEWSTATE");
			NodeList nodeList_1 = parser.extractAllNodesThatMatch(attrfilter_1);
			viewState = ((InputTag) nodeList_1.elementAt(0))
					.getAttribute("value");

			parser.reset();
			HasAttributeFilter attrfilter_2 = new HasAttributeFilter("id",
					"__EVENTVALIDATION");
			NodeList nodeList_2 = parser.extractAllNodesThatMatch(attrfilter_2);
			eventValidation = ((InputTag) nodeList_2.elementAt(0))
					.getAttribute("value");

			parser.reset();
			HasAttributeFilter attrfilter_3 = new HasAttributeFilter("id",
					"ctl00_ContentPlaceHolder1_grd_CallbackState");
			NodeList nodeList_3 = parser.extractAllNodesThatMatch(attrfilter_3);
			ctl00_ContentPlaceHolder1_grd_CallbackState = ((InputTag) nodeList_3
					.elementAt(0)).getAttribute("value");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}

		String[][] result = new String[Integer.parseInt(str_all_count) + 4][1];
		System.out.println("共有记录:" + str_all_count + "条");
		result[0][0] = "共有记录:" + str_all_count + "条";
		System.out
				.println("---------------------------------------------------------------------------------------");
		result[1][0] = "---------------------------------------------------------------------------------------";
		System.out
				.println("序号  工号      姓名    刷卡时间                刷卡类型  星期    其他说明");
		result[2][0] = "序号  工号      姓名    刷卡时间                刷卡类型  星期    其他说明";
		System.out
				.print("---------------------------------------------------------------------------------------");
		result[3][0] = "---------------------------------------------------------------------------------------";
		try {
			for (int n = 1; n <= Integer.parseInt(str_page_count); n++) {
				post = new PostMethod(
						"https://hr.com/WorkingTime/CardRecord.aspx");
				post.addParameter("__CALLBACKID",
						"ctl00$ContentPlaceHolder1$grd");
				if (n <= 10)
					post.addParameter("__CALLBACKPARAM",
							"c0:GB|20;12|PAGERONCLICK3|PN" + (n - 1) + ";");
				else
					post.addParameter("__CALLBACKPARAM",
							"c0:GB|21;12|PAGERONCLICK4|PN" + (n - 1) + ";");
				post.addParameter("__EVENTVALIDATION", eventValidation);
				post.addParameter(
						"ctl00$ContentPlaceHolder1$grd$CallbackState",
						ctl00_ContentPlaceHolder1_grd_CallbackState);
				post.addParameter("__VIEWSTATE", viewState);
				client.executeMethod(post);
				InputStream in = post.getResponseBodyAsStream();
				ByteArrayOutputStream out = new ByteArrayOutputStream();
				byte[] buf = new byte[2048];
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				in.close();
				out.close();
				buffer = out.toByteArray();
				ByteBuffer bbuf = ByteBuffer.allocate(buffer.length);
				bbuf.put(buffer);
				bbuf.flip();
				CharBuffer charBuf = decoder.decode(bbuf);
				parser = new Parser();
				parser.setInputHTML(charBuf.toString());
				parser.setEncoding("utf8");

				HasAttributeFilter attrfilter = new HasAttributeFilter("class",
						"dxgvDataRow");
				NodeList nodeList = parser.extractAllNodesThatMatch(attrfilter);
				for (int i = 0; i < nodeList.size(); i++) {
					Node n_tr = nodeList.elementAt(i);
					NodeList td_list = n_tr.getChildren();
					if (td_list.size() == 7) {
						System.out.println();
						System.out.print((n - 1) * 20 + i + 1);
						str_temp = String.valueOf(Integer
								.parseInt(str_all_count)
								- ((n - 1) * 20 + i));
						System.out.print("  "
								+ td_list.elementAt(1).toPlainTextString());
						str_temp = str_temp + "  "
								+ td_list.elementAt(1).toPlainTextString();
						System.out.print("  "
								+ td_list.elementAt(2).toPlainTextString());
						str_temp = str_temp + "  "
								+ td_list.elementAt(2).toPlainTextString();
						System.out.print("  "
								+ td_list.elementAt(3).toPlainTextString());
						str_temp = str_temp + "  "
								+ td_list.elementAt(3).toPlainTextString();
						System.out.print("  "
								+ td_list.elementAt(4).toPlainTextString());
						str_temp = str_temp + "  "
								+ td_list.elementAt(4).toPlainTextString();
						System.out.print("  "
								+ WeekDay.getWeekDay(td_list.elementAt(3)
										.toPlainTextString()));
						str_temp = str_temp
								+ "  "
								+ WeekDay.getWeekDay(td_list.elementAt(3)
										.toPlainTextString());
						System.out.print("  "
								+ td_list.elementAt(5).toPlainTextString());
						str_temp = str_temp + "  "
								+ td_list.elementAt(5).toPlainTextString();
						System.out.println();
						System.out
								.print("---------------------------------------------------------------------------------------");
						str_temp = str_temp
								+ "<br />---------------------------------------------------------------------------------------";
						result[(n - 1) * 20 + i + 4][0] = str_temp;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
		return result;
	}
}

package com.lxp;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;

import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.HttpClientError;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class EasySSLProtocolSocketFactory implements ProtocolSocketFactory {

	/** Log object for this class. */
    private static final Log LOG = LogFactory.getLog(EasySSLProtocolSocketFactory.class);

    private SSLContext sslcontext = null;

    /**
     * Constructor for EasySSLProtocolSocketFactory.
     */
    public EasySSLProtocolSocketFactory() {
        super();
    }

    private static SSLContext createEasySSLContext() {
        try {
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(
              null, 
              new TrustManager[] {new EasyX509TrustManager(null)}, 
              null);
            return context;
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new HttpClientError(e.toString());
        }
    }

    private SSLContext getSSLContext() {
        if (this.sslcontext == null) {
            this.sslcontext = createEasySSLContext();
        }
        return this.sslcontext;
    }

    /**
     * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
     */
    public Socket createSocket(
        String host,
        int port,
        InetAddress clientHost,
        int clientPort)
        throws IOException, UnknownHostException {

        return getSSLContext().getSocketFactory().createSocket(
            host,
            port,
            clientHost,
            clientPort
        );
    }

    /**
     * Attempts to get a new socket connection to the given host within the given time limit.
     * <p>
     * To circumvent the limitations of older JREs that do not support connect timeout a 
     * controller thread is executed. The controller thread attempts to create a new socket 
     * within the given limit of time. If socket constructor does not return until the 
     * timeout expires, the controller terminates and throws an {@link ConnectTimeoutException}
     * </p>
     *  
     * @param host the host name/IP
     * @param port the port on the host
     * @param clientHost the local host name/IP to bind the socket to
     * @param clientPort the port on the local machine
     * @param params {@link HttpConnectionParams Http connection parameters}
     * 
     * @return Socket a new socket
     * 
     * @throws IOException if an I/O error occurs while creating the socket
     * @throws UnknownHostException if the IP address of the host cannot be
     * determined
     */
    public Socket createSocket(
        final String host,
        final int port,
        final InetAddress localAddress,
        final int localPort,
        final HttpConnectionParams params
    ) throws IOException, UnknownHostException, ConnectTimeoutException {
        if (params == null) {
            throw new IllegalArgumentException("Parameters may not be null");
        }
        int timeout = params.getConnectionTimeout();
        SocketFactory socketfactory = getSSLContext().getSocketFactory();
        if (timeout == 0) {
            return socketfactory.createSocket(host, port, localAddress, localPort);
        } else {
            Socket socket = socketfactory.createSocket();
            SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
            SocketAddress remoteaddr = new InetSocketAddress(host, port);
            socket.bind(localaddr);
            socket.connect(remoteaddr, timeout);
            return socket;
        }
    }

    /**
     * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)
     */
    public Socket createSocket(String host, int port)
        throws IOException, UnknownHostException {
        return getSSLContext().getSocketFactory().createSocket(
            host,
            port
        );
    }

    /**
     * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
     */
    public Socket createSocket(
        Socket socket,
        String host,
        int port,
        boolean autoClose)
        throws IOException, UnknownHostException {
        return getSSLContext().getSocketFactory().createSocket(
            socket,
            host,
            port,
            autoClose
        );
    }

    public boolean equals(Object obj) {
        return ((obj != null) && obj.getClass().equals(EasySSLProtocolSocketFactory.class));
    }

    public int hashCode() {
        return EasySSLProtocolSocketFactory.class.hashCode();
    }



}

package com.lxp;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory;


public class EasyX509TrustManager implements X509TrustManager {

	private X509TrustManager standardTrustManager = null;

    /** Log object for this class. */
    private static final Log LOG = LogFactory.getLog(EasyX509TrustManager.class);

    /**
     * Constructor for EasyX509TrustManager.
     */
    public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
        super();
        TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        factory.init(keystore);
        TrustManager[] trustmanagers = factory.getTrustManagers();
        if (trustmanagers.length == 0) {
            throw new NoSuchAlgorithmException("no trust manager found");
        }
        this.standardTrustManager = (X509TrustManager)trustmanagers[0];
    }

    /**
     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
     */
    public void checkClientTrusted(X509Certificate[] certificates,String authType) throws CertificateException {
        standardTrustManager.checkClientTrusted(certificates,authType);
    }

    /**
     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
     */
    public void checkServerTrusted(X509Certificate[] certificates,String authType) throws CertificateException {
//        if ((certificates != null) && LOG.isDebugEnabled()) {
//            LOG.debug("Server certificate chain:");
//            for (int i = 0; i < certificates.length; i++) {
//                LOG.debug("X509Certificate[" + i + "]=" + certificates[i]);
//            }
//        }
//        if ((certificates != null) && (certificates.length == 1)) {
//            certificates[0].checkValidity();
//        } else {
//            standardTrustManager.checkServerTrusted(certificates,authType);
//        }
    }

    /**
     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
     */
    public X509Certificate[] getAcceptedIssuers() {
        return this.standardTrustManager.getAcceptedIssuers();
    }

}

package com.lxp;

import java.util.*;
import java.text.*;

public class WeekDay {
	public static void main(String[] args) {
		System.out.println(getWeekDay("2011-02-26 21:24:21"));
	}

	public static String getWeekDay(String my_date) {
		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");
		Date d = null;
		try {
			d = formatYMD.parse(my_date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (dayOfWeek < 0)
			dayOfWeek = 0;
		final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
				"星期六" };
		return dayNames[dayOfWeek];
	}
}

package com.lxp;

import java.io.IOException;
import java.io.StringReader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import net.paoding.analysis.analyzer.PaodingAnalyzer;

public class MyPaodingAnalyzer {

	public static void main(String[] args) throws IOException {

	}

	public static String[][] getPaodingAnalyzerResult(String source)
			throws IOException {
		String str_temp = "";
		String[][] result_temp = new String[100][1];
		Analyzer analyzer = new PaodingAnalyzer();
		String indexStr = source;
		StringReader reader = new StringReader(indexStr);
		TokenStream ts = analyzer.tokenStream(indexStr, reader);
		ts.addAttribute(TermAttribute.class);
		int i = 0;
		while (ts.incrementToken()) {
			TermAttribute ta = ts.getAttribute(TermAttribute.class);
			str_temp = ta.term();
			System.out.println(str_temp);
			result_temp[i][0] = str_temp;
			i += 1;
		}
		int n = 0;
		String[][] result = new String[i][1];
		for (int m = 0; m < result_temp.length; m++) {
			if (result_temp[m][0] != null) {
				result[n][0] = "[" + (n + 1) + "]" + result_temp[m][0];
				n += 1;
			}
		}
		return result;
	}
}

你可能感兴趣的:(抓取OA考勤记录)