You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by yo...@apache.org on 2006/06/26 20:14:55 UTC

svn commit: r417265 [1/6] - in /lucene/java/trunk/contrib/gdata-server: ./ lib/ src/java/ src/java/org/apache/lucene/gdata/server/ src/java/org/apache/lucene/gdata/server/registry/ src/java/org/apache/lucene/gdata/servlet/ src/java/org/apache/lucene/gd...

Author: yonik
Date: Mon Jun 26 11:14:53 2006
New Revision: 417265

URL: http://svn.apache.org/viewvc?rev=417265&view=rev
Log:
gdata dev update from Simon 2006-06-06

Added:
    lucene/java/trunk/contrib/gdata-server/lib/commons-beanutils.jar   (with props)
    lucene/java/trunk/contrib/gdata-server/lib/commons-collections-3.2.jar   (with props)
    lucene/java/trunk/contrib/gdata-server/lib/commons-digester-1.7.jar   (with props)
Modified:
    lucene/java/trunk/contrib/gdata-server/build.xml
    lucene/java/trunk/contrib/gdata-server/src/java/lucenestorage.properties.xml
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataEntityBuilder.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataRequest.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataResponse.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataService.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/Service.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceException.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceFactory.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/DataBuilderException.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/FeedInstanceConfigurator.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/GDataServerRegistry.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryBuilder.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryContextListener.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/package.html
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractGdataRequestHandler.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultDeleteHandler.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultGetHandler.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultInsertHandler.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultRequestHandlerFactory.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultUpdateHandler.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestHandlerFactory.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/IDGenerator.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/Storage.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/StorageController.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/StorageFactory.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageBuffer.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreController.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageEntryWrapper.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageImplementation.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageModifier.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java
    lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/configuration/StorageConfigurator.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataRequest.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataResponse.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestFeedRegistry.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestGDataEntityBuilder.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageModifier.java
    lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/TestStorageQuery.java
    lucene/java/trunk/contrib/gdata-server/webroot/WEB-INF/web.xml

Modified: lucene/java/trunk/contrib/gdata-server/build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/build.xml?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/build.xml (original)
+++ lucene/java/trunk/contrib/gdata-server/build.xml Mon Jun 26 11:14:53 2006
@@ -16,7 +16,11 @@
         <pathelement location="lib/gdata-client-1.0.jar" /> 
         <pathelement location="lib/commons-logging-1.1.jar" /> 
         <pathelement location="lib/commons-jxpath-1.2.jar" /> 
-        <pathelement location="lib/je.jar" /> 
+        <pathelement location="lib/commons-digester-1.7.jar" /> 
+        <pathelement location="lib/commons-beanutils.jar" /> 
+        <pathelement location="lib/commons-collections-3.2.jar" /> 
+
+  
          
          
     </path> 
@@ -36,15 +40,19 @@
      <target name="war-gdata" depends="prepare-dist"> 
          <echo>Distributing GData War </echo> 
         <war destfile="${dist.dir}/${gdata.war.name}.war" 
-             webxml="webroot/WEB-INF/web.xml"> 
+             webxml="webroot/WEB-INF/web.xml" > 
+        	<metainf dir="webroot/meta-inf"/>
+        		
+
         <fileset dir="webroot" excludes="WEB-INF/web.xml"/> 
- 
             <lib dir="${gdata.lib.dir}" includes="commons-logging-1.1.jar"/> 
             <lib dir="${gdata.lib.dir}" includes="gdata-client-1.0.jar"/> 
- 
+        	<lib dir="${gdata.lib.dir}" includes="commons-digester-1.7.jar" /> 
+        	<lib dir="${gdata.lib.dir}" includes="commons-beanutils.jar" /> 
+        	<lib dir="${gdata.lib.dir}" includes="commons-collections-3.2.jar" /> 
         <lib dir="${build.dir}" includes="${final.name}.jar"/> 
         <lib file="${lucene.jar}" /> 
         </war> 
       </target> 
- 
+
 </project> 

