mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -25,6 +25,8 @@
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -32,6 +34,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
@@ -155,17 +158,13 @@ public class UploadContentServlet extends BaseServlet
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the encoding
|
||||
String encoding = req.getParameter(ARG_ENCODING);
|
||||
if (encoding == null || encoding.length() == 0)
|
||||
{
|
||||
encoding = "UTF-8";
|
||||
}
|
||||
|
||||
// get the services we need to retrieve the content
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
ContentService contentService = serviceRegistry.getContentService();
|
||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||
MimetypeService mimetypeService = serviceRegistry.getMimetypeService();
|
||||
|
||||
InputStream inputStream = req.getInputStream();
|
||||
|
||||
// Sort out the mimetype
|
||||
String mimetype = req.getParameter(ARG_MIMETYPE);
|
||||
@@ -188,6 +187,16 @@ public class UploadContentServlet extends BaseServlet
|
||||
}
|
||||
}
|
||||
|
||||
// Get the encoding
|
||||
String encoding = req.getParameter(ARG_ENCODING);
|
||||
if (encoding == null || encoding.length() == 0)
|
||||
{
|
||||
// Get the encoding
|
||||
ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
|
||||
Charset charset = charsetFinder.getCharset(inputStream, mimetype);
|
||||
encoding = charset.name();
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
if (nodeRef != null) {logger.debug("Found NodeRef: " + nodeRef.toString());}
|
||||
|
Reference in New Issue
Block a user