鄧華

          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 鄧華的碎碎念 閱讀(731) | 評論 (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 鄧華的碎碎念 閱讀(264) | 評論 (0)編輯 收藏

          碰到include亂碼的情況下.

          根據當時頁面情況加入

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

          這個,在include頁面編譯的時候,可以明確指定該頁面用utf-8的編碼編譯
          posted @ 2006-03-16 11:57 鄧華的碎碎念 閱讀(365) | 評論 (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 鄧華的碎碎念 閱讀(132) | 評論 (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 鄧華的碎碎念 閱讀(442) | 評論 (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 鄧華的碎碎念 閱讀(592) | 評論 (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 鄧華的碎碎念 閱讀(135) | 評論 (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 鄧華的碎碎念 閱讀(155) | 評論 (0)編輯 收藏

          在1G內存下.用這個參數很管用. 速度感覺加快

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

          posted @ 2006-03-16 11:54 鄧華的碎碎念 閱讀(547) | 評論 (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 鄧華的碎碎念 閱讀(103) | 評論 (0)編輯 收藏

          僅列出標題
          共5頁: 上一頁 1 2 3 4 5 下一頁 
          主站蜘蛛池模板: 安徽省| 观塘区| 寿宁县| 特克斯县| 怀安县| 临洮县| 易门县| 定西市| 南安市| 香格里拉县| 册亨县| 万荣县| 屏南县| 长沙县| 禄丰县| 贵南县| 寻甸| 阿拉善盟| 邻水| 盈江县| 海晏县| 白水县| 伊宁市| 双鸭山市| 遂昌县| 祁门县| 杨浦区| 巴林右旗| 五峰| 宝丰县| 萝北县| 张掖市| 益阳市| 五常市| 巴青县| 漠河县| 常宁市| 绥德县| 体育| 竹山县| 眉山市|