Author: riverma
Date: Mon Jul 23 18:32:57 2012
New Revision: 1364745

URL: http://svn.apache.org/viewvc?rev=1364745&view=rev
Log:
OODT-466 resolution: Allow MIME type (HTTP content-type) configurability for 
product handlers' generated content

Modified:
    oodt/trunk/product/src/main/conf/ofsn-ps.xml
    
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNFileHandler.java
    
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java

Modified: oodt/trunk/product/src/main/conf/ofsn-ps.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/product/src/main/conf/ofsn-ps.xml?rev=1364745&r1=1364744&r2=1364745&view=diff
==============================================================================
--- oodt/trunk/product/src/main/conf/ofsn-ps.xml (original)
+++ oodt/trunk/product/src/main/conf/ofsn-ps.xml Mon Jul 23 18:32:57 2012
@@ -72,6 +72,13 @@ FIXME: Change XML namespace URI for oodt
        
        where some name is the name of the configuration property and some 
value is the
        value of the configuration property.
+       
+       Optional properties (for GET handlers):
+       
+       property name: mimeType
+       property value: the desired MIME type (also referred to as 
content-type) a handler should return
+       content as (eg. "text/plain"). More formally, any value of the form 
+       "type/subtype(; parameter=...)*" as defined in RFC 2045.
     -->
     
         
@@ -159,6 +166,10 @@ FIXME: Change XML namespace URI for oodt
    -->
    
    <handler name="MD5" type="get"
-       class="org.apache.oodt.product.handlers.ofsn.MD5GetHandler"/>
+       class="org.apache.oodt.product.handlers.ofsn.MD5GetHandler">
+       
+       <property name="mimeType" value="text/plain"/>
+       
+   </handler>
 
 </oodt:ofsn>

Modified: 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNFileHandler.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNFileHandler.java?rev=1364745&r1=1364744&r2=1364745&view=diff
==============================================================================
--- 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNFileHandler.java
 (original)
+++ 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNFileHandler.java
 Mon Jul 23 18:32:57 2012
@@ -31,11 +31,13 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 //APACHE imports
+import org.apache.tika.mime.MediaType;
 import org.apache.tika.mime.MimeTypesFactory;
 
 //OODT imports
 import org.apache.oodt.commons.xml.XMLUtils;
 import org.apache.oodt.product.handlers.ofsn.metadata.OFSNMetKeys;
+import org.apache.oodt.product.handlers.ofsn.metadata.OFSNXMLConfigMetKeys;
 import org.apache.oodt.product.handlers.ofsn.metadata.OFSNXMLMetKeys;
 import org.apache.oodt.product.handlers.ofsn.metadata.XMLQueryMetKeys;
 import org.apache.oodt.product.handlers.ofsn.util.OFSNObjectFactory;
@@ -57,7 +59,7 @@ import org.apache.oodt.xmlquery.XMLQuery
  * @version $Revision$
  */
 public class OFSNFileHandler implements LargeProductQueryHandler,
-    XMLQueryMetKeys, OFSNXMLMetKeys, OFSNMetKeys {
+    XMLQueryMetKeys, OFSNXMLMetKeys, OFSNMetKeys, OFSNXMLConfigMetKeys {
 
   private static final Logger LOG = Logger.getLogger(OFSNFileHandler.class
       .getName());
@@ -130,12 +132,28 @@ public class OFSNFileHandler implements 
     } else if (isGetCmd(cmd)) {
       OFSNGetHandler handler = getGetHandler(cmd, cfg.getClassName());
       String rtAndPath = cmd + CMD_SEPARATOR + realPath;
-
+      String mimeType;
+      
+      // check for and use mimetype conf property if available
+      if (cfg.getHandlerConf().containsKey(PROPERTY_MIMETYPE_ATTR)) {
+         MediaType mediaType = MediaType.parse(cfg.getHandlerConf()
+                         .getProperty(PROPERTY_MIMETYPE_ATTR));
+         if (mediaType == null) {
+                 LOG.log(Level.WARNING, "MIME type ["
+                                 
+cfg.getHandlerConf().getProperty(PROPERTY_MIMETYPE_ATTR)+"] specified "
+                                 +"for handler ["+cfg.getClassName()+"] 
invalid. Defaulting to MIME type ["
+                                 +MediaType.OCTET_STREAM.toString()+"]");
+                 mediaType = MediaType.OCTET_STREAM;
+         }
+         mimeType = mediaType.toString();
+      } else { // use default mimetype of product on disk
+         mimeType = MimeTypesFactory.create().getMimeType(new 
File(realPath)).getName();
+      }
+      
       xmlQuery.getResults().add(
-          new LargeResult(/* id */rtAndPath,/* mimeType */
-          MimeTypesFactory.create().getMimeType(new File(realPath)).getName(), 
/* profileID */
-          null, /* resourceID */new File(realPath).getName(),
-              Collections.EMPTY_LIST, handler.sizeOf(realPath)));
+          new LargeResult(/* id */rtAndPath,/* mimeType */ mimeType, /* 
profileID */null, 
+                         /* resourceID */new File(realPath).getName(), 
Collections.EMPTY_LIST, 
+                         handler.sizeOf(realPath)));
     } else {
       throw new ProductException("return type: [" + cmd + "] is unsupported!");
     }

Modified: 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java?rev=1364745&r1=1364744&r2=1364745&view=diff
==============================================================================
--- 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java
 (original)
+++ 
oodt/trunk/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java
 Mon Jul 23 18:32:57 2012
@@ -50,5 +50,8 @@ public interface OFSNXMLConfigMetKeys {
   public static final String PROPERTY_NAME_ATTR = "name";
 
   public static final String PROPERTY_VALUE_ATTR = "value";
+  
+  /* optional handler property attributes supported by all handlers */
+  public static final String PROPERTY_MIMETYPE_ATTR = "mimeType"; 
 
 }


Reply via email to