Index: contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileImportCommand.java =================================================================== --- contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileImportCommand.java (revision 240307) +++ contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileImportCommand.java (working copy) @@ -19,6 +19,7 @@ import javax.jcr.Node; import java.io.InputStream; import java.util.Calendar; +import org.apache.log4j.Logger; /** * This Class implements an import command that creates a "nt:resource" node or @@ -26,11 +27,13 @@ * data as binary property. It further sets the following properties: * */ public class FileImportCommand extends AbstractImportCommand { + private static final Logger log = Logger.getLogger(FileImportCommand.class); /** * The name of the nodetype for the resource node. Default: nt:resource @@ -52,7 +55,10 @@ Node content = parentNode.hasNode(JCR_CONTENT) ? parentNode.getNode(JCR_CONTENT) : parentNode.addNode(JCR_CONTENT, resourceNodeType); - content.setProperty(JCR_MIMETYPE, ctx.getContentType()); + content.setProperty(JCR_MIMETYPE, + parseContentType(ctx.getContentType())); + content.setProperty(JCR_ENCODING, + parseContentCharset(ctx.getContentType())); content.setProperty(JCR_DATA, in); Calendar lastMod = Calendar.getInstance(); if (ctx.getModificationTime() != 0) { @@ -80,4 +86,48 @@ public boolean canHandle(String contentType) { return true; } + + /** + * Returns the main media type from a MIME Content-Type + * specification. + */ + protected String parseContentType(String contentType) { + if (contentType == null) { + return null; + } + // strip any parameters + int semi = contentType.indexOf(";"); + if (semi == -1) { + return contentType; + } + return contentType.substring(0, semi); + } + + /** + * Returns the charset parameter of a MIME Content-Type + * specification, or null if the parameter is not + * included. + */ + protected String parseContentCharset(String contentType) { + if (contentType == null) { + return null; + } + // find the charset parameter + int equal = contentType.indexOf("charset="); + if (equal == -1) { + return null; + } + String charset = contentType.substring(equal + 8); + // get rid of any other parameters that might be specified + // after the charset + int semi = charset.indexOf(";"); + if (semi != -1) { + charset = charset.substring(0, semi); + } + // strip off enclosing quotes + if (charset.startsWith("\"") || charset.startsWith("'")) { + charset = charset.substring(1, charset.length() - 1); + } + return charset; + } }