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

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

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

    幸せのちから

    平凡的世界
    看似平常實(shí)崎嶇
    成如容易卻艱辛

    eXtremeComponents導(dǎo)出時(shí)的中文文件名問題

    ??? ??? eXtremeComponents的中文的問題,目前知道的就是導(dǎo)出使用中文文件名的亂碼問題,eXtremeComponents已經(jīng)默認(rèn)使用UTF來導(dǎo)出XLS,也已經(jīng)給出了PDF導(dǎo)出的解決方案:最新eXtremeComponents包:支持 PDF中文導(dǎo)出
    ??? ???? 網(wǎng)友seno指出可以參照SpringSide的解決方案,對文件名進(jìn)行toUtf8編碼。不過,在我自己實(shí)際應(yīng)用中,我的一個(gè)應(yīng)用根本不需要進(jìn)行任何形式的修正就能正確地生成正確的文件名輸出,如果我在eXtremeComponents添加了toUtf8導(dǎo)出的文件名反而亂碼。所以現(xiàn)在的問題是我什么時(shí)候需要對文件名進(jìn)行toUtf8編碼?這是這段時(shí)間一直困擾我的問題,在網(wǎng)友冷月宮主和MagicYang的幫助,昨天經(jīng)過一整天的查找測試找到了一個(gè)暫時(shí)看來令我比較滿意的解決方案(暫時(shí)沒有CheckIn): 我對得到的文件名字符串使用jchardet(http://jchardet.sourceforge.net/)進(jìn)行編碼檢測,如果檢測編碼是ASCII碼則直接返回原字符串,否則的話是用SpringSide提供的toUtf8方法(比我原來的簡潔有效)對字符串進(jìn)行編碼后再返回新的字符串。對應(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)過我們?nèi)齻€(gè)人測試是成功的。歡迎大家?guī)椭鷾y試。大家如果有任何意見、建議可與我聯(lián)系: xplucky@gmail.com
    ????? 壓縮文件只包含: eXtremeComponents.jar eXtremeComponents.tld 和 jchardet.jar
    ?????? eXtremeComponents.rar??

    posted on 2006-04-08 18:03 Lucky 閱讀(3014) 評(píng)論(14)  編輯  收藏 所屬分類: extremeComponents

    評(píng)論

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-04-08 21:07 江南白衣

    期望能盡快將此特性改進(jìn)核心版本里,springside就可以去掉對et的擴(kuò)展了:)  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-04-09 14:58 xplucky

    我也想在eXtremeComponents正式發(fā)布之前將此特性納入核心版本,所以希望大家能幫助測試一下,看看會(huì)不會(huì)有別的暫時(shí)還沒有想到的問題。  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-04-11 12:43 Ivan Chen

    這里有必要搞一個(gè)自己的toUtf8方法嗎?直接用URLEncoder.encode也可以啊。  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-04-11 12:53 xplucky

    @Ivan Chen
    呵呵,如果你能給我一個(gè)示例的話那會(huì)更好。
      回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-11-08 16:30 dodo

    請問如何用eXtremeComponents實(shí)現(xiàn)點(diǎn)擊表頭,按中文拼音排序的功能?  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-11-09 11:46 yaolin

    我只是把ExportFilterUtils中的

    exportFileName = context.getParameter(exportFileNameStr);

    改成:

    try {
    exportFileName = URLEncoder.encode(context
    .getParameter(exportFileNameStr), DEFAULT_ENCODING);
    } catch (UnsupportedEncodingException e) {
    exportFileName = context.getParameter(exportFileNameStr);
    logger.error(e);
    }

    就好用了。  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-11-09 12:09 yaolin

    哦,補(bǔ)充一句,那個(gè)DEFAULT_ENCODING實(shí)在開頭定義的:

    private static final String DEFAULT_ENCODING = "UTF-8";  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-11-23 17:40

    我測試不行嗎,“業(yè)務(wù)室名稱”文件名變成CA4H2V41  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2006-11-23 17:53

    兩位,怎么偶試都不行呢

      回復(fù)  更多評(píng)論   

    # 無法導(dǎo)出xls文件 2007-06-01 15:42 sweetleaf

    我在appfuse中,試著使用eXtremeComponents的標(biāo)簽庫,test.jsp頁面能正常顯示,但是加入<ec:exportXls
    fileName="dd.xls"
    tooltip="Export Excel"
    text="XLS"
    />后,點(diǎn)擊導(dǎo)出xls的圖標(biāo),頁面跳轉(zhuǎn)到一個(gè)空頁面,名稱也為test.jsp,無任何內(nèi)容顯示,請問,這是怎么回事?
      回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2007-06-29 18:44 peterwillcn

    @sweetleaf
    需要在web.xml文件中加入eXtremeComponents的導(dǎo)出過濾器的配置,內(nèi)容如下:

    <filter> <filter-name>eXtremeExport</filter-name> <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class> <init-param> <param-name>responseHeadersSetBeforeDoFilter</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>eXtremeExport</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
    這樣篩選功能就變成亂碼了  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2009-01-06 17:30 Ivan Chen(西濱)

    toUtf8在ie7下出錯(cuò)。  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2009-05-13 20:01 jti

    導(dǎo)出excel時(shí),數(shù)據(jù)列長度過長,導(dǎo)致顯示為 科學(xué)技術(shù)法,請問如何解決這種問題?  回復(fù)  更多評(píng)論   

    # re: eXtremeComponents導(dǎo)出時(shí)的中文文件名問題 2009-05-14 00:05 Lucky

    這個(gè)項(xiàng)目已經(jīng)快3年沒有維護(hù)了,建議你看看GT-grid http://ecside.group.javaeye.com/  回復(fù)  更多評(píng)論   

    <2006年4月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    30123456

    導(dǎo)航

    隨筆分類(125)

    文章分類(5)

    日本語

    搜索

    積分與排名

    最新隨筆

    最新評(píng)論

    主站蜘蛛池模板: 亚洲国产精品久久久天堂| 情侣视频精品免费的国产| 久久久久亚洲精品成人网小说| jizz免费在线影视观看网站| 亚洲成AV人网址| 国产裸体美女永久免费无遮挡| 丝袜熟女国偷自产中文字幕亚洲| eeuss草民免费| 亚洲国产精品无码久久久蜜芽| 无码午夜成人1000部免费视频| 日韩精品一区二区亚洲AV观看| 91福利视频免费| 亚洲精品国产日韩| 一级毛片直播亚洲| 精品无码一级毛片免费视频观看| 亚洲精品成人片在线观看精品字幕 | 18观看免费永久视频| 亚洲天堂中文字幕在线观看| 成年女人免费视频播放体验区| 亚洲AV无码成人网站在线观看| 亚洲国产精品毛片av不卡在线| 好吊色永久免费视频大全| 久久久久亚洲AV无码专区体验| 免费v片在线观看视频网站| 亚洲砖码砖专无区2023| 免费大片在线观看网站| 永久免费av无码入口国语片| 91亚洲导航深夜福利| 永久久久免费浮力影院| 99在线免费视频| 国产精品亚洲精品青青青| 亚洲国产午夜福利在线播放| 无码av免费网站| 亚洲精品无码不卡在线播放| 精品国产亚洲男女在线线电影| 日本免费人成视频在线观看| 亚洲精品无码久久久久秋霞 | 日本不卡在线观看免费v| 国偷自产一区二区免费视频| 亚洲国产系列一区二区三区| 亚洲一区二区三区偷拍女厕 |