Added: lucene/java/trunk/contrib/gdata-server/lib/commons-beanutils.jar
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/lib/commons-beanutils.jar?rev=417265&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lucene/java/trunk/contrib/gdata-server/lib/commons-beanutils.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lucene/java/trunk/contrib/gdata-server/lib/commons-collections-3.2.jar
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/lib/commons-collections-3.2.jar?rev=417265&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lucene/java/trunk/contrib/gdata-server/lib/commons-collections-3.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lucene/java/trunk/contrib/gdata-server/lib/commons-digester-1.7.jar
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/lib/commons-digester-1.7.jar?rev=417265&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lucene/java/trunk/contrib/gdata-server/lib/commons-digester-1.7.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: lucene/java/trunk/contrib/gdata-server/src/java/lucenestorage.properties.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/lucenestorage.properties.xml?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/lucenestorage.properties.xml (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/lucenestorage.properties.xml Mon Jun 26 11:14:53 2006
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?> 
-<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> 
-<properties> 
-<comment>Lucene Storage Properties</comment> 
-<entry key="gdata.server.storage.lucene.buffersize">20</entry> 
-<entry key="gdata.server.storage.lucene.optimizeInterval">20</entry> 
-<entry key="gdata.server.storage.lucene.persistFactor">20</entry> 
-<entry key="gdata.server.storage.lucene.directory">/tmp/storage/</entry> 
-<entry key="gdata.server.storage.lucene.recover">true</entry> 
-<entry key="gdata.server.storage.lucene.recover.keepFiles">false</entry> 
-</properties> 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataEntityBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataEntityBuilder.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataEntityBuilder.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataEntityBuilder.java Mon Jun 26 11:14:53 2006
@@ -12,160 +12,160 @@
  * 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. 
- */ 
-package org.apache.lucene.gdata.server; 
- 
-import java.io.IOException; 
-import java.io.Reader; 
- 
-import org.apache.lucene.gdata.server.registry.DataBuilderException; 
-import org.apache.lucene.gdata.server.registry.FeedInstanceConfigurator; 
-import org.apache.lucene.gdata.server.registry.GDataServerRegistry; 
- 
-import com.google.gdata.data.BaseEntry; 
-import com.google.gdata.data.BaseFeed; 
-import com.google.gdata.data.ExtensionProfile; 
-import com.google.gdata.util.ParseException; 
- 
-/** 
- * {@link com.google.gdata.data.BaseFeed}, 
- * {@link com.google.gdata.data.BaseEntry} instances have to be build from a 
- * {@link java.io.Reader} instance as they come in from a client request or out 
- * of a storage. 
- * <p> 
- * To provide a generic builder class the {@link GDataEntityBuilder} requests 
- * the type of the feed / entry and the corresponding 
- * {@link com.google.gdata.data.ExtensionProfile} form the global 
- * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} and builds the 
- * instances from the provided reader. 
- * </p> 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class GDataEntityBuilder { 
-    private static final GDataServerRegistry REGISTRY = GDataServerRegistry.getRegistry(); // TODO find another way for getting the registered feeds 
- 
-    /** 
-     * Builds a {@link BaseFeed} instance from the {@link Reader} provided by 
-     * the {@link GDataRequest} 
-     *  
-     * @param request - 
-     *            the request to build the instance from 
-     * @return - a BaseFeed instance 
-     * @throws FeedNotFoundException - 
-     *             if the feed is not registered 
-     * @throws IOException - 
-     *             if an I/O Exception occures on the provided reader 
-     * @throws ParseException - 
-     *             if the feed could not be parsed 
-     */ 
-    public static BaseFeed buildFeed(final GDataRequest request) 
-            throws FeedNotFoundException, IOException, ParseException { 
-        if (request == null) 
-            throw new IllegalArgumentException("request must not be null"); 
-        return buildFeed(request.getFeedId(), request.getReader(),request.getExtensionProfile()); 
-    } 
- 
-    /** 
-     * Builds a {@link BaseFeed} from the provided {@link Reader} 
-     *  
-     * @param feedId - 
-     *            the feed ID to request the feed type from the registry 
-     * @param reader - 
-     *            the reader to build the feed from 
-     * @param profile - extension profile to parse the resource 
-     * @return - a BaseFeed instance 
-     * @throws FeedNotFoundException - 
-     *             if the feed is not registered 
-     * @throws IOException - 
-     *             if an I/O Exception occures on the provided reader 
-     * @throws ParseException - 
-     *             if the feed could not be parsed 
-     */ 
-    public static BaseFeed buildFeed(final String feedId, final Reader reader,final ExtensionProfile profile) 
-            throws FeedNotFoundException, ParseException, IOException { 
- 
-        BaseFeed retVal = null; 
-        try { 
-            retVal = (BaseFeed) createEntityInstance(feedId); 
-        } catch (FeedNotFoundException e) { 
-            throw e; 
-        } catch (Exception e) { 
-            DataBuilderException ex = new DataBuilderException( 
-                    "Could not build Feed for Feed class ", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-        retVal.parseAtom(profile, reader); 
- 
-        return retVal; 
-    } 
- 
-    /** 
-     * Builds a {@link BaseEntry} instance from the {@link Reader} provided by 
-     * the {@link GDataRequest} 
-     *  
-     * @param request - 
-     *            the request to build the instance from 
-     * @return - a BaseEntry instance 
-     * @throws FeedNotFoundException - 
-     *             if the feed, requested by the client is not registered 
-     * @throws IOException - 
-     *             if an I/O Exception occures on the provided reader 
-     * @throws ParseException - 
-     *             if the entry could not be parsed 
-     */ 
-    public static BaseEntry buildEntry(final GDataRequest request) 
-            throws FeedNotFoundException, IOException, ParseException { 
-        if (request == null) 
-            throw new IllegalArgumentException("request must not be null"); 
-        return buildEntry(request.getFeedId(), request.getReader(),request.getExtensionProfile()); 
-    } 
- 
-    /** 
-     * Builds a {@link BaseFeed} instance from the {@link Reader} provided by 
-     * the {@link GDataRequest} 
-     * @param feedId - 
-     *            the feed ID to request the feed type from the registry 
-     * @param reader - 
-     *            the reader to build the feed from  
-     * @param profile - extension profile to parse the resource 
-     * @return - a BaseFeed instance 
-     * @throws FeedNotFoundException - 
-     *             if the feed is not registered 
-     * @throws IOException - 
-     *             if an I/O Exception occures on the provided reader 
-     * @throws ParseException - 
-     *             if the entry could not be parsed 
-     */ 
-    public static BaseEntry buildEntry(final String feedId, final Reader reader,final ExtensionProfile profile) 
-            throws FeedNotFoundException, ParseException, IOException { 
- 
-        BaseEntry retVal = null; 
-        try { 
-            retVal = ((BaseFeed) createEntityInstance(feedId)).createEntry(); 
-        } catch (FeedNotFoundException e) { 
-            throw e; 
-        } catch (Exception e) { 
-            DataBuilderException ex = new DataBuilderException( 
-                    "Could not build Entry for Entry class ", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-        retVal.parseAtom(new ExtensionProfile(), reader); 
-        return retVal; 
-    } 
- 
-    private static Object createEntityInstance(String feedId) 
-            throws FeedNotFoundException, InstantiationException, 
-            IllegalAccessException { 
-        FeedInstanceConfigurator config = REGISTRY.getFeedConfigurator(feedId); 
-        if (config == null) 
-            throw new FeedNotFoundException( 
-                    "No feed for requested feed ID found - " + feedId); 
-        Class feedClass = config.getFeedType(); 
-        return feedClass.newInstance(); 
-    } 
- 
-} 
+ */
+package org.apache.lucene.gdata.server;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.BaseFeed;
+import com.google.gdata.util.ParseException;
+
+/**
+ * {@link com.google.gdata.data.BaseFeed},
+ * {@link com.google.gdata.data.BaseEntry} instances have to be build from a
+ * {@link java.io.Reader} instance as they come in from a client request or out
+ * of a storage.
+ * <p>
+ * To provide a generic builder class the {@link GDataEntityBuilder} requests
+ * the type of the feed / entry and the corresponding
+ * {@link com.google.gdata.data.ExtensionProfile} form the global
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} and
+ * builds the instances from the provided reader.
+ * </p>
+ * <p>
+ * This build will not returne the abstract base classes.
+ * </p>
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class GDataEntityBuilder {
+
+    /**
+     * Builds a {@link BaseFeed} instance from the {@link Reader} provided by
+     * the {@link GDataRequest}
+     * 
+     * @param request -
+     *            the request to build the instance from
+     * @return - a BaseFeed instance
+     * 
+     * @throws IOException -
+     *             if an I/O Exception occures on the provided reader
+     * @throws ParseException -
+     *             if the feed could not be parsed
+     */
+    public static BaseFeed buildFeed(final GDataRequest request)
+            throws IOException, ParseException {
+        if (request == null)
+            throw new IllegalArgumentException("request must not be null");
+        ProvidedService config = request.getConfigurator();
+        return buildFeed(request.getReader(), config);
+    }
+
+    /**
+     * Builds a {@link BaseFeed} from the provided {@link Reader}
+     * 
+     * 
+     * @param reader -
+     *            the reader to build the feed from
+     * @param config -
+     *            the feed instance config containing the extension profile to
+     *            parse the resource
+     * @return - a BaseFeed instance
+     * 
+     * @throws IOException -
+     *             if an I/O Exception occures on the provided reader
+     * @throws ParseException -
+     *             if the feed could not be parsed
+     */
+    public static BaseFeed buildFeed(final Reader reader,
+            final ProvidedService config) throws ParseException, IOException {
+
+        BaseFeed retVal = null;
+        retVal = createEntityInstance(config);
+        retVal.parseAtom(config.getExtensionProfile(), reader);
+      
+        return retVal;
+    }
+
+    /**
+     * Builds a {@link BaseEntry} instance from the {@link Reader} provided by
+     * the {@link GDataRequest}
+     * 
+     * @param request -
+     *            the request to build the instance from
+     * @return - a BaseEntry instance
+     * 
+     * @throws IOException -
+     *             if an I/O Exception occures on the provided reader
+     * @throws ParseException -
+     *             if the entry could not be parsed
+     */
+    public static BaseEntry buildEntry(final GDataRequest request)
+            throws IOException, ParseException {
+        if (request == null)
+            throw new IllegalArgumentException("request must not be null");
+        ProvidedService config = request.getConfigurator();
+        return buildEntry(request.getReader(), config);
+    }
+
+    /**
+     * Builds a {@link BaseFeed} instance from the {@link Reader} provided by
+     * the {@link GDataRequest}
+     * 
+     * @param reader -
+     *            the reader to build the feed from
+     * @param config -
+     *            the instance config containing the extension profile to parse
+     *            the resource
+     * @return - a BaseFeed instance
+     * 
+     * @throws IOException -
+     *             if an I/O Exception occures on the provided reader
+     * @throws ParseException -
+     *             if the entry could not be parsed
+     */
+    public static BaseEntry buildEntry(final Reader reader,
+            final ProvidedService config) throws ParseException, IOException {
+       
+        BaseEntry e = createEntityInstance(config).createEntry();
+        e.parseAtom(config.getExtensionProfile(), reader);
+        return e;
+    }
+
+    private static BaseFeed createEntityInstance(
+            final ProvidedService config) {
+        if(config.getFeedType() == null)
+            throw new IllegalArgumentException("feedtype is null in ProvidedService");
+        
+        BaseFeed retVal = null;
+        try {
+            retVal = (BaseFeed) config.getFeedType().newInstance();
+        } catch (Exception e) {
+            throw new EntityBuilderException("Can't instanciate Feed for feedType "+config.getFeedType().getName(),e);
+        }
+        return retVal;
+    }
+    static class EntityBuilderException extends RuntimeException{
+
+        /**
+         * 
+         */
+        private static final long serialVersionUID = 7224011324202237951L;
+
+        EntityBuilderException(String arg0) {
+            super(arg0);
+           
+        }
+
+        EntityBuilderException(String arg0, Throwable arg1) {
+            super(arg0, arg1);
+           
+        }
+        
+    }
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataRequest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataRequest.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataRequest.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataRequest.java Mon Jun 26 11:14:53 2006
@@ -12,431 +12,526 @@
  * 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. 
- */ 
- 
-package org.apache.lucene.gdata.server; 
- 
-import java.io.IOException; 
-import java.io.Reader; 
-import java.util.Enumeration; 
-import java.util.Map; 
-import java.util.StringTokenizer; 
- 
-import javax.servlet.http.HttpServletRequest; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
-import org.apache.lucene.gdata.server.registry.GDataServerRegistry; 
- 
-import com.google.gdata.data.ExtensionProfile; 
- 
-/** 
- * The GDataRequest Class wraps the incoming HttpServletRequest. Needed 
- * information coming with the HttpServletRequest can be accessed directly. It 
- * represents an abstraction on the plain HttpServletRequest. Every GData 
- * specific data coming from the client will be availiable and can be accessed 
- * via the GDataRequest. 
- * <p> 
- * GDataRequest instances will be passed to any action requested by the client. 
- * This class also holds the logic to retrieve important information like 
- * response format, the reqeusted feed instance and query parameters. 
- *  
- * </p> 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-/* this class might be extracted as an interface in later development */ 
-public class GDataRequest { 
- 
-    private static final Log LOG = LogFactory.getLog(GDataRequest.class); 
- 
-    private static final String RESPONSE_FORMAT_PARAMETER = "alt"; 
- 
-    private static final String RESPONSE_FORMAT_PARAMETER_RSS = "rss"; 
- 
-    private static final int DEFAULT_ITEMS_PER_PAGE = 25; 
- 
-    private static final int DEFAULT_START_INDEX = 1; 
- 
-    private static final String START_INDEX_NEXT_PAGE_PARAMETER = "start-index"; 
- 
-    private static final String ITEMS_PER_PAGE_PARAMETER = "max-results"; 
- 
-    private String contextPath; 
- 
-    @SuppressWarnings("unused") 
-    private static final String RESPONSE_FORMAT_PARAMETER_ATOM = "atom"; 
- 
-    // Atom is the default resopnse format 
-    private OutputFormat responseFormat = OutputFormat.ATOM; 
- 
-    private final HttpServletRequest request; 
- 
-    private String feedId = null; 
- 
-    private String entryId = null; 
-     
-    private ExtensionProfile extensionProfile= null; 
- 
-    private String entryVersion = null; 
- 
-    private GDataRequestType type; 
- 
-    /** 
-     * Creates a new FeedRequest 
-     *  
-     * @param requst - 
-     *            the incoming HttpServletReqeust 
-     * @param type - 
-     *            the request type 
-     *  
-     */ 
-    public GDataRequest(final HttpServletRequest requst, 
-            final GDataRequestType type) { 
-        if (requst == null) 
-            throw new IllegalArgumentException("request must not be null "); 
-        if (type == null) 
-            throw new IllegalArgumentException("request type must not be null "); 
-        this.request = requst; 
-        this.type = type; 
-         
-    } 
- 
-    /** 
-     * Initialize the GDataRequest. This will initialize all needed values / 
-     * attributes in this request. 
-     *  
-     * @throws GDataRequestException 
-     */ 
-    public void initializeRequest() throws GDataRequestException { 
-        generateIdentificationProperties(); 
-        setOutputFormat(); 
-        /* 
-         * ExtensionProfile is used for building the Entry / Feed Instances from an inputstream or reader 
-         */ 
-        this.extensionProfile = GDataServerRegistry.getRegistry().getExtensionProfile(this.feedId); 
-        if(this.extensionProfile == null) 
-            throw new GDataRequestException("feed is not registered or extension profile could not be created"); 
-    } 
- 
-    /** 
-     * @return - the id of the requested feed 
-     */ 
-    public String getFeedId() { 
- 
-        return this.feedId; 
-    } 
- 
-    /** 
-     * @return - the entry id of the requested Entry if specified, otherwise 
-     *         <code>null</code> 
-     */ 
-    public String getEntryId() { 
- 
-        return this.entryId; 
-    } 
- 
-    /** 
-     * @return the version Id of the requested Entry if specified, otherwise 
-     *         <code>null</code> 
-     */ 
-    public String getEntryVersion() { 
-        return this.entryVersion; 
-    } 
- 
-    /** 
-     * A Reader instance to read form the client input stream 
-     *  
-     * @return - the HttpServletRequest {@link Reader} 
-     * @throws IOException - 
-     *             if an I/O Exception occures 
-     */ 
-    public Reader getReader() throws IOException { 
-        return this.request.getReader(); 
-    } 
- 
-    /** 
-     * Returns the {@link HttpServletRequest} parameter map containig all <i>GET</i> 
-     * request parameters. 
-     *  
-     * @return the parameter map 
-     */ 
-    @SuppressWarnings("unchecked") 
-    public Map<String, String[]> getQueryParameter() { 
-        return this.request.getParameterMap(); 
-    } 
- 
-    /** 
-     * The {@link HttpServletRequest} request parameter names 
-     *  
-     * @return parameter names enumeration 
-     */ 
-    @SuppressWarnings("unchecked") 
-    public Enumeration<String> getQueryParameterNames() { 
-        return this.request.getParameterNames(); 
-    } 
- 
-    /** 
-     * Either <i>Atom</i> or <i>RSS</i> 
-     *  
-     * @return - The output format requested by the client 
-     */ 
-    public OutputFormat getRequestedResponseFormat() { 
- 
-        return this.responseFormat; 
-    } 
- 
-    private void generateIdentificationProperties() 
-            throws GDataRequestException { 
-        /* generate all needed data to identify the requested feed/entry */ 
-        String pathInfo = this.request.getPathInfo(); 
-        /* 
-         * TODO this has to be changed to support the category queries. Category 
-         * queries could also be rewrited in the Servlet. 
-         */ 
-        if (pathInfo.length() <= 1) 
-            throw new GDataRequestException( 
-                    "No feed or entry specified for this request"); 
-        StringTokenizer tokenizer = new StringTokenizer(pathInfo, "/"); 
-        this.feedId = tokenizer.nextToken(); 
-        this.entryId = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""; 
-        this.entryVersion = tokenizer.hasMoreTokens() ? tokenizer.nextToken() 
-                : ""; 
- 
-    } 
- 
-    private void setOutputFormat() { 
-        String formatParameter = this.request 
-                .getParameter(RESPONSE_FORMAT_PARAMETER); 
-        if (formatParameter == null) 
-            return; 
-        if (formatParameter.equalsIgnoreCase(RESPONSE_FORMAT_PARAMETER_RSS)) 
-            this.responseFormat = OutputFormat.RSS; 
- 
-    } 
- 
-    /** 
-     * @return - the number of returned items per page 
-     */ 
-    public int getItemsPerPage() { 
- 
-        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) == null) 
-            return DEFAULT_ITEMS_PER_PAGE; 
-        int retval = -1; 
-        try { 
-            retval = new Integer(this.request 
-                    .getParameter(ITEMS_PER_PAGE_PARAMETER)).intValue(); 
-        } catch (Exception e) { 
-            LOG.warn("Intems per page could not be parsed - " + e.getMessage(), 
-                    e); 
-        } 
-        return retval < 0 ? DEFAULT_ITEMS_PER_PAGE : retval; 
-    } 
- 
-    /** 
-     * Start index represents the number of the first entry of the query - 
-     * result. The order depends on the query. Is the query a search query the 
-     * this value will be assinged to the score in a common feed query the value 
-     * will be assigned to the update time of the entries. 
-     *  
-     * @return - the requested start index 
-     */ 
-    public int getStartIndex() { 
-        if (this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER) == null) 
-            return DEFAULT_START_INDEX; 
-        int retval = -1; 
-        try { 
-            retval = new Integer(this.request 
-                    .getParameter(START_INDEX_NEXT_PAGE_PARAMETER)).intValue(); 
-        } catch (Exception e) { 
-            LOG.warn("Start-index could not be parsed - " + e.getMessage(), e); 
-        } 
-        return retval < 0 ? DEFAULT_START_INDEX : retval; 
-    } 
- 
-    /** 
-     * The selfid is <i>href</i> pointing to the requested resource 
-     *  
-     * @return - the self id 
-     */ 
-    public String getSelfId() { 
-        StringBuilder builder = new StringBuilder(); 
-        builder.append(buildRequestIDString(false)); 
- 
-        builder.append(getQueryString()); 
- 
-        return builder.toString(); 
-    } 
- 
-    /** 
-     * The <i>href</i> id of the next page of the requested resource. 
-     *  
-     * @return the id of the next page 
-     */ 
-    public String getNextId() { 
-        // StringBuilder builder = new StringBuilder(); 
-        // builder.append(buildRequestIDString()); 
-        //         
-        // builder.append(getQueryString()); 
-        //         
-        // if(this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER)== 
-        // null){ 
-        // builder.append("&").append(START_INDEX_NEXT_PAGE_PARAMETER).append("="); 
-        // builder.append(DEFAULT_ITEMS_PER_PAGE+1); 
-        // } 
-        // else{ 
-        //             
-        // int next = 0; 
-        // try{ 
-        // next = 
-        // Integer.parseInt(this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER)); 
-        // }catch (Exception e) { 
-        // // 
-        // } 
-        //             
-        // if(next < 0) 
-        // builder.append(DEFAULT_ITEMS_PER_PAGE+1); 
-        // else 
-        // builder.append(next+DEFAULT_ITEMS_PER_PAGE); 
-        // int pos = builder.indexOf(START_INDEX_NEXT_PAGE_PARAMETER); 
-        // boolean end = builder.lastIndexOf("&",pos) < pos; 
-        // builder.replace(pos+START_INDEX_NEXT_PAGE_PARAMETER.length()+1,pos+START_INDEX_NEXT_PAGE_PARAMETER.length()+3,""+next); 
-        //             
-        //             
-        // System.out.println(end); 
-        // } 
-        //             
-        //         
-        //         
-        // return builder.toString(); 
-        return buildRequestIDString(false); 
- 
-    } 
- 
-    private String buildRequestIDString(boolean endingSlash) { 
-        StringBuilder builder = new StringBuilder("http://"); 
-        builder.append(this.request.getHeader("Host")); 
-        builder.append(this.request.getRequestURI()); 
-        if (endingSlash && !this.request.getRequestURI().endsWith("/")) 
-            builder.append("/"); 
- 
-        return builder.toString(); 
-    } 
- 
-    /** 
-     * This will return the current query string including all parameters. 
-     * Additionaly the <code>max-resul</code> parameter will be added if not 
-     * specified. 
-     * <p> 
-     * <code>max-resul</code> indicates the number of results returned to the 
-     * client. The default value is 25. 
-     * </p> 
-     *  
-     * @return - the query string incluing all parameters 
-     */ 
-    public String getQueryString() { 
-        String retVal = this.request.getQueryString(); 
- 
-        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) != null) 
-            return retVal; 
-        String tempString = (retVal == null ? "?" + ITEMS_PER_PAGE_PARAMETER 
-                + "=" + DEFAULT_ITEMS_PER_PAGE : "&" + ITEMS_PER_PAGE_PARAMETER 
-                + "=" + DEFAULT_ITEMS_PER_PAGE); 
- 
-        return retVal == null ? tempString : retVal + tempString; 
- 
-    } 
- 
-    /** 
-     * This enum represents the OutputFormat of the GDATA Server 
-     *  
-     * @author Simon Willnauer 
-     *  
-     */ 
-    public static enum OutputFormat { 
-        /** 
-         * Output format ATOM. ATOM is the default response format. 
-         */ 
-        ATOM, 
-        /** 
-         * Output format RSS 
-         */ 
-        RSS 
-    } 
- 
-    /** 
-     * Returns the requested path including the domain name and the requested 
-     * resource <i>http://www.apache.org/path/resource/</i> 
-     *  
-     * @return the context path 
-     */ 
-    public String getContextPath() { 
-        if (this.contextPath == null) 
-            this.contextPath = buildRequestIDString(true); 
-        return this.contextPath; 
-    } 
- 
-    /** 
-     * Indicates the request type 
-     *  
-     * @author Simon Willnauer 
-     *  
-     */ 
-    public enum GDataRequestType { 
-        /** 
-         * Type FeedRequest 
-         */ 
-        GET, 
-        /** 
-         * Type UpdateRequest 
-         */ 
-        UPDATE, 
-        /** 
-         * Type DeleteRequest 
-         */ 
-        DELETE, 
-        /** 
-         * Type InsertRequest 
-         */ 
-        INSERT 
-    } 
- 
-    /** 
-     * {@link GDataRequestType} 
-     *  
-     * @return the current request type 
-     */ 
-    public GDataRequestType getType() { 
-        return this.type; 
-    } 
- 
-    /** 
-     * If the reuquest is a {@link GDataRequestType#GET} request and there is 
-     * no entry id specified, the requested resource is a feed. 
-     *  
-     * @return - <code>true</code> if an only if the requested resource is a feed 
-     */ 
-    public boolean isFeedRequested() { 
- 
-        return (this.type.equals(GDataRequestType.GET) && (this.entryId == null|| this.entryId.length() == 0|| (this.entryId.equals('/')))); 
-    } 
- 
-    /** 
-     * * If the reuquest is a {@link GDataRequestType#GET} request and there is 
-     * an entry id specified, the requested resource is an entry. 
-     *  
-     * @return - <code>true</code> if an only if the requested resource is an entry 
-     */ 
-    public boolean isEntryRequested() { 
-        return !this.isFeedRequested(); 
-    } 
- 
-    /** 
-     * @return - the extensionProfile for the requested resource 
-     */ 
-    public ExtensionProfile getExtensionProfile() { 
-        return this.extensionProfile; 
-    } 
- 
-} 
+ */
+
+package org.apache.lucene.gdata.server;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.server.authentication.AuthenticationController;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.storage.Storage;
+import org.apache.lucene.gdata.storage.StorageController;
+
+/**
+ * The GDataRequest Class wraps the incoming HttpServletRequest. Needed
+ * information coming with the HttpServletRequest can be accessed directly. It
+ * represents an abstraction on the plain HttpServletRequest. Every GData
+ * specific data coming from the client will be availiable and can be accessed
+ * via the GDataRequest.
+ * <p>
+ * GDataRequest instances will be passed to any action requested by the client.
+ * This class also holds the logic to retrieve important information like
+ * response format, the reqeusted feed instance and query parameters.
+ * 
+ * </p>
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+/* this class might be extracted as an interface in later development */
+public class GDataRequest {
+
+    private static final Log LOG = LogFactory.getLog(GDataRequest.class);
+
+    private static final String RESPONSE_FORMAT_PARAMETER = "alt";
+
+    private static final String RESPONSE_FORMAT_PARAMETER_RSS = "rss";
+
+    private static final int DEFAULT_ITEMS_PER_PAGE = 25;
+
+    private static final int DEFAULT_START_INDEX = 1;
+
+    private static final String START_INDEX_NEXT_PAGE_PARAMETER = "start-index";
+
+    private static final String ITEMS_PER_PAGE_PARAMETER = "max-results";
+
+    private String contextPath;
+
+    @SuppressWarnings("unused")
+    private static final String RESPONSE_FORMAT_PARAMETER_ATOM = "atom";
+
+    private static final String HTTP_HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
+
+    private static final String HTTP_HEADER_AUTH = "Authorization";
+
+    // Atom is the default resopnse format
+    private OutputFormat responseFormat = OutputFormat.ATOM;
+
+    private final HttpServletRequest request;
+
+    private String feedId = null;
+
+    private String entryId = null;
+
+    private ProvidedService configurator = null;
+
+    private String entryVersion = null;
+
+    private GDataRequestType type;
+
+    /**
+     * Creates a new FeedRequest
+     * 
+     * @param requst -
+     *            the incoming HttpServletReqeust
+     * @param type -
+     *            the request type
+     * 
+     */
+    public GDataRequest(final HttpServletRequest requst,
+            final GDataRequestType type) {
+        if (requst == null)
+            throw new IllegalArgumentException("request must not be null ");
+        if (type == null)
+            throw new IllegalArgumentException("request type must not be null ");
+        this.request = requst;
+        this.type = type;
+
+    }
+
+    /**
+     * Initialize the GDataRequest. This will initialize all needed values /
+     * attributes in this request.
+     * 
+     * @throws GDataRequestException
+     */
+    public void initializeRequest() throws GDataRequestException {
+        generateIdentificationProperties();
+        setOutputFormat();
+        // TODO remove this dependency
+        StorageController controller = GDataServerRegistry.getRegistry()
+                .lookup(StorageController.class,
+                        ComponentType.STORAGECONTROLLER);
+        try {
+
+            Storage storage = controller.getStorage();
+
+            String service = storage.getServiceForFeed(this.feedId);
+            /*
+             * ExtensionProfile and the type is used for building the Entry /
+             * Feed Instances from an inputstream or reader
+             * 
+             */
+            this.configurator = GDataServerRegistry.getRegistry()
+                    .getProvidedService(service);
+            if (this.configurator == null)
+                throw new GDataRequestException(
+                        "feed is not registered or extension profile could not be created");
+
+        } catch (Exception e) {
+            throw new GDataRequestException(
+                    "feed is not registered or extension profile could not be created");
+        }
+
+    }
+
+    /**
+     * @return - the id of the requested feed
+     */
+    public String getFeedId() {
+
+        return this.feedId;
+    }
+
+    /**
+     * @return - the entry id of the requested Entry if specified, otherwise
+     *         <code>null</code>
+     */
+    public String getEntryId() {
+
+        return this.entryId;
+    }
+
+    /**
+     * @return the version Id of the requested Entry if specified, otherwise
+     *         <code>null</code>
+     */
+    public String getEntryVersion() {
+        return this.entryVersion;
+    }
+
+    /**
+     * A Reader instance to read form the client input stream
+     * 
+     * @return - the HttpServletRequest {@link Reader}
+     * @throws IOException -
+     *             if an I/O Exception occures
+     */
+    public Reader getReader() throws IOException {
+        return this.request.getReader();
+    }
+
+    /**
+     * Returns the {@link HttpServletRequest} parameter map containig all <i>GET</i>
+     * request parameters.
+     * 
+     * @return the parameter map
+     */
+    @SuppressWarnings("unchecked")
+    public Map<String, String[]> getQueryParameter() {
+        return this.request.getParameterMap();
+    }
+
+    /**
+     * The {@link HttpServletRequest} request parameter names
+     * 
+     * @return parameter names enumeration
+     */
+    @SuppressWarnings("unchecked")
+    public Enumeration<String> getQueryParameterNames() {
+        return this.request.getParameterNames();
+    }
+
+    /**
+     * Either <i>Atom</i> or <i>RSS</i>
+     * 
+     * @return - The output format requested by the client
+     */
+    public OutputFormat getRequestedResponseFormat() {
+
+        return this.responseFormat;
+    }
+
+    private void generateIdentificationProperties()
+            throws GDataRequestException {
+        /* generate all needed data to identify the requested feed/entry */
+        String pathInfo = this.request.getPathInfo();
+        /*
+         * TODO this has to be changed to support the category queries. Category
+         * queries could also be rewrited in the Servlet.
+         */
+        if (pathInfo.length() <= 1)
+            throw new GDataRequestException(
+                    "No feed or entry specified for this request");
+        StringTokenizer tokenizer = new StringTokenizer(pathInfo, "/");
+        this.feedId = tokenizer.nextToken();
+        this.entryId = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : "";
+        this.entryVersion = tokenizer.hasMoreTokens() ? tokenizer.nextToken()
+                : "";
+
+    }
+
+    private void setOutputFormat() {
+        String formatParameter = this.request
+                .getParameter(RESPONSE_FORMAT_PARAMETER);
+        if (formatParameter == null)
+            return;
+        if (formatParameter.equalsIgnoreCase(RESPONSE_FORMAT_PARAMETER_RSS))
+            this.responseFormat = OutputFormat.RSS;
+
+    }
+
+    /**
+     * @return - the number of returned items per page
+     */
+    public int getItemsPerPage() {
+
+        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) == null)
+            return DEFAULT_ITEMS_PER_PAGE;
+        int retval = -1;
+        try {
+            retval = new Integer(this.request
+                    .getParameter(ITEMS_PER_PAGE_PARAMETER)).intValue();
+        } catch (Exception e) {
+            LOG.warn("Intems per page could not be parsed - " + e.getMessage(),
+                    e);
+        }
+
+        return retval < 0 ? DEFAULT_ITEMS_PER_PAGE : retval;
+    }
+
+    /**
+     * Start index represents the number of the first entry of the query -
+     * result. The order depends on the query. Is the query a search query the
+     * this value will be assinged to the score in a common feed query the value
+     * will be assigned to the update time of the entries.
+     * 
+     * @return - the requested start index
+     */
+    public int getStartIndex() {
+        if (this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER) == null)
+            return DEFAULT_START_INDEX;
+        int retval = -1;
+        try {
+            retval = new Integer(this.request
+                    .getParameter(START_INDEX_NEXT_PAGE_PARAMETER)).intValue();
+        } catch (Exception e) {
+            LOG.warn("Start-index could not be parsed - " + e.getMessage(), e);
+        }
+        return retval < 0 ? DEFAULT_START_INDEX : retval;
+    }
+
+    /**
+     * The selfid is <i>href</i> pointing to the requested resource
+     * 
+     * @return - the self id
+     */
+    public String getSelfId() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(buildRequestIDString(false));
+        builder.append("?");
+        builder.append(getQueryString());
+
+        return builder.toString();
+    }
+
+    /**
+     * The <i>href</i> id of the next page of the requested resource.
+     * 
+     * @return the id of the next page
+     */
+    public String getNextId() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(buildRequestIDString(false));
+        builder.append("?");
+
+        Enumeration parameters = this.request.getParameterNames();
+        while (parameters.hasMoreElements()) {
+            String element = (String) parameters.nextElement();
+            String[] values = this.request.getParameterValues(element);
+            for (int i = 0; i < values.length; i++) {
+
+                builder.append(element).append("=");
+                if (element.equals(START_INDEX_NEXT_PAGE_PARAMETER)) {
+                    int tempVal = DEFAULT_START_INDEX;
+                    try {
+                        tempVal = Integer.parseInt(values[i]);
+                    } catch (Exception e) {
+                        LOG.info("Can not parse StartIndex -- use defaut");
+                    }
+                    builder.append(tempVal + getItemsPerPage());
+                    break;
+                }
+
+                builder.append(values[i]);
+
+            }
+            if (parameters.hasMoreElements())
+                builder.append("&");
+
+        }
+        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) == null) {
+            if (builder.charAt(builder.length() - 1) != '?')
+                builder.append('&');
+            builder.append(ITEMS_PER_PAGE_PARAMETER).append("=").append(
+                    DEFAULT_ITEMS_PER_PAGE);
+        }
+        if (this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER) == null) {
+            builder.append('&');
+            builder.append(START_INDEX_NEXT_PAGE_PARAMETER).append("=");
+            builder.append(DEFAULT_ITEMS_PER_PAGE + 1);
+        }
+
+        return builder.toString();
+
+    }
+
+    private String buildRequestIDString(boolean endingSlash) {
+        StringBuilder builder = new StringBuilder("http://");
+        builder.append(this.request.getHeader("Host"));
+        builder.append(this.request.getRequestURI());
+        if (endingSlash && !this.request.getRequestURI().endsWith("/"))
+            builder.append("/");
+
+        return builder.toString();
+    }
+
+    /**
+     * This will return the current query string including all parameters.
+     * Additionaly the <code>max-resul</code> parameter will be added if not
+     * specified.
+     * <p>
+     * <code>max-resul</code> indicates the number of results returned to the
+     * client. The default value is 25.
+     * </p>
+     * 
+     * @return - the query string incluing all parameters
+     */
+    public String getQueryString() {
+        String retVal = this.request.getQueryString();
+
+        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) != null)
+            return retVal;
+        String tempString = (retVal == null ? ITEMS_PER_PAGE_PARAMETER + "="
+                + DEFAULT_ITEMS_PER_PAGE : "&" + ITEMS_PER_PAGE_PARAMETER + "="
+                + DEFAULT_ITEMS_PER_PAGE);
+
+        return retVal == null ? tempString : retVal + tempString;
+
+    }
+
+    /**
+     * This enum represents the OutputFormat of the GDATA Server
+     * 
+     * @author Simon Willnauer
+     * 
+     */
+    public static enum OutputFormat {
+        /**
+         * Output format ATOM. ATOM is the default response format.
+         */
+        ATOM,
+        /**
+         * Output format RSS
+         */
+        RSS
+    }
+
+    /**
+     * Returns the requested path including the domain name and the requested
+     * resource <i>http://www.apache.org/path/resource/</i>
+     * 
+     * @return the context path
+     */
+    public String getContextPath() {
+        if (this.contextPath == null)
+            this.contextPath = buildRequestIDString(true);
+        return this.contextPath;
+    }
+
+    /**
+     * Indicates the request type
+     * 
+     * @author Simon Willnauer
+     * 
+     */
+    public enum GDataRequestType {
+        /**
+         * Type FeedRequest
+         */
+        GET,
+        /**
+         * Type UpdateRequest
+         */
+        UPDATE,
+        /**
+         * Type DeleteRequest
+         */
+        DELETE,
+        /**
+         * Type InsertRequest
+         */
+        INSERT
+    }
+
+    /**
+     * {@link GDataRequestType}
+     * 
+     * @return the current request type
+     */
+    public GDataRequestType getType() {
+        return this.type;
+    }
+
+    /**
+     * If the reuquest is a {@link GDataRequestType#GET} request and there is no
+     * entry id specified, the requested resource is a feed.
+     * 
+     * @return - <code>true</code> if an only if the requested resource is a
+     *         feed
+     */
+    public boolean isFeedRequested() {
+
+        return (this.type.equals(GDataRequestType.GET) && (this.entryId == null
+                || this.entryId.length() == 0 || (this.entryId.equals('/'))));
+    }
+
+    /**
+     * * If the reuquest is a {@link GDataRequestType#GET} request and there is
+     * an entry id specified, the requested resource is an entry.
+     * 
+     * @return - <code>true</code> if an only if the requested resource is an
+     *         entry
+     */
+    public boolean isEntryRequested() {
+        return !this.isFeedRequested();
+    }
+
+    /**
+     * @return the configuration for this request
+     */
+    public ProvidedService getConfigurator() {
+        return this.configurator;
+    }
+
+    /**
+     * @return - Returns the Internet Protocol (IP) address of the client or
+     *         last proxy that sent the request.
+     */
+    public String getRemoteAddress() {
+        return this.request.getRemoteAddr();
+    }
+
+    /**
+     * @return - the value for the send auth token. The auth token will be send
+     *         as a request <tt>Authentication</tt> header.
+     */
+    public String getAuthToken() {
+        String token = this.request.getHeader(HTTP_HEADER_AUTH);
+        if (token == null)
+            return null;
+        token = token.substring(token.indexOf("=") + 1);
+        return token;
+    }
+
+    /**
+     * @return - Returns an array containing all of the Cookie objects the
+     *         client sent with underlaying HttpServletRequest.
+     */
+    public Cookie[] getCookies() {
+        return this.request.getCookies();
+    }
+
+    /**
+     * @return - the cookie set instead of the authentication token or
+     *         <code>null</code> if not auth cookie is set
+     */
+    public Cookie getAuthCookie() {
+        Cookie[] cookies = this.request.getCookies();
+        if (cookies == null)
+            return null;
+        for (int i = 0; i < cookies.length; i++) {
+            if (cookies[i].getName().equals(AuthenticationController.TOKEN_KEY))
+                return cookies[i];
+        }
+        return null;
+    }
+
+    /**
+     * @return - the date string of the <tt>If-Modified-Since</tt> HTTP
+     *         request header, or null if header is not set
+     */
+    public String getModifiedSince() {
+        return this.request.getHeader(HTTP_HEADER_IF_MODIFIED_SINCE);
+    }
+
+    /**
+     * @return - the underlaying HttpServletRequest
+     */
+    public HttpServletRequest getHttpServletRequest() {
+
+        return this.request;
+    }
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataResponse.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataResponse.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataResponse.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataResponse.java Mon Jun 26 11:14:53 2006
@@ -12,231 +12,279 @@
  * 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. 
- */ 
- 
-package org.apache.lucene.gdata.server; 
- 
-import java.io.IOException; 
-import java.io.Writer; 
- 
-import javax.servlet.http.HttpServletResponse; 
- 
-import org.apache.lucene.gdata.server.GDataRequest.OutputFormat; 
- 
-import com.google.gdata.data.BaseEntry; 
-import com.google.gdata.data.BaseFeed; 
-import com.google.gdata.data.ExtensionProfile; 
-import com.google.gdata.util.common.xml.XmlWriter; 
-import com.google.gdata.util.common.xml.XmlWriter.Namespace; 
- 
-/** 
- * The FeedRequest Class wraps the curren HttpServletResponse. Any action on the 
- * HttpServletRequest will be executed via this class. This represents an 
- * abstraction on the plain {@link HttpServletResponse}. Any action which has 
- * to be performed on the underlaying {@link HttpServletResponse} will be 
- * executed within this class. 
- * <p> 
- * The GData basicly writes two different kinds ouf reponse to the output 
- * stream. 
- * <ol> 
- * <li>update, delete or insert requests will respond with a statuscode and if 
- * successful the feed entry modified or created</li> 
- * <li>get requests will respond with a statuscode and if successful the 
- * requested feed</li> 
- * </ol> 
- *  
- * For this purpose the {@link GDataResponse} class provides the overloaded 
- * method 
- * {@link org.apache.lucene.gdata.server.GDataResponse#sendResponse(BaseEntry, ExtensionProfile)} 
- * which sends the entry e.g feed to the output stream. 
- * </p> 
- *  
- *  
- *  
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class GDataResponse { 
-    private int error; 
- 
-    private boolean isError = false; 
- 
-    private String encoding; 
- 
-    private OutputFormat outputFormat; 
- 
-    private final HttpServletResponse response; 
- 
-    private static final String DEFAUL_NAMESPACE_URI = "http://www.w3.org/2005/Atom"; 
- 
-    private static final Namespace DEFAULT_NAMESPACE = new Namespace("", 
-            DEFAUL_NAMESPACE_URI); 
- 
-    /** 
-     * Creates a new GDataResponse 
-     *  
-     * @param response - 
-     *            The underlaying {@link HttpServletResponse} 
-     */ 
-    public GDataResponse(HttpServletResponse response) { 
-        if (response == null) 
-            throw new IllegalArgumentException("response must not be null"); 
-        this.response = response; 
-        this.response.setContentType("text/xml"); 
-    } 
- 
-    /** 
-     * Sets an error code to this FeedResponse. 
-     *  
-     * @param errorCode - 
-     *            {@link HttpServletResponse} error code 
-     */ 
-    public void setError(int errorCode) { 
-        this.isError = true; 
-        this.error = errorCode; 
-    } 
-    /** 
-     * Sets the status of the underlaying response 
-     * @see HttpServletResponse 
-     * @param responseCode - the status of the response 
-     */ 
-    public void setResponseCode(int responseCode){ 
-        this.response.setStatus(responseCode); 
-    } 
-    /** 
-     * This method sends the specified error to the user if set 
-     *  
-     * @throws IOException - 
-     *             if an I/O Exception occures 
-     */ 
-    public void sendError() throws IOException { 
-        if (this.isError) 
-            this.response.sendError(this.error); 
-    } 
- 
-    /** 
-     * @return - the {@link HttpServletResponse} writer 
-     * @throws IOException - 
-     *             If an I/O exception occures 
-     */ 
-    public Writer getWriter() throws IOException { 
-        return this.response.getWriter(); 
-    } 
- 
-    /** 
-     * Sends a response for a get e.g. query request. This method must not 
-     * invoked in a case of an error performing the requeste action. 
-     *  
-     * @param feed - 
-     *            the feed to respond to the client 
-     * @param profile - 
-     *            the extension profil for the feed to write 
-     * @throws IOException - 
-     *             if an I/O exception accures, often caused by an already 
-     *             closed Writer or OutputStream 
-     *  
-     */ 
-    public void sendResponse(BaseFeed feed, ExtensionProfile profile) 
-            throws IOException { 
-        if (feed == null) 
-            throw new IllegalArgumentException("feed must not be null"); 
-        if(profile == null) 
-            throw new IllegalArgumentException("extension profil must not be null"); 
-        XmlWriter writer = createWriter(); 
-         
-        if (this.outputFormat.equals(OutputFormat.ATOM)) 
-            feed.generateAtom(writer, profile); 
-        else 
-            feed.generateRss(writer, profile); 
- 
-    } 
- 
-    /** 
-     *  
-     * Sends a response for an update, insert or delete request. This method 
-     * must not invoked in a case of an error performing the requeste action. 
-     * If the specified response format is ATOM the default namespace will be set to ATOM. 
-     * @param entry - 
-     *            the modified / created entry to send 
-     * @param profile - 
-     *            the entries extension profile 
-     * @throws IOException - 
-     *             if an I/O exception accures, often caused by an already 
-     *             closed Writer or OutputStream 
-     */ 
-    public void sendResponse(BaseEntry entry, ExtensionProfile profile) 
-            throws IOException { 
-        if (entry == null) 
-            throw new IllegalArgumentException("entry must not be null"); 
-        if(profile == null) 
-            throw new IllegalArgumentException("extension profil must not be null"); 
-        XmlWriter writer = createWriter(); 
-        if (this.outputFormat.equals(OutputFormat.ATOM)) 
-            entry.generateAtom(writer, profile); 
-        else 
-            entry.generateRss(writer, profile); 
-    } 
- 
-    private XmlWriter createWriter() throws IOException { 
-        XmlWriter writer = new XmlWriter(getWriter(), this.encoding); 
-        // set the default namespace to Atom if Atom is the response format 
-        if(this.outputFormat.equals(OutputFormat.ATOM)) 
-            writer.setDefaultNamespace(DEFAULT_NAMESPACE); 
-        return writer; 
-    } 
- 
-    /** 
-     * This encoding will be used to encode the xml representation of feed or 
-     * entry written to the {@link HttpServletResponse} output stream. 
-     *  
-     * @return - the entry / feed encoding 
-     */ 
-    public String getEncoding() { 
-        return this.encoding; 
-    } 
- 
-    /** 
-     * This encoding will be used to encode the xml representation of feed or 
-     * entry written to the {@link HttpServletResponse} output stream. <i>UTF-8</i> 
-     * <i>ISO-8859-1</i> 
-     *  
-     * @param encoding - 
-     *            string represents the encoding 
-     */ 
-    public void setEncoding(String encoding) { 
-        this.encoding = encoding; 
-    } 
- 
-    /** 
-     * @return - the response 
-     *         {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat} 
-     */ 
-    public OutputFormat getOutputFormat() { 
-        return this.outputFormat; 
-    } 
- 
-    /** 
-     * @param outputFormat - 
-     *            the response 
-     *            {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat} 
-     */ 
-    public void setOutputFormat(OutputFormat outputFormat) { 
-        this.outputFormat = outputFormat; 
-    } 
-    /** 
-     * @see Object#toString() 
-     */ 
-    @Override 
-    public String toString(){ 
-        StringBuilder builder = new StringBuilder(" GDataResponse: "); 
-        builder.append("Error: ").append(this.error); 
-        builder.append(" outputFormat: ").append(getOutputFormat()); 
-        builder.append(" encoding: ").append(this.encoding); 
-         
-        return builder.toString(); 
-         
-         
-    } 
- 
-} 
+ */
+
+package org.apache.lucene.gdata.server;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Date;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.lucene.gdata.server.GDataRequest.OutputFormat;
+import org.apache.lucene.gdata.utils.DateFormater;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.BaseFeed;
+import com.google.gdata.data.DateTime;
+import com.google.gdata.data.ExtensionProfile;
+import com.google.gdata.util.common.xml.XmlWriter;
+import com.google.gdata.util.common.xml.XmlWriter.Namespace;
+
+/**
+ * The FeedRequest Class wraps the curren HttpServletResponse. Any action on the
+ * HttpServletRequest will be executed via this class. This represents an
+ * abstraction on the plain {@link HttpServletResponse}. Any action which has
+ * to be performed on the underlaying {@link HttpServletResponse} will be
+ * executed within this class.
+ * <p>
+ * The GData basicly writes two different kinds ouf reponse to the output
+ * stream.
+ * <ol>
+ * <li>update, delete or insert requests will respond with a statuscode and if
+ * successful the feed entry modified or created</li>
+ * <li>get requests will respond with a statuscode and if successful the
+ * requested feed</li>
+ * </ol>
+ * 
+ * For this purpose the {@link GDataResponse} class provides the overloaded
+ * method
+ * {@link org.apache.lucene.gdata.server.GDataResponse#sendResponse(BaseEntry, ExtensionProfile)}
+ * which sends the entry e.g feed to the output stream.
+ * </p>
+ * <p>
+ * This class will set the HTTP <tt>Last-Modified</tt> Header to enable
+ * clients to send <tt>If-Modified-Since</tt> request header to avoid
+ * retrieving the content again if it hasn't changed. If the content hasn't
+ * changed since the If-Modified-Since time, then the GData service returns a
+ * 304 (Not Modified) HTTP response.
+ * </p>
+ * 
+ * 
+ * 
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class GDataResponse {
+    private int error;
+
+    private boolean isError = false;
+
+    private String encoding;
+
+    private OutputFormat outputFormat;
+
+    private final HttpServletResponse response;
+
+    protected static final String XMLMIME_ATOM = "text/xml";
+
+    protected static final String XMLMIME_RSS = "text/xml";
+
+    private static final String DEFAUL_NAMESPACE_URI = "http://www.w3.org/2005/Atom";
+
+    private static final Namespace DEFAULT_NAMESPACE = new Namespace("",
+            DEFAUL_NAMESPACE_URI);
+
+    private static final String HEADER_LASTMODIFIED = "Last-Modified";
+
+    /**
+     * Creates a new GDataResponse
+     * 
+     * @param response -
+     *            The underlaying {@link HttpServletResponse}
+     */
+    public GDataResponse(HttpServletResponse response) {
+        if (response == null)
+            throw new IllegalArgumentException("response must not be null");
+        this.response = response;
+
+    }
+
+    /**
+     * Sets an error code to this FeedResponse.
+     * 
+     * @param errorCode -
+     *            {@link HttpServletResponse} error code
+     */
+    public void setError(int errorCode) {
+        this.isError = true;
+        this.error = errorCode;
+    }
+
+    /**
+     * Sets the status of the underlaying response
+     * 
+     * @see HttpServletResponse
+     * @param responseCode -
+     *            the status of the response
+     */
+    public void setResponseCode(int responseCode) {
+        this.response.setStatus(responseCode);
+    }
+
+    /**
+     * This method sends the specified error to the user if set
+     * 
+     * @throws IOException -
+     *             if an I/O Exception occures
+     */
+    public void sendError() throws IOException {
+        if (this.isError)
+            this.response.sendError(this.error);
+        
+    }
+
+    /**
+     * @return - the {@link HttpServletResponse} writer
+     * @throws IOException -
+     *             If an I/O exception occures
+     */
+    public Writer getWriter() throws IOException {
+        return this.response.getWriter();
+    }
+
+    /**
+     * Sends a response for a get e.g. query request. This method must not
+     * invoked in a case of an error performing the requeste action.
+     * 
+     * @param feed -
+     *            the feed to respond to the client
+     * @param profile -
+     *            the extension profil for the feed to write
+     * @throws IOException -
+     *             if an I/O exception accures, often caused by an already
+     *             closed Writer or OutputStream
+     * 
+     */
+    public void sendResponse(BaseFeed feed, ExtensionProfile profile)
+            throws IOException {
+        if (feed == null)
+            throw new IllegalArgumentException("feed must not be null");
+        if (profile == null)
+            throw new IllegalArgumentException(
+                    "extension profil must not be null");
+        DateTime time = feed.getUpdated();
+        if (time != null)
+            setLastModifiedHeader(time.getValue());
+        XmlWriter writer = createWriter();
+
+        if (this.outputFormat.equals(OutputFormat.ATOM)) {
+            this.response.setContentType(XMLMIME_ATOM);
+            feed.generateAtom(writer, profile);
+        } else {
+            this.response.setContentType(XMLMIME_RSS);
+            feed.generateRss(writer, profile);
+        }
+
+    }
+
+    /**
+     * 
+     * Sends a response for an update, insert or delete request. This method
+     * must not invoked in a case of an error performing the requeste action. If
+     * the specified response format is ATOM the default namespace will be set
+     * to ATOM.
+     * 
+     * @param entry -
+     *            the modified / created entry to send
+     * @param profile -
+     *            the entries extension profile
+     * @throws IOException -
+     *             if an I/O exception accures, often caused by an already
+     *             closed Writer or OutputStream
+     */
+    public void sendResponse(BaseEntry entry, ExtensionProfile profile)
+            throws IOException {
+        if (entry == null)
+            throw new IllegalArgumentException("entry must not be null");
+        if (profile == null)
+            throw new IllegalArgumentException(
+                    "extension profil must not be null");
+        DateTime time = entry.getUpdated();
+        if (time != null)
+            setLastModifiedHeader(time.getValue());
+        XmlWriter writer = createWriter();
+        if (this.outputFormat.equals(OutputFormat.ATOM))
+            entry.generateAtom(writer, profile);
+        else
+            entry.generateRss(writer, profile);
+    }
+
+    private XmlWriter createWriter() throws IOException {
+        XmlWriter writer = new XmlWriter(getWriter(), this.encoding);
+        // set the default namespace to Atom if Atom is the response format
+        if (this.outputFormat.equals(OutputFormat.ATOM))
+            writer.setDefaultNamespace(DEFAULT_NAMESPACE);
+        return writer;
+    }
+
+    /**
+     * This encoding will be used to encode the xml representation of feed or
+     * entry written to the {@link HttpServletResponse} output stream.
+     * 
+     * @return - the entry / feed encoding
+     */
+    public String getEncoding() {
+        return this.encoding;
+    }
+
+    /**
+     * This encoding will be used to encode the xml representation of feed or
+     * entry written to the {@link HttpServletResponse} output stream. <i>UTF-8</i>
+     * <i>ISO-8859-1</i>
+     * 
+     * @param encoding -
+     *            string represents the encoding
+     */
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    /**
+     * @return - the response
+     *         {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat}
+     */
+    public OutputFormat getOutputFormat() {
+        return this.outputFormat;
+    }
+
+    /**
+     * @param outputFormat -
+     *            the response
+     *            {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat}
+     */
+    public void setOutputFormat(OutputFormat outputFormat) {
+        this.outputFormat = outputFormat;
+    }
+
+    /**
+     * @see Object#toString()
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder(" GDataResponse: ");
+        builder.append("Error: ").append(this.error);
+        builder.append(" outputFormat: ").append(getOutputFormat());
+        builder.append(" encoding: ").append(this.encoding);
+
+        return builder.toString();
+
+    }
+
+    protected void setLastModifiedHeader(long lastModified) {
+        String lastMod = DateFormater.formatDate(new Date(lastModified),
+                DateFormater.HTTP_HEADER_DATE_FORMAT);
+        this.response.setHeader(HEADER_LASTMODIFIED, lastMod);
+    }
+    
+    /**
+     * @see HttpServletResponse#setStatus(int)
+     * @param status - the request status code
+     */
+    public void setStatus(int status){
+        this.response.setStatus(status);
+    }
+
+}