Partial fix for AWC-999: Content upload guesses character encoding and offers the user the chance to change it.

TODO: Fix the "Modify Content Properties" to include the encoding as a changeable option.

Modified other entry points of content into the system.  All calls to ContentWriter.setEncoding("UTF-8") need some serious examination.
It is no longer necessary to assume anything about the encoding.  The worst case scenario is that we guess the encoding from the stream
without giving the user the chance to change it.  This works for most non-interactive scenarios like CIFS, WebDAV and FTP, now.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6113 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-26 21:48:19 +00:00
parent 0dd05fe40f
commit e29e24e761
16 changed files with 528 additions and 17 deletions

View File

@@ -25,6 +25,8 @@
package org.alfresco.web.bean.ajax;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URLDecoder;
import java.util.HashMap;
@@ -125,8 +127,31 @@ public class FileUploadBean
NodeRef containerRef = pathToNodeRef(fc, currentPath);
if (containerRef != null)
{
// Try and extract metadata from the file
// Guess the mimetype
String mimetype = Repository.getMimeTypeForFileName(fc, filename);
// Now guess the encoding
String encoding = "UTF-8";
InputStream is = null;
try
{
is = new FileInputStream(file);
encoding = Repository.guessEncoding(fc, is, mimetype);
}
catch (Throwable e)
{
// Bad as it is, it's not terminal
logger.error("Failed to guess character encoding of file: " + file, e);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e) {}
}
}
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(file);
cr.setMimetype(mimetype);
@@ -170,7 +195,7 @@ public class FileUploadBean
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.setEncoding("UTF-8");
writer.setEncoding(encoding);
writer.putContent(file);
}
}