邓华

BlogJava 联系 聚合 管理
  48 Posts :: 0 Stories :: 149 Comments :: 0 Trackbacks

#

为了解决linux上的中方问题,今天在google上搜索了一圈, 发现都是需要在linux的全局加入字体,在java中引用才能解决。不死心,因为在原来的PHP程序中可以直接使用TTF字体,在JAVA类库中有了发现。

呵呵,不多写了,直接帖上测试原码。

 

import java.io.File;
import java.awt.*;

public class testFont {

  private static String fontpath = "D:\\work\\WORK\\fonts\\";
  private static java.io.File file = new java.io.File(fontpath + "simhei.ttf");

  public testFont() {
  }

  public static void main(String args[]) {

    if (!file.exists()) {
      System.out.println("file not found");
      return;
    }
    try {
      java.io.FileInputStream fi = new java.io.FileInputStream(file);
      java.io.BufferedInputStream fb = new java.io.BufferedInputStream(fi);
      Font nf = Font.createFont(Font.TRUETYPE_FONT, fb);

      nf = nf.deriveFont(Font.BOLD, 10);
      System.out.println(nf.getFontName());
      System.out.println(nf.getSize());
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }

}

 

posted @ 2006-03-16 11:58 邓华的碎碎念 阅读(722) | 评论 (0)编辑 收藏

如何获得一个字符的宽度和高度? 
来源:ChinaITLab.com
2003-9-30 16:22:00
ChinaITLab新标志正式启动,新鲜出炉大激赏!
 
 
  如何获得一个字符的宽度和高度?                                               
                                                                               
   可以利用FontMetrics 对象所提供的getHeight(), charWidth()或者是stringWidth()
 
