r1131 - xwiki/trunk/src/main/java/com/xpn/xwiki/web

Ludovic Dubost ludovic at users.forge.objectweb.org
Thu Aug 10 20:22:33 CEST 2006


Author: ludovic
Date: 2006-08-10 20:22:33 +0200 (Thu, 10 Aug 2006)
New Revision: 1131

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/DownloadAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
Log:
Reverted a change in setContentLength that would not work in non UTF8 environments.
Transform + into spaces in attachment names when downloading them

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/DownloadAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/DownloadAction.java	2006-08-10 16:09:03 UTC (rev 1130)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/DownloadAction.java	2006-08-10 18:22:33 UTC (rev 1131)
@@ -1,31 +1,32 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author moghrabix
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author moghrabix
+ * @author sdumitriu
+ */
 package com.xpn.xwiki.web;
 
 import java.io.IOException;
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.doc.XWikiAttachment;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.plugin.XWikiPluginManager;
@@ -60,6 +61,8 @@
         String mimetype = attachment.getMimeType(context);
         response.setContentType(mimetype);
 
+        String ofilename = XWiki.getURLEncoded(attachment.getFilename()).replaceAll("\\+", " ");
+        response.addHeader("Content-disposition", "attachment; filename=\"" +  ofilename + "\"");
         response.setDateHeader("Last-Modified", attachment.getDate().getTime());
         // Sending the content of the attachment
         byte[] data = attachment.getContent(context);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java	2006-08-10 16:09:03 UTC (rev 1130)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java	2006-08-10 18:22:33 UTC (rev 1131)
@@ -108,10 +108,9 @@
             if (context.getResponse() instanceof XWikiServletResponse) {
                 // Set the content length to the numnber of bytes, not the
                 // string length, so as to handle multi-byte encodings
-                try{
-                    response.setContentLength(content.getBytes("UTF-8").length);
+
+                response.setContentLength(content.getBytes().length);
             }
-                  catch(UnsupportedEncodingException ex){response.setContentLength(content.getBytes().length);}            }
 
             try {
                 if (write)





More information about the Xwiki-notifications mailing list