├── .classpath ├── .gitignore ├── .project ├── README.md ├── bin ├── performance_monitor.sh ├── restart-server.sh └── sys_performance_monitor.sh ├── conf └── main.properties ├── doc ├── img │ ├── monitor__report.png │ └── performanceAnalysis.png └── readme.txt ├── pom.xml └── src └── main ├── assembly └── assembly.xml ├── java └── org │ └── langke │ └── jetty │ ├── bean │ └── Menu.java │ ├── common │ ├── Config.java │ ├── CostTime.java │ ├── DateUtil.java │ ├── Dbop.java │ ├── ExecutorFactory.java │ ├── HttpClientUtil.java │ ├── RequestUtil.java │ ├── Share.java │ ├── StrIntBag.java │ ├── StringPair.java │ ├── TableUtil.java │ └── chart │ │ ├── ChartUtil.java │ │ ├── CustomXYURLGenerator.java │ │ ├── MyDrawer.java │ │ └── WindowURLTagFragmentGenerator.java │ ├── controller │ └── MenuController.java │ ├── dao │ ├── IAppMonitorDao.java │ ├── IMenuDao.java │ └── impl │ │ ├── AppMonitorDao.java │ │ └── MenuDao.java │ ├── resp │ └── Response.java │ ├── server │ ├── AppMonitorJettyServer.java │ ├── Job.java │ └── SpringApplicationContext.java │ ├── service │ ├── AppMonitorService.java │ ├── MenuService.java │ └── impl │ │ ├── AppMonitorServiceImpl.java │ │ └── MenuServiceImpl.java │ └── servlet │ ├── LogFilter.java │ ├── MonitorHandler.java │ └── TestServlet.java ├── resources ├── applicationContext.xml └── log4j.properties └── webapp ├── META-INF └── MANIFEST.MF ├── WEB-INF ├── dispatcher-servlet.xml └── web.xml ├── css ├── base.css ├── component.css └── frame.css ├── favicon.ico ├── fbtn.jsp ├── head.jsp ├── img ├── btn.gif ├── frame.gif └── frame_btn.gif ├── index.jsp ├── js ├── DatePicker │ ├── My97DatePicker.htm │ ├── WdatePicker.js │ ├── calendar.js │ ├── config.js │ ├── lang │ │ ├── en.js │ │ ├── zh-cn.js │ │ └── zh-tw.js │ └── skin │ │ ├── WdatePicker.css │ │ ├── datePicker.gif │ │ ├── default │ │ ├── datepicker.css │ │ └── img.gif │ │ └── whyGreen │ │ ├── bg.jpg │ │ ├── datepicker.css │ │ └── img.gif ├── jquery-1.4.2.js ├── jquery-ui.min.js ├── jquery.clipboard.min.js ├── jquery.form.js ├── jquery.query-2.1.7.js └── validate │ ├── images │ ├── checked.gif │ └── unchecked.gif │ ├── jquery.validate.css │ ├── jquery.validate.js │ └── messages_cn.js ├── menu ├── menuList.jsp └── url.jsp ├── side.jsp ├── subframe.jsp └── test └── velocity.html /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /logs 3 | /h2 4 | /.settings 5 | .idea/* 6 | .project 7 | .classpath 8 | /*.iml 9 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app_monitor 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.m2e.core.maven2Nature 38 | org.eclipse.jdt.core.javanature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | app_monitor 2 | =============== 3 | 4 | app_monitor是基于jetty嵌入式容器的java性能分析工具,内嵌H2 database,以图表形式直观展现当前应用的性能数据 5 | ![应用性能分析图表](https://raw.github.com/langke93/app_monitor/master/doc/img/performanceAnalysis.png)(https://raw.github.com/langke93/app_monitor/master/doc/img/monitor__report.png) 6 | 7 | 部署目录结构: 8 | \bin 9 | \lib 10 | \src 11 | \conf 12 | 启动服务端运行bin/restart_server.sh 13 | 14 | 客户端执行 sh performance_monitor.sh > performance_monitor.sh.log 2>&1 & 15 | 需要配置host:app.monitor.server指向服务端IP 16 | 17 | #验证 hello servlet 18 | http://localhost:9009/servlet/test?helloworld=this-is-jetty-embed-http 19 | 20 | #验证 jsp 21 | http://localhost:9009/index.jsp 22 | 23 | #查看报表 24 | http://localhost:9009/monitor/_report 25 | 26 | #2013.1.20 27 | 整合UI、增加菜单管理 28 | 29 | #1.javamelody集成Application 30 | 启动main函数加: 31 | new JavaMelodyMonitorServer(o.serverName(),o.getServerAddress().getHost(),o.getServerAddress().getPort()); 32 | 33 | spring 加: 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 需要的jar包 54 | javamelody.jar 55 | jetty-6.1.26.jar 56 | jetty-util-6.1.26.jar 57 | jrobin-1.5.9.1.jar 58 | org.springframework.web-3.1.0.RELEASE.jar 59 | servlet-api-3.0.jar 60 | cglib-nodep-2.2.2.jar 61 | 62 | #2.web集成: 63 | 在被监控项目web.xml中加入如下代码 64 | 65 | monitoring 66 | net.bull.javamelody.MonitoringFilter 67 | 68 | 69 | monitoring 70 | /* 71 | 72 | 73 | net.bull.javamelody.SessionListener 74 | 75 | 将javamelody.jar,jrobin-1.5.9.1.jar复制到被监控项目的lib目录 76 | 77 | 通过http://localhost:8080/monitoring访问 -------------------------------------------------------------------------------- /bin/performance_monitor.sh: -------------------------------------------------------------------------------- 1 | DIRNAME=/usr/bin/dirname 2 | BASE_PATH=`$DIRNAME $0` 3 | cd $BASE_PATH 4 | #export PATH=/usr/local/jdk1.6.0_26/bin:$PATH 5 | TMPFILE=/tmp/per_mointor.tmp 6 | IP=`/sbin/ip a |grep 'inet '|awk -F'/' '{print $1}'|awk '{print $2}'|grep -v 127.0.0.1|grep -v lo:*|head -1` 7 | JPS_FILE=/tmp/jps_file.tmp 8 | function_send_data(){ 9 | url="http://app.monitor.server:9009/monitor/_add" 10 | #echo $url "-d $body" 11 | curl -m 3 -E --connect-timeout=3 --compressed -XPOST $url -d"${body}" 12 | } 13 | 14 | function_thread_state(){ 15 | body="[" 16 | for i in `pgrep java` ;do 17 | pid=$i 18 | serverName= 19 | jstack $i |grep java.lang.Thread.State|awk '{print $2}'|sort|uniq -c >$TMPFILE 2>&1 20 | while read line 21 | do 22 | # skip blank lines 23 | if [ "${line}" = "" ]; then 24 | continue 25 | fi 26 | value=`echo "${line}" | cut -d" " -f1` 27 | key=`echo "${line}" | cut -d" " -f2` 28 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 29 | if [ "$serverName" = "" ]; then 30 | continue 31 | fi 32 | #key=$serverName:$key 33 | #echo $serverName $key $value 34 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"thread\",\"status\":\"$key\",\"val\":$value}, 35 | done < ${TMPFILE} 36 | done 37 | body=$body"]" 38 | #echo $body 39 | function_send_data $body 40 | } 41 | 42 | function_network_conn(){ 43 | body="[" 44 | for i in `pgrep java` ;do 45 | pid=$i 46 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 47 | if [ "$serverName" = "" ]; then 48 | continue 49 | fi 50 | key="conn" 51 | value=`netstat -anp|awk '{print $7}'|grep "$pid/java"|awk -F/ '{print $1}'|wc -l` 52 | #echo $serverName $key $value 53 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"network\",\"status\":\"$key\",\"val\":$value}, 54 | done 55 | body=$body"]" 56 | #echo $body 57 | function_send_data $body 58 | } 59 | 60 | function_cpu_use(){ 61 | body="[" 62 | for i in `pgrep java` ;do 63 | pid=$i 64 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 65 | if [ "$serverName" = "" ]; then 66 | continue 67 | fi 68 | key="use" 69 | value=`ps aux|grep $serverName|grep $pid |awk '{print $3}'` 70 | #echo $serverName $key $value 71 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"cpu\",\"status\":\"$key\",\"val\":$value}, 72 | done 73 | body=$body"]" 74 | #echo $body 75 | function_send_data $body 76 | } 77 | 78 | while true ;do 79 | jps|egrep -v "Jps|Launcher" > $JPS_FILE 80 | function_thread_state 81 | function_network_conn 82 | function_cpu_use 83 | echo "sleep 60" 84 | sleep 60 85 | done 86 | 87 | #netstat -anp| awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr|more 88 | 89 | 90 | -------------------------------------------------------------------------------- /bin/restart-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ "`whoami`" != "root" ] ; then 3 | echo 4 | # echo Must start use root 5 | echo 6 | # exit 1 7 | fi 8 | 9 | DIRNAME=/usr/bin/dirname 10 | BASE_PATH=`$DIRNAME $0`/.. 11 | cd $BASE_PATH 12 | echo `/bin/pwd` 13 | 14 | #export JAVA_HOME=/usr/local/jdk1.6.0_26 15 | #export PATH=/usr/local/jdk1.6.0_26/bin:$PATH 16 | 17 | CLASSPATH=$BASE_PATH/conf/:$JAVA_HOME/lib/dt.jar:/$JAVA_HOME/lib/tools.jar:$CLASSPATH 18 | for i in bin/*.jar ;do 19 | CLASSPATH=$CLASSPATH:$i; 20 | done 21 | for i in lib/*.jar ;do 22 | CLASSPATH=$CLASSPATH:$i; 23 | done 24 | 25 | SEARCH_VER=9 26 | #DEFAULT_OPTS="-server -Xms100M -Xmx500M" 27 | DEFAULT_OPTS="$DEFAULT_OPTS -Dcom.sun.management.jmxremote.port=89${SEARCH_VER}6" 28 | DEFAULT_OPTS="$DEFAULT_OPTS -Dcom.sun.management.jmxremote.authenticate=false" 29 | DEFAULT_OPTS="$DEFAULT_OPTS -Dcom.sun.management.jmxremote.ssl=false" 30 | DEFAULT_OPTS="$DEFAULT_OPTS -Djava.awt.headless=true" 31 | DEBUG_INFO=" -Xdebug -Xrunjdwp:transport=dt_socket,address=1527${SEARCH_VER},server=y,suspend=n " 32 | DEBUG="" 33 | case $1 in 34 | "debug") DEBUG=${DEBUG_INFO};; 35 | esac; 36 | shift; 37 | PNAME=org.langke.jetty.server.AppMonitorJettyServer 38 | if test $(pgrep -f ${PNAME}|wc -l) -ne 0;then 39 | echo "closing...... $PNAME" 40 | pkill -f $PNAME 41 | sleep 1 42 | fi 43 | 44 | 45 | # process 46 | CMD="java -cp $CLASSPATH $DEFAULT_OPTS $DEBUG ${PNAME} > /dev/null 2>&1 &" 47 | eval $CMD 48 | echo "start ~~ $CMD" 49 | echo "as pid:`pgrep -f ${PNAME}`" 50 | -------------------------------------------------------------------------------- /bin/sys_performance_monitor.sh: -------------------------------------------------------------------------------- 1 | DIRNAME=/usr/bin/dirname 2 | BASE_PATH=`$DIRNAME $0` 3 | cd $BASE_PATH 4 | TMPFILE=/tmp/sys_per_mointor.tmp 5 | IP=`/sbin/ip a |grep 'inet '|awk -F'/' '{print $1}'|awk '{print $2}'|grep -v 127.0.0.1|grep -v lo:*|head -1` 6 | JPS_FILE=/tmp/jps_file.tmp 7 | function_send_data(){ 8 | url="http://10.59.107.154:9009/monitor/_add" 9 | #echo $url "-d $body" 10 | curl -m 3 -E --connect-timeout=3 --compressed -XPOST $url -d"${body}" 11 | } 12 | 13 | function_gcutil(){ 14 | body="[" 15 | for i in `pgrep java` ;do 16 | pid=$i 17 | serverName= 18 | for j in {3,4,6,7,8,9} ; 19 | do 20 | # skip blank lines 21 | line=`jstat -gcutil $i|awk -v var=$j '{print $var}'` 22 | if [ "${line}" = "" ]; then 23 | continue 24 | fi 25 | value=`echo ${line}|awk '{print $2}'` 26 | key=`echo ${line}|awk '{print $1}'` 27 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 28 | if [ "$serverName" = "" ]; then 29 | continue 30 | fi 31 | #key=$serverName:$key 32 | #echo $serverName $key $value 33 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"gc\",\"status\":\"$key\",\"val\":$value}, 34 | done < ${TMPFILE} 35 | done 36 | body=$body"]" 37 | #echo $body 38 | function_send_data $body 39 | } 40 | 41 | function_thread_state(){ 42 | body="[" 43 | for i in `pgrep java` ;do 44 | pid=$i 45 | serverName= 46 | jstack $i |grep java.lang.Thread.State|awk '{print $2}'|sort|uniq -c >$TMPFILE 2>&1 47 | while read line 48 | do 49 | # skip blank lines 50 | if [ "${line}" = "" ]; then 51 | continue 52 | fi 53 | value=`echo "${line}" | cut -d" " -f1` 54 | key=`echo "${line}" | cut -d" " -f2` 55 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 56 | if [ "$serverName" = "" ]; then 57 | continue 58 | fi 59 | #key=$serverName:$key 60 | #echo $serverName $key $value 61 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"thread\",\"status\":\"$key\",\"val\":$value}, 62 | done < ${TMPFILE} 63 | done 64 | body=$body"]" 65 | #echo $body 66 | function_send_data $body 67 | } 68 | 69 | function_network_conn(){ 70 | body="[" 71 | for i in `pgrep java` ;do 72 | pid=$i 73 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 74 | if [ "$serverName" = "" ]; then 75 | continue 76 | fi 77 | key="conn" 78 | value=`netstat -anp|awk '{print $7}'|grep "$pid/java"|awk -F/ '{print $1}'|wc -l` 79 | #echo $serverName $key $value 80 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"network\",\"status\":\"$key\",\"val\":$value}, 81 | done 82 | body=$body"]" 83 | #echo $body 84 | function_send_data $body 85 | } 86 | 87 | function_cpu_use(){ 88 | body="[" 89 | for i in `pgrep java` ;do 90 | pid=$i 91 | serverName=`cat $JPS_FILE |grep $pid|awk '{print $2}'` 92 | if [ "$serverName" = "" ]; then 93 | continue 94 | fi 95 | key="use" 96 | value=`ps aux|grep $serverName|grep $pid |awk '{print $3}'` 97 | #echo $serverName $key $value 98 | body=$body{\"server_ip\":\"$IP\",\"app_name\":\"$serverName\",\"type\":\"cpu\",\"status\":\"$key\",\"val\":$value}, 99 | done 100 | body=$body"]" 101 | #echo $body 102 | function_send_data $body 103 | } 104 | 105 | while true ;do 106 | jps|egrep -v "Jps|Launcher" > $JPS_FILE 107 | function_thread_state 108 | function_network_conn 109 | function_cpu_use 110 | function_gcutil 111 | echo "sleep 60" 112 | sleep 60 113 | done 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /conf/main.properties: -------------------------------------------------------------------------------- 1 | jsp.title=PerformanceAnalysis 2 | jsp.logo=PerformanceAnalysis 3 | port=9009 4 | threadNum=50 5 | contextPath=/ 6 | webPath=./src/main/webapp -------------------------------------------------------------------------------- /doc/img/monitor__report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/doc/img/monitor__report.png -------------------------------------------------------------------------------- /doc/img/performanceAnalysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/doc/img/performanceAnalysis.png -------------------------------------------------------------------------------- /doc/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/doc/readme.txt -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.langke.jetty 5 | app_monitor 6 | jar 7 | 0.0.1-SNAPSHOT 8 | A base jetty app monitor 9 | 10 | 11 | 12 | org.eclipse.jetty 13 | jetty-webapp 14 | 7.6.3.v20120416 15 | 16 | 17 | 18 | 19 | org.eclipse.jetty 20 | jetty-jsp-2.1 21 | 7.5.4.v20111024 22 | 23 | 24 | org.mortbay.jetty 25 | jsp-2.1-glassfish 26 | 2.1.v20100127 27 | 28 | 29 | 30 | 31 | org.slf4j 32 | slf4j-log4j12 33 | 1.6.1 34 | 35 | 36 | log4j 37 | log4j 38 | 1.2.17 39 | 40 | 41 | org.springframework 42 | spring-context 43 | 3.2.0.RELEASE 44 | 45 | 46 | org.springframework 47 | spring-jdbc 48 | 3.2.0.RELEASE 49 | 50 | 51 | org.springframework 52 | spring-web 53 | 3.2.0.RELEASE 54 | 55 | 56 | org.springframework 57 | spring-webmvc 58 | 3.2.0.RELEASE 59 | 60 | 61 | 62 | net.bull.javamelody 63 | javamelody-core 64 | 1.74.0 65 | 66 | 67 | 68 | com.lowagie 69 | itext 70 | 2.1.7 71 | 72 | 73 | bcmail-jdk14 74 | bouncycastle 75 | 76 | 77 | bcprov-jdk14 78 | bouncycastle 79 | 80 | 81 | bctsp-jdk14 82 | bouncycastle 83 | 84 | 85 | 86 | 87 | com.thoughtworks.xstream 88 | xstream 89 | 1.4.6 90 | 91 | 92 | org.jrobin 93 | jrobin 94 | 1.5.9 95 | 96 | 97 | 98 | com.alibaba 99 | fastjson 100 | 1.2.67 101 | 102 | 103 | 104 | 105 | org.apache.commons 106 | commons-lang3 107 | 3.1 108 | 109 | 110 | commons-httpclient 111 | commons-httpclient 112 | 3.1 113 | 114 | 115 | 116 | commons-dbcp 117 | commons-dbcp 118 | 1.4 119 | 120 | 121 | 122 | jfree 123 | jfreechart 124 | 1.0.12 125 | 126 | 127 | 128 | com.h2database 129 | h2 130 | 1.3.170 131 | 132 | 133 | org.apache.zookeeper 134 | zookeeper 135 | 3.4.14 136 | 137 | 138 | net.sf.opencsv 139 | opencsv 140 | 2.3 141 | 142 | 143 | org.jsoup 144 | jsoup 145 | 1.7.3 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | org.apache.maven.plugins 155 | maven-compiler-plugin 156 | 2.3.1 157 | 158 | 1.6 159 | 1.6 160 | UTF-8 161 | 162 | 163 | 164 | 165 | org.apache.maven.plugins 166 | maven-jar-plugin 167 | 168 | 169 | *.properties 170 | *.xml 171 | 172 | 173 | 174 | 175 | maven-assembly-plugin 176 | 177 | ${project.artifactId} 178 | false 179 | src/main/assembly/assembly.xml 180 | 181 | 182 | 183 | make-assembly 184 | package 185 | 186 | single 187 | 188 | 189 | 190 | 191 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | assembly 18 | 19 | zip 20 | 21 | true 22 | 23 | 24 | bin 25 | bin 26 | 0755 27 | 28 | 29 | src/main/resources 30 | conf 31 | 0644 32 | 33 | 34 | conf 35 | conf 36 | 0644 37 | 38 | 39 | src/main/webapp 40 | webapp 41 | 0644 42 | 43 | 44 | 45 | 46 | lib 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/bean/Menu.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.bean; 2 | 3 | import java.util.List; 4 | 5 | public class Menu { 6 | 7 | private Integer id; 8 | private Integer f_id; 9 | private String name; 10 | private String url; 11 | private byte status; 12 | private String extend; 13 | private Integer orders; 14 | private String f_name; 15 | private List childen ; 16 | 17 | public Integer getId() { 18 | return id; 19 | } 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | public Integer getF_id() { 24 | return f_id; 25 | } 26 | public void setF_id(Integer f_id) { 27 | this.f_id = f_id; 28 | } 29 | public String getName() { 30 | return name; 31 | } 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | public String getUrl() { 36 | return url; 37 | } 38 | public void setUrl(String url) { 39 | this.url = url; 40 | } 41 | public byte getStatus() { 42 | return status; 43 | } 44 | public void setStatus(byte status) { 45 | this.status = status; 46 | } 47 | public String getExtend() { 48 | return extend; 49 | } 50 | public void setExtend(String extend) { 51 | this.extend = extend; 52 | } 53 | public Integer getOrders() { 54 | return orders; 55 | } 56 | public void setOrders(Integer orders) { 57 | this.orders = orders; 58 | } 59 | public String getF_name() { 60 | return f_name; 61 | } 62 | public void setF_name(String f_name) { 63 | this.f_name = f_name; 64 | } 65 | public List getChilden() { 66 | return childen; 67 | } 68 | public void setChilden(List childen) { 69 | this.childen = childen; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/Config.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * @author langke 13 | * @version 1.0 14 | */ 15 | public abstract class Config { 16 | private static final Logger log = LoggerFactory.getLogger(Config.class); 17 | private static final Config CONFIG = new Config() { 18 | java.util.Properties p = new Properties(); 19 | boolean changed = false; 20 | private final File cf = new File("conf/main.properties"); 21 | long lmd; 22 | 23 | { 24 | try { 25 | if (!cf.exists()) { 26 | cf.getParentFile().mkdirs(); 27 | 28 | cf.createNewFile(); 29 | } 30 | java.lang.Runtime.getRuntime().addShutdownHook( 31 | new Thread("store-config") { 32 | public void run() { 33 | try { 34 | if (changed) { 35 | boolean autoUpdate = p 36 | .containsKey("autoUpdate"); 37 | if (autoUpdate) { 38 | FileOutputStream fos = new java.io.FileOutputStream( 39 | cf); 40 | p.store(fos, 41 | "add an key to auto update config form default values"); 42 | fos.close(); 43 | } 44 | } 45 | } catch (Exception ex) { 46 | log.warn("store config", ex); 47 | } 48 | } 49 | }); 50 | 51 | p.load(new java.io.FileInputStream(cf)); 52 | log.info("loading config from:" + cf.getAbsolutePath()); 53 | 54 | lmd = cf.lastModified(); 55 | 56 | Thread t = new Thread(new Runnable() { 57 | public void run() { 58 | while (true) { 59 | try { 60 | Thread.sleep(60000); 61 | } catch (InterruptedException e) { 62 | } 63 | long newlmd = cf.lastModified(); 64 | if (newlmd > lmd) { 65 | lmd = newlmd; 66 | log.info("Config file " + cf.getAbsolutePath() 67 | + " is changed,reloading ..."); 68 | try { 69 | p.load(new java.io.FileInputStream(cf)); 70 | } catch (IOException e) { 71 | log.error("Error while loading config file: " 72 | + cf.getAbsolutePath()); 73 | } 74 | } 75 | } 76 | } 77 | }, "Config file refresher"); 78 | t.setDaemon(true); 79 | log.info(t.getName() + " setDaemon"); 80 | t.start(); 81 | 82 | } catch (IOException ex) { 83 | log.warn("cannot create log file", ex); 84 | } 85 | 86 | } 87 | 88 | public String get(String k, String defaultValue) { 89 | String s = p.getProperty(k); 90 | if (s == null) { 91 | 92 | p.setProperty(k, defaultValue); 93 | changed = true; 94 | 95 | return defaultValue; 96 | } 97 | 98 | return s; 99 | } 100 | 101 | public int getInt(String k, int defaultValue) { 102 | String s = this.get(k, defaultValue + ""); 103 | 104 | try { 105 | return Integer.parseInt(s); 106 | } catch (Exception e) { 107 | return defaultValue; 108 | } 109 | 110 | } 111 | 112 | public float getFloat(String k, float defaultValue) { 113 | String s = this.get(k, defaultValue + ""); 114 | 115 | try { 116 | return Float.parseFloat(s); 117 | } catch (Exception e) { 118 | return defaultValue; 119 | } 120 | } 121 | 122 | public boolean getBoolean(String k, boolean defaultValue) { 123 | String s = this.get(k, defaultValue + ""); 124 | try { 125 | return Boolean.parseBoolean(s); 126 | } catch (Exception e) { 127 | return defaultValue; 128 | } 129 | 130 | } 131 | 132 | public boolean setProperty(String key, String value) { 133 | p.setProperty(key, value); 134 | try { 135 | FileOutputStream fos = new java.io.FileOutputStream(cf); 136 | p.store(fos, ""); 137 | fos.close(); 138 | return true; 139 | } catch (Exception ex) { 140 | log.warn("store config", ex); 141 | return false; 142 | } 143 | } 144 | 145 | public String get(String key) { 146 | return p.getProperty(key); 147 | } 148 | }; 149 | 150 | private Config() { 151 | } 152 | 153 | abstract public String get(String k, String defaultValue); 154 | 155 | abstract public int getInt(String k, int defaultValue); 156 | 157 | abstract public float getFloat(String k, float defaultValue); 158 | 159 | abstract public boolean getBoolean(String k, boolean defaultValue); 160 | 161 | abstract public boolean setProperty(String key, String value); 162 | 163 | abstract public String get(String key); 164 | 165 | public static final Config get() { 166 | return CONFIG; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/CostTime.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | /* 4 | * @copyright (c) langke 2011 5 | * @author langke Aug 11, 2011 6 | */ 7 | 8 | public class CostTime { 9 | 10 | private transient long start; 11 | 12 | public void start(){ 13 | this.start = System.currentTimeMillis(); 14 | } 15 | 16 | public long cost(){ 17 | return System.currentTimeMillis() - start; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/DateUtil.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | /** 9 | * 日期转换工具 10 | */ 11 | public class DateUtil 12 | { 13 | private static final String FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss"; 14 | private static final String FORMAT_DATE = "yyyy-MM-dd"; 15 | 16 | public static boolean isDate(String date){ 17 | return date.matches("\\d{4}-\\d{2}-\\d{2}"); 18 | } 19 | 20 | public static String getCurrentDateStr(){ 21 | return getCurrentDateStr(FORMAT_DATETIME); 22 | } 23 | 24 | public static String getDatetimeStr(long datetime){ 25 | return format(new Date(datetime),FORMAT_DATETIME); 26 | } 27 | 28 | public static String getDateStr(long datetime){ 29 | return format(new Date(datetime),FORMAT_DATE); 30 | } 31 | 32 | public static Date getCurrentDate(){ 33 | Calendar cal = Calendar.getInstance(); 34 | Date currDate = cal.getTime(); 35 | return currDate; 36 | } 37 | 38 | /** 39 | * param 2010-09-01 40 | */ 41 | public static Date parseStringToDate(String date_str){ 42 | SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE); 43 | Date date = null; 44 | try { 45 | date = sdf.parse(date_str); 46 | } catch (ParseException e) { 47 | e.printStackTrace(); 48 | } 49 | return date; 50 | } 51 | /** 52 | * param 2010-09-01 19:29:10 53 | */ 54 | public static Date parseStringToDateTime(String date_str){ 55 | SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME); 56 | Date date = null; 57 | try { 58 | date = sdf.parse(date_str); 59 | } catch (ParseException e) { 60 | e.printStackTrace(); 61 | } 62 | return date; 63 | } 64 | 65 | private static String getCurrentDateStr(String strFormat){ 66 | Calendar cal = Calendar.getInstance(); 67 | Date currDate = cal.getTime(); 68 | return format(currDate, strFormat); 69 | } 70 | 71 | public static String format(Date aTs_Datetime, String as_Pattern){ 72 | if (aTs_Datetime == null || as_Pattern == null){ 73 | return null; 74 | } 75 | SimpleDateFormat dateFromat = new SimpleDateFormat(as_Pattern); 76 | return dateFromat.format(aTs_Datetime); 77 | } 78 | public static void main(String[] args){ 79 | System.out.println(getCurrentDateStr()); 80 | System.out.println(parseStringToDateTime(getCurrentDateStr()).getTime()); 81 | System.out.println(getDatetimeStr(System.currentTimeMillis())); 82 | System.out.println(getCurrentDateStr("yyyy.MM.dd HH:mm:ss")); 83 | System.out.println(format(new Date(System.currentTimeMillis()),"yyyy.MM.dd HH:mm:ss")); 84 | } 85 | } 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/Dbop.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | import java.sql.Connection; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.sql.Statement; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import javax.sql.DataSource; 13 | 14 | import org.langke.jetty.server.SpringApplicationContext; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | /*** 19 | * 数据源用于报表 20 | * @author lee 21 | * 22 | */ 23 | public class Dbop { 24 | 25 | Object obj ; 26 | public int ErrorCode=0; 27 | public String ErrorMsg; 28 | private static DataSource dataSource; 29 | private static final Logger log = LoggerFactory.getLogger(Dbop.class); 30 | private DataSource createDataSource(){ 31 | return createDataSource("dataSource"); 32 | } 33 | private DataSource createDataSource(String dsname){ 34 | //获取连接池对象 35 | return (DataSource) SpringApplicationContext.getInstance().getService(dsname); 36 | } 37 | 38 | public Dbop() { 39 | try{ 40 | if(dataSource == null) 41 | dataSource = createDataSource(); 42 | }catch(Exception ex){ 43 | ErrorCode=-1; 44 | ErrorMsg=ex.getMessage(); 45 | log.error("Dbop--获取连接池对象异常:"+ErrorMsg,ex); 46 | } 47 | } 48 | 49 | public Dbop(String dsname) { 50 | try{ 51 | if(dataSource == null) 52 | dataSource = createDataSource(dsname); 53 | }catch(Exception ex){ 54 | ErrorCode=-1; 55 | ErrorMsg=ex.getMessage(); 56 | log.error("Dbop--获取连接池对象异常:"+ErrorMsg,ex); 57 | } 58 | } 59 | 60 | public Connection GetConnection(){ 61 | Connection conn; 62 | try{ 63 | conn=dataSource.getConnection(); 64 | conn.setAutoCommit(false); 65 | return conn; 66 | }catch (SQLException ex){ 67 | log.error("",ex); 68 | try{ 69 | conn=dataSource.getConnection(); 70 | conn.setAutoCommit(false); 71 | }catch(SQLException ex2){ 72 | ex2.printStackTrace(); 73 | ErrorCode = ex.getErrorCode(); 74 | ErrorMsg = ex.getMessage(); 75 | return null; 76 | } 77 | return conn; 78 | } 79 | } 80 | 81 | 82 | public int CloseConnection(Connection conn){ 83 | try { 84 | if (conn != null){ 85 | conn.close(); 86 | conn = null; 87 | } 88 | CloseContext(); 89 | return 0; 90 | } 91 | catch (SQLException ex) { 92 | log.error("",ex); 93 | ErrorMsg = "关闭连接错误" + ex.getMessage(); 94 | ErrorCode = ex.getErrorCode(); 95 | return -1; 96 | } 97 | } 98 | 99 | public int CloseContext(){ 100 | try { 101 | return(0); 102 | }catch (Exception ex) { 103 | log.error("",ex); 104 | return(-1); 105 | } 106 | } 107 | 108 | 109 | /** 110 | * 实现修改 111 | * @param sql 112 | * @return 113 | */ 114 | public static boolean executeUpdate(String sql) { 115 | Dbop dbop = new Dbop(); 116 | Connection connection = dbop.GetConnection(); 117 | Statement st = null; 118 | try { 119 | st = connection.createStatement(); 120 | int i = st.executeUpdate(sql); 121 | if (i > 0) { 122 | return true; 123 | } else { 124 | return false; 125 | } 126 | } catch (SQLException e) { 127 | log.error("",e); 128 | } finally { 129 | if(st!=null) 130 | try { 131 | st.close(); 132 | } catch (SQLException e) { 133 | e.printStackTrace(); 134 | } 135 | dbop.CloseConnection(connection); 136 | } 137 | return false; 138 | } 139 | 140 | /** 141 | * 实现查询 142 | * @param sql 143 | * @return 144 | */ 145 | public static List> getQueryList(String sql) { 146 | Dbop dbop = new Dbop(); 147 | Connection connection = dbop.GetConnection(); 148 | List> list = null; 149 | Statement st = null; 150 | ResultSet rs = null; 151 | try { 152 | st = connection.createStatement(); 153 | rs = st.executeQuery(sql); 154 | list = new ArrayList>(); 155 | while(rs.next()){ 156 | int cols= rs.getMetaData().getColumnCount(); 157 | Map map = new HashMap(); 158 | for(int i=1;i<=cols;i++){ 159 | //System.out.print(rs.getMetaData().getColumnName(i)+":"+rs.getString(i)+" "); 160 | map.put(rs.getMetaData().getColumnName(i),rs.getString(i)); 161 | } 162 | list.add(map); 163 | } 164 | } catch (SQLException e) { 165 | log.error("",e); 166 | }finally{ 167 | if(st!=null) 168 | try { 169 | st.close(); 170 | } catch (SQLException e) { 171 | e.printStackTrace(); 172 | } 173 | dbop.CloseConnection(connection); 174 | } 175 | return list; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/ExecutorFactory.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.ScheduledExecutorService; 6 | 7 | /* 8 | * @copyright (c) langke 2011 9 | * @author langke 2011-5-1 10 | */ 11 | public class ExecutorFactory { 12 | 13 | public static ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); 14 | public static ExecutorService fixedExecutor = Executors.newFixedThreadPool(10); 15 | public static ExecutorService cachedExecutor = Executors.newCachedThreadPool(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/HttpClientUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.langke.jetty.common; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | 11 | import org.apache.commons.httpclient.HttpClient; 12 | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 13 | import org.apache.commons.httpclient.methods.GetMethod; 14 | import org.apache.commons.httpclient.methods.PostMethod; 15 | import org.apache.commons.httpclient.methods.RequestEntity; 16 | import org.apache.commons.httpclient.methods.StringRequestEntity; 17 | import org.apache.commons.httpclient.params.HttpConnectionManagerParams; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import com.alibaba.fastjson.JSONObject; 23 | 24 | 25 | public class HttpClientUtil { 26 | private static final Logger log = LoggerFactory.getLogger(HttpClientUtil.class); 27 | private static HttpClient client = null; 28 | private static MultiThreadedHttpConnectionManager conn_manager = null; 29 | private static HttpConnectionManagerParams cmanager_params = null; 30 | static{ 31 | if(client==null) init(); 32 | } 33 | private static void init(){ 34 | if (conn_manager == null) 35 | conn_manager = new MultiThreadedHttpConnectionManager(); 36 | if (cmanager_params == null) 37 | cmanager_params = new HttpConnectionManagerParams(); 38 | // config the HTTP client visit performance. 39 | cmanager_params.setDefaultMaxConnectionsPerHost(1000); 40 | cmanager_params.setMaxTotalConnections(1024); 41 | cmanager_params.setConnectionTimeout(300000); 42 | conn_manager.setParams(cmanager_params); 43 | if (client == null) 44 | client = new HttpClient(conn_manager); 45 | } 46 | 47 | public static StrIntBag executeGet(String url){ 48 | return executeGet(url, null); 49 | } 50 | 51 | public static StrIntBag executeGet(String url,String host){ 52 | GetMethod get = null; 53 | StrIntBag bag = new StrIntBag(); 54 | try { 55 | get = new GetMethod(url); 56 | get.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8"); 57 | get.getParams().setParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); 58 | if(host!=null) 59 | get.getParams().setParameter(HttpMethodParams.VIRTUAL_HOST, host); 60 | int status = client.executeMethod(get); 61 | String resp = null; 62 | if(get.getResponseContentLength()!=-1) 63 | resp = get.getResponseBodyAsString(); 64 | else 65 | resp = getStreamToString(get.getResponseBodyAsStream()); 66 | bag._str = resp; 67 | bag._int = status; 68 | return bag; 69 | } catch (Exception e) { 70 | log.error("{}", e); 71 | } finally{ 72 | if(get != null){ 73 | get.releaseConnection(); 74 | } 75 | } 76 | return null; 77 | } 78 | public static StrIntBag tryExecuteGet(String url){ 79 | StrIntBag bag = executeGet(url); 80 | if(bag != null){ 81 | return bag; 82 | } 83 | int tryCount = 3; 84 | while(bag == null && (tryCount--) > 0 ){ 85 | bag = executeGet(url); 86 | try { 87 | Thread.sleep(20); 88 | } catch (InterruptedException e) { 89 | log.error("{}",e); 90 | } 91 | } 92 | return bag; 93 | } 94 | 95 | /** 96 | * ald 转url post使用 97 | * @param uri 98 | * @param requestBody 99 | * @return 100 | */ 101 | public static StrIntBag executeForAld(String uri, String requestBody){ 102 | PostMethod post = null; 103 | StrIntBag bag = new StrIntBag(); 104 | try { 105 | post = new PostMethod(uri); 106 | post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8"); 107 | post.getParams().setParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); 108 | if(requestBody != null){ 109 | RequestEntity reqEntity = new StringRequestEntity(requestBody,"application/json","UTF-8"); 110 | post.setRequestEntity(reqEntity); 111 | } 112 | int status = client.executeMethod(post); 113 | String resp = getStreamToString(post.getResponseBodyAsStream()); 114 | bag._str = resp; 115 | bag._int = status; 116 | return bag; 117 | } catch (Exception e) { 118 | log.error("{}",e); 119 | } finally{ 120 | if(post != null){ 121 | post.releaseConnection(); 122 | } 123 | } 124 | return null; 125 | } 126 | 127 | 128 | 129 | public static StrIntBag execute(String uri, String requestBody){ 130 | PostMethod post = null; 131 | StrIntBag bag = new StrIntBag(); 132 | try { 133 | post = new PostMethod(uri); 134 | post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8"); 135 | post.getParams().setParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); 136 | if(requestBody != null){ 137 | RequestEntity reqEntity = new StringRequestEntity(requestBody,"application/json","UTF-8"); 138 | post.setRequestEntity(reqEntity); 139 | } 140 | int status = client.executeMethod(post); 141 | String resp = post.getResponseBodyAsString(); 142 | bag._str = resp; 143 | bag._int = status; 144 | return bag; 145 | } catch (Exception e) { 146 | log.error("{},{}",uri,requestBody); 147 | log.error("",e); 148 | } finally{ 149 | if(post != null){ 150 | post.releaseConnection(); 151 | } 152 | } 153 | return null; 154 | } 155 | 156 | /** 157 | * 失败后,重试3次 158 | * @param uri 159 | * @param requestBody 160 | * @return 161 | */ 162 | public static StrIntBag tryExecute(String uri, String requestBody){ 163 | StrIntBag bag = execute(uri, requestBody); 164 | if(bag != null){ 165 | return bag; 166 | } 167 | int tryCount = 3; 168 | while(bag == null && (tryCount--) > 0 ){ 169 | bag = execute(uri, requestBody); 170 | try { 171 | Thread.sleep(20); 172 | } catch (InterruptedException e) { 173 | log.error("{}", e); 174 | } 175 | } 176 | return bag; 177 | } 178 | 179 | 180 | public static JSONObject callUrlToJSON(String url,String json){ 181 | StrIntBag bag = null; 182 | if(log.isInfoEnabled()){ 183 | String key = "password"; 184 | String key2 = "newPassword"; 185 | String body = json; 186 | if(body!=null && body.indexOf(key)!=-1){ 187 | JSONObject bodyObj= JSONObject.parseObject(body); 188 | if(bodyObj.containsKey(key)){ 189 | bodyObj.put(key, "***"); 190 | } 191 | body = bodyObj.toJSONString(); 192 | bodyObj = null; 193 | } 194 | if(body!=null && body.indexOf(key2)!=-1){ 195 | JSONObject bodyObj= JSONObject.parseObject(body); 196 | if(bodyObj.containsKey(key2)){ 197 | bodyObj.put(key2, "***"); 198 | } 199 | body = bodyObj.toJSONString(); 200 | bodyObj = null; 201 | } 202 | log.info("{} {}",url,body); 203 | } 204 | try { 205 | CostTime cost = new CostTime(); 206 | cost.start(); 207 | bag = HttpClientUtil.execute(url,json); 208 | if(log.isWarnEnabled() && cost.cost()>300){ 209 | log.warn("{} costTime:{}", url,cost.cost()); 210 | } 211 | } catch (Exception e) { 212 | log.error("{},{},{}", url+json); 213 | } 214 | if(bag == null || bag._int != 200){ 215 | log.warn("{},{}", url, bag); 216 | return null; 217 | } 218 | String respBody = bag._str; 219 | JSONObject jsonObj = null ; 220 | try{ 221 | jsonObj = JSONObject.parseObject(respBody); 222 | }catch(Exception e){ 223 | log.error("url:{},parm:{}",url,json); 224 | log.error("resp:{}",respBody); 225 | } 226 | //if(log.isInfoEnabled()) 227 | // log.info("{} {}",url,jsonObj); 228 | return jsonObj; 229 | } 230 | 231 | public static String getStreamToString(InputStream resStream) throws IOException { 232 | BufferedReader br = new BufferedReader(new InputStreamReader(resStream)); 233 | StringBuffer resBuffer = new StringBuffer(); 234 | String resTemp = ""; 235 | while((resTemp = br.readLine()) != null){ 236 | resBuffer.append(resTemp); 237 | } 238 | String resp = resBuffer.toString(); 239 | br.close(); 240 | resStream.close(); 241 | return resp; 242 | } 243 | 244 | public static void main(String[] args) { 245 | StrIntBag resp = execute("http://10.10.10.201:9200/imggather/_search","{\"query\":\"时尚\"}"); 246 | System.out.println(resp._str); 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/RequestUtil.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.IOException; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | public class RequestUtil { 9 | 10 | public static String getRequestString(HttpServletRequest request) throws IOException{ 11 | String str=""; 12 | if(request.getInputStream().available()==0){ 13 | for(Object obj:request.getParameterMap().keySet()){ 14 | str += obj.toString(); 15 | } 16 | }else{ 17 | BufferedInputStream bis=new BufferedInputStream(request.getInputStream()); 18 | try{ 19 | byte read[] = new byte[200*1024]; 20 | while(( bis.read(read)) != -1 ){ 21 | str+=new String(read); 22 | } 23 | }finally{ 24 | //bis.close(); 25 | } 26 | } 27 | return str.trim(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/common/Share.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.common; 2 | import java.io.InputStream; 3 | import java.io.PrintWriter; 4 | import java.io.UnsupportedEncodingException; 5 | import java.lang.reflect.Field; 6 | import java.lang.reflect.Type; 7 | import java.net.URL; 8 | import java.net.URLDecoder; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.regex.Matcher; 13 | import java.util.regex.Pattern; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | import com.alibaba.fastjson.util.TypeUtils; 19 | 20 | public class Share { 21 | 22 | 23 | /** 24 | * 返回字符信息到客户端 ajax 使用 25 | * @param content 26 | * @param response 27 | */ 28 | public static void printWriter(Object content,HttpServletResponse response){ 29 | PrintWriter writer = null; 30 | try{ 31 | writer = response.getWriter(); 32 | writer.print(content); 33 | 34 | } 35 | catch(Exception e){ 36 | e.printStackTrace(); 37 | }finally{ 38 | if(writer!=null){ 39 | writer.flush(); 40 | writer.close(); 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * 返回字符信息到客户端 iframe使用 47 | * @param content 内容 48 | * @param function 父框架方法 49 | * @param response 50 | */ 51 | public static void printWriter(Object content,String function,HttpServletResponse response){ 52 | PrintWriter writer = null; 53 | try{ 54 | content = ""; 55 | writer = response.getWriter(); 56 | writer.print(content); 57 | 58 | } 59 | catch(Exception e){ 60 | e.printStackTrace(); 61 | }finally{ 62 | if(writer!=null){ 63 | writer.flush(); 64 | writer.close(); 65 | } 66 | } 67 | } 68 | 69 | /** 70 | * 封装请求参数 71 | * 72 | * @param request 73 | * @param c 74 | * 封装类 75 | * @return c对象 76 | * @return 77 | * @throws UnsupportedEncodingException 78 | */ 79 | public static Object requestBean(HttpServletRequest request, Class c) { 80 | Object o = null; 81 | try { 82 | o = c.newInstance(); 83 | Field[] fieldlist = c.getDeclaredFields(); 84 | for (int i = 0; i < fieldlist.length; i++) { 85 | Field field = fieldlist[i]; 86 | field.setAccessible(true); 87 | String value = request.getParameter(field.getName()); 88 | if (value != null && !value.equals("")) { 89 | try { 90 | try{ 91 | value = java.net.URLDecoder.decode(value, "UTF-8"); 92 | }catch (Exception e) { 93 | } 94 | value = value.replace("%26","&"); 95 | field.set(o, TypeUtils.castToJavaBean(value.trim(), field.getType())); 96 | } 97 | catch (Exception e) { 98 | e.printStackTrace(); 99 | } 100 | } 101 | } 102 | } 103 | catch (Exception e) { 104 | e.printStackTrace(); 105 | } 106 | return o; 107 | } 108 | 109 | /** 110 | * 封装请求参数 111 | * 112 | * @param request 113 | * @param c 114 | * 封装类 115 | * @param decode 116 | * 是否进行utf-8编码 117 | * @return c对象 118 | * @throws UnsupportedEncodingException 119 | */ 120 | public static Object requestBean(HttpServletRequest request, Class c, boolean decode) { 121 | Object o = null; 122 | try { 123 | o = c.newInstance(); 124 | Field[] fieldlist = c.getDeclaredFields(); 125 | for (int i = 0; i < fieldlist.length; i++) { 126 | Field field = fieldlist[i]; 127 | field.setAccessible(true); 128 | String value = request.getParameter(field.getName()); 129 | if (value != null && !value.equals("")) { 130 | try { 131 | if (decode) { 132 | try{ 133 | value = java.net.URLDecoder.decode(value, "UTF-8"); 134 | }catch (Exception e) { 135 | } 136 | } 137 | field.set(o, TypeUtils.castToJavaBean(value.trim(), field.getType())); 138 | } 139 | catch (Exception e) { 140 | e.printStackTrace(); 141 | } 142 | } 143 | } 144 | } 145 | catch (Exception e) { 146 | e.printStackTrace(); 147 | } 148 | return o; 149 | } 150 | 151 | /** 152 | * 反编码对象内的String属性 utf-8 153 | * 154 | * @param obj 155 | * @return 156 | */ 157 | public static Object ojbectDecoder(Object obj) { 158 | try { 159 | if (obj == null) { 160 | return null; 161 | } 162 | Field[] fields = obj.getClass().getDeclaredFields(); 163 | for (int i = 0; i < fields.length; i++) { 164 | Field field = fields[i]; 165 | field.setAccessible(true); 166 | Type type = field.getGenericType(); 167 | if (!type.equals(String.class)) 168 | continue; 169 | Object value = field.get(obj); 170 | if (value != null && !value.toString().equals("")) { 171 | field.set(obj, URLDecoder.decode(value.toString(), "UTF-8")); 172 | } 173 | } 174 | return obj; 175 | } 176 | catch (Exception e) { 177 | e.printStackTrace(); 178 | } 179 | return null; 180 | } 181 | 182 | /** 183 | * 取客户端IP地址,传说可取到通过代理的IP 184 | * @param request 185 | * @return 186 | */ 187 | public static String getIpAddr(HttpServletRequest request) { 188 | String ip = request.getHeader("x-forwarded-for"); 189 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 190 | ip = request.getHeader("Proxy-Client-IP"); 191 | } 192 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 193 | ip = request.getHeader("WL-Proxy-Client-IP"); 194 | } 195 | if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 196 | ip = request.getRemoteAddr(); 197 | } 198 | return ip; 199 | } 200 | 201 | /** 202 | * 取用户权限对象 203 | * @param request 204 | * @return 205 | */ 206 | public static List getAclObject(HttpServletRequest request){ 207 | List list = (List) request.getSession().getAttribute("aclObject"); 208 | return list; 209 | } 210 | 211 | public static boolean isNumeric(String str){ 212 | Pattern pattern = Pattern.compile("[0-9]*"); 213 | Matcher isNum = pattern.matcher(str); 214 | if( !isNum.matches() ){ 215 | return false; 216 | } 217 | return true; 218 | } 219 | 220 | /** 221 | * 取参数 222 | * @param request 223 | * @return 224 | */ 225 | public String getQueryString(HttpServletRequest request){ 226 | String str = request.getQueryString(); 227 | if(str==null) 228 | str=""; 229 | else 230 | str = "?"+str; 231 | return str; 232 | } 233 | 234 | public static String htmlFilter(String inputString) { 235 | if (inputString==null) return null; 236 | String htmlStr = inputString; // 含html标签的字符串 237 | String textStr = ""; 238 | java.util.regex.Pattern p_script; 239 | java.util.regex.Matcher m_script; 240 | java.util.regex.Pattern p_style; 241 | java.util.regex.Matcher m_style; 242 | java.util.regex.Pattern p_html; 243 | java.util.regex.Matcher m_html; 244 | try { 245 | String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; // 定义script的正则表达式{或"; 167 | script +="\n"; 169 | htmlstr +=script; 170 | 171 | htmlstr+="
\n"; 172 | if(StringUtils.isNotEmpty(series)){ 173 | htmlstr += ""; 174 | } 175 | htmlstr+=" server:\n"; 181 | htmlstr+=" from To \n"; 182 | htmlstr+=" \n"; 183 | htmlstr+=" auto load 1/min"; 184 | htmlstr+=" \n"; 188 | htmlstr+=" "; 189 | htmlstr+="
"; 190 | out.println(htmlstr); 191 | out.println(""); 192 | barSQL = "select type,status from "+table_name+" where 1=1 "+where+" group by status order by type,status desc"; 193 | String mapUrl = null; 194 | cost.start(); 195 | list = Dbop.getQueryList(barSQL); 196 | log.debug("sql:{} time:{}", barSQL,cost.cost()); 197 | for(int i=0;ii+1) 200 | map2 = list.get(i+1); 201 | mapUrl = request.getContextPath()+"/monitor/_report"; 202 | out.println(""); 220 | 221 | /** right td **/ 222 | if(list.size()>i+1) 223 | ; 224 | else 225 | continue; 226 | out.println(" "); 243 | } 244 | out.print("
"); 203 | //thread count 204 | if(DBType.equalsIgnoreCase("H2")){ 205 | barSQL = "select app_name,PARSEDATETIME( add_time,'yyyy-MM-d H:m') add_time,val from(select app_name,FORMATDATETIME(add_time,'yyyy-MM-d H:m') add_time,sum(val) val from "+table_name+" where 1=1 and status='"+map.get("STATUS")+"' "+where+" group by FORMATDATETIME(add_time,'yyyy-MM-d H:m'),app_name) a";//h2搞什么?函数不统一 206 | }else{ 207 | barSQL = "select app_name,str_to_date(add_time,'%Y-%m-%d %H:%i') add_time, val from(select app_name,date_format(add_time,'%Y-%m-%d %H:%i') add_time,sum(val) val from "+table_name+" where 1=1 and status='"+map.get("STATUS")+"' "+where+" group by date_format(add_time,'%Y-%m-%d %H:%i'),app_name) a"; 208 | } 209 | 210 | try { 211 | cost.start(); 212 | analysisfilename = ChartUtil.generateXYCurveLineChart(barSQL, pw,map.get("TYPE")+"-"+ map.get("STATUS"),null,null,true, mapUrl, true, width, height, "frame_"+i); 213 | log.debug("sql:{} time:{}", barSQL,cost.cost()); 214 | } catch (Exception e) { 215 | e.printStackTrace(); 216 | } 217 | analysisgraphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + analysisfilename; 218 | out.println(""); 219 | out.println(" "); 227 | 228 | if(DBType.equalsIgnoreCase("H2")){ 229 | barSQL = "select app_name,PARSEDATETIME( add_time,'yyyy-MM-d H:m') add_time,val from(select app_name,FORMATDATETIME(add_time,'yyyy-MM-d H:m') add_time,sum(val) val from "+table_name+" where 1=1 and status='"+map2.get("STATUS")+"' "+where+" group by FORMATDATETIME(add_time,'yyyy-MM-d H:m'),app_name) a";//h2写法 230 | }else{ 231 | barSQL = "select app_name,str_to_date(add_time,'%Y-%m-%d %H:%i') add_time, val from(select app_name,date_format(add_time,'%Y-%m-%d %H:%i') add_time,sum(val) val from "+table_name+" where 1=1 and status='"+map2.get("status")+"' "+where+" group by date_format(add_time,'%Y-%m-%d %H:%i'),app_name) a"; 232 | } 233 | try { 234 | cost.start(); 235 | analysisfilename = ChartUtil.generateXYCurveLineChart(barSQL, pw,map2.get("TYPE")+"-"+ map2.get("STATUS"),null,null,true, mapUrl, true, width, height,"frame_"+i); 236 | log.debug("sql:{} time:{}", barSQL,cost.cost()); 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | } 240 | analysisgraphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + analysisfilename; 241 | out.println(""); 242 | out.println("
"); 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /src/main/java/org/langke/jetty/servlet/TestServlet.java: -------------------------------------------------------------------------------- 1 | package org.langke.jetty.servlet; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.langke.jetty.common.CostTime; 11 | import org.langke.jetty.resp.Response; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.alibaba.fastjson.JSONObject; 16 | import com.alibaba.fastjson.serializer.SerializerFeature; 17 | 18 | public class TestServlet extends HttpServlet{ 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = -6491268125454178487L; 24 | private static final Logger log = LoggerFactory.getLogger(TestServlet.class); 25 | /** 26 | * @see HttpServlet#HttpServlet() 27 | */ 28 | public TestServlet() { 29 | super(); 30 | } 31 | 32 | @Override 33 | public void init() throws ServletException { 34 | super.init(); 35 | } 36 | @Override 37 | public void destroy() { 38 | super.destroy(); 39 | } 40 | /** 41 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 42 | */ 43 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 44 | doPost(request, response); 45 | } 46 | 47 | /** 48 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 49 | */ 50 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 51 | response.setCharacterEncoding("utf-8"); 52 | response.setContentType("application/json"); 53 | CostTime cost = new CostTime(); 54 | cost.start(); 55 | String method = request.getRequestURI(); 56 | Response resp = new Response(); 57 | Object result = request.getParameterMap(); 58 | log.debug("request:{} {}",method,request); 59 | resp.setResult(result); 60 | resp.setCostTime(cost.cost()); 61 | response.getWriter().print(JSONObject.toJSONString(resp, SerializerFeature.PrettyFormat)); 62 | // log.info("{} {}", method,cost.cost()); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log.dir=logs 2 | log.file=app_monitor.log 3 | 4 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 5 | log4j.appender.CONSOLE.Target=System.out 6 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c{2}(%L) %m%n 8 | 9 | log4j.rootLogger=INFO,CONSOLE,DRFA 10 | 11 | # Custom Logging levels 12 | 13 | log4j.logger.org.langke=DEBUG 14 | log4j.logger.java.sql.Connection=DEBUG 15 | log4j.logger.java.sql.Statement=DEBUG 16 | log4j.logger.java.sql.PreparedStatement=DEBUG 17 | log4j.logger.org.springframework.jdbc.core=DEBUG 18 | 19 | # Logging Threshold 20 | log4j.threshhold=ALL 21 | 22 | # 23 | # Daily Rolling File Appender 24 | # 25 | log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender 26 | log4j.appender.DRFA.File=${log.dir}/${log.file} 27 | 28 | # Rollver at midnight 29 | log4j.appender.DRFA.DatePattern=.yyyy-MM-dd 30 | 31 | # 30-day backup 32 | #log4j.appender.DRFA.MaxBackupIndex=30 33 | log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout 34 | 35 | # Pattern format: Date LogLevel LoggerName LogMessage 36 | log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n 37 | -------------------------------------------------------------------------------- /src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/dispatcher-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | text/html;charset=UTF-8 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | app monitor 7 | 8 | contextConfigLocation 9 | 10 | classpath:applicationContext.xml 11 | 12 | 13 | 14 | 15 | org.springframework.web.context.ContextLoaderListener 16 | 17 | 18 | net.bull.javamelody.SessionListener 19 | 20 | 21 | 22 | encodingFilter 23 | org.springframework.web.filter.CharacterEncodingFilter 24 | 25 | encoding 26 | utf-8 27 | 28 | 29 | 30 | logFilter 31 | org.langke.jetty.servlet.LogFilter 32 | 33 | 34 | monitorFilter 35 | net.bull.javamelody.MonitoringFilter 36 | 37 | 38 | 39 | encodingFilter 40 | /* 41 | 42 | 43 | logFilter 44 | /* 45 | 46 | 47 | monitorFilter 48 | /monitoring 49 | 50 | 51 | 52 | dispatcher 53 | 54 | org.springframework.web.servlet.DispatcherServlet 55 | 56 | 1 57 | 58 | 59 | dispatcher 60 | *.do 61 | 62 | 63 | 64 | monitorHandler 65 | org.langke.jetty.servlet.MonitorHandler 66 | 67 | 68 | monitorHandler 69 | /monitor/* 70 | 71 | 72 | 73 | DisplayChart 74 | org.jfree.chart.servlet.DisplayChart 75 | 76 | 77 | DisplayChart 78 | /servlet/DisplayChart 79 | 80 | 81 | test 82 | org.langke.jetty.servlet.TestServlet 83 | 84 | 85 | test 86 | /servlet/test 87 | 88 | 89 | index.html 90 | index.htm 91 | index.jsp 92 | default.html 93 | default.htm 94 | default.jsp 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/main/webapp/css/base.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/css/base.css -------------------------------------------------------------------------------- /src/main/webapp/css/component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/css/component.css -------------------------------------------------------------------------------- /src/main/webapp/css/frame.css: -------------------------------------------------------------------------------- 1 | @charset "gb2312"; 2 | * { margin:0; padding:0; } 3 | html { width:100%; height:100%; overflow:hidden; } 4 | body { text-align:left; font:12px/20px simsun; cursor:default; } 5 | ul { list-style:none; } 6 | a { color:#4C4C4C; } 7 | img { border:none; } 8 | .v_m{ vertical-align: middle;} 9 | /**/ 10 | .c_yellow { color:#FFF600; } 11 | /**/ 12 | .hd { height:55px; background:#58B1E9; overflow:hidden; position:relative; border-bottom:1px solid #fff; color:#fff; } 13 | .side { background:#fff; height:100%; overflow:auto; zoom:1; } 14 | .fbtn { background:url(../img/frame_btn.gif) repeat-y; width:8px; position:relative; height:100%; } 15 | /**/ 16 | .logo { position:absolute; top:20px; left:15px; font:20px/20px Verdana; } 17 | /**/ 18 | .nav { position:absolute; top:31px; left:180px; right:0; zoom:1; overflow:hidden; height:25px; } 19 | .nav li { float:left; overflow:hidden; width:72px; height:25px; text-align:center; margin-right:2px; } 20 | .nav li a { text-decoration:none; display:block; white-space:nowrap; background:url(../img/frame.gif) no-repeat 0 -32px; margin-top:1px; line-height:23px; width:72px; height:23px; padding-top:1px; } 21 | .nav li.selected a, .nav li a:hover { margin-top:0; background-position:0 0; padding-top:2px; color:#1C8DBE; font-weight:bold; } 22 | /**/ 23 | .user { position:absolute; white-space:nowrap; position:absolute; top:5px; right:10px; } 24 | /**/ 25 | .menu_box { text-align:center; border:1px solid #B5D6E4; padding:1px; margin:0px; } 26 | .menu_box h2 { background:url(../img/frame.gif) repeat-x 0 -64px; line-height:25px; font-size:12px; margin-bottom:1px; cursor: pointer;} 27 | .menu_box h2, .menu_box h2 a { display:block; height:25px; text-decoration:none; color:#fff; } 28 | .menu_box ul { margin-bottom:-1px; } 29 | .menu_box li { background:#EEF7FB; line-height:24px; margin-bottom:1px; } 30 | .menu_box li, .menu_box li a { display:block; zoom:1; color:#1C8DBE; text-decoration:none; } 31 | .menu_box li.selected, .menu_box li.selected a, .menu_box li a:hover { color:#4C4C4C; font-weight:bold; } 32 | /**/ 33 | .fbtn a.open, .fbtn a.close { background:url(../img/frame_btn.gif); display:block; width:8px; height:50px; position:absolute; left:0; top:50%; margin:-25px 0; overflow:hidden; text-indent:-1000px; } 34 | .fbtn a.open { background-position:-16px 0; } 35 | .fbtn a.close { background-position:-8px 0; } 36 | -------------------------------------------------------------------------------- /src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /src/main/webapp/fbtn.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=utf-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | %> 5 | 6 | 7 | 8 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/webapp/head.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=utf-8"%> 2 | <%@page import="java.util.*"%> 3 | <% 4 | String path = request.getContextPath(); 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/webapp/img/btn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/img/btn.gif -------------------------------------------------------------------------------- /src/main/webapp/img/frame.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/img/frame.gif -------------------------------------------------------------------------------- /src/main/webapp/img/frame_btn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langke93/app_monitor/e45e2c313b9d41ffa24f973f77460be9f2c733c1/src/main/webapp/img/frame_btn.gif -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=utf-8"%> 2 | <%@page import="java.util.*"%> 3 | <% 4 | String path = request.getContextPath(); 5 | %> 6 | 7 | <%=org.langke.jetty.common.Config.get().get("jsp.title") %> 8 | 9 | 10 | 11 | 12 | 13 | 14 | <body> 15 | 16 | </body> 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/webapp/js/DatePicker/My97DatePicker.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | My97DatePicker 5 | 6 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/webapp/js/DatePicker/WdatePicker.js: -------------------------------------------------------------------------------- 1 | /* 2 | * My97 DatePicker 4.6 Beta4 3 | * SITE: http://dp.my97.net 4 | * BLOG: http://my97.cnblogs.com 5 | * MAIL: smallcarrot@163.com 6 | */ 7 | var $dp,WdatePicker;(function(){var _={ 8 | $wdate:true, 9 | $dpPath:"", 10 | $crossFrame:true, 11 | doubleCalendar:false, 12 | position:{}, 13 | lang:"auto", 14 | skin:"default", 15 | dateFmt:"yyyy-MM-dd", 16 | realDateFmt:"yyyy-MM-dd", 17 | realTimeFmt:"HH:mm:ss", 18 | realFullFmt:"%Date %Time", 19 | minDate:"1900-01-01 00:00:00", 20 | maxDate:"2099-12-31 23:59:59", 21 | startDate:"", 22 | alwaysUseStartDate:false, 23 | yearOffset:1911, 24 | firstDayOfWeek:0, 25 | isShowWeek:false, 26 | highLineWeekDay:true, 27 | isShowClear:true, 28 | isShowToday:true, 29 | isShowOthers:true, 30 | readOnly:false, 31 | errDealMode:0, 32 | autoPickDate:null, 33 | qsEnabled:true, 34 | 35 | specialDates:null,specialDays:null,disabledDates:null,disabledDays:null,opposite:false,onpicking:null,onpicked:null,onclearing:null,oncleared:null,ychanging:null,ychanged:null,Mchanging:null,Mchanged:null,dchanging:null,dchanged:null,Hchanging:null,Hchanged:null,mchanging:null,mchanged:null,schanging:null,schanged:null,eCont:null,vel:null,errMsg:"",quickSel:[],has:{}};WdatePicker=U;var X=window,O="document",J="documentElement",C="getElementsByTagName",V,A,T,I,b;switch(navigator.appName){case"Microsoft Internet Explorer":T=true;break;case"Opera":b=true;break;default:I=true;break}A=L();if(_.$wdate)M(A+"skin/WdatePicker.css");V=X;if(_.$crossFrame){try{while(V.parent[O]!=V[O]&&V.parent[O][C]("frameset").length==0)V=V.parent}catch(P){}}if(!V.$dp)V.$dp={ff:I,ie:T,opera:b,el:null,win:X,status:0,defMinDate:_.minDate,defMaxDate:_.maxDate,flatCfgs:[]};B();if($dp.status==0)Z(X,function(){U(null,true)});if(!X[O].docMD){E(X[O],"onmousedown",D);X[O].docMD=true}if(!V[O].docMD){E(V[O],"onmousedown",D);V[O].docMD=true}E(X,"onunload",function(){if($dp.dd)Q($dp.dd,"none")});function B(){V.$dp=V.$dp||{};obj={$:function($){return(typeof $=="string")?this.win[O].getElementById($):$},$D:function($,_){return this.$DV(this.$($).value,_)},$DV:function(_,$){if(_!=""){this.dt=$dp.cal.splitDate(_,$dp.cal.dateFmt);if($)for(var A in $){if(this.dt[A]===undefined)this.errMsg="invalid property:"+A;this.dt[A]+=$[A]}if(this.dt.refresh())return this.dt}return""},show:function(){Q(this.dd,"block")},hide:function(){Q(this.dd,"none")},attachEvent:E};for(var $ in obj)V.$dp[$]=obj[$];$dp=V.$dp}function E(A,$,_){if(T)A.attachEvent($,_);else{var B=$.replace(/on/,"");_._ieEmuEventHandler=function($){return _($)};A.addEventListener(B,_._ieEmuEventHandler,false)}}function L(){var _,A,$=X[O][C]("script");for(var B=0;B<$.length;B++){_=$[B].src.substring(0,$[B].src.toLowerCase().indexOf("wdatepicker.js"));A=_.lastIndexOf("/");if(A>0)_=_.substring(0,A+1);if(_)break}return _}function F(F){var E,C;if(F.substring(0,1)!="/"&&F.indexOf("://")==-1){E=V.location.href;C=location.href;if(E.indexOf("?")>-1)E=E.substring(0,E.indexOf("?"));if(C.indexOf("?")>-1)C=C.substring(0,C.indexOf("?"));var G,I,$="",D="",A="",J,H,B="";for(J=0;J_.scrollLeft||A.scrollLeft>_.scrollLeft))?A:_;return{"top":B.scrollTop,"left":B.scrollLeft}}function D($){src=$?($.srcElement||$.target):null;if($dp&&$dp.cal&&!$dp.eCont&&$dp.dd&&Q($dp.dd)=="block"&&src!=$dp.el)$dp.cal.close()}function Y(){$dp.status=2;H()}function H(){if($dp.flatCfgs.length>0){var $=$dp.flatCfgs.shift();$.el={innerHTML:""};$.autoPickDate=true;$.qsEnabled=false;K($)}}var R,$;function U(E,_){$dp.win=X;B();E=E||{};if(_){if(!D()){$=$||setInterval(function(){if(V[O].readyState=="complete")clearInterval($);U(null,true)},50);return}if($dp.status==0){$dp.status=1;K({el:{innerHTML:""}},true)}else return}else if(E.eCont){E.eCont=$dp.$(E.eCont);$dp.flatCfgs.push(E);if($dp.status==2)H()}else{if($dp.status==0){U(null,true);return}if($dp.status!=2)return;var C=A();if(C){$dp.srcEl=C.srcElement||C.target;C.cancelBubble=true}E.el=$dp.$(E.el||$dp.srcEl);if(!E.el||E.el.disabled||(E.el==$dp.el&&Q($dp.dd)!="none"&&$dp.dd.style.left!="-1970px"))return;K(E)}function D(){if(T&&V!=X&&V[O].readyState!="complete")return false;return true}function A(){if(I){func=A.caller;while(func!=null){var $=func.arguments[0];if($&&($+"").indexOf("Event")>=0)return $;func=func.caller}return null}return event}}function S(_,$){return _.currentStyle?_.currentStyle[$]:document.defaultView.getComputedStyle(_,false)[$]}function Q(_,$){if(_)if($!=null)_.style.display=$;else return S(_,"display")}function K(H,$){for(var D in _)if(D.substring(0,1)!="$")$dp[D]=_[D];for(D in H)if($dp[D]===undefined)$dp.errMsg="invalid property:"+D;else $dp[D]=H[D];var E=$dp.el?$dp.el.nodeName:"INPUT";if($||$dp.eCont||new RegExp(/input|textarea|div|span|p|a/ig).test(E))$dp.elProp=E=="INPUT"?"value":"innerHTML";else return;if($dp.lang=="auto")$dp.lang=T?navigator.browserLanguage.toLowerCase():navigator.language.toLowerCase();if(!$dp.dd||$dp.eCont||($dp.lang&&$dp.realLang&&$dp.realLang.name!=$dp.lang&&$dp.getLangIndex&&$dp.getLangIndex($dp.lang)>=0)){if($dp.dd&&!$dp.eCont)V[O].body.removeChild($dp.dd);if(_.$dpPath=="")F(A);var B="";if($dp.eCont){$dp.eCont.innerHTML=B;Z($dp.eCont.childNodes[0],Y)}else{$dp.dd=V[O].createElement("DIV");$dp.dd.style.cssText="position:absolute;z-index:19700";$dp.dd.innerHTML=B;V[O].body.insertBefore($dp.dd,V[O].body.firstChild);Z($dp.dd.childNodes[0],Y);if($)$dp.dd.style.left=$dp.dd.style.top="-1970px";else{$dp.show();C()}}}else if($dp.cal){$dp.show();$dp.cal.init();if(!$dp.eCont)C()}function C(){var F=$dp.position.left,B=$dp.position.top,C=$dp.el;if(C!=$dp.srcEl&&(Q(C)=="none"||C.type=="hidden"))C=$dp.srcEl;var H=W(C),$=G(X),D=N(V),A=a(V),E=$dp.dd.offsetHeight,_=$dp.dd.offsetWidth;if(isNaN(B)){if(B=="above"||(B!="under"&&(($.topM+H.bottom+E>D.height)&&($.topM+H.top-E>0))))B=A.top+$.topM+H.top-E-3;else B=A.top+$.topM+H.bottom;B+=T?-1:1}else B+=A.top+$.topM;if(isNaN(F))F=A.left+Math.min($.leftM+H.left,D.width-_-5)-(T?2:0);else F+=A.left+$.leftM;$dp.dd.style.top=B+"px";$dp.dd.style.left=F+"px"}}})() -------------------------------------------------------------------------------- /src/main/webapp/js/DatePicker/calendar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * My97 DatePicker 4.6 Beta4 3 | * SITE: http://dp.my97.net 4 | * BLOG: http://my97.cnblogs.com 5 | * MAIL: smallcarrot@163.com 6 | */ 7 | eval(function(B,D,A,G,E,F){function C(A){return A<62?String.fromCharCode(A+=A<26?65:A<52?71:-4):A<63?'_':A<64?'$':C(A>>6)+C(A&63)}while(A>0)E[C(G--)]=D[--A];return B.replace(/[\w\$]+/g,function(A){return E[A]==F[A]?A:E[A]})}('l g;d(FG){E6.DJ.__defineSetter__("C8",_(b){d(!b){q.Bl();}5 b;});E6.DJ.__defineGetter__("FC",_(){l b=q.Fx;CK(b.FM!=U){b=b.parentNode;}5 b;});HTMLElement.DJ.Cq=_(a,A){l b=a.7(/Er/,"");A.Ec=_(b){Fs.BI=b;5 A();};q.addEventListener(b,A.Ec,z);};}_ EM(){g=q;q.CW=[];c=CS.createElement("m");c.$="EA";c.BP=\'<4 B5=T Bz=T Bx=T>&Dj;\';EI(c,_(){Co();});a();q.FV();b();D7("S,K,H,P,R");c.EL.9=_(){D6(U);};c.Ek.9=_(){D6(-U);};c.EC.9=_(){d(c.BV.3.De!="Fm"){g.D0();C3(c.BV);}r{t(c.BV);}};EI(c.Cj,_(){d(j.Bi.3.De!="E5"){c.BO.EB();}BI.C8=z;});CS.body.EK(c);_ a(){l a=b("L");x=b("m"),BS=b("BH"),D$=b("BX"),FH=b("Dg");c.DM=a[T];c.Cg=a[U];c.DN=a[W];c.Cw=a[V];c.C0=x[Z];c.BO=BS[T];c.BG=BS[U];c.Dn=x[T];c.Cp=x[BA];c.CN=x[BJ];c.BV=x[B4];c.CT=x[Dx];c.EJ=x[B3];c.EW=x[13];c.E_=x[14];c.Fc=x[Dw];c.EC=x[16];c.Ee=x[17];c.Cz=BS[V];c.Dr=BS[BA];c.D4=BS[BJ];c.Cs=BS[Y];c.By=BS[Ce];c.Cj=BS[Z];c.EL=D$[T];c.Ek=D$[U];c.Fh=FH[T];_ b(b){5 c.DW(b);}}_ b(){c.DM.9=_(){BN=BN<=T?BN-U:-U;d(BN%X==T){c.BG.EB();5;}c.BG.2=k.S-U;c.BG.CD();};c.Cg.9=_(){k.w("K",-U);c.BO.CD();};c.DN.9=_(){k.w("K",U);c.BO.CD();};c.Cw.9=_(){BN=BN>=T?BN+U:U;d(BN%X==T){c.BG.EB();5;}c.BG.2=k.S+U;c.BG.CD();};}}EM.DJ={FV:_(){BN=T;j.DE=q;d(j.Ci&&j.f.Ci!=v){j.f.Ci=s;j.f.Ds();}b();q.Bg=j.Bg;q.E4();q.CE=j.CE==v?(j.n.BZ&&j.n.BZ?z:s):j.CE;k=q.newdate=o Bn();BF=o Bn();Bw=q.CR=o Bn();q.FI=q.Ca("disabledDates");q.FB=q.Ca("disabledDays");q.E1=q.Ca("specialDates");q.FW=q.Ca("specialDays");q.BW=q.Cx(j.BW,j.BW!=j.Ei?j.Be:j.CL,j.Ei);q.Ba=q.Cx(j.Ba,j.Ba!=j.Ft?j.Be:j.CL,j.Ft);d(q.BW.Br(q.Ba)>T){j.D2=1.err_1;}d(q.Bh()){q.Eh();q.B$=j.f[j.BE];}r{q.Bf(z,V);}i("S");i("K");i("M");i("H");i("P");i("R");c.Fh.BP=1.timeStr;c.Cs.2=1.clearStr;c.By.2=1.todayStr;c.Cj.2=1.okStr;q.EV();q.Ev();d(j.D2){alert(j.D2);}q.D9();Co();d(j.f.FM==U){j.Cq(j.f,"EE",_(b){d(j.f==(b.FC||b.Fx)){EZ=(b.Bu==CX)?b.D5:b.Bu;d(EZ==Z){d(!j.DE.Dt()){b.Bl?b.Bl():b.C8=z;j.DE.Bf(z,V);j.Bq();}r{j.DE.Bf(s);j.t();}}}});}_ b(){l a,b;p(a=T;(b=CS.DW("link")[a]);a++){d(w(b,"rel").BL("3")!=-U&&w(b,"Fn")){b.Bv=s;d(w(b,"Fn")==j.skin){b.Bv=z;}}}}},Eh:_(){l A=q.Cd(),b=s;d(A!=T){b=z;l a;d(A>T){a=q.Ba;}r{a=q.BW;}d(j.n.DA){k.S=a.S;k.K=a.K;k.M=a.M;}d(j.n.BZ){k.H=a.H;k.P=a.P;k.R=a.R;}}5 b;},Cl:_(K,F,EU,a,D,B,A,ET,G){l E;d(K&&K.Bh){E=K;}r{E=o Bn();d(K!=""){F=F||j.Bg;l J,DX=T,I,C=/Ct|Cc|DQ|S|B8|CQ|Cr|K|Bi|M|E2|H|Ez|P|FS|R|B_|D|Dy|CA|Ch/Bk,CB=F.EH(C);C.C7=T;d(G){I=K.Du(/\\CA+/);}r{l b=T,H="^";CK((I=C.DC(F))!==v){d(b>T){H+=F.CM(b,I.C_);}b=I.C_-b;b=C.C7;CY(I[T]){u"Ct":H+="(\\\\M{BA})";0;u"Cc":H+="(\\\\M{W})";0;Fr:d(o DS("B8|CQ|B_|D|Dy|CA|Ch").D8(I[T])){H+="(\\\\D+)";}r{H+="(\\\\M\\\\M?)";}0;}}H+=".*b";I=o DS(H).DC(K);DX=U;}d(I){p(J=T;J=T){b=b.7(/%E9/Bk,"T");a.M=T;a.K=DB(a.K)+U;}a.CI();}5 a;},Bh:_(){l A,a;d(j.alwaysUseStartDate||(j.ER!=""&&j.f[j.BE]=="")){A=q.C2(j.ER);a=j.Be;}r{A=j.f[j.BE];a=q.Bg;}k.DG(q.Cl(A,a));d(A!=""){l b=U;d(j.n.DA&&!q.DO(k)){k.S=BF.S;k.K=BF.K;k.M=BF.M;b=T;}d(j.n.BZ&&!q.Db(k)){k.H=BF.H;k.P=BF.P;k.R=BF.R;b=T;}5 b&&q.BQ(k);}5 U;},DO:_(b){d(b.S!=v){b=CH(b.S,BA)+"-"+b.K+"-"+b.M;}5 b.EH(/^((\\M{V}(([El][048])|([Ew][26]))[\\-\\/\\R]?((((T?[Ey])|(U[FO]))[\\-\\/\\R]?((T?[U-Z])|([U-V][T-Z])|(W[FN])))|(((T?[En])|(Dx))[\\-\\/\\R]?((T?[U-Z])|([U-V][T-Z])|(CP)))|(T?V[\\-\\/\\R]?((T?[U-Z])|([U-V][T-Z])))))|(\\M{V}(([El][1235679])|([Ew][01345789]))[\\-\\/\\R]?((((T?[Ey])|(U[FO]))[\\-\\/\\R]?((T?[U-Z])|([U-V][T-Z])|(W[FN])))|(((T?[En])|(Dx))[\\-\\/\\R]?((T?[U-Z])|([U-V][T-Z])|(CP)))|(T?V[\\-\\/\\R]?((T?[U-Z])|(U[T-Z])|(V[T-Ce]))))))(\\R(((T?[T-Z])|([U-V][T-W]))\\:([T-X]?[T-Z])((\\R)|(\\:([T-X]?[T-Z])))))?b/);},Db:_(b){d(b.H!=v){b=b.H+":"+b.P+":"+b.R;}5 b.EH(/^([T-Z]|([T-U][T-Z])|([V][T-W])):([T-Z]|([T-X][T-Z])):([T-Z]|([T-X][T-Z]))b/);},Cd:_(b,a){a=a||k;l A=a.Br(q.BW,b);d(A>T){A=a.Br(q.Ba,b);d(AU){C-=Y;}G.L("<4 y=Fl C$=ED% Bx=T B5=T Bz=T>");G.L("");d(j.FT){G.L(""+A[T]+"");}p(a=T;a"+A[(B+a)%Y+U]+"");}G.L("");p(a=U,F=C;a");p(b=T;b"+Dk(J,U)+"");}G.L(""+J.M+"");}r{G.L(">");}}G.L("");}G.L("");5 G.O();},FR:_(b){5 q.Dq(b,q.FI);},Et:_(b){5 q.Dp(b,q.FB);},Fi:_(b){5 q.Dq(b,q.E1,U);},FK:_(b){5 q.Dp(b,q.FW,U);},Dq:_(A,b){l a=b&&b.D8(q.C4(j.Be,A));5 a;},Dp:_(b,A){l a=A&&A.D8(b);5 a;},CZ:_(Q,BC,Da,EX,Bp){l R=o B6(),DU=Bp?"Da"+Q:Q;Es=k[Q];R.L("<4 B5=T Bz=W Bx=T");p(l N=T;N\');p(l O=T;O"+(Q=="K"?1.Bt[k[Q]-U]:k[Q])+"");}R.L("");}R.L("");k[Q]=Es;5 R.O();},DT:_(a,A){d(a){l b=a.offsetLeft;d(EY){b=a.getBoundingClientRect().CC;}A.3.CC=b;}},_fM:_(b){q.DT(b,c.Cp);c.Cp.BP=q.CZ("K",V,BJ,"N+O*BJ+U",b==c.Bm);},Dc:_(A,b){l a=o B6();b=BR(b,k.S-X);a.L(q.CZ("S",V,X,b+"+N+O*X",A==c.B1));a.L("<4 B5=T Bz=W Bx=T Dd=D_>\\u2190\\E7b+B4?"y=\'BD\' B7=\\"q.$=\'CV\'\\" Bs=\\"q.$=\'BD\'\\" Cu=\'d(BI.Bl)BI.Bl();BI.EO=s;g.Dc(T,"+(b+B4)+")\'":"y=\'Dm\'");a.L(">\\u2192");q.DT(A,c.CN);c.CN.BP=a.O();},DL:_(b,A,a){c[b+"D"].BP=q.CZ(b,BJ,A,a);},_fH:_(){q.DL("H",BA,"N * BJ + O");},_fm:_(){q.DL("P",V,"N * CP + O * X");},_fs:_(){q.DL("R",U,"O * B4");},D0:_(b){q.Fg();l C=q.CW,B=C.3,A=o B6();A.L(\'<4 y=Fl C$="\'+c.CT.FD+\'DH" Eg="\'+c.CT.Ea+\'DH" Bx=T B5=T Bz=T>\');A.L(\'\'+1.quickStr+"");d(!b){A.L(\'\\E7\');}A.L("");p(l a=T;a\');A.L("&Dj;"+q.C4(v,C[a]));A.L("");}r{A.L("&Dj;");}}A.L("");c.BV.BP=A.O();},E4:_(){b(/Ch/);b(/Dy|CA/);b(/B_|D/);b(/Ct|Cc|DQ|S/);b(/B8|CQ|Cr|K/);b(/Bi|M/);b(/E2|H/);b(/Ez|P/);b(/FS|R/);j.n.DA=(j.n.S||j.n.K||j.n.M)?s:z;j.n.BZ=(j.n.H||j.n.P||j.n.R)?s:z;j.CL=j.CL.7(/%BU/,j.Fu).7(/%Time/,j.Fa);d(j.n.DA){d(j.n.BZ){j.Be=j.CL;}r{j.Be=j.Fu;}}r{j.Be=j.Fa;}_ b(a){l b=(a+"").Dz(U,V);j.n[b]=a.DC(j.Bg)?(j.n.DV=b,s):z;}},EV:_(){l b=T;j.n.S?(b=U,Bq(c.BG,c.DM,c.Cw)):t(c.BG,c.DM,c.Cw);j.n.K?(b=U,Bq(c.BO,c.Cg,c.DN)):t(c.BO,c.Cg,c.DN);b?Bq(c.Dn):t(c.Dn);d(j.n.BZ){Bq(c.EJ);DF(c.Cz,j.n.H);DF(c.Dr,j.n.P);DF(c.D4,j.n.R);}r{t(c.EJ);}Cy(c.Cs,j.isShowClear);Cy(c.By,j.isShowToday);Cy(c.EC,(j.n.M&&j.qsEnabled));d(j.FZ){t(c.Ee);}},Bf:_(B,b){l a=j.f,D=FG?"y":"$";d(B){C(a);}r{d(b==v){b=j.errDealMode;}CY(b){u T:d(confirm(1.errAlertMsg)){a[j.BE]=q.B$;C(a);}r{A(a);}0;u U:a[j.BE]=q.B$;C(a);0;u V:A(a);0;}}_ C(b){l A=b.$;d(A){l a=A.7(/Fj/Bk,"");d(A!=a){w(b,D,a);}}}_ A(b){w(b,D,b.$+" Fj");}},BY:_(F,G,E){E=E||Bw;l B,D=[F+F,F],b,C=E[F],a=_(b){5 CH(C,b.6);};CY(F.B0(T)){u"Ch":C=Bc(E);0;u"D":l A=Bc(E)+U;a=_(b){5 b.6==V?1.aLongWeekStr[A]:1.Fp[A];};0;u"CA":C=Dk(E);0;u"S":D=["Ct","Cc","DQ","S"];a=_(b){5 CH((b.6=T){G=G.7(b,a(b));}}5 G;},C4:_(C,A){A=A||Bw;C=C||q.Bg;l b="ydHmswW";p(l B=T;B");b.L(q.Cn());b.L("");k.w("K",U);b.L(q.Cn());c.Bm=c.BO.FA(s);c.B1=c.BG.FA(s);c.C0.EK(c.Bm);c.C0.EK(c.B1);c.Bm.2=1.Bt[k.K-U];w(c.Bm,"DK",k.K);c.B1.2=k.S;D7("Ff,FX");c.Bm.$=c.B1.$="Cb";k.w("K",-U);b.L("");c.CT.BP=b.O();}r{c.$="EA";c.CT.BP=q.Cn();}d(!j.n.M){q.D0(s);C3(c.BV);}r{t(c.BV);}q.E3();},E3:_(){l b=parent.CS.DW("iframe");p(l a=T;aT){k.M--;}q.Dh();d(!j.FZ){d(q.BQ(k)){g.Bf(s);t(j.Bi);}r{g.Bf(z);}}d(j.ES){Bj("ES");}r{d(q.B$!=j.f[j.BE]&&j.f.Fv){C6(j.f,"Ef");}}},Ev:_(){c.Cs.9=_(){d(!Bj("onclearing")){j.f[j.BE]="";g.Cv("");t(j.Bi);d(j.Fk){Bj("Fk");}r{d(g.B$!=j.f[j.BE]&&j.f.Fv){C6(j.f,"Ef");}}}};c.Cj.9=_(){CG();};d(q.BQ(BF)){c.By.Bv=z;c.By.9=_(){k.DG(BF);CG();};}r{c.By.Bv=s;}},Fg:_(){l H,B,C,A,F=[],E=X,a=j.E8.6,G=j.n.DV;d(a>E){a=E;}r{d(G=="P"||G=="R"){F=[T,Dw,CP,Fe,FY,-60,-Fe,-CP,-Dw,-U];}r{p(H=T;H=T){BT=Ck(BT,T,FY);}}}d(Bw[Q]!=BT&&!Bj(Q+"changing")){l Fq=\'i("\'+Q+\'",\'+BT+")",DD=g.Cd();d(DD==T){CO(Fq);}r{d(DDT){Dl(g.Ba);}}}d(!FP&&"yMd".BL(Q)>=T){g.D9();}Bj(Q+"changed");}_ Dl(b){i("S",b.S);i("K",b.K);i("M",b.M);d(j.n.BZ){i("H",b.H);i("P",b.P);i("R",b.R);}}}_ CG(H,E,G,a,b,C){l F=k.S,D=k.K,B=k.M;k.S=H||F;k.K=E||D;k.M=G||B;d(!Bj("onpicking")){l A=F==H&&D==E&&B==G;d(!A&&CU.6!=T){BC("S",H,s);BC("K",E,s);BC("M",G);}d(g.CE||A||CU.6==T){g.EQ();}}r{k.S=F;k.K=D;k.M=B;}}_ Bj(b){l a;d(j[b]){a=j[b].call(j.f,j);}5 a;}_ i(a,b){b=b||k[a];Bw[a]=k[a]=b;d("yHms".BL(a)>=T){c[a+"BK"].2=b;}d(a=="K"){w(c.BO,"DK",b);c.BO.2=1.Bt[b-U];}}_ w(b,A,a){d(a===CX){5 b.getAttribute(A);}r{d(b.FJ){b.FJ(A,a);}}}_ Ck(A,a,b){d(Ab){A=b;}}5 A;}_ EI(b,a){b.Cq("EE",_(){l A=BI,b=(A.Bu==CX)?A.D5:A.Bu;d(b==Z){a();}});}_ CH(b,a){b=b+"";CK(b.6=T?C:X;p(l b=T;b<=C;b++){A=a.B0(b);D=q[A]-B[A];d(D>T){5 U;}r{d(D=T){l b=q.M;q.M=U;q[A]+=a;q.CI();q.M=b;}};q.Bh(b,a,B,C,A,D);}_ DB(b){5 parseInt(b,B4);}_ 8(a,b){a=DB(a);d(FL(a)){a=b;}5 a;}_ BR(b,a){5 b==v?a:b;}_ C6(b,a){d(EY){b.C6("Er"+a);}r{l A=CS.createEvent("HTMLEvents");A.initEvent(a,s,s);b.dispatchEvent(A);}}_ EF(A){l b,a,B="S,K,H,P,R,FX,Ff".Du(",");p(a=T;a=48&&a<=57)||(a>=96&&a<=105)||a==Ce||a==46||a==37||a==39||a==Z)){b.C8=z;}}_ D7(A){l b=A.Du(",");p(l a=T;aminVersion[0]||(flashDetectedVersion[0]==minVersion[0]&&flashDetectedVersion[1]>minVersion[1])||(flashDetectedVersion[0]==minVersion[0]&&flashDetectedVersion[1]==minVersion[1]&&flashDetectedVersion[2]>=minVersion[2])){minVersionOk=true;} 9 | if(flashDetectedVersion[0]599){clearInterval($.clipboardReady.timer);debug("Waited "+$.clipboardReady.counter/10+" seconds for Flash object to load, terminating.");return false;} 15 | if(($.clipboardReady.counter%100)==0){debug("Waited "+$.clipboardReady.counter/10+" seconds for Flash object to load so far...");} 16 | var swf=$("#jquery_clipboard_swf:first");var swfdom=$(swf).get(0);if(typeof swfdom.jqueryClipboardCopy=="function"&&swfdom.jqueryClipboardAvailable){clearInterval($.clipboardReady.timer);$.clipboardReady.timer=null;$.clipboard.method='flash';for(var i=0;i<$.clipboardReady.ready.length;i++){$.clipboardReady.ready[i]();} 17 | $.clipboardReady.ready=null;$.clipboardReady.done=true;debug("jQuery.clipboard: OK. Initialized and ready to copy using Flash method.");}};$.clipboardReady=function(f,options){options=jQuery.extend({swfpath:"jquery.clipboard.swf",debug:false},options);swfpath=options.swfpath;debugging=options.debug;if(iecopydetect()){$.clipboard.method='ie';debug("jQuery.clipboard: OK. Initialized and ready to copy using native IE method.");return f();} 18 | if($.clipboardReady.done){return f();} 19 | if($.clipboardReady.timer){$.clipboardReady.ready.push(f);}else{if(flashdetect(flashMinVersion,flashMaxVersion)){$("#jquery_clipboard_swf").remove();$("#jquery_clipboard_div").remove();var div;div=$("
").attr("id","jquery_clipboard_div").css("width","0").css("height","0").appendTo("body").html("");var swf;swf=$('');$(swf).css("width","0").css("height","0").appendTo(div);$.clipboardReady.ready=[f];$.clipboardReady.timer=setInterval(swfready,100);debug("jQuery.clipboard: INFO. Waiting for Flash object to become ready. Detected Flash version: "+flashDetectedVersion[0]+"."+flashDetectedVersion[1]+"."+flashDetectedVersion[2]);}else if(flashDetectedVersion[0]===0){debug("jQuery.clipboard: ERROR. Flash plugin not detected.");return false;}else{debug("jQuery.clipboard: ERROR. Flash version not supported. Minimum: "+flashMinVersion[0]+"."+flashMinVersion[1]+"."+flashMinVersion[2]+" Maximum: "+flashMaxVersion[0]+"."+flashMaxVersion[1]+"."+flashMaxVersion[2]+" Detected: "+flashDetectedVersion[0]+"."+flashDetectedVersion[1]+"."+flashDetectedVersion[2]);return false;}}};$.clipboard=function(text){if(arguments.length<1||typeof text!="string"){debug("jQuery.clipboard: ERROR. Nothing to copy. You must specify a string as the first parameter.");return false;} 20 | if($.clipboard.method=='ie'){try{window.clipboardData.setData("Text",text);debug("jQuery.clipboard: OK. Copied "+text.length+" bytes to clipboard using native IE method.");return true;}catch(e){debug("jQuery.clipboard: ERROR. Tried to copy using native IE method but an unknown error occurred.");return false;}} 21 | if($.clipboard.method=='flash'){var swf=$("#jquery_clipboard_swf:first");var swfdom=$(swf).get(0);if(swfdom.jqueryClipboardCopy(text)){debug("jQuery.clipboard: OK. Copied "+text.length+" bytes to clipboard using Flash method.");return true;}else{debug("jQuery.clipboard: ERROR. Tried to copy using Flash method but an unknown error occurred.");return false;}} 22 | debug("jQuery.clipboard: ERROR. You must use $.clipboardReady() in conjunction with $.clipboard().");return false;};})(jQuery); -------------------------------------------------------------------------------- /src/main/webapp/js/jquery.form.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery form plugin 3 | * @requires jQuery v1.0.3 4 | * 5 | * Dual licensed under the MIT and GPL licenses: 6 | * http://www.opensource.org/licenses/mit-license.php 7 | * http://www.gnu.org/licenses/gpl.html 8 | * 9 | * Revision: $Id: jquery.form.js,v 1.2 2010/02/05 01:18:00 zym Exp $ 10 | * Version: .97 11 | */ 12 | 13 | /** 14 | * ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX. 15 | * 16 | * ajaxSubmit accepts a single argument which can be either a success callback function 17 | * or an options Object. If a function is provided it will be invoked upon successful 18 | * completion of the submit and will be passed the response from the server. 19 | * If an options Object is provided, the following attributes are supported: 20 | * 21 | * target: Identifies the element(s) in the page to be updated with the server response. 22 | * This value may be specified as a jQuery selection string, a jQuery object, 23 | * or a DOM element. 24 | * default value: null 25 | * 26 | * url: URL to which the form data will be submitted. 27 | * default value: value of form's 'action' attribute 28 | * 29 | * type: The method in which the form data should be submitted, 'GET' or 'POST'. 30 | * default value: value of form's 'method' attribute (or 'GET' if none found) 31 | * 32 | * beforeSubmit: Callback method to be invoked before the form is submitted. 33 | * default value: null 34 | * 35 | * success: Callback method to be invoked after the form has been successfully submitted 36 | * and the response has been returned from the server 37 | * default value: null 38 | * 39 | * dataType: Expected dataType of the response. One of: null, 'xml', 'script', or 'json' 40 | * default value: null 41 | * 42 | * semantic: Boolean flag indicating whether data must be submitted in semantic order (slower). 43 | * default value: false 44 | * 45 | * resetForm: Boolean flag indicating whether the form should be reset if the submit is successful 46 | * 47 | * clearForm: Boolean flag indicating whether the form should be cleared if the submit is successful 48 | * 49 | * 50 | * The 'beforeSubmit' callback can be provided as a hook for running pre-submit logic or for 51 | * validating the form data. If the 'beforeSubmit' callback returns false then the form will 52 | * not be submitted. The 'beforeSubmit' callback is invoked with three arguments: the form data 53 | * in array format, the jQuery object, and the options object passed into ajaxSubmit. 54 | * The form data array takes the following form: 55 | * 56 | * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] 57 | * 58 | * If a 'success' callback method is provided it is invoked after the response has been returned 59 | * from the server. It is passed the responseText or responseXML value (depending on dataType). 60 | * See jQuery.ajax for further details. 61 | * 62 | * 63 | * The dataType option provides a means for specifying how the server response should be handled. 64 | * This maps directly to the jQuery.httpData method. The following values are supported: 65 | * 66 | * 'xml': if dataType == 'xml' the server response is treated as XML and the 'after' 67 | * callback method, if specified, will be passed the responseXML value 68 | * 'json': if dataType == 'json' the server response will be evaluted and passed to 69 | * the 'after' callback, if specified 70 | * 'script': if dataType == 'script' the server response is evaluated in the global context 71 | * 72 | * 73 | * Note that it does not make sense to use both the 'target' and 'dataType' options. If both 74 | * are provided the target will be ignored. 75 | * 76 | * The semantic argument can be used to force form serialization in semantic order. 77 | * This is normally true anyway, unless the form contains input elements of type='image'. 78 | * If your form must be submitted with name/value pairs in semantic order and your form 79 | * contains an input of type='image" then pass true for this arg, otherwise pass false 80 | * (or nothing) to avoid the overhead for this logic. 81 | * 82 | * 83 | * When used on its own, ajaxSubmit() is typically bound to a form's submit event like this: 84 | * 85 | * $("#form-id").submit(function() { 86 | * $(this).ajaxSubmit(options); 87 | * return false; // cancel conventional submit 88 | * }); 89 | * 90 | * When using ajaxForm(), however, this is done for you. 91 | * 92 | * @example 93 | * $('#myForm').ajaxSubmit(function(data) { 94 | * alert('Form submit succeeded! Server returned: ' + data); 95 | * }); 96 | * @desc Submit form and alert server response 97 | * 98 | * 99 | * @example 100 | * var options = { 101 | * target: '#myTargetDiv' 102 | * }; 103 | * $('#myForm').ajaxSubmit(options); 104 | * @desc Submit form and update page element with server response 105 | * 106 | * 107 | * @example 108 | * var options = { 109 | * success: function(responseText) { 110 | * alert(responseText); 111 | * } 112 | * }; 113 | * $('#myForm').ajaxSubmit(options); 114 | * @desc Submit form and alert the server response 115 | * 116 | * 117 | * @example 118 | * var options = { 119 | * beforeSubmit: function(formArray, jqForm) { 120 | * if (formArray.length == 0) { 121 | * alert('Please enter data.'); 122 | * return false; 123 | * } 124 | * } 125 | * }; 126 | * $('#myForm').ajaxSubmit(options); 127 | * @desc Pre-submit validation which aborts the submit operation if form data is empty 128 | * 129 | * 130 | * @example 131 | * var options = { 132 | * url: myJsonUrl.php, 133 | * dataType: 'json', 134 | * success: function(data) { 135 | * // 'data' is an object representing the the evaluated json data 136 | * } 137 | * }; 138 | * $('#myForm').ajaxSubmit(options); 139 | * @desc json data returned and evaluated 140 | * 141 | * 142 | * @example 143 | * var options = { 144 | * url: myXmlUrl.php, 145 | * dataType: 'xml', 146 | * success: function(responseXML) { 147 | * // responseXML is XML document object 148 | * var data = $('myElement', responseXML).text(); 149 | * } 150 | * }; 151 | * $('#myForm').ajaxSubmit(options); 152 | * @desc XML data returned from server 153 | * 154 | * 155 | * @example 156 | * var options = { 157 | * resetForm: true 158 | * }; 159 | * $('#myForm').ajaxSubmit(options); 160 | * @desc submit form and reset it if successful 161 | * 162 | * @example 163 | * $('#myForm).submit(function() { 164 | * $(this).ajaxSubmit(); 165 | * return false; 166 | * }); 167 | * @desc Bind form's submit event to use ajaxSubmit 168 | * 169 | * 170 | * @name ajaxSubmit 171 | * @type jQuery 172 | * @param options object literal containing options which control the form submission process 173 | * @cat Plugins/Form 174 | * @return jQuery 175 | * @see formToArray 176 | * @see ajaxForm 177 | * @see $.ajax 178 | * @author jQuery Community 179 | */ 180 | jQuery.fn.ajaxSubmit = function(options) { 181 | if (typeof options == 'function') 182 | options = { success: options }; 183 | 184 | options = jQuery.extend({ 185 | url: this.attr('action') || window.location, 186 | type: this.attr('method') || 'GET' 187 | }, options || {}); 188 | 189 | var a = this.formToArray(options.semantic); 190 | 191 | // give pre-submit callback an opportunity to abort the submit 192 | if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this; 193 | 194 | // fire vetoable 'validate' event 195 | var veto = {}; 196 | jQuery.event.trigger('form.submit.validate', [a, this, options, veto]); 197 | if (veto.veto) 198 | return this; 199 | 200 | var q = jQuery.param(a);//.replace(/%20/g,'+'); 201 | 202 | if (options.type.toUpperCase() == 'GET') { 203 | options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; 204 | options.data = null; // data is null for 'get' 205 | } 206 | else 207 | options.data = q; // data is the query string for 'post' 208 | 209 | var $form = this, callbacks = []; 210 | if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); 211 | if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); 212 | 213 | // perform a load on the target only if dataType is not provided 214 | if (!options.dataType && options.target) { 215 | var oldSuccess = options.success || function(){}; 216 | callbacks.push(function(data, status) { 217 | jQuery(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, [data, status]); 218 | }); 219 | } 220 | else if (options.success) 221 | callbacks.push(options.success); 222 | 223 | options.success = function(data, status) { 224 | for (var i=0, max=callbacks.length; i < max; i++) 225 | callbacks[i](data, status); 226 | }; 227 | 228 | // are there files to upload? 229 | var files = jQuery('input:file', this).fieldValue(); 230 | var found = false; 231 | for (var j=0; j < files.length; j++) 232 | if (files[j]) 233 | found = true; 234 | 235 | if (options.iframe || found) // options.iframe allows user to force iframe mode 236 | fileUpload(); 237 | else 238 | jQuery.ajax(options); 239 | 240 | // fire 'notify' event 241 | jQuery.event.trigger('form.submit.notify', [this, options]); 242 | return this; 243 | 244 | 245 | // private function for handling file uploads (hat tip to YAHOO!) 246 | function fileUpload() { 247 | var form = $form[0]; 248 | var opts = jQuery.extend({}, jQuery.ajaxSettings, options); 249 | 250 | var id = 'jqFormIO' + jQuery.fn.ajaxSubmit.counter++; 251 | var $io = jQuery('