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

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

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

    空間站

    北極心空

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks
     eXtremeComponents的中文的問(wèn)題,目前知道的就是導(dǎo)出使用中文文件名的亂碼問(wèn)題,eXtremeComponents已經(jīng)默認(rèn)使用UTF來(lái)導(dǎo)出XLS,也已經(jīng)給出了PDF導(dǎo)出的解決方案:最新eXtremeComponents包:支持 PDF中文導(dǎo)出
             網(wǎng)友seno指出可以參照SpringSide的解決方案,對(duì)文件名進(jìn)行toUtf8編碼。不過(guò),在我自己實(shí)際應(yīng)用中,我的一個(gè)應(yīng)用根本不需要進(jìn)行任何形式的修正就能正確地生成正確的文件名輸出,如果我在eXtremeComponents添加了toUtf8導(dǎo)出的文件名反而亂碼。所以現(xiàn)在的問(wèn)題是我什么時(shí)候需要對(duì)文件名進(jìn)行toUtf8編碼?這是這段時(shí)間一直困擾我的問(wèn)題,在網(wǎng)友冷月宮主和MagicYang的幫助,昨天經(jīng)過(guò)一整天的查找測(cè)試找到了一個(gè)暫時(shí)看來(lái)令我比較滿意的解決方案(暫時(shí)沒(méi)有CheckIn): 我對(duì)得到的文件名字符串使用jchardet(http://jchardet.sourceforge.net/)進(jìn)行編碼檢測(cè),如果檢測(cè)編碼是ASCII碼則直接返回原字符串,否則的話是用SpringSide提供的toUtf8方法(比我原來(lái)的簡(jiǎn)潔有效)對(duì)字符串進(jìn)行編碼后再返回新的字符串。對(duì)應(yīng)的代碼如下:
        
    /*
     * 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);
        }
    }
          經(jīng)過(guò)我們?nèi)齻€(gè)人測(cè)試是成功的。歡迎大家?guī)椭鷾y(cè)試。大家如果有任何意見(jiàn)、建議可與我聯(lián)系: xplucky@gmail.com
          壓縮文件只包含: eXtremeComponents.jar eXtremeComponents.tld 和 jchardet.jar
           eXtremeComponents.rar  
    posted on 2008-07-09 08:59 蘆葦 閱讀(441) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): JAVA
    主站蜘蛛池模板: 女bbbbxxxx另类亚洲| 亚洲色婷婷综合开心网| 99久久婷婷免费国产综合精品| 亚洲小说图区综合在线| 亚洲天堂中文资源| 亚洲精品夜夜夜妓女网| 亚洲国产精品综合久久网络| 大学生高清一级毛片免费| 免费A级毛片无码A∨免费| 免费看少妇高潮成人片| 一个人看的免费观看日本视频www| 亚洲日韩精品国产3区| 亚洲制服丝袜第一页| 亚洲综合综合在线| 亚洲成AV人在线观看天堂无码| 久久精品国产亚洲一区二区三区| 日本免费一区二区三区最新| 黄页网站在线观看免费高清| 国产妇乱子伦视频免费| 亚洲网站免费观看| 3344永久在线观看视频免费首页| 国内少妇偷人精品视频免费| 中国在线观看免费的www| AAAAA级少妇高潮大片免费看| 成人无码精品1区2区3区免费看| 免费在线观看一区| 青青青视频免费观看| 四虎精品成人免费视频| 九九久久精品国产免费看小说 | 成年网在线观看免费观看网址| 日韩国产欧美亚洲v片| 亚洲中文字幕无码中文字| 亚洲综合av一区二区三区不卡| 中文有码亚洲制服av片| 亚洲精品9999久久久久无码| 日韩欧美亚洲中文乱码| 曰批免费视频播放免费 | 中文字幕中韩乱码亚洲大片| 亚洲人色婷婷成人网站在线观看 | 麻豆成人久久精品二区三区免费| 桃子视频在线观看高清免费视频|