Example #1
0
 public static String sanitize(String filename, String mimeType) {
   filename = sanitize(filename);
   if (mimeType == null) return filename;
   if (filename.indexOf('.') >= 0) {
     String oldExt = filename.substring(filename.lastIndexOf('.'));
     if (DefaultMIMETypes.isValidExt(mimeType, oldExt)) return filename;
   }
   String defaultExt = DefaultMIMETypes.getExtension(filename);
   if (defaultExt == null) return filename;
   else return filename + '.' + defaultExt;
 }
Example #2
0
 /** Create a DirPutFile from a SimpleFieldSet. */
 public static DirPutFile create(
     SimpleFieldSet subset, String identifier, boolean global, BucketFactory bf)
     throws MessageInvalidException {
   String name = subset.get("Name");
   if (name == null)
     throw new MessageInvalidException(
         ProtocolErrorMessage.MISSING_FIELD, "Missing field Name", identifier, global);
   String contentTypeOverride = subset.get("Metadata.ContentType");
   if (contentTypeOverride != null
       && (!contentTypeOverride.equals(""))
       && !DefaultMIMETypes.isPlausibleMIMEType(contentTypeOverride)) {
     throw new MessageInvalidException(
         ProtocolErrorMessage.BAD_MIME_TYPE,
         "Bad MIME type in Metadata.ContentType",
         identifier,
         global);
   }
   String type = subset.get("UploadFrom");
   if ((type == null) || type.equalsIgnoreCase("direct")) {
     return DirectDirPutFile.create(name, contentTypeOverride, subset, identifier, global, bf);
   } else if (type.equalsIgnoreCase("disk")) {
     return DiskDirPutFile.create(name, contentTypeOverride, subset, identifier, global);
   } else if (type.equalsIgnoreCase("redirect")) {
     return RedirectDirPutFile.create(name, contentTypeOverride, subset, identifier, global);
   } else {
     throw new MessageInvalidException(
         ProtocolErrorMessage.INVALID_FIELD,
         "Unsupported or unknown UploadFrom: " + type,
         identifier,
         global);
   }
 }
Example #3
0
 public static String sanitize(String filename, String mimeType) {
   filename = sanitize(filename);
   if (mimeType == null) return filename;
   return DefaultMIMETypes.forceExtension(filename, mimeType);
 }
Example #4
0
 protected static String guessMIME(String name) {
   // Guess it just from the name
   return DefaultMIMETypes.guessMIMEType(name, true);
 }