Skip to content

Commit b6062be

Browse files
author
Ulric
committed
init project
1 parent dac8b49 commit b6062be

File tree

367 files changed

+32979
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

367 files changed

+32979
-0
lines changed

build.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project basedir="." default="build" name="iperl">
3+
<property name="debug" value="true"/>
4+
<property name="target" value="1.6"/>
5+
<property name="source" value="1.6"/>
6+
<property name="encoding" value="UTF-8"/>
7+
<property name="build.classes.dir" value="webapp/WEB-INF/classes"/>
8+
9+
<path id="iperl.classpath">
10+
<pathelement location="${build.classes.dir}"/>
11+
<fileset dir="lib" includes="*.jar" />
12+
<fileset dir="webapp/WEB-INF/lib" includes="*.jar" />
13+
</path>
14+
15+
<target name="init" depends="clean">
16+
<mkdir dir="${build.classes.dir}"/>
17+
<copy includeemptydirs="false" todir="${build.classes.dir}">
18+
<fileset dir="src" excludes="**/*.java"/>
19+
<fileset dir="conf" excludes="**/*.java"/>
20+
</copy>
21+
</target>
22+
23+
<target depends="init" name="build">
24+
<echo message="${ant.project.name}: ${ant.file}"/>
25+
<javac debug="${debug}" encoding="${encoding}" destdir="${build.classes.dir}" source="${source}" target="${target}">
26+
<src path="conf"/>
27+
<src path="src"/>
28+
<classpath refid="iperl.classpath"/>
29+
</javac>
30+
</target>
31+
32+
<target name="clean">
33+
<delete dir="${build.classes.dir}"/>
34+
</target>
35+
</project>

conf/db.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# DataSource
2+
jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
3+
jdbc.show_sql=true
4+
5+
# Database Configurations
6+
jdbc.driverClass=com.mysql.jdbc.Driver
7+
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/iperl?autoReconnect=true&useUnicode=true&characterEncoding=utf-8
8+
jdbc.user=root
9+
jdbc.password=
10+
jdbc.maxPoolSize=50
11+
jdbc.minPoolSize=2
12+
jdbc.initialPoolSize=2
13+
jdbc.acquireIncrement=2
14+
jdbc.maxStatements=1000
15+
jdbc.maxIdleTime=300
16+
jdbc.checkoutTimeout=5000

conf/ehcache.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd"
3+
updateCheck="false" dynamicConfig="false">
4+
5+
<diskStore path="java.io.tmpdir" />
6+
7+
<defaultCache maxElementsInMemory="1000" eternal="false"
8+
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />
9+
10+
<cache name="User" maxElementsInMemory="100" eternal="false"
11+
timeToIdleSeconds="3600" timeToLiveSeconds="36000" overflowToDisk="true" />
12+
13+
<cache name="hour1" maxElementsInMemory="200" eternal="false"
14+
timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" />
15+
16+
<cache name="min5" maxElementsInMemory="200" eternal="false"
17+
timeToIdleSeconds="300" timeToLiveSeconds="300" overflowToDisk="true" />
18+
19+
<cache name="session" maxElementsInMemory="1000" eternal="false"
20+
timeToIdleSeconds="1800" timeToLiveSeconds="1800" overflowToDisk="true" />
21+
22+
<cache name="BlogCatalog" maxElementsInMemory="100" eternal="false"
23+
timeToIdleSeconds="3600" timeToLiveSeconds="36000" overflowToDisk="true" />
24+
25+
<cache name="BlogTag" maxElementsInMemory="2000" eternal="false"
26+
timeToIdleSeconds="3600" timeToLiveSeconds="36000" overflowToDisk="true" />
27+
28+
<cache name="Tag" maxElementsInMemory="200" eternal="false"
29+
timeToIdleSeconds="3600" timeToLiveSeconds="36000" overflowToDisk="true" />
30+
31+
<cache name="Page" maxElementsInMemory="200" eternal="false"
32+
timeToIdleSeconds="3600" timeToLiveSeconds="36000" overflowToDisk="true" />
33+
34+
<cache name="Blog" maxElementsInMemory="1000" eternal="false"
35+
timeToIdleSeconds="300" timeToLiveSeconds="300" overflowToDisk="true" />
36+
</ehcache>

conf/log4j.properties

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### set log levels ###
2+
log4j.rootLogger =info, stdout, D, E
3+
4+
5+
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
6+
log4j.appender.stdout.Target = System.out
7+
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
8+
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c:%L - %m%n
9+
10+
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
11+
log4j.appender.D.File = ~/logs/iperl-java-log.log
12+
log4j.appender.D.Append = true
13+
14+
log4j.appender.D.Threshold = DEBUG
15+
log4j.appender.D.layout = org.apache.log4j.PatternLayout
16+
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - %c:%L - [%p] %m%n
17+
18+
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
19+
20+
log4j.appender.E.File = ~/logs/iperl-java-error.log
21+
log4j.appender.E.Append = true
22+
23+
log4j.appender.E.Threshold = ERROR
24+
log4j.appender.E.layout = org.apache.log4j.PatternLayout
25+
log4j.appender.E.layout.ConversionPattern =%-d{yyyy-MM-dd HH\:mm\:ss} [%t\:%r] - %c\:%L - [%p] %m%n

data/iperl.sql

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
set names 'utf8';
2+
3+
use iperl;
4+
5+
drop table if exists iperl_users;
6+
create table iperl_users
7+
(
8+
id int unsigned not null auto_increment,
9+
ident varchar(20) not null comment '用户自己给自己起的ID,English,url后缀,也可以用来登陆',
10+
nickname varchar(20) comment 'e.g. iPerler',
11+
pwd varchar(40) not null,
12+
portrait varchar(255) comment '头像',
13+
resume varchar(255) comment '一句话简介',
14+
role tinyint not null comment '用户角色,0是普通用户,-1是不法用户,1是编辑,2是root',
15+
blogcnt int unsigned not null default 0 comment '用户正式发表的博文数目',
16+
ctime timestamp not null default CURRENT_TIMESTAMP,
17+
primary key (id)
18+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
19+
20+
create unique index idx_user_name on iperl_users ( ident );
21+
22+
/*init pwd is abc*/
23+
insert into iperl_users(ident,nickname,pwd,role,resume) values('iperler','iPerler','9ef2bdeea2b1bae79b9ddb930427d0b2c880bdac',2,'^_^I am admin of iperl.org^_^');
24+
25+
drop table if exists iperl_blog_catalogs;
26+
/*博客分类*/
27+
create table iperl_blog_catalogs
28+
(
29+
id int unsigned not null auto_increment,
30+
name varchar(32) not null comment '分类名称',
31+
ident varchar(50) not null comment '分类英文名称',
32+
dorder smallint not null comment 'display order排序权值',
33+
primary key (id)
34+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
35+
insert into iperl_blog_catalogs(name,ident,dorder) values('未分类','uncategorized',999);
36+
37+
38+
drop table if exists iperl_blogs;
39+
create table iperl_blogs
40+
(
41+
id int unsigned not null auto_increment,
42+
title varchar(128) not null comment '文章标题',
43+
ident varchar(128) comment 'E文标题',
44+
keywords varchar(255) comment 'for seo,实际可以使用用户填写的tag',
45+
desn varchar(512) comment '导读内容,同时用于html的description',
46+
type tinyint not null default 0 comment '0:原创,1:翻译,2:转载',
47+
url varchar(512) comment '转载的原始地址',
48+
content text comment '文章内容',
49+
user int unsigned not null comment '发布文章的人',
50+
catalog int unsigned not null comment '文章分类',
51+
status tinyint not null comment '文章状态0:草稿,1:发布',
52+
ctime timestamp not null default CURRENT_TIMESTAMP comment '创建时间',
53+
hits mediumint not null default 0 comment '点击次数',
54+
primary key (id)
55+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
56+
57+
create index idx_blog_user on iperl_blogs ( user );
58+
create index idx_blog_catalog on iperl_blogs ( catalog );
59+
60+
61+
drop table if exists iperl_tags;
62+
create table iperl_tags
63+
(
64+
id int unsigned not null auto_increment,
65+
name varchar(32) not null,
66+
cnt int unsigned not null default 0 comment '这个tag关联的blog数目',
67+
primary key (id)
68+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
69+
70+
create index idx_tag_name on iperl_tags ( name );
71+
72+
drop table if exists iperl_blog_tags;
73+
create table iperl_blog_tags
74+
(
75+
id int unsigned not null auto_increment,
76+
blog int unsigned not null,
77+
tag int unsigned not null,
78+
primary key (id)
79+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
80+
81+
create index idx_btag_blog on iperl_blog_tags ( blog );
82+
create index idx_btag_tag on iperl_blog_tags ( tag );
83+
84+
drop table if exists iperl_pages;
85+
create table iperl_pages
86+
(
87+
id int unsigned not null auto_increment,
88+
user int unsigned not null,
89+
content text comment '页面内容',
90+
primary key (id)
91+
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
92+
93+
create index idx_page_user on iperl_pages ( user );
94+

src/my/cache/Cache.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package my.cache;
2+
3+
import java.util.List;
4+
5+
/**
6+
* 缓存接口
7+
* @author Winter Lau
8+
*/
9+
public interface Cache {
10+
11+
/**
12+
* Get an item from the cache, nontransactionally
13+
* @param key
14+
* @return the cached object or <tt>null</tt>
15+
* @throws CacheException
16+
*/
17+
public Object get(Object key) throws CacheException;
18+
19+
/**
20+
* Add an item to the cache, nontransactionally, with
21+
* failfast semantics
22+
* @param key
23+
* @param value
24+
* @throws CacheException
25+
*/
26+
public void put(Object key, Object value) throws CacheException;
27+
28+
/**
29+
* Add an item to the cache
30+
* @param key
31+
* @param value
32+
* @throws CacheException
33+
*/
34+
public void update(Object key, Object value) throws CacheException;
35+
36+
@SuppressWarnings("rawtypes")
37+
public List keys() throws CacheException ;
38+
39+
/**
40+
* Remove an item from the cache
41+
*/
42+
public void remove(Object key) throws CacheException;
43+
44+
/**
45+
* Clear the cache
46+
*/
47+
public void clear() throws CacheException;
48+
49+
/**
50+
* Clean up
51+
*/
52+
public void destroy() throws CacheException;
53+
54+
}

src/my/cache/CacheDirective.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package my.cache;
2+
3+
import java.io.IOException;
4+
import java.io.Serializable;
5+
import java.io.StringWriter;
6+
import java.io.Writer;
7+
import java.util.Hashtable;
8+
9+
import org.apache.commons.lang.StringUtils;
10+
import org.apache.velocity.context.InternalContextAdapter;
11+
import org.apache.velocity.exception.MethodInvocationException;
12+
import org.apache.velocity.exception.ParseErrorException;
13+
import org.apache.velocity.exception.ResourceNotFoundException;
14+
import org.apache.velocity.runtime.directive.Directive;
15+
import org.apache.velocity.runtime.parser.node.Node;
16+
import org.apache.velocity.runtime.parser.node.SimpleNode;
17+
18+
/**
19+
* Velocity模板上用于控制缓存的指令
20+
* @author Winter Lau
21+
* @date 2009-3-16 下午04:40:19
22+
*/
23+
public class CacheDirective extends Directive {
24+
25+
final static Hashtable<String,String> body_tpls = new Hashtable<String, String>();
26+
27+
@Override
28+
public String getName() { return "cache"; } //指定指令的名称
29+
30+
@Override
31+
public int getType() { return BLOCK; } //指定指令类型为块指令
32+
33+
/* (non-Javadoc)
34+
* @see org.apache.velocity.runtime.directive.Directive#render()
35+
*/
36+
@Override
37+
public boolean render(InternalContextAdapter context, Writer writer, Node node)
38+
throws IOException, ResourceNotFoundException, ParseErrorException,
39+
MethodInvocationException
40+
{
41+
//获得缓存信息
42+
SimpleNode sn_region = (SimpleNode) node.jjtGetChild(0);
43+
String region = (String)sn_region.value(context);
44+
SimpleNode sn_key = (SimpleNode) node.jjtGetChild(1);
45+
Serializable key = (Serializable)sn_key.value(context);
46+
47+
Node body = node.jjtGetChild(2);
48+
//检查内容是否有变化
49+
String tpl_key = key+"@"+region;
50+
String body_tpl = body.literal();
51+
String old_body_tpl = body_tpls.get(tpl_key);
52+
String cache_html = CacheManager.get(String.class, region, key);
53+
if(cache_html == null || !StringUtils.equals(body_tpl, old_body_tpl)){
54+
StringWriter sw = new StringWriter();
55+
body.render(context, sw);
56+
cache_html = sw.toString();
57+
CacheManager.set(region, key, cache_html);
58+
body_tpls.put(tpl_key, body_tpl);
59+
}
60+
writer.write(cache_html);
61+
return true;
62+
}
63+
}
64+
65+
66+
/*
67+
使用方法:
68+
#cache("News","home")
69+
## 读取数据库中最新新闻并显示
70+
<ul>
71+
#foreach($news in $NewsTool.ListTopNews(10))
72+
<li>
73+
<span class='date'>
74+
$date.format("yyyy-MM-dd",${news.pub_time})
75+
</span>
76+
<span class='title'>${news.title}</span>
77+
</li>
78+
#end
79+
</ul>
80+
#end
81+
82+
*/

src/my/cache/CacheException.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package my.cache;
2+
3+
/**
4+
* 缓存异常
5+
* @author Winter Lau
6+
*/
7+
public class CacheException extends RuntimeException {
8+
9+
private static final long serialVersionUID = -8747630300668561700L;
10+
11+
public CacheException(String s) {
12+
super(s);
13+
}
14+
15+
public CacheException(String s, Throwable e) {
16+
super(s, e);
17+
}
18+
19+
public CacheException(Throwable e) {
20+
super(e);
21+
}
22+
23+
}

0 commit comments

Comments
 (0)