   方法来获得显示某个字符或者是字符串所需要的高度和宽度。例如,在Graphics g中:


                                                                               
   String Info = "Test String".FontMetrics metrics = getFontMetrics(g.getFont()); 
   int height = metrics.getHeight();         
   int width = metrics.stringWidth(Info);                                                                                
   关于这些方法的具体情况,请参考FontMetrics类的API文档。   
 

posted @ 2006-03-16 11:57 邓华的碎碎念 阅读(247) | 评论 (0)编辑 收藏

碰到include乱码的情况下.

根据当时页面情况加入

<%@ page pageEncoding="UTF-8"  %>

这个,在include页面编译的时候,可以明确指定该页面用utf-8的编码编译
posted @ 2006-03-16 11:57 邓华的碎碎念 阅读(355) | 评论 (0)编辑 收藏

大家都知道,JAVA程序启动时都会JVM都会分配一个初始内存和最大内存给这个应用程序。这个初始内存和最大内存在一定程度都会影响程序的性能。比如说在应用程序用到最大内存的时候,JVM是要先去做垃圾回收的动作,释放被占用的一些内存。
        所以想调整Tomcat的启动时初始内存和最大内存就需要向JVM声明,一般的JAVA程序在运行都可以通过中-Xms -Xmx来调整应用程序的初始内存和最大内存: 
        如:java -Xms64m  -Xmx128m  a.jar.
tomcat的启动程序是包装过的,不能直接使用java -X..... tomcat.*来改变内存的设置。在Tomcat在改变这个设置
有两种方法:
1.    就需要在环境变量中加上TOMCAT_OPTS, CATALINA_OPTS两个属性,
        如 SET  CATALINA_OPTS= -Xms64m -Xmx512m;
        ms是最小的,mx是最大,64m, 512m分别是指内存的容量.

2.    修改Catalina.bat文件
       在166行“rem Execute Java with the applicable properties ”以下每行
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% 中的%CATALINA_OPTS% 替换成-Xms64m -Xmx512m

其上为方法一
--------------------------------------------------------------------------------------------------------------

另外一个方法是
在 tomcat_home/bin/catalina.sh 这个文件里
找到下面:
# ----- Execute The Requested Command -----------------------------------------
echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

然后增加一行..
# ----- Execute The Requested Command -----------------------------------------
JAVA_OPTS="-server -Xmx512m -Xms128m -Djava.awt.headless=true "
echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

就OK了.
posted @ 2006-03-16 11:56 邓华的碎碎念 阅读(123) | 评论 (0)编辑 收藏

java webapp i18n处理实践   打印  E-mail 
执笔: 曹晓钢    
 
Sunday,2004年June月13日

java webapp i18n处理实践
要点:为了实现同屏多语言显示/按照不同用户locale显示不同语言,必须全程采用UTF-8编码。

这几天笔者刚好在处理roller的i18n,做一下总结。

1, 对properties的处理,必须使用natice2ascii进行编译;然后采用boudle load.
建议使用jstl进行处理。
例子:
<%@ taglib uri="http://java.sun.com/jstl/fmt"                   prefix="fmt" %>

<fmt:message key="bookmarkForm.correctBookmark" />

2, 对jdbc连接的处理。对于特定的数据库jdbc driver,需要调整参数。
mysql的例子是:
 jdbc:mysql://localhost/roller?user=roller&password=roller&autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8

3, 对request/response处理,可以采用servlet filter进行设置:
    public void doFilter(
        ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException
    {
        try
        {
            // insure that incoming data is parsed as UTF-8
            req.setCharacterEncoding("UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            throw new ServletException("Can't set incoming encoding to UTF-8");
        }
       
        // keep JSTL and Struts Locale's in synch
        HttpSession session = ((HttpServletRequest)req).getSession();
        if (null != session)
        {
            Locale locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
            if (locale == null)
            {
                locale = req.getLocale();
            }
            if (req.getParameter("locale") != null)
            {
                locale = new Locale(req.getParameter("locale"));
            }
            session.setAttribute(Globals.LOCALE_KEY, locale);
            Config.set(session, Config.FMT_LOCALE, locale);
        }
        chain.doFilter(req, res);
 ...
    }

(这段代码是从roller的代码中摘录的,seasky指出其编写不够规范,需要refactor)

4。对每个页面,在response和页面中都要指定为utf-8
<%@ page language="java"
         errorPage="/error.jsp"
         contentType="text/html; charset=UTF-8" %>


5, 对velocity的处理:
in velocity.properties:
# set encoding/charset to UTF-8
input.encoding=UTF-8
output.encoding=UTF-8
default.contentType=text/html; charset=utf-8

同时,在java代码中进行template render时,指定utf-8:
VelocityEngine ve = ....;
Template outty = getTemplate( "templateName", "UTF-8" );

6, 对Gzip的处理:
其实对Gzip处理没有什么特殊,记住不要对ByteArrayStream转换成char[]再进行处理,而是在任何时候都使用byte[]。

下载区中有一个例子

7, 对regexp的处理。已经有报告说java.util.RegExp处理会导致输出错误。估计也是里面变换的时候用byte[]和char[]倒来倒去出了错。有条件的请try oro.
(我还没有测试)。

8,对lucene 的修改。
经过测试,lucene 1.3-final不需要任何处理已经可以正确处理中文,GB2312和utf-8都可以。





Struts原理与实践(5)
作者:罗会波 发文时间:2004.09.24
一个支持i18n的应用程序应该有如下一些特征:
1增加支持的语言时要求不更改程序代码
2字符元素、消息、和图象保存在原代码之外
3依赖于不同文化的数据如:日期时间、小数、及现金符号等数据对用户的语言和地理位置应该有正确的格式
4应用程序能迅速地适应新语言和/或新地区

Struts主要采用两个i18n组件来实现国际化编程:

第一个组件是一个被应用程序控制器管理的消息类,它引用包含地区相关信息串的资源包。第二个组件是一个JSP定制标签,,它用于在View层呈现被控制器管理的实际的字符串。在我们前面的登录例子中这两方面的内容都出现过。

用Struts实现国际化编程的标准做法是:生成一个java属性文件集。每个文件包含您的应用程序要显示的所有消息的键/值对。

这些文件的命名要遵守如下规则,代表英文消息的文件可作为缺省的文件,它的名称是ApplicationResources.properties;其他语种的文件在文件名中都要带上相应的地区和语言编码串,如代表中文的文件名应为ApplicationResources_zh_CN.properties。并且其他语种的文件与ApplicationResources.properties文件要放在同一目录中。

ApplicationResources.properties文件的键/值都是英文的,而其他语种文件的键是英文的,值则是对应的语言。如在我们前面的登录例子中的键/值对:logon.jsp.prompt.username=Username:在中文文件中就是:logon.jsp.prompt.username=用户名:当然,在实际应用时要把中文转换为AscII码。

有了上一篇文章和以上介绍的一些基础知识后。我们就可以将我们的登录程序进行国际化编程了。

首先,我们所有jsp页面文件的字符集都设置为UTF-8。即在页面文件的开始写如下指令行:

,在我们的登录例子中已经这样做了,这里不需要再改动。

其次,将所有的request的字符集也设置为UTF-8。虽然,我们可以在每个文件中加入这样的句子:request.setCharacterEncoding("UTF-8");来解决,但这样显得很麻烦。一种更简单的解决方法是使用filter。具体步骤如下:

在mystruts\WEB-INF\classes目录下再新建一个名为filters的目录,新建一个名为:SetCharacterEncodingFilter的类,并保存在该目录下。其实,这个类并不要您亲自来写,可以借用tomcat中的例子。现将该例子的程序节选如下:

package filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;

/**
 * <p>Example filter that sets the character encoding to be used in parsing the
 * incoming request, either unconditionally or only if the client did not
 * specify a character encoding.  Configuration of this filter is based on
 * the following initialization parameters:</p>
 * <ul>
 * <li><strong>encoding</strong> - The character encoding to be configured
 *     for this request, either conditionally or unconditionally based on
 *     the <code>ignore</code> initialization parameter.  This parameter
 *     is required, so there is no default.</li>
 * <li><strong>ignore</strong> - If set to "true", any character encoding
 *     specified by the client is ignored, and the value returned by the
 *     <code>selectEncoding()</code> method is set.  If set to "false,
 *     <code>selectEncoding()</code> is called <strong>only</strong> if the
 *     client has not already specified an encoding.  By default, this
 *     parameter is set to "true".</li>
 * </ul>
 *
 * <p>Although this filter can be used unchanged, it is also easy to
 * subclass it and make the <code>selectEncoding()</code> method more
 * intelligent about what encoding to choose, based on characteristics of
 * the incoming request (such as the values of the <code>Accept-Language</code>
 * and <code>User-Agent</code> headers, or a value stashed in the current
 * user's session.</p>
 *
 * @author Craig McClanahan
 * @version $Revision: 1.2 $ $Date: 2001/10/17 22:53:19 $
 */

public class SetCharacterEncodingFilter implements Filter {


    // ----------------------------------------------------- Instance Variables


    /**
     * The default character encoding to set for requests that pass through
     * this filter.
     */
    protected String encoding = null;


    /**
     * The filter configuration object we are associated with.  If this value
     * is null, this filter instance is not currently configured.
     */
    protected FilterConfig filterConfig = null;


    /**
     * Should a character encoding specified by the client be ignored?
     */
    protected boolean ignore = true;


    // --------------------------------------------------------- Public Methods


    /**
     * Take this filter out of service.
     */
    public void destroy() {

        this.encoding = null;
        this.filterConfig = null;

    }


    /**
     * Select and set (if specified) the character encoding to be used to
     * interpret request parameters for this request.
     *
     * @param request The servlet request we are processing
     * @param result The servlet response we are creating
     * @param chain The filter chain we are processing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
        throws IOException, ServletException {

        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
                request.setCharacterEncoding(encoding);
        }

        // Pass control on to the next filter
        chain.doFilter(request, response);

    }


    /**
     * Place this filter into service.
     *
     * @param filterConfig The filter configuration object
     */
    public void init(FilterConfig filterConfig) throws ServletException {

        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if (value == null)
            this.ignore = true;
        else if (value.equalsIgnoreCase("true"))
            this.ignore = true;
        else if (value.equalsIgnoreCase("yes"))
            this.ignore = true;
        else
            this.ignore = false;

    }


    // ------------------------------------------------------ Protected Methods


    /**
     * Select an appropriate character encoding to be used, based on the
     * characteristics of the current request and/or filter initialization
     * parameters.  If no character encoding should be set, return
     * <code>null</code>.
     * <p>
     * The default implementation unconditionally returns the value configured
     * by the <strong>encoding</strong> initialization parameter for this
     * filter.
     *
     * @param request The servlet request we are processing
     */
    protected String selectEncoding(ServletRequest request) {

        return (this.encoding);

    }

}


其中,request.setCharacterEncoding(encoding);是一个关键句子。

为了让该类工作,我们还要在web.xml文件中对它进行配置,配置代码如下:

<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


最后,就是准备资源包文件,我们以创建一个中文文件为例:

将ApplicationResources.properties文件打开,另存为ApplicationResources_zh.properties,这只是一个过渡性质的文件。将文件中键/值对的值都用中文表示。更改完后的代码如下:

#Application Resource for the logon.jsp
logon.jsp.title=登录页
logon.jsp.page.heading=欢迎 世界!
logon.jsp.prompt.username=用户名:
logon.jsp.prompt.password=口令:
logon.jsp.prompt.submit=提交
logon.jsp.prompt.reset=复位

#Application Resource for the main.jsp
main.jsp.title=主页
main.jsp.welcome=欢迎:

#Application Resource for the LogonAction.java
error.missing.username=<li><font color="red">没有输入用户名</font></li>
error.missing.password=<li><font color="red">没有输入口令</font></li>

#Application Resource for the UserInfoBo.java
error.noMatch=<li><font color="red">没有匹配的用户</font></li>

#Application Resource for the UserInfoBo.java
error.logon.invalid=<li><font color="red">用户名/口令是无效的</font></li>
error.removed.user=<li><font color="red">找不到该用户</font></li>
error.unexpected=<li><font color="red">不可预期的错误</font></li>


使用native2ascii工具将上面文件中的中文字符转换为ascii码,并生成一个最终使用的资源文件ApplicationResources_zh_CN.properties。

具体做法是打开一个dos窗口,到mystruts\WEB-INF\classes目录下,运行如下语句:

native2ascii -encoding GBK ApplicationResources_zh.properties ApplicationResources_zh_CN.properties

生成的文件ApplicationResources_zh_CN.properties的内容如下:

#Application Resource for the logon.jsp
logon.jsp.title=\u767b\u5f55\u9875
logon.jsp.page.heading=\u6b22\u8fce \u4e16\u754c!
logon.jsp.prompt.username=\u7528\u6237\u540d:
logon.jsp.prompt.password=\u53e3\u4ee4:
logon.jsp.prompt.submit=\u63d0\u4ea4
logon.jsp.prompt.reset=\u590d\u4f4d

#Application Resource for the main.jsp
main.jsp.title=\u4e3b\u9875
main.jsp.welcome=\u6b22\u8fce:

#Application Resource for the LogonAction.java
error.missing.username=<li><font color="red">\u6ca1\u6709\u8f93\u5165\u7528\u6237\u540d</font></li>
error.missing.password=<li><font color="red">\u6ca1\u6709\u8f93\u5165\u53e3\u4ee4</font></li>

#Application Resource for the UserInfoBo.java
error.noMatch=<li><font color="red">\u6ca1\u6709\u5339\u914d\u7684\u7528\u6237</font></li>

#Application Resource for the UserInfoBo.java
error.logon.invalid=<li><font color="red">\u7528\u6237\u540d/\u53e3\u4ee4\u662f\u65e0\u6548\u7684</font></li>
error.removed.user=<li><font color="red">\u627e\u4e0d\u5230\u8be5\u7528\u6237</font></li>
error.unexpected=<li><font color="red">\u4e0d\u53ef\u9884\u671f\u7684\u9519\u8bef</font></li>


从这里可以看出,所有的中文字都转换成了对应的Unicode码。

现在,再运行登录例子程序,您会发现它已经是显示的中文了。在浏览器的"工具"--"Internet选项"的"语言首选项"对话框中,去掉"中文(中国)"加上英文,再试登录程序,此时,又会显示英文。这就是说不同国家(地区)的客户都可以看到自己语言的内容,这就实现了国际化编程的基本要求。如果还要显示其他语言,可采用类似处理中文的方法进行,这里就不细讲了。

本文中的例子程序所采用的数据库仍然是MS SQLServer2000,数据库字符集为gbk。实验表明,对简、繁体中文,英文及日文字符都能支持。

参考文献:
《Programming Jakarta Struts》Chuck Cavaness著
《Mastering Jakarta Struts》James Goodwill著

本文作者:罗会波 湖北省当阳市国税局信息中心 可通过lhbf@sina.com与他联系
posted @ 2006-03-16 11:56 邓华的碎碎念 阅读(432) | 评论 (0)编辑 收藏

/**
 * @(#)CnToSpell.java
 * 版权声明 Easydozer 版权所有 违者必究
 *
 * 修订记录:
 * 1)更改者:Easydozer
 *   时 间:2004-10-20 
 *   描 述:创建
 */
package com.easydozer.commons.util;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;

/**
 * <pre>汉字转化为全拼</pre>
 * <BR><DL><DT><B>JDK版本:</B></DT><BR><DD>1.4</DD></DL>
 * @author   谢计生
 * @version  1.0
 * @see     
 * @since   1.0
 */
public class CnToSpell
{
  private static LinkedHashMap spellMap = null;

  static
  {
    if(spellMap == null){
      spellMap = new LinkedHashMap(400);
    }
    initialize();
    System.out.println("Chinese transfer Spell Done.");
  }

  private CnToSpell()
  {
  }

  private static void spellPut(String spell,int ascii)
  {
    spellMap.put(spell,new Integer(ascii));
  }

  private static void initialize()
  {
    spellPut("a", -20319);
    spellPut("ai", -20317);
    spellPut("an", -20304);
    spellPut("ang", -20295);
    spellPut("ao", -20292);
    spellPut("ba", -20283);
    spellPut("bai", -20265);
    spellPut("ban", -20257);
    spellPut("bang", -20242);
    spellPut("bao", -20230);
    spellPut("bei", -20051);
    spellPut("ben", -20036);
    spellPut("beng", -20032);
    spellPut("bi", -20026);
    spellPut("bian", -20002);
    spellPut("biao", -19990);
    spellPut("bie", -19986);
    spellPut("bin", -19982);
    spellPut("bing", -19976);
    spellPut("bo", -19805);
    spellPut("bu", -19784);
    spellPut("ca", -19775);
    spellPut("cai", -19774);
    spellPut("can", -19763);
    spellPut("cang", -19756);
    spellPut("cao", -19751);
    spellPut("ce", -19746);
    spellPut("ceng", -19741);
    spellPut("cha", -19739);
    spellPut("chai", -19728);
    spellPut("chan", -19725);
    spellPut("chang", -19715);
    spellPut("chao", -19540);
    spellPut("che", -19531);
    spellPut("chen", -19525);
    spellPut("cheng", -19515);
    spellPut("chi", -19500);
    spellPut("chong", -19484);
    spellPut("chou", -19479);
    spellPut("chu", -19467);
    spellPut("chuai", -19289);
    spellPut("chuan", -19288);
    spellPut("chuang", -19281);
    spellPut("chui", -19275);
    spellPut("chun", -19270);
    spellPut("chuo", -19263);
    spellPut("ci", -19261);
    spellPut("cong", -19249);
    spellPut("cou", -19243);
    spellPut("cu", -19242);
    spellPut("cuan", -19238);
    spellPut("cui", -19235);
    spellPut("cun", -19227);
    spellPut("cuo", -19224);
    spellPut("da", -19218);
    spellPut("dai", -19212);
    spellPut("dan", -19038);
    spellPut("dang", -19023);
    spellPut("dao", -19018);
    spellPut("de", -19006);
    spellPut("deng", -19003);
    spellPut("di", -18996);
    spellPut("dian", -18977);
    spellPut("diao", -18961);
    spellPut("die", -18952);
    spellPut("ding", -18783);
    spellPut("diu", -18774);
    spellPut("dong", -18773);
    spellPut("dou", -18763);
    spellPut("du", -18756);
    spellPut("duan", -18741);
    spellPut("dui", -18735);
    spellPut("dun", -18731);
    spellPut("duo", -18722);
    spellPut("e", -18710);
    spellPut("en", -18697);
    spellPut("er", -18696);
    spellPut("fa", -18526);
    spellPut("fan", -18518);
    spellPut("fang", -18501);
    spellPut("fei", -18490);
    spellPut("fen", -18478);
    spellPut("feng", -18463);
    spellPut("fo", -18448);
    spellPut("fou", -18447);
    spellPut("fu", -18446);
    spellPut("ga", -18239);
    spellPut("gai", -18237);
    spellPut("gan", -18231);
    spellPut("gang", -18220);
    spellPut("gao", -18211);
    spellPut("ge", -18201);
    spellPut("gei", -18184);
    spellPut("gen", -18183);
    spellPut("geng", -18181);
    spellPut("gong", -18012);
    spellPut("gou", -17997);
    spellPut("gu", -17988);
    spellPut("gua", -17970);
    spellPut("guai", -17964);
    spellPut("guan", -17961);
    spellPut("guang", -17950);
    spellPut("gui", -17947);
    spellPut("gun", -17931);
    spellPut("guo", -17928);
    spellPut("ha", -17922);
    spellPut("hai", -17759);
    spellPut("han", -17752);
    spellPut("hang", -17733);
    spellPut("hao", -17730);
    spellPut("he", -17721);
    spellPut("hei", -17703);
    spellPut("hen", -17701);
    spellPut("heng", -17697);
    spellPut("hong", -17692);
    spellPut("hou", -17683);
    spellPut("hu", -17676);
    spellPut("hua", -17496);
    spellPut("huai", -17487);
    spellPut("huan", -17482);
    spellPut("huang", -17468);
    spellPut("hui", -17454);
    spellPut("hun", -17433);
    spellPut("huo", -17427);
    spellPut("ji", -17417);
    spellPut("jia", -17202);
    spellPut("jian", -17185);
    spellPut("jiang", -16983);
    spellPut("jiao", -16970);
    spellPut("jie", -16942);
    spellPut("jin", -16915);
    spellPut("jing", -16733);
    spellPut("jiong", -16708);
    spellPut("jiu", -16706);
    spellPut("ju", -16689);
    spellPut("juan", -16664);
    spellPut("jue", -16657);
    spellPut("jun", -16647);
    spellPut("ka", -16474);
    spellPut("kai", -16470);
    spellPut("kan", -16465);
    spellPut("kang", -16459);
    spellPut("kao", -16452);
    spellPut("ke", -16448);
    spellPut("ken", -16433);
    spellPut("keng", -16429);
    spellPut("kong", -16427);
    spellPut("kou", -16423);
    spellPut("ku", -16419);
    spellPut("kua", -16412);
    spellPut("kuai", -16407);
    spellPut("kuan", -16403);
    spellPut("kuang", -16401);
    spellPut("kui", -16393);
    spellPut("kun", -16220);
    spellPut("kuo", -16216);
    spellPut("la", -16212);
    spellPut("lai", -16205);
    spellPut("lan", -16202);
    spellPut("lang", -16187);
    spellPut("lao", -16180);
    spellPut("le", -16171);
    spellPut("lei", -16169);
    spellPut("leng", -16158);
    spellPut("li", -16155);
    spellPut("lia", -15959);
    spellPut("lian", -15958);
    spellPut("liang", -15944);
    spellPut("liao", -15933);
    spellPut("lie", -15920);
    spellPut("lin", -15915);
    spellPut("ling", -15903);
    spellPut("liu", -15889);
    spellPut("long", -15878);
    spellPut("lou", -15707);
    spellPut("lu", -15701);
    spellPut("lv", -15681);
    spellPut("luan", -15667);
    spellPut("lue", -15661);
    spellPut("lun", -15659);
    spellPut("luo", -15652);
    spellPut("ma", -15640);
    spellPut("mai", -15631);
    spellPut("man", -15625);
    spellPut("mang", -15454);
    spellPut("mao", -15448);
    spellPut("me", -15436);
    spellPut("mei", -15435);
    spellPut("men", -15419);
    spellPut("meng", -15416);
    spellPut("mi", -15408);
    spellPut("mian", -15394);
    spellPut("miao", -15385);
    spellPut("mie", -15377);
    spellPut("min", -15375);
    spellPut("ming", -15369);
    spellPut("miu", -15363);
    spellPut("mo", -15362);
    spellPut("mou", -15183);
    spellPut("mu", -15180);
    spellPut("na", -15165);
    spellPut("nai", -15158);
    spellPut("nan", -15153);
    spellPut("nang", -15150);
    spellPut("nao", -15149);
    spellPut("ne", -15144);
    spellPut("nei", -15143);
    spellPut("nen", -15141);
    spellPut("neng", -15140);
    spellPut("ni", -15139);
    spellPut("nian", -15128);
    spellPut("niang", -15121);
    spellPut("niao", -15119);
    spellPut("nie", -15117);
    spellPut("nin", -15110);
    spellPut("ning", -15109);
    spellPut("niu", -14941);
    spellPut("nong", -14937);
    spellPut("nu", -14933);
    spellPut("nv", -14930);
    spellPut("nuan", -14929);
    spellPut("nue", -14928);
    spellPut("nuo", -14926);
    spellPut("o", -14922);
    spellPut("ou", -14921);
    spellPut("pa", -14914);
    spellPut("pai", -14908);
    spellPut("pan", -14902);
    spellPut("pang", -14894);
    spellPut("pao", -14889);
    spellPut("pei", -14882);
    spellPut("pen", -14873);
    spellPut("peng", -14871);
    spellPut("pi", -14857);
    spellPut("pian", -14678);
    spellPut("piao", -14674);
    spellPut("pie", -14670);
    spellPut("pin", -14668);
    spellPut("ping", -14663);
    spellPut("po", -14654);
    spellPut("pu", -14645);
    spellPut("qi", -14630);
    spellPut("qia", -14594);
    spellPut("qian", -14429);
    spellPut("qiang", -14407);
    spellPut("qiao", -14399);
    spellPut("qie", -14384);
    spellPut("qin", -14379);
    spellPut("qing", -14368);
    spellPut("qiong", -14355);
    spellPut("qiu", -14353);
    spellPut("qu", -14345);
    spellPut("quan", -14170);
    spellPut("que", -14159);
    spellPut("qun", -14151);
    spellPut("ran", -14149);
    spellPut("rang", -14145);
    spellPut("rao", -14140);
    spellPut("re", -14137);
    spellPut("ren", -14135);
    spellPut("reng", -14125);
    spellPut("ri", -14123);
    spellPut("rong", -14122);
    spellPut("rou", -14112);
    spellPut("ru", -14109);
    spellPut("ruan", -14099);
    spellPut("rui", -14097);
    spellPut("run", -14094);
    spellPut("ruo", -14092);
    spellPut("sa", -14090);
    spellPut("sai", -14087);
    spellPut("san", -14083);
    spellPut("sang", -13917);
    spellPut("sao", -13914);
    spellPut("se", -13910);
    spellPut("sen", -13907);
    spellPut("seng", -13906);
    spellPut("sha", -13905);
    spellPut("shai", -13896);
    spellPut("shan", -13894);
    spellPut("shang", -13878);
    spellPut("shao", -13870);
    spellPut("she", -13859);
    spellPut("shen", -13847);
    spellPut("sheng", -13831);
    spellPut("shi", -13658);
    spellPut("shou", -13611);
    spellPut("shu", -13601);
    spellPut("shua", -13406);
    spellPut("shuai", -13404);
    spellPut("shuan", -13400);
    spellPut("shuang", -13398);
    spellPut("shui", -13395);
    spellPut("shun", -13391);
    spellPut("shuo", -13387);
    spellPut("si", -13383);
    spellPut("song", -13367);
    spellPut("sou", -13359);
    spellPut("su", -13356);
    spellPut("suan", -13343);
    spellPut("sui", -13340);
    spellPut("sun", -13329);
    spellPut("suo", -13326);
    spellPut("ta", -13318);
    spellPut("tai", -13147);
    spellPut("tan", -13138);
    spellPut("tang", -13120);
    spellPut("tao", -13107);
    spellPut("te", -13096);
    spellPut("teng", -13095);
    spellPut("ti", -13091);
    spellPut("tian", -13076);
    spellPut("tiao", -13068);
    spellPut("tie", -13063);
    spellPut("ting", -13060);
    spellPut("tong", -12888);
    spellPut("tou", -12875);
    spellPut("tu", -12871);
    spellPut("tuan", -12860);
    spellPut("tui", -12858);
    spellPut("tun", -12852);
    spellPut("tuo", -12849);
    spellPut("wa", -12838);
    spellPut("wai", -12831);
    spellPut("wan", -12829);
    spellPut("wang", -12812);
    spellPut("wei", -12802);
    spellPut("wen", -12607);
    spellPut("weng", -12597);
    spellPut("wo", -12594);
    spellPut("wu", -12585);
    spellPut("xi", -12556);
    spellPut("xia", -12359);
    spellPut("xian", -12346);
    spellPut("xiang", -12320);
    spellPut("xiao", -12300);
    spellPut("xie", -12120);
    spellPut("xin", -12099);
    spellPut("xing", -12089);
    spellPut("xiong", -12074);
    spellPut("xiu", -12067);
    spellPut("xu", -12058);
    spellPut("xuan", -12039);
    spellPut("xue", -11867);
    spellPut("xun", -11861);
    spellPut("ya", -11847);
    spellPut("yan", -11831);
    spellPut("yang", -11798);
    spellPut("yao", -11781);
    spellPut("ye", -11604);
    spellPut("yi", -11589);
    spellPut("yin", -11536);
    spellPut("ying", -11358);
    spellPut("yo", -11340);
    spellPut("yong", -11339);
    spellPut("you", -11324);
    spellPut("yu", -11303);
    spellPut("yuan", -11097);
    spellPut("yue", -11077);
    spellPut("yun", -11067);
    spellPut("za", -11055);
    spellPut("zai", -11052);
    spellPut("zan", -11045);
    spellPut("zang", -11041);
    spellPut("zao", -11038);
    spellPut("ze", -11024);
    spellPut("zei", -11020);
    spellPut("zen", -11019);
    spellPut("zeng", -11018);
    spellPut("zha", -11014);
    spellPut("zhai", -10838);
    spellPut("zhan", -10832);
    spellPut("zhang", -10815);
    spellPut("zhao", -10800);
    spellPut("zhe", -10790);
    spellPut("zhen", -10780);
    spellPut("zheng", -10764);
    spellPut("zhi", -10587);
    spellPut("zhong", -10544);
    spellPut("zhou", -10533);
    spellPut("zhu", -10519);
    spellPut("zhua", -10331);
    spellPut("zhuai", -10329);
    spellPut("zhuan", -10328);
    spellPut("zhuang", -10322);
    spellPut("zhui", -10315);
    spellPut("zhun", -10309);
    spellPut("zhuo", -10307);
    spellPut("zi", -10296);
    spellPut("zong", -10281);
    spellPut("zou", -10274);
    spellPut("zu", -10270);
    spellPut("zuan", -10262);
    spellPut("zui", -10260);
    spellPut("zun", -10256);
    spellPut("zuo", -10254);
  }

  /**
   * 获得单个汉字的Ascii.
   * @param cn char
   * 汉字字符
   * @return int
   * 错误返回 0,否则返回ascii
   */
  public static int getCnAscii(char cn)
  {
    byte[] bytes = (String.valueOf(cn)).getBytes();
    if(bytes == null || bytes.length > 2 || bytes.length <= 0){ //错误
      return 0;
    }
    if(bytes.length == 1){ //英文字符
      return bytes[0];
    }
    if(bytes.length == 2){ //中文字符
      int hightByte = 256 + bytes[0];
      int lowByte = 256 + bytes[1];

      int ascii = (256 * hightByte + lowByte) - 256 * 256;

      //System.out.println("ASCII=" + ascii);

      return ascii;
    }

    return 0; //错误
  }

  /**
   * 根据ASCII码到SpellMap中查找对应的拼音
   * @param ascii int
   * 字符对应的ASCII
   * @return String
   * 拼音,首先判断ASCII是否>0&<160,如果是返回对应的字符,
   * <BR>否则到SpellMap中查找,如果没有找到拼音,则返回null,如果找到则返回拼音.
   */
  public static String getSpellByAscii(int ascii)
  {
    if(ascii > 0 && ascii < 160){ //单字符
      return String.valueOf((char)ascii);
    }

    if(ascii < -20319 || ascii > -10247){ //不知道的字符
      return null;
    }

    Set keySet = spellMap.keySet();
    Iterator it = keySet.iterator();

    String spell0 = null;;
    String spell = null;

    int asciiRang0 = -20319;
    int asciiRang;
    while(it.hasNext()){

      spell = (String)it.next();
      Object valObj = spellMap.get(spell);
      if(valObj instanceof Integer){
        asciiRang = ((Integer)valObj).intValue();

        if(ascii >= asciiRang0 && ascii < asciiRang){ //区间找到
          return(spell0 == null) ? spell : spell0;
        }
        else{
          spell0 = spell;
          asciiRang0 = asciiRang;
        }
      }
    }

    return null;

  }

  /**
   * 返回字符串的全拼,是汉字转化为全拼,其它字符不进行转换
   * @param cnStr String
   * 字符串
   * @return String
   * 转换成全拼后的字符串
   */
  public static String getFullSpell(String cnStr)
  {
    if(null == cnStr || "".equals(cnStr.trim())){
      return cnStr;
    }

    char[] chars = cnStr.toCharArray();
    StringBuffer retuBuf = new StringBuffer();
    for(int i = 0,Len = chars.length;i < Len;i++){
      int ascii = getCnAscii(chars[i]);
      if(ascii == 0){ //取ascii时出错
        retuBuf.append(chars[i]);
      }
      else{
        String spell = getSpellByAscii(ascii);
        if(spell == null){
          retuBuf.append(chars[i]);
        }
        else{
          retuBuf.append(spell);
        } // end of if spell == null
      } // end of if ascii <= -20400
    } // end of for

    return retuBuf.toString();
  }

  public static String getFirstSpell(String cnStr)
  {
    return null;
  }

  public static void main(String[] args)
  {
    String str = null;
    str = "谢海101普降喜雨";
    System.out.println("Spell=" + CnToSpell.getFullSpell(str));
   
    str = "张牙舞爪》。,";
    System.out.println("Spell=" + CnToSpell.getFullSpell(str));
   
    str = "李鹏,可耻下场。";
    System.out.println("Spell=" + CnToSpell.getFullSpell(str));
   
    str = "猪油,猪八戒。";
    System.out.println("Spell=" + CnToSpell.getFullSpell(str));
  }
}

posted @ 2006-03-16 11:55 邓华的碎碎念 阅读(581) | 评论 (0)编辑 收藏

当在linux服务器上没有装xwindows时, 处理图像时会报
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
这个错.

解决方法:

在tomcat的catalina.sh文件中

找到

# ----- Execute The Requested Command -----------------------------------------
echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

加入

JAVA_OPTS="-Djava.awt.headless=true "

就能解决问题.
posted @ 2006-03-16 11:54 邓华的碎碎念 阅读(124) | 评论 (0)编辑 收藏

hibernate8ide在新版本中已经改名叫console了.  用如下方法运行,可以利用项目中已经建好的配置文件, 不用再配置, 减少了hibernamte8ide出错的机会. 以前直接RUN的时候, 有各种错误出现. 搞得人很头晕的.

下载最新版hibernate-extensions, 解压到相关目录.

在jb的工程中引入console目录下的hibernateconsole.jar, 再引入console\lib目录下的所有jar文件

创建一个StartHibern8IDE.java文件, 拷贝下面的代码,然后run.

参考了一篇hibernate8ide运行在eclipse中的文章.

当然,下面的代码,再eclipse中是一样的用的.

用下面的代码运行,可以解决中文问题.

import java.awt.Font;

import javax.swing.UIManager;

import com.jgoodies.clearlook.ClearLookManager;
import com.jgoodies.clearlook.ClearLookMode;
import com.jgoodies.plaf.plastic.PlasticXPLookAndFeel;


import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.console.*;


public class StartHibern8IDE {

public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();

try {
    if (System.getProperty("sun.awt.exception.handler")==null) {
       System.setProperty("sun.awt.exception.handler", AWTExceptionHandler.class.getName());
    } else {
       System.err.println("could not install AWT handler ;(");
    }
    ClearLookManager.setMode(ClearLookMode.ON);
    UIManager.setLookAndFeel(new PlasticXPLookAndFeel());

 setUIFont (new javax.swing.plaf.FontUIResource("宋体",Font.PLAIN,12));
          
 configuration.configure();

// run

 Start.startWith(configuration);

 } catch (Exception e) { // noop
     e.printStackTrace();
 }

}

public static void setUIFont (javax.swing.plaf.FontUIResource f){
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get (key);
      if (value instanceof javax.swing.plaf.FontUIResource)
        UIManager.put (key, f);
      }
    }
}

 

posted @ 2006-03-16 11:54 邓华的碎碎念 阅读(149) | 评论 (0)编辑 收藏

在1G内存下.用这个参数很管用. 速度感觉加快

eclipse.exe -vmargs -Xverify:none -XX:+UseParallelGC -XX:PermSize=20M -Xms64M -Xmx512M

posted @ 2006-03-16 11:54 邓华的碎碎念 阅读(541) | 评论 (0)编辑 收藏

我们知道,在jbuilder中,编辑xml文件的话, 如果在头部加了dtd, JB会自动去网上下载这个DTD,来验证XML文件, 这功能当然是非

常好的, 但是,给我们造成了速度慢的困扰, 特别是打开xml和保存,修改的时候.

其实在jb中,是可以改变这个速度的. 采用的是地址映射的方法, 把HTTP地址,映射到本地的目录上来.

我是在hibernate的xml文件中实践的

先用flashget 下载 http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd 这个DTD文件. 把他放到硬盘上的一

个目录里,然后在JB里,选择TOOLS, preferences,  然后选xml 下面的 System ID Catalog, 点ADD,加入一个映射

在输入框是里填入http://hibernate.sourceforge.net/ 这代表要把这段网址映射成硬盘上的某个目录, 然后下面选directy, 选择放上面dtd的目录.

当然也可以映射文件. 方法同上,只是remap成file就OK了.

以上方法,是在jbuilderX中通过的

posted @ 2006-03-16 11:53 邓华的碎碎念 阅读(93) | 评论 (0)编辑 收藏

仅列出标题
共5页: 上一页 1 2 3 4 5 下一页