<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    空間站

    北極心空

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks
     eXtremeComponents的中文的問題,目前知道的就是導出使用中文文件名的亂碼問題,eXtremeComponents已經默認使用UTF來導出XLS,也已經給出了PDF導出的解決方案:最新eXtremeComponents包:支持 PDF中文導出
             網友seno指出可以參照SpringSide的解決方案,對文件名進行toUtf8編碼。不過,在我自己實際應用中,我的一個應用根本不需要進行任何形式的修正就能正確地生成正確的文件名輸出,如果我在eXtremeComponents添加了toUtf8導出的文件名反而亂碼。所以現在的問題是我什么時候需要對文件名進行toUtf8編碼?這是這段時間一直困擾我的問題,在網友冷月宮主和MagicYang的幫助,昨天經過一整天的查找測試找到了一個暫時看來令我比較滿意的解決方案(暫時沒有CheckIn): 我對得到的文件名字符串使用jchardet(http://jchardet.sourceforge.net/)進行編碼檢測,如果檢測編碼是ASCII碼則直接返回原字符串,否則的話是用SpringSide提供的toUtf8方法(比我原來的簡潔有效)對字符串進行編碼后再返回新的字符串。對應的代碼如下:
        
    /*
     * Copyright 2004 original author or authors.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *    
    http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     
    */
    package org.extremecomponents.table.filter;

    import org.apache.commons.lang.StringUtils;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.extremecomponents.table.context.Context;
    import org.extremecomponents.table.core.TableConstants;
    import org.mozilla.intl.chardet.nsDetector;
    import org.mozilla.intl.chardet.nsICharsetDetectionObserver;
    import org.mozilla.intl.chardet.nsPSMDetector;

    /**
     * 
    @author Jeff Johnston
     
    */
    public final class ExportFilterUtils {
        
    private static Log logger = LogFactory.getLog(ExportFilterUtils.class);
        
    public static boolean found = false;

        
    private ExportFilterUtils() {
        }

        
    public static boolean isExported(Context context) {
            
    return StringUtils.isNotBlank(getTableId(context));
        }

        
    public static String getExportFileName(Context context) {

            String tableId 
    = getTableId(context);

            
    if (StringUtils.isNotBlank(tableId)) {
                String exportFileNameStr 
    = tableId + "_" + TableConstants.EXPORT_FILE_NAME;
                String exportFileName 
    = verifyEncoding(context.getParameter(exportFileNameStr));

                
    if (logger.isDebugEnabled()) {
                    logger.debug(
    "eXtremeTable export file name [" + exportFileNameStr + "] is [" + exportFileName + "]");
                }

                
    return exportFileName;
            }

            
    return null;
        }

        
    private static String verifyEncoding(String exportFileName) {
            nsDetector det 
    = new nsDetector(nsPSMDetector.ALL);
            det.Init(
    new nsICharsetDetectionObserver() {
                
    public void Notify(String charset) {
                    ExportFilterUtils.found 
    = true;
                }
            });

            
    boolean done = false;
            
    boolean isAscii = true;
            
    byte[] buf = exportFileName.getBytes();
            
    for (int i = 0; i < buf.length; i++) {
                
    if (isAscii)
                    isAscii 
    = det.isAscii(buf, i);
                
    if (!isAscii && !done)
                    done 
    = det.DoIt(buf, i, false);
            }
            det.DataEnd();

            
    if (isAscii) {
                
    return exportFileName;
            }
            
    return toUtf8(exportFileName);

        }

        
    public static String toUtf8(String src) {
            
    byte[] b = src.getBytes();
            
    char[] c = new char[b.length];
            
    for (int i = 0; i < b.length; i++) {
                c[i] 
    = (char) (b[i] & 0x00FF);
            }
            
    return new String(c);
        }

        
    /**
         * There can only be one table instance (tableId) per form. If the instance
         * variable exists that means there is an export being done.
         *
         * 
    @param context
         * 
    @return
         
    */
        
    public static String getTableId(Context context) {
            
    return context.getParameter(TableConstants.EXPORT_TABLE_ID);
        }
    }
          經過我們三個人測試是成功的。歡迎大家幫助測試。大家如果有任何意見、建議可與我聯系: xplucky@gmail.com
          壓縮文件只包含: eXtremeComponents.jar eXtremeComponents.tld 和 jchardet.jar
           eXtremeComponents.rar  
    posted on 2008-07-09 08:59 蘆葦 閱讀(441) 評論(0)  編輯  收藏 所屬分類: JAVA
    主站蜘蛛池模板: 亚洲国产午夜中文字幕精品黄网站 | 亚洲AV无码一区二区三区性色| 深夜国产福利99亚洲视频| 国产乱妇高清无乱码免费| 亚洲黄色在线观看视频| 国产乱子伦片免费观看中字| 免费精品99久久国产综合精品| 亚洲一区二区三区免费在线观看| 亚洲Av无码国产情品久久 | 四虎国产成人永久精品免费| 亚洲国产精品无码观看久久| 亚洲成AV人在线观看天堂无码| 四虎成人免费观看在线网址| a级在线观看免费| 精品亚洲国产成人av| 老汉色老汉首页a亚洲| 亚洲国产精品尤物YW在线观看 | 亚洲精品成人av在线| 国产一区二区三区免费视频 | a级毛片无码免费真人| 中文成人久久久久影院免费观看 | 久久www免费人成看国产片| 亚洲首页国产精品丝袜| 亚洲中文字幕在线乱码| 色www永久免费视频| 91热成人精品国产免费| 丰满人妻一区二区三区免费视频| 亚洲精品无码mⅴ在线观看| 亚洲欧洲一区二区| 国产成人高清亚洲| 国产福利免费观看| 一个人看www在线高清免费看| 四虎成人精品永久免费AV| 91在线视频免费观看| 污视频网站免费观看| 在线a亚洲老鸭窝天堂av高清| 亚洲国产综合专区电影在线| 国产成人精品日本亚洲| 亚洲欧洲日产国码高潮αv| 国产精品免费一级在线观看| 日韩一区二区a片免费观看|