Author: rlaidlaw
Date: Sun Apr 21 11:33:28 2013
New Revision: 1470284

URL: http://svn.apache.org/r1470284
Log:
OODT-470: Enabled RSSProductTransferServlet to be configured using an XML 
configuration file.

Added:
    oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml   (with 
props)
Modified:
    oodt/trunk/CHANGES.txt
    
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSConfigMetKeys.java
    
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSProductTransferServlet.java
    oodt/trunk/webapp/fmprod/src/main/resources/cas-product-tomcat-5.5.9.xml

Modified: oodt/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1470284&r1=1470283&r2=1470284&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sun Apr 21 11:33:28 2013
@@ -2,6 +2,8 @@ Apache OODT Change Log
 ======================
 Release 0.6 - Current Development
 --------------------------------------------
+* OODT-470 Enabled RSSProductTransferServlet to be configured using an XML
+configuration file (rlaidlaw)
 
 * OODT-560 XmlStructFactory::getProductTypeMapXmlDocument does not 
   output virtual product types (Varun Ratnakar via mattmann)

Modified: 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSConfigMetKeys.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSConfigMetKeys.java?rev=1470284&r1=1470283&r2=1470284&view=diff
==============================================================================
--- 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSConfigMetKeys.java
 (original)
+++ 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSConfigMetKeys.java
 Sun Apr 21 11:33:28 2013
@@ -30,4 +30,5 @@ package org.apache.oodt.cas.product.rss;
 public interface RSSConfigMetKeys {
 
   public static final String RSS_CONTEXT_CONF_KEY = "filemgr.rssconf.file";
+  public static final String RSS_TRANSFER_CONF_KEY = 
"filemgr.rss-transfer-conf.file";
 }

Modified: 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSProductTransferServlet.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSProductTransferServlet.java?rev=1470284&r1=1470283&r2=1470284&view=diff
==============================================================================
--- 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSProductTransferServlet.java
 (original)
+++ 
oodt/trunk/webapp/fmprod/src/main/java/org/apache/oodt/cas/product/rss/RSSProductTransferServlet.java
 Sun Apr 21 11:33:28 2013
@@ -31,21 +31,22 @@ import javax.xml.transform.TransformerEx
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.logging.Logger;
 import java.util.logging.Level;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.text.ParseException;
 
 //OODT imports
+import static 
org.apache.oodt.cas.product.rss.RSSConfigMetKeys.RSS_TRANSFER_CONF_KEY;
 import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
 import org.apache.oodt.cas.filemgr.structs.exceptions.DataTransferException;
 import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
@@ -75,12 +76,13 @@ public class RSSProductTransferServlet e
     /* our client to the file manager */
     private static XmlRpcFileManagerClient fClient = null;
 
+    /* RSS config */
+    private RSSConfig rssconf;
+
     /* our log stream */
     private Logger LOG = Logger.getLogger(RSSProductTransferServlet.class
             .getName());
 
-    private static final Map NS_MAP = new HashMap();
-
     public static final String COPYRIGHT_BOILER_PLATE = "Copyright 2010: 
Apache Software Foundation";
 
     public static final String RSS_FORMAT_STR = "E, dd MMM yyyy HH:mm:ss z";
@@ -88,10 +90,6 @@ public class RSSProductTransferServlet e
     public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(
             RSS_FORMAT_STR);
 
-    static {
-        NS_MAP.put("cas", "http://oodt.jpl.nasa.gov/1.0/cas";);
-    }
-
     /**
      * <p>
      * Default Constructor
@@ -131,6 +129,17 @@ public class RSSProductTransferServlet e
                     "Unable to initialize file manager url in RSS Servlet: 
[url="
                             + fileManagerUrl + "], Message: " + 
e.getMessage());
         }
+
+        try
+        {
+          rssconf = RSSConfigReader.readConfig(new File(PathUtils
+              .replaceEnvVariables(config.getServletContext().getInitParameter(
+                  (RSS_TRANSFER_CONF_KEY)))));
+        }
+        catch (FileNotFoundException e)
+        {
+          throw new ServletException(e);
+        }
     }
 
     public void doGet(HttpServletRequest req, HttpServletResponse resp)
@@ -172,8 +181,14 @@ public class RSSProductTransferServlet e
 
                 Element rss = XMLUtils.addNode(doc, doc, "rss");
                 XMLUtils.addAttribute(doc, rss, "version", "2.0");
-                XMLUtils.addAttribute(doc, rss, "xmlns:cas", (String) NS_MAP
-                        .get("cas"));
+
+                // add namespace attributes from config file to rss tag
+                for (RSSNamespace namespace : rssconf.getNamespaces())
+                {
+                  XMLUtils.addAttribute(doc, rss,
+                      "xmlns:" + namespace.getPrefix(), namespace.getUri());
+                }
+
                 Element channel = XMLUtils.addNode(doc, rss, "channel");
 
                 XMLUtils.addNode(doc, channel, "title",
@@ -225,19 +240,22 @@ public class RSSProductTransferServlet e
                             XMLUtils.addNode(doc, item, "pubDate",
                                     dateFormatter.format(receivedTime));
                         }
+
+                        // set product transfer metadata
+                        m.addMetadata("BytesTransferred",
+                          "" + status.getBytesTransferred());
+                        m.addMetadata("TotalBytes",
+                          "" + status.getFileRef().getFileSize());
+                        m.addMetadata("PercentComplete",
+                          "" + status.computePctTransferred());
+
                     } catch (CatalogException ignore) {
                     }
 
-                    XMLUtils.addNode(doc, item, "source",
-                            "file manager transfers");
-                    XMLUtils.addNode(doc, item, "cas:source",
-                            "file manager transfers");
-                    XMLUtils.addNode(doc, item, "cas:bytesTransferred", ""
-                            + status.getBytesTransferred());
-                    XMLUtils.addNode(doc, item, "cas:totalBytes", ""
-                            + status.getFileRef().getFileSize());
-                    XMLUtils.addNode(doc, item, "cas:percentComplete", ""
-                            + status.computePctTransferred());
+                    // add additional elements from the RSSConfig
+                    for (RSSTag tag : rssconf.getTags()) {
+                      item.appendChild(RSSUtils.emitRSSTag(tag, m, doc, item));
+                    }
 
                 }
 

Modified: 
oodt/trunk/webapp/fmprod/src/main/resources/cas-product-tomcat-5.5.9.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/main/resources/cas-product-tomcat-5.5.9.xml?rev=1470284&r1=1470283&r2=1470284&view=diff
==============================================================================
--- oodt/trunk/webapp/fmprod/src/main/resources/cas-product-tomcat-5.5.9.xml 
(original)
+++ oodt/trunk/webapp/fmprod/src/main/resources/cas-product-tomcat-5.5.9.xml 
Sun Apr 21 11:33:28 2013
@@ -24,6 +24,7 @@ the License.
   <Parameter name="filemgr.url" value="http://localhost:9000"; override="false" 
/>
   <Parameter name="filemgr.rdfconf.file" value="/path/to/rdfconf.xml" 
override="false"/>
   <Parameter name="filemgr.rssconf.file" value="/path/to/rssconf.xml" 
override="false"/>
+  <Parameter name="filemgr.rss-transfer-conf.file" 
value="/path/to/rss-transfer-conf.xml" override="false"/>
   <Parameter name="filemgr.working.dir" value="/tmp" override="false" />
 
 </Context>

Added: oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml
URL: 
http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml?rev=1470284&view=auto
==============================================================================
--- oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml (added)
+++ oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml Sun Apr 
21 11:33:28 2013
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+  license agreements.  See the NOTICE file distributed with this work for
+  additional information regarding copyright ownership.  The ASF licenses this
+  file to you under the Apache License, Version 2.0 (the "License"); you may 
not
+  use this file except in compliance with the License.  You may obtain a copy 
of
+  the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+  License for the specific language governing permissions and limitations under
+  the License.
+
+  Author: rlaidlaw
+  Description: This file configures the CAS RSS web service for File Manager
+  product transfers.  It allows metadata for a product being transferred to be
+  assigned to RSS compatible tags.
+-->
+<rss:rssconf xmlns:rss="http://oodt.apache.org/ns/rss";>
+
+  <namespace prefix="cas" uri="http://oodt.apache.org/ns/cas"/>
+  <tag name="cas:bytesTransferred" source="[BytesTransferred]"/>
+  <tag name="cas:totalBytes" source="[TotalBytes]"/>
+  <tag name="cas:percentComplete" source="[PercentComplete]"/>
+
+</rss:rssconf>

Propchange: oodt/trunk/webapp/fmprod/src/main/resources/rss-transfer-conf.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to