2005年12月23日

apache 2.0.55
jk 1.2.15

httpd.conf中设置JkMount /pay/* paycore
当form的action(如/pay/do/%ab%df123456)已经用url编码编码过后再提交时,jk无法识别,不能正确转化到对应的tomcat上.
posted @ 2005-12-23 17:32 zzzhc 阅读(241) | 评论 (0)编辑 收藏
 

由docbook生成pdf,且基本上没有中访问题的简单方法:

将hibernate文档部分源码(:pserver:anonymous@cvs.sourceforge.net:/cvsroot/hibernate下的doc/reference)取下,将zh-cn目录下的xml文件用自已的代替,修改zh-cn/styles/fopdf.xsl,将与hibernate相关的部分改为自已的内容,主要是version和logo,通过在文件中查找hibernate很容易找得到,用原来的fopdf.xsl生成的pdf的subtitle为乱码,将fopdf.xsl文件中的

<fo:block font-family="Helvetica" font-size="22pt" padding-before="10mm">
                                <xsl:value-of select="bookinfo/subtitle"/>
                            </fo:block>
                            <fo:block font-family="Helvetica" font-size="12pt" padding="10mm">
                                Version:
                                <xsl:value-of select="bookinfo/releaseinfo"/>
                            </fo:block>

修改为

<fo:block font-family="simsun" font-size="22pt" padding-before="10mm">
                                <xsl:value-of select="bookinfo/subtitle"/>
                            </fo:block>
                            <fo:block font-family="simsun" font-size="12pt" padding="10mm">
                                Version:
                                <xsl:value-of select="bookinfo/releaseinfo"/>
                            </fo:block>

换一下subtitle的字体,就不会有乱码了.删除en目录,修改一下build.xml,去掉<antcall target="lang.all"><param name="lang" value="en"/></antcall>,只生成中文结果.

有点难受的是标点还是有可能会出现在句首.

参考:

http://www.donews.net/limodou/archive/2004/04/01/9917.aspx

http://www.blogcn.com/user6/caoxg/blog/2402234.html


文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!106.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(513) | 评论 (0)编辑 收藏
 

用figure表示图形,再用fop转换成pdf时,如果图片的大小比pdf的一页的大小还大时,fop会出错,拒绝工作,它不会把图片缩小一点的,自已把图片缩小一点就可以了.害我找了半天才发现原因,晕啊.


文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!121.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(248) | 评论 (0)编辑 收藏
 

smc源自于 Bob Martin 的状态机编译器,能根据定义文件生成c++,java,tcl,vb.net,c#状态机.

定义文件一般格式

当前状态

{

状态变迁  变迁后状态

                {

                    变迁时执行的动作

                 }

}


文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!123.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(329) | 评论 (0)编辑 收藏
 
      对于没有外键关系的简单表,hbm文件中不要做修改就能映射成dom4j的Element,默认每个属性都映射为一个node;有外键关系的要在many-to-one中加入 embed-xml="false",要不的话经常会造成堆栈溢出或者dom4j试图给一个节点设置多个父节点.
简单测试:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
 package="test">
 
 <class name="Xml" table="xml" lazy="true" node="xml">
  <id name="id" column="id" type="long" node="@id">
   <generator class="native"/>
  </id>
  <property name="name" column="name" not-null="true" length="250" node="@name"/>
  
  <bag name="subs" table="sub" inverse="true" node="subs">
   <key column="parent" />
   <one-to-many class="Sub" node="sub"/>
  </bag>
 </class>
 
</hibernate-mapping>
 
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
 package="test">
 
 <class name="Sub" table="sub" lazy="true" node="sub">
  <id name="id" column="id" type="long" node="@id">
   <generator class="native"/>
  </id>
  <property name="name" column="name" not-null="true" length="250" node="@name"/>
  
  <many-to-one name="parent" column="parent" class="Xml" embed-xml="false"/>
 </class>
 
</hibernate-mapping>
 
复杂一点的:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
 package="test">
 <class name="Dir" table="dir" lazy="true">
  <id name="id" column="id" type="long" node="@id">
   <generator class="native"/>
  </id>
  <property name="name" column="name" not-null="true" length="50" node="@name"/>
  
  <many-to-one name="parent" column="parent_id" class="Dir" node="@parentId" embed-xml="false"/>
  
  <bag name="children" inverse="true" cascade="all" node="dirs">
   <key column="parent_id"/>
   <one-to-many class="Dir"/>
  </bag>
  
  <bag name="files" inverse="true" table="file" node="files">
   <key column="parent_id" />
   <one-to-many class="File"/>
  </bag>
  
 </class>
 
</hibernate-mapping>
 
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
 package="test">
 
 <class name="File" table="file" lazy="true">
  <id name="id" column="id" type="long" node="@id">
   <generator class="native"/>
  </id>
  <property name="title" column="title" not-null="true" length="250"/>
  <property name="content" column="content" not-null="true" type="string"
   lazy="true" length="10000"/>
  <many-to-one name="parent" column="parent_id" class="Dir" not-null="true" node="@parentId" embed-xml="false"/>
 </class>
 
</hibernate-mapping>
 

文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!124.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(487) | 评论 (0)编辑 收藏
 
参考http://www.wespoke.com/archives/000978.html,用python重写了一下,可以指定目录,指定保存路径
#! /usr/bin/python
import urllib, re,sys,os,os.path,getopt
threadNum = 20
savePath = "mp3-2"
optlist,left = getopt.getopt(sys.argv[1:], "t:d:")
for opt in optlist:
    print opt
    if (opt[0]=='-t'):
        threadNum = int(opt[1])
    if (opt[0]=='-d'):
        savePath = opt[1]
print "threadnum="+str(threadNum)
print "savePath="+savePath
if (not os.path.exists(savePath)):
    os.makedirs(savePath)
base = "http://list.mp3.baidu.com/topso/"
url = "http://list.mp3.baidu.com/topso/mp3topsong.html"
def getUrlData(url):
    num = 0
    while (num<3):
        num = num+1
        try :
            f = urllib.urlopen( url )
            data = f.readlines()
            f.close()
            return data
        except:
            pass
    return []
   
data = getUrlData(url)
pattern = re.compile( r'href="(.*?tsomp3.htm)' )
target = [];
for line in data:
    if ( line.find( "tsomp3.htm" )!=-1 ):
        items = pattern.findall( line )
        for item in items:
            target.append( item )
           
print "find ",len( target )," mp3 "
mp3Pattern = re.compile( r'href="(.*?\.mp3)"' )
titlePattern = re.compile( r'<title>.*?_(.*?)\s+</title>' )
import threading
lock = threading.Lock()
def getMp3():
    while True:
        t = ""
        lock.acquire()
        if ( len( target )>0 ):
            t = target[0]
            target.remove( t )
        else :
            return
        lock.release()
        tempUrl = base+t
        data = getUrlData(tempUrl)
        mp3Target = []
        title = "";
        for line in data:
            if ( line.find( "title" )!=-1 ):
                m = titlePattern.search( line )
                if ( m ):
                    title = m.group( 1 )
                    break
        for line in data:
            if ( len( mp3Target )>10 ):
                break
            if ( line.find( ".mp3" )!=-1 ):
                items = mp3Pattern.findall( line )
                for item in items:
                    mp3Target.append( item )
        filename = savePath+"/"+title+".mp3"
        for t in mp3Target:
            try :
                print "try to get "+title+".mp3,url=",t
                ret = urllib.urlretrieve( t, filename )
                size = os.path.getsize(filename)
                if (size>500*1024):
                    print "done:"+title+".mp3"
                    break
            except :
                print "fail to get "+title+".mp3 with url "+t
                pass
for num in range(threadNum):
    thread = threading.Thread( None, getMp3 )
    thread.start()
    print "start thread ",num
   

文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!125.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(1027) | 评论 (0)编辑 收藏
 
apache(2.0.55) rewrite+proxy 至少需要三个module: rewrite_module, proxy_module, proxy_http_module 配置文件片断: LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/proxy_http.so rewriteengine on #注意 不是proxyrequest proxyrequests on #ProxyPass ^/(.*)$ http://host/$1 rewriterule ^/(.*)$ http://host/$1 [P,L] apache已安装后要新添加module可以用apache安装目录/bin下的apxs ,apxs -i -a –c foo_module.c 参考资料: apxs - APache扩展工具 http://www.uplinux.com/download/doc/apache/ApacheManual/programs/apxs.html Apache 重写规则的常见应用 (rewrite) http://fanqiang.chinaunix.net/a6/b1/20010905/0800001238.html

文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!128.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(382) | 评论 (0)编辑 收藏
 
 
对于简单的图形验证码(字体规则,没有杂点或杂点容易过滤掉),用模板匹配的方式可以比较容易地识别出来.
0.图片黑白化,用1表示有字的像素,0表示无字的像素
1.字块分隔,将图片分隔成只包含成单字的最小块
2.生成模板,将字块与字符关联
3.识别,将新图片分块并与模板匹配
java(jdk1.5)实现:
//先运行TemplateCreator创建模板,再运行Recognize2识别
//图片数据表示,也用来表示字块
package pay365;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
public class ImageData {
    public int[][] data;
    public int w;
    public int h;
    public char code;
   
    public ImageData() {
    }
   
    public ImageData(BufferedImage bi) {
        this(bi,new WhiteFilter());
    }
    public ImageData(BufferedImage bi,Filter filter) {
        h = bi.getHeight();
        w = bi.getWidth();
        data = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int p = bi.getRGB(j, i);
                data[i][j] = p;
            }
        }
        filter.doFilter(data);
    }
    public ImageData[] split() {
        ArrayList list = new ArrayList();
        ImageIterator ite = new ImageIterator(this);
        while (ite.hasNext()) {
            list.add(ite.next());
        }
        return (ImageData[]) list.toArray(new ImageData[0]);
    }
    int skipEmpty(int begin, boolean isX, int value) {
        if (isX) {
            for (int i = begin; i < w; i++) {
                for (int j = 0; j < h; j++) {
                    if (data[j][i] != value) {
                        return i;
                    }
                }
            }
            return -1;
        } else {
            for (int i = begin; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (data[i][j] != value) {
                        return i;
                    }
                }
            }
            return -1;
        }
    }
    int skipEntity(int begin, boolean isX, int value) {
        if (isX) {
            for (int i = begin; i < w; i++) {
                for (int j = 0; j < h; j++) {
                    if (data[j][i] == value) {
                        break;
                    }
                    if (j == h - 1)
                        return i;
                }
            }
            return -1;
        } else {
            for (int i = begin; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (data[i][j] == value) {
                        break;
                    }
                    if (j == w - 1)
                        return i;
                }
            }
            return -1;
        }
    }
    class ImageIterator implements Iterator {
        int x;
        ImageData ia;
        ImageData next;
        public ImageIterator(ImageData ia) {
            this.ia = ia;
        }
        public boolean hasNext() {
            if (next != null)
                return true;
            next = getNext();
            return next != null;
        }
        ImageData getNext() {
            int x1 = skipEmpty(x, true, 0);
            if (x1 == -1) {
                return null;
            }
            int x2 = skipEntity(x1, true, 1);
            if (x2 == -1) {
                x2 = w;
            }
            x = x2;
            int y1 = skipEmpty(0, false, 0);
            if (y1 == -1)
                return null;
            int y2 = skipEntity(y1, false, 1);
            if (y2 == -1)
                y2 = h;
            return ia.clone(x1, y1, x2 - x1, y2 - y1);
        }
        public Object next() {
            ImageData temp = next;
            next = null;
            return temp;
        }
        public void remove() {
        }
    }
    ImageData clone(int x, int y, int w0, int h0) {
        ImageData ia = new ImageData();
        ia.w = w0;
        ia.h = h0;
        ia.data = new int[ia.h][ia.w];
        for (int i = 0; i < h0; i++) {
            for (int j = 0; j < w0; j++) {
                ia.data[i][j] = data[i + y][j + x];
            }
        }
        return ia;
    }
    public void show() {
        System.out.println();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                System.out.print((data[i][j] == 1 ? "1" : " ") + "");
            }
            System.out.println();
        }
        System.out.println();
    }
    public int hashCode() {
        int code = w ^ h;
        int count = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (data[i][j] == 1)
                    count++;
            }
        }
        code ^= count;
        return code;
    }
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof ImageData) {
            ImageData o = (ImageData) obj;
            if (o.h != h)
                return false;
            if (o.w != w)
                return false;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (o.data[i][j] != data[i][j])
                        return false;
                }
            }
            return true;
        } else {
            return false;
        }
    }
    public static ImageData[] decodeFromFile(String path) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(
                new File(path)));
        String line;
        ArrayList list = new ArrayList();
        while ((line = reader.readLine()) != null) {
            ImageData ia = decode(line);
            if (ia != null) {
                list.add(ia);
            }
        }
        return (ImageData[]) list.toArray(new ImageData[0]);
    }
    public static ImageData decode(String s) {
        String[] ss = s.split("\\,", 4);
        if (ss.length != 4)
            return null;
        if (ss[0].length() != 1)
            return null;
        ImageData ia = new ImageData();
        ia.code = ss[0].charAt(0);
        ia.w = Integer.parseInt(ss[1]);
        ia.h = Integer.parseInt(ss[2]);
        if (ss[3].length() != ia.w * ia.h) {
            return null;
        }
        ia.data = new int[ia.h][ia.w];
        for (int i = 0; i < ia.h; i++) {
            for (int j = 0; j < ia.w; j++) {
                if (ss[3].charAt(i * ia.w + j) == '1') {
                    ia.data[i][j] = 1;
                } else {
                    ia.data[i][j] = 0;
                }
            }
        }
        return ia;
    }
    public String encode() {
        StringBuffer sb = new StringBuffer();
        sb.append(code).append(",");
        sb.append(w).append(",");
        sb.append(h).append(",");
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (data[i][j] == 1) {
                    sb.append('1');
                } else {
                    sb.append('0');
                }
            }
        }
        return sb.toString();
    }
}
//像素过滤接口
package pay365;
public interface Filter {
   
    void doFilter(int[][] data);
}
//
package pay365;
public abstract class AbstractFilter  implements Filter {
    public void doFilter(int[][] data) {
        int h = data.length;
        if (h<=0)
            return;
        int w = data[0].length;
        if (w<=0)
            return ;
        for(int i=0;i<h;i++) {
            for(int j=0;j<w;j++) {
                data[i][j] = filter(data[i][j]);
            }
        }
    }
   
    protected abstract int filter(int p);
}
//过滤csdn验证码的过滤器
package pay365;
public class CsdnFilter extends AbstractFilter {
    protected int filter(int p) {
        return isNotWhite(p)?1:0;
    }
    private boolean isNotWhite(int p) {
        boolean b = (p & 0x0ff) == 255 && (p >> 8 & 0x0ff) == 255
                && (p >> 16 & 0xff) == 255;
        return !b;
    }
}
//过滤前景色为白色的过滤器
package pay365;
public class WhiteFilter extends AbstractFilter {
   
    protected int filter(int p) {
        if (isWhite(p)) {
            return 1;
        }
        else {
            return 0;
        }
    }
    private boolean isWhite(int p) {
        return (p & 0x0ff) > 240 && (p >> 8 & 0x0ff) > 240
                && (p >> 16 & 0xff) > 240;
    }
}
//模板创建类
package pay365;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.imageio.ImageIO;
public class TemplateCreator {
    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        Set set = new HashSet();
       
        String url = "http://passport.csdn.net/member/ShowExPwd.aspx";
        String filterClazz = "pay365.CsdnFilter";
        if (args.length>=1) {
            url = args[0];
        }
        if (args.length>=2) {
            filterClazz = args[1];
        }
        Filter csdnFilter = (Filter) Class.forName(filterClazz).newInstance();
        for (int i = 1; i < 10; i++) {
            URL u = new URL(url);
            BufferedImage bi = ImageIO.read(u);
            ImageData ia2 = new ImageData(bi,csdnFilter);
            ImageData[] ii = ia2.split();
            for (int x = 0; x < ii.length; x++) {
                ImageData imageArr = ii[x];
                set.add(imageArr);
            }
            // set.addAll(Arrays.asList(ia2.split()));
        }
        System.out.println(set.size());
        for (Iterator iter = set.iterator(); iter.hasNext();) {
            ImageData ele = (ImageData) iter.next();
            ele.show();
            System.out.print("char:");
            String s = readLine();
            if (s.length() == 1) {
                ele.code = s.charAt(0);
            }
        }
       
        PrintWriter pw = new PrintWriter(new File("template.data"));
        for (Iterator iter = set.iterator(); iter.hasNext();) {
            ImageData ele = (ImageData) iter.next();
            pw.println(ele.encode());
        }
        pw.flush();
        pw.close();
    }
    private static BufferedReader reader = new BufferedReader(
            new InputStreamReader(System.in));
    private static String readLine() {
        try {
            return reader.readLine();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}

//识别类
package pay365;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.imageio.ImageIO;
public class Recognize2 {
    static Filter filter;
    public static void main(String[] args) throws Exception {
        if (args.length >= 1) {
            url = args[0];
        }
        String filterClazz = "pay365.CsdnFilter";
        if (args.length >= 2) {
            filterClazz = args[1];
        }
        filter = (Filter) Class.forName(filterClazz).newInstance();
        int total = 10;
        int count = 0;
        for (int i = 0; i < total; i++) {
            boolean b = recognize(i);
            if (b)
                count++;
        }
        System.out.println("rate:" + (count * 1.0 / total * 100) + "%100");
    }
    /**
     * @throws IOException
     */
    private static boolean recognize(int num) throws IOException {
        BufferedImage bi = ImageIO.read(new URL(url));
        ImageIO.write(bi,"png",new File(num+".png"));
        ImageData ia2 = new ImageData(bi, filter);
        ImageData[] ii = ia2.split();
        ArrayList list = new ArrayList();
        ImageData[] template = ImageData.decodeFromFile("template.data");
        HashMap map = new HashMap();
        for (int i = 0; i < template.length; i++) {
            map.put(template[i], new Character(template[i].code));
        }
        for (int x = 0; x < ii.length; x++) {
            ImageData imageArr = ii[x];
            if (imageArr.w > 15)
                continue;
            Character c = (Character) map.get(imageArr);
            if (c != null) {
                list.add(c);
            }
        }
        String s = "";
        System.out.print(num + ":");
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Character c = (Character) iter.next();
            s += c;
            System.out.print(c);
        }
        System.out.println();
        return s.length() != 0;
    }
}
 

文章来源:http://spaces.msn.com/members/zzzhc/Blog/cns!1pPbKg7hHgS7AKKQm6CWG1ZQ!129.entry
posted @ 2005-12-23 15:13 zzzhc 阅读(978) | 评论 (3)编辑 收藏
仅列出标题