yegucheng

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            9 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

          2007年3月7日 #

               摘要: 圖片縮放功能的實現(這里只實現了圖片縮小功能,放大原理類似)  閱讀全文
          posted @ 2007-12-15 16:06 yegucheng 閱讀(1879) | 評論 (0)編輯 收藏

               摘要: 在weblogic中,不能將 JDBC 存儲配置為使用配置為支持全局事務的 JDBC 數據源  閱讀全文
          posted @ 2007-12-07 21:36 yegucheng 閱讀(2294) | 評論 (0)編輯 收藏

               摘要: 很多筆記本的讀卡器,在2003下都不能識別,使用上面的驅動可以解決這一問題
            閱讀全文
          posted @ 2007-11-11 15:28 yegucheng 閱讀(488) | 評論 (0)編輯 收藏

               摘要: 使用Collections.emptyList()生成的List不支持add方法  閱讀全文
          posted @ 2007-10-29 12:28 yegucheng 閱讀(2461) | 評論 (1)編輯 收藏

          筆者的場景是這樣的,筆者使用code smith作為代碼生成工具,并在Eclipse中做插件開發,code smith天生
          對GB的支持比較弱,只能生成UTF-8編碼,這在Eclipse開發的過程中不會存在問題,但是在使用Eclipse的導出
          功能時,Eclipse底層使用ANT的執行方式,ANT的默認字符集默認使用當前系統的字符集,這時在編譯導出的時候,
          會出現字符無法識別的問題,導致導出或者打包失敗。
           一種方式可以改變Eclipse工程的默認字符集,以及自動生成的ant配置文件中字符集的配置,這對于單個工程是有
          效的,但處理工程間依賴時,被依賴的工程同樣會出現字符集問題,即使被依賴工程設定ant的字符集。
           另一種方式,是手工轉換,講UTF-8的字符集轉換為GBK的,微軟的網站提供了一個批量轉換工具,但是在轉換之后,
          文檔的最前面還會有可能存在多于字符,并導致ant打包失敗
           最后,沒辦法自己寫了一個字符集轉換工具,因為是自己用,所以夠用就行,下面是轉換部分的代碼,實現UTF8到
          GBK的轉換,其他轉換可以對代碼稍作修改。

           
          import org.apache.commons.lang.ArrayUtils;

          public class EncodeRepairTool {
           public static final byte[] bPre = "EFBBBF".getBytes();
           private int i = 0;

           /**
            * @param args
            */
           public static void main(String[] args) {  
            String path = "D:\\eclipse-dev-3.3\\workspace";
            File file = new File(path);
            EncodeRepairTool scanner = new EncodeRepairTool();
            scanner.scanFolder(file);

           }

           

           public void scanFolder(File file) {
            if (file.isDirectory()) {
             File[] files = file.listFiles();
             for (int i = 0; i < files.length; i++) {
              scanFolder(files[i]);
             }
            } else if (file.getName().endsWith(".java")) {
             removePreCode(file);
            }
           }

           private void removePreCode(File file) {
            try {
             FileInputStream fis = new FileInputStream(file);
             int size = fis.available();
             if (size < 24) {
              return;
             }
             i ++ ;
             byte[] bs = new byte[size];
             fis.read(bs);
             byte[] tbs = ArrayUtils.subarray(bs, 0, 3);
             byte[] tbs1 = new byte[] { new Integer(0xEF).byteValue(),
               new Integer(0xBB).byteValue(),
               new Integer(0xBF).byteValue() };
             boolean bol = false;
             if (tbs[0] == tbs1[0] && tbs[1] == tbs1[1] && tbs[2] == tbs1[2]) {
              bol = true;
             }
             fis.close();
             if (!bol) {
              System.out.println("  " + i + " : " + file.getName());
              tbs = bs;
             }
             else {
              System.out.println("**" + i + " : " + file.getName());
              tbs = ArrayUtils.subarray(bs, 3, size);
              
             }   
             InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(tbs), "UTF-8");
             BufferedReader br = new BufferedReader(reader);
             StringBuffer buffer = new StringBuffer();
             String s = br.readLine();
             while (s != null) {
              buffer.append(s);
              buffer.append("\n");
              s =  br.readLine();
             }
             reader.close();
             byte[] nbs = buffer.toString().getBytes("GBK");   
             FileOutputStream fos = new FileOutputStream(file);
             fos.write(nbs);
             fos.flush();
             fos.close();
             
            } catch (FileNotFoundException e) {
             // TODO 自動生成 catch 塊
             e.printStackTrace();
            } catch (IOException e) {
             // TODO 自動生成 catch 塊
             e.printStackTrace();
            }

           }

          }

          posted @ 2007-10-26 10:01 yegucheng 閱讀(2238) | 評論 (5)編輯 收藏

          在使用apache的net包處理Serv-U和x-lighgt時遇到的幾點不同
          進入一個空目錄:
           在serv-U下,調用fTPClient.changeWorkingDirectory("")方法沒有任何問題(指向一個空的目錄)
           在x-light下,調用方法,會返回501信息
          當下載完文件后:
           使用 fTPClient.retrieveFileStream(url)方法下載文件,在serv-U下,可以直接下載下一個文件
           但是在x-light下,調用 fTPClient.retrieveFileStream(url)方法后,
           必須執行 fTPClient.completePendingCommand()方法,關閉當前下載操作,
           才能執行下一個下載任務(在net包的API中有相關的規定)。
           
          posted @ 2007-10-26 09:08 yegucheng 閱讀(742) | 評論 (0)編輯 收藏

               摘要: 在使用TAB型的屬性頁時,設定Section標題的方法  閱讀全文
          posted @ 2007-04-02 15:36 yegucheng 閱讀(1043) | 評論 (0)編輯 收藏

          ??? 經常使用開源產品,開源項目的升級又非常的快,到不同的網站查找源代碼經常是很費時的事情,雖然不難,但是很是瑣碎。
          ? ? 最近在看一篇介紹maven的文檔的時候,看到一個很不錯的網站:www.ibiblio.org,這兒包含了幾乎你用到的所有的開源項目,而且提供maven方式的下載。
          ??? 當然,在平時的使用時,不一定必須使用maven來構建,那就直接手工去找吧,可以在google中輸入如下的字符串(site:www.ibiblio.org maven2 xxx),就可以在該網站找到自己要的開源產品的jar和源碼,其中xxx代表開源產品的名字,例如要找log4j,可以輸入:site:www.ibiblio.org maven2 log4j。
          posted @ 2007-03-30 09:28 yegucheng 閱讀(1559) | 評論 (2)編輯 收藏

          今天看到兩種使用EMF解析.xml為EMF模型的策略:
          一種是通過如下代碼:

          IFileEditorInput?modelFile? = ?(IFileEditorInput)getEditorInput();
          URI?resourceURI?
          = ?URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString());;
          resource? = ?editingDomain.getResourceSet().getResource(resourceURI,? true );
          上面這種方式會引用一個AdapterFactoryEditingDomain類,但我們基于模型做編輯器時,有時并不需要用這個類,例如GEF,它具有自身的EditorDomain。

          另外一種方式是使用EMF模型自動生成的Process,該類一般在模型的Util包下面,引用代碼如下:
          IFileEditorInput?modelFile?=?(IFileEditorInput)getEditorInput();????????
          XMLProcessor?processor?
          =??new?DesignXMLProcessor();????????????
          ?resource?
          =?processor.load(new?InputSource(new?InputStreamReader(modelFile.getFile().getContents(),?"GBK")),?null);
          ????????

          其實,對于EMF而言,上面兩種解釋方式,歸根到底都需要EMF獲得 業務模型相關的解析器,對于第一種方式,EMF是如何獲取到業務模型的解析器呢?主要是通過擴展的方式,擴展定義在模型的plugin.xml中,代碼片斷如下圖所示:
          ??<extension?point="org.eclipse.emf.ecore.extension_parser">
          ????
          <parser?
          ???????type
          ="design"?
          ???????
          class="com.neusoft.report.design.util.DesignResourceFactoryImpl"?/>
          ??
          </extension>

          這樣,解析.xml文件時,EMF從ResourceFactory注冊中,根據相應的type,獲取解析器(DesignResourceFactoryImpl),完成解析。
          posted @ 2007-03-07 13:08 yegucheng 閱讀(1642) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 玛曲县| 喀喇沁旗| 顺义区| 临桂县| 盖州市| 屯门区| 隆回县| 富锦市| 栾川县| 玉林市| 皋兰县| 塘沽区| 乌什县| 隆化县| 嘉定区| 海门市| 蓬莱市| 南通市| 玛纳斯县| 新河县| 哈巴河县| 新丰县| 永平县| 扎囊县| 宜章县| 亳州市| 河东区| 徐闻县| 吉木萨尔县| 贵南县| 新郑市| 曲周县| 罗田县| 唐山市| 汤阴县| 自贡市| 博客| 临猗县| 咸丰县| 惠州市| 华坪县|