lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r430568 [5/8] - in /lucene/java/trunk/contrib/gdata-server: ./ lib/ src/java/org/apache/lucene/gdata/data/ src/java/org/apache/lucene/gdata/search/ src/java/org/apache/lucene/gdata/search/analysis/ src/java/org/apache/lucene/gdata/search/co...
Date Thu, 10 Aug 2006 22:32:47 GMT
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultInsertHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultInsertHandler.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultInsertHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultInsertHandler.java Thu Aug 10 15:32:40 2006
@@ -26,6 +26,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
 import org.apache.lucene.gdata.server.GDataRequestException;
+import org.apache.lucene.gdata.server.GDataResponse;
 import org.apache.lucene.gdata.server.ServiceException;
 import org.apache.lucene.gdata.server.GDataRequest.GDataRequestType;
 
@@ -40,7 +41,7 @@
  * </p>
  * <ol>
  * <li>if the entry was added - HTTP status code <i>200 OK</i></li>
- * <li>if an error occures - HTTP status code <i>500 INTERNAL SERVER ERROR</i></li>
+ * <li>if an error occurs - HTTP status code <i>500 INTERNAL SERVER ERROR</i></li>
  * <li>if the resource could not found - HTTP status code <i>404 NOT FOUND</i></li>
  * </ol>
  * <p>The added entry will be send back to the client if the insert request was successful.</p>
@@ -64,7 +65,7 @@
             return;
         }
         if(!authenticateAccount(this.feedRequest,AccountRole.ENTRYAMINISTRATOR)){
-            setError(HttpServletResponse.SC_UNAUTHORIZED);
+            setError(GDataResponse.UNAUTHORIZED);
             sendError();
             return;
         }
@@ -72,12 +73,13 @@
         try{        
         BaseEntry entry = this.service.createEntry(this.feedRequest,this.feedResponse);
         setFeedResponseFormat();
-        setFeedResponseStatus(HttpServletResponse.SC_CREATED);        
+        setFeedResponseStatus(GDataResponse.CREATED);        
         this.feedResponse.sendResponse(entry, this.feedRequest.getConfigurator().getExtensionProfile());
         
         }catch (ServiceException e) {
            LOG.error("Could not process GetFeed request - "+e.getMessage(),e);
-           this.feedResponse.sendError();
+           setError(e.getErrorCode());
+           sendError();
         }finally{
         closeService();
         }

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultUpdateHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultUpdateHandler.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultUpdateHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultUpdateHandler.java Thu Aug 10 15:32:40 2006
@@ -25,6 +25,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
 import org.apache.lucene.gdata.server.GDataRequestException;
+import org.apache.lucene.gdata.server.GDataResponse;
 import org.apache.lucene.gdata.server.ServiceException;
 import org.apache.lucene.gdata.server.GDataRequest.GDataRequestType;
 
@@ -39,7 +40,7 @@
  * </p>
  * <ol>
  * <li>if the entry was successfully updated - HTTP status code <i>200 OK</i></li>
- * <li>if an error occures - HTTP status code <i>500 INTERNAL SERVER ERROR</i></li>
+ * <li>if an error occurs - HTTP status code <i>500 INTERNAL SERVER ERROR</i></li>
  * <li>if the resource could not found - HTTP status code <i>404 NOT FOUND</i></li>
  * </ol>
  * 
@@ -61,7 +62,7 @@
 		try {
 			initializeRequestHandler(request, response,GDataRequestType.UPDATE);
 		} catch (GDataRequestException e) {
-            setError(HttpServletResponse.SC_UNAUTHORIZED);
+            setError(GDataResponse.UNAUTHORIZED);
 			sendError();
 			return;
 		}
@@ -74,13 +75,13 @@
 			BaseEntry entry = this.service.updateEntry(this.feedRequest,
 					this.feedResponse);
 			setFeedResponseFormat();
-			setFeedResponseStatus(HttpServletResponse.SC_OK);
 			this.feedResponse.sendResponse(entry, this.feedRequest.getConfigurator().getExtensionProfile());
 		
 		}
 		catch (ServiceException e) {
 			LOG.error("Could not process UpdateFeed request - "
 					+ e.getMessage(), e);
+            setError(e.getErrorCode());
 			sendError();
 		}finally{
         closeService();

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DeleteFeedHandler.java Thu Aug 10 15:32:40 2006
@@ -25,6 +25,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.GDataResponse;
+import org.apache.lucene.gdata.server.ServiceException;
 import org.apache.lucene.gdata.server.ServiceFactory;
 import org.apache.lucene.gdata.server.administration.AdminService;
 import org.apache.lucene.gdata.server.registry.ComponentType;
@@ -52,16 +54,16 @@
                 GDataServerRegistry registry = GDataServerRegistry.getRegistry();
                 ServiceFactory serviceFactory = registry.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
                 if(serviceFactory == null){
-                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"required component is not available");
+                    setError(GDataResponse.SERVER_ERROR,"required component is not available");
                     throw new FeedHandlerException("Can't save feed - ServiceFactory is null");
                 }
                 service = serviceFactory.getAdminService();
                 service.deleteFeed(feed);
             } catch (FeedHandlerException e) {
                 LOG.error("Can not delete feed -- "+e.getMessage(),e);
-            }catch (Exception e) {
+            }catch (ServiceException e) {
                 LOG.error("Can not delete feed -- "+e.getMessage(),e);
-                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"can not create feed");
+                setError(e.getErrorCode(),"can not create feed");
             }finally{
                 if(service != null)
                     service.close();
@@ -76,7 +78,7 @@
     private ServerBaseFeed createDeleteFeed(final HttpServletRequest request) throws FeedHandlerException {
         String feedId = request.getParameter("feedid");
         if(feedId == null){
-            setError(HttpServletResponse.SC_BAD_REQUEST,"No feed id specified");
+            setError(GDataResponse.BAD_REQUEST,"No feed id specified");
             throw new FeedHandlerException("no feed Id specified");
         }
         ServerBaseFeed retVal = new ServerBaseFeed();

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/InsertFeedHandler.java Thu Aug 10 15:32:40 2006
@@ -26,12 +26,15 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.data.GDataAccount;
 import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.GDataResponse;
 import org.apache.lucene.gdata.server.ServiceException;
 import org.apache.lucene.gdata.server.ServiceFactory;
 import org.apache.lucene.gdata.server.administration.AdminService;
 import org.apache.lucene.gdata.server.registry.ComponentType;
 import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
 
+import com.google.gdata.util.ParseException;
+
 /**
  * @author Simon Willnauer
  * 
@@ -66,12 +69,14 @@
                 service = serviceFactory.getAdminService();
                 service.createFeed(feed, account);
             } catch (ServiceException e) {
-                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                setError(GDataResponse.SERVER_ERROR,
                         "can not create feed");
                 LOG.error("Can not create feed -- " + e.getMessage(), e);
-            } catch (Exception e) {
+            } catch (FeedHandlerException e) {
                 LOG.error("Can not create feed -- " + e.getMessage(), e);
 
+            }catch (ParseException e) {
+                LOG.error("Can not create feed -- " + e.getMessage(), e);
             }finally{
                 if(service != null)
                     service.close();

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/UpdateFeedHandler.java Thu Aug 10 15:32:40 2006
@@ -26,6 +26,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.data.GDataAccount;
 import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.GDataResponse;
 import org.apache.lucene.gdata.server.ServiceException;
 import org.apache.lucene.gdata.server.ServiceFactory;
 import org.apache.lucene.gdata.server.administration.AdminService;
@@ -59,7 +60,7 @@
                 ServiceFactory serviceFactory = registry.lookup(
                         ServiceFactory.class, ComponentType.SERVICEFACTORY);
                 if (serviceFactory == null) {
-                    setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                    setError(GDataResponse.SERVER_ERROR,
                             "required component is not available");
                     throw new FeedHandlerException(
                             "Can't update feed - ServiceFactory is null");
@@ -67,7 +68,7 @@
                 service = serviceFactory.getAdminService();
                 service.updateFeed(feed, account);
             } catch (ServiceException e) {
-                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                setError(e.getErrorCode(),
                         "can not update feed");
                 LOG.error("Can not update feed -- " + e.getMessage(), e);
             } catch (Exception e) {

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oController.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oController.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oController.java Thu Aug 10 15:32:40 2006
@@ -156,13 +156,14 @@
                 false);
         Db4o.configure().objectClass(ServerBaseFeed.class)
                 .maximumActivationDepth(0);
-        Db4o.configure().objectClass(BaseFeed.class).minimumActivationDepth(10);
+        Db4o.configure().objectClass(BaseFeed.class).minimumActivationDepth(1);
         Db4o.configure().objectClass(BaseEntry.class)
-                .minimumActivationDepth(10);
+                .minimumActivationDepth(1);
         Db4o.configure().objectClass(BaseFeed.class).cascadeOnDelete(true);
         Db4o.configure().objectClass(DB4oEntry.class).cascadeOnDelete(true);
         Db4o.configure().objectClass(GDataAccount.class).cascadeOnDelete(true);
         Db4o.configure().weakReferences(this.weakReferences);
+        Db4o.configure().optimizeNativeQueries(false);
         if (this.runAsServer) {
             this.server = Db4o.openServer(this.filePath, this.port);
             this.server.grantAccess(this.user, this.password);
@@ -181,8 +182,7 @@
         try {
             createAdminAccount();
         } catch (StorageException e) {
-
-            e.printStackTrace();
+            LOG.error("Can not create admin account -- ",e);
         }
     }
 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oStorage.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oStorage.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oStorage.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/db4o/DB4oStorage.java Thu Aug 10 15:32:40 2006
@@ -25,6 +25,7 @@
 import org.apache.lucene.gdata.data.ServerBaseEntry;
 import org.apache.lucene.gdata.data.ServerBaseFeed;
 import org.apache.lucene.gdata.storage.ModificationConflictException;
+import org.apache.lucene.gdata.storage.ResourceNotFoundException;
 import org.apache.lucene.gdata.storage.Storage;
 import org.apache.lucene.gdata.storage.StorageController;
 import org.apache.lucene.gdata.storage.StorageException;
@@ -38,7 +39,7 @@
 
 /**
  * 
- * Storage implementaion for the DB4o storage component
+ * Storage implementation for the DB4o storage component
  * @author Simon Willnauer
  * 
  */
@@ -92,7 +93,7 @@
             throw new StorageException("can not store entry -- feed id is null");
         if (LOG.isDebugEnabled())
             LOG.debug("Storing entry for feed: " + entry.getFeedId());
-        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId());
+        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId(),entry.getServiceType());
        refreshPersistentObject(feed);
         try {
             StringBuilder idBuilder = new StringBuilder(entry.getFeedId());
@@ -181,7 +182,7 @@
         if(persistentEntry.getVersion() != entry.getVersion())
             throw new ModificationConflictException(
                     "Current version does not match given version  -- currentVersion: "+persistentEntry.getVersion()+"; given Version: "+entry.getVersion() );
-        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId());
+        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId(),entry.getServiceType());
         refreshPersistentObject(feed);
         DateTime time = DateTime.now();
         if (persistentEntry.getEntry().getUpdated() != null)
@@ -226,7 +227,7 @@
                     "Current version does not match given version  -- currentVersion: "+persistentEntry.getVersion()+"; given Version: "+entry.getVersion() );
         
         setUpdated(entry, persistentEntry);
-        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId());
+        BaseFeed<BaseFeed, BaseEntry> feed = getFeedOnly(entry.getFeedId(),entry.getServiceType());
         refreshPersistentObject(feed);
         BaseEntry retVal = entry.getEntry(); 
         DB4oEntry newEntry = new DB4oEntry();
@@ -255,6 +256,8 @@
         return retVal;
 
     }
+    
+
 
     /**
      * @see org.apache.lucene.gdata.storage.Storage#getFeed(org.apache.lucene.gdata.data.ServerBaseFeed)
@@ -270,10 +273,10 @@
 
         if (LOG.isInfoEnabled())
             LOG.info("Fetching feed for feedID: " + feed.getId()
-                    + "; startindex: " + feed.getStartIndex()
+                    + "; start-index: " + feed.getStartIndex()
                     + "; items per page: " + feed.getItemsPerPage());
 
-       BaseFeed<BaseFeed, BaseEntry> persistentFeed = getFeedOnly(feed.getId());
+       BaseFeed<BaseFeed, BaseEntry> persistentFeed = getFeedOnly(feed.getId(),feed.getServiceType());
        /*
         * prevent previously added entries in long running storage instances
         */
@@ -290,7 +293,7 @@
         if (size < feed.getStartIndex()) {
             if (LOG.isDebugEnabled())
                 LOG.debug("no entries found for feed constrain -- feedID: "
-                        + feed.getId() + "; startindex: "
+                        + feed.getId() + "; start-index: "
                         + feed.getStartIndex() + "; items per page: "
                         + feed.getItemsPerPage());
             return persistentFeed;
@@ -311,22 +314,34 @@
     }
 
     @SuppressWarnings("unchecked")
-    private BaseFeed<BaseFeed, BaseEntry> getFeedOnly(String feedId)
+    private BaseFeed<BaseFeed, BaseEntry> getFeedOnly(final String feedId, final String serviceId)
             throws StorageException {
+        if(!checkService(feedId,serviceId))
+            throw new StorageException();
         Query query = this.container.query();
+        query.constrain(ServerBaseFeed.class);
+      
         query.constrain(BaseFeed.class);
+
         query.descend("id").constrain(feedId).equal();
+
         ObjectSet set = query.execute();
         if (set.size() > 1)
             throw new StorageException("Query for feed id " + feedId
                     + " returns more than one result");
         if (set.hasNext())
-            return (BaseFeed<BaseFeed, BaseEntry>) set.next();
-        throw new StorageException("can not find feed for given feed id -- "
+        return (BaseFeed<BaseFeed, BaseEntry>) set.next();
+        throw new ResourceNotFoundException("can not find feed for given feed id -- "
                 + feedId);
 
     }
-
+    private boolean checkService(String feedId,String serviceId){
+        Query query = this.container.query();
+        query.constrain(ServerBaseFeed.class);
+        query.descend("feed").descend("id").constrain(feedId).equal();
+        query.descend("serviceType").constrain(serviceId).equal();
+        return query.execute().size() == 1;
+    }
     private ObjectSet getEnriesForFeedID(String feedId) {
         Query query = this.container.query();
         query.constrain(DB4oEntry.class);
@@ -360,7 +375,7 @@
                     "Entry query returned not a unique result");
         if (resultSet.hasNext())
             return resultSet.next();
-        throw new StorageException("no entry with entryID: " + id
+        throw new ResourceNotFoundException("no entry with entryID: " + id
                 + " stored -- query returned no result");
     }
 
@@ -432,7 +447,7 @@
     public void deleteAccount(String accountname) throws StorageException {
         if (accountname == null)
             throw new StorageException(
-                    "can not delete account -- accountname is null");
+                    "can not delete account -- account name is null");
         GDataAccount account = this.getAccount(accountname);
         refreshPersistentObject(account);
         if (LOG.isInfoEnabled())
@@ -474,7 +489,7 @@
         refreshPersistentObject(account);
         feed.setAccount(account);
         /*
-         * service config not requiered in db4o storage.
+         * service config not required in db4o storage.
          * Entries/Feeds don't have to be build from xml
          */
         feed.setServiceConfig(null);
@@ -566,7 +581,7 @@
             this.container.commit();
         } catch (Exception e) {
             LOG
-                    .error("Error occured on persisting changes -- rollback changes");
+                    .error("Error occurred on persisting changes -- rollback changes");
             this.container.rollback();
             throw new StorageException("Can not persist changes -- "
                     + e.getMessage(), e);
@@ -582,7 +597,7 @@
         if(feedId == null)
             throw new StorageException("can not get Service for feed -- feed id is null");
         if(LOG.isInfoEnabled())
-            LOG.info("retriving Service for feed -- feed id: "+feedId);
+            LOG.info("Retrieving Service for feed -- feed id: "+feedId);
         Query query = this.container.query();
         query.constrain(ServerBaseFeed.class);
         query.descend("feed").descend("id").constrain(feedId);
@@ -593,9 +608,10 @@
         if (feed.size() < 1)
             throw new StorageException("can not find feed for given feed id -- "
                 + feedId);
+        
         ServerBaseFeed result = feed.next();
         if(LOG.isInfoEnabled())
-            LOG.info("retrived Service for feed -- serviceType: "+result.getServiceType());
+            LOG.info("Retrieved Service for feed -- serviceType: "+result.getServiceType());
         return result.getServiceType();
     }
 
@@ -605,7 +621,7 @@
     public GDataAccount getAccount(String accountName) throws StorageException {
         if (accountName == null)
             throw new StorageException(
-                    "Can not get account -- accountname is null");
+                    "Can not get account -- account name is null");
         if (LOG.isInfoEnabled())
             LOG.info("Retrieving account for account name: " + accountName);
         Query query = this.container.query();
@@ -617,7 +633,7 @@
                     "Account query returned not a unique result -- account name: "
                             + accountName);
         if (!set.hasNext())
-            throw new StorageException(
+            throw new ResourceNotFoundException(
                     "No such account stored -- query returned not result for account name: "
                             + accountName);
 
@@ -676,8 +692,8 @@
     }
     
     /*
-     * !Caution! -- could instanciate a lot of objects if used with certain classes!!
-     * refreshs a persistend object with a depth of 100
+     * !Caution! -- could instantiate a lot of objects if used with certain classes!!
+     * Refresh a persisted object with a depth of 100
      * 
      */
     private void refreshPersistentObject(Object o){

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/ModifiedEntryFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/ModifiedEntryFilter.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/ModifiedEntryFilter.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/ModifiedEntryFilter.java Thu Aug 10 15:32:40 2006
@@ -1,79 +0,0 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
- * 
- * Licensed 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. 
- */ 
- 
-package org.apache.lucene.gdata.storage.lucenestorage; 
- 
-import java.io.IOException;
-import java.util.BitSet;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.search.Filter;
- 
-/** 
- * The {@link ModifiedEntryFilter} filters the given entryIds from the lucene 
- * {@link org.apache.lucene.search.Hits} set. This filter is used to prevent the 
- * storage from retrieving already deleted or updated entries still remainig in 
- * the {@link org.apache.lucene.gdata.storage.lucenestorage.StorageBuffer}. 
- *  
- * @see org.apache.lucene.search.Filter 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class ModifiedEntryFilter extends Filter { 
-    /** 
-     * impl Serializable 
-     */ 
-    private static final long serialVersionUID = -1551686287704213591L; 
- 
-    private final String[] entyIds; 
- 
-    /** 
-     * Creates a new {@link ModifiedEntryFilter} 
-     * @param entryIds the entry id's to filter  
-     *  
-     */ 
-    public ModifiedEntryFilter(final String[] entryIds) { 
-        super(); 
-        this.entyIds = entryIds; 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader) 
-     */ 
-    @Override 
-    public BitSet bits(IndexReader reader) throws IOException { 
-        BitSet bitSet = new BitSet(reader.maxDoc()); 
-        bitSet.flip(0, reader.maxDoc()); // set all docs  
-        int[] docs = new int[1]; 
-        int[] freq = new int[1]; 
-        for (String id : this.entyIds) { 
-            if (id != null) { 
-                TermDocs termDocs = reader.termDocs(new Term( 
-                        StorageEntryWrapper.FIELD_ENTRY_ID, id)); 
-                int count = termDocs.read(docs, freq); 
-                if (count == 1) 
-                    bitSet.flip(docs[0]); 
- 
-            } 
-        } 
- 
-        return bitSet; 
-    } 
- 
-} 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageBuffer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageBuffer.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageBuffer.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageBuffer.java Thu Aug 10 15:32:40 2006
@@ -32,6 +32,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+import org.apache.lucene.gdata.utils.ModifiedEntryFilter;
 
 import com.google.gdata.data.BaseEntry;
 import com.google.gdata.data.ExtensionProfile;

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreController.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreController.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreController.java Thu Aug 10 15:32:40 2006
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
 package org.apache.lucene.gdata.storage.lucenestorage;
 
 import java.io.File;
@@ -19,7 +34,7 @@
 import org.apache.lucene.gdata.storage.StorageException;
 import org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverController;
 import org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverException;
-import org.apache.lucene.gdata.storage.lucenestorage.util.ReferenceCounter;
+import org.apache.lucene.gdata.utils.ReferenceCounter;
 import org.apache.lucene.index.IndexModifier;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
@@ -212,7 +227,7 @@
      * <p>
      * if the reference counter has no remaining references the resource e.g.
      * the <tt>StorageQuery</tt> will be closed. This ensures that a
-     * <tt>StorageQuery</tt> instance will be arround as long as needed and
+     * <tt>StorageQuery</tt> instance will be around as long as needed and
      * the resources will be released. The reference counter should be
      * decremented by clients after finished using the query instance.
      * </p>
@@ -232,7 +247,7 @@
                 this.storageQuery = getNewStorageQueryHolder(new StorageQuery(
                         this.currentBuffer, this.searcher));
                 if (LOG.isInfoEnabled())
-                    LOG.info("Relese new StorageQuery");
+                    LOG.info("Release new StorageQuery");
             }
             this.storageQuery.increamentReference();
             return this.storageQuery;
@@ -271,7 +286,7 @@
      * changes available for searching.
      * 
      * @throws IOException -
-     *             if an IO exception occures
+     *             if an IO exception occurs
      */
     protected void registerNewStorageQuery() throws IOException {
     	if(this.isClosed.get())
@@ -324,7 +339,7 @@
      * 
      * @return - a new modifier
      * @throws IOException -
-     *             if an IO exception occures
+     *             if an IO exception occurs
      */
     protected IndexModifier createIndexModifier() throws IOException {
     	if(this.isClosed.get())
@@ -380,7 +395,7 @@
      * Forces the StorageModifier to write all buffered changes.
      * 
      * @throws IOException -
-     *             if an IO exception occures
+     *             if an IO exception occurs
      * 
      */
     public void forceWrite() throws IOException {
@@ -492,7 +507,7 @@
 
     /**
      * An integer value after how many changes to the StorageModifier the
-     * buffered changes will be persisted / wirtten to the index
+     * buffered changes will be persisted / written to the index
      * 
      * @return - the persist factor
      */

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageImplementation.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageImplementation.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageImplementation.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageImplementation.java Thu Aug 10 15:32:40 2006
@@ -31,7 +31,7 @@
 import org.apache.lucene.gdata.storage.StorageController;
 import org.apache.lucene.gdata.storage.StorageException;
 import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
-import org.apache.lucene.gdata.storage.lucenestorage.util.ReferenceCounter;
+import org.apache.lucene.gdata.utils.ReferenceCounter;
 
 import com.google.gdata.data.BaseEntry;
 import com.google.gdata.data.BaseFeed;
@@ -42,7 +42,7 @@
  * StorageImplementation provides access to the
  * {@link org.apache.lucene.gdata.storage.lucenestorage.StorageQuery} and the
  * {@link org.apache.lucene.gdata.storage.lucenestorage.StorageModifier}. This
- * class will be instanciated per client request.
+ * class will be instantiated per client request.
  * 
  * 
  * 
@@ -80,7 +80,7 @@
         if (entry == null)
             throw new StorageException("entry is null");
         if(entry.getFeedId() == null)
-            throw new StorageException("feedid is null");
+            throw new StorageException("feed-id is null");
         if(entry.getVersion() != 1)
             throw new StorageException("entry version must be 1");
         if(entry.getServiceConfig() == null)
@@ -223,7 +223,7 @@
         if (feed == null)
             throw new StorageException("feed is null");
         if (LOG.isInfoEnabled())
-            LOG.info("get feed: " + feed.getId() + " startindex: "
+            LOG.info("get feed: " + feed.getId() + " start-index: "
                     + feed.getStartIndex() + " resultCount: "
                     + feed.getItemsPerPage());
         ReferenceCounter<StorageQuery> query = null;
@@ -514,7 +514,7 @@
     public String getAccountNameForFeedId(String feedId)
             throws StorageException {
         if (feedId == null)
-            throw new StorageException("feedid must not be null");
+            throw new StorageException("feed-id must not be null");
         ReferenceCounter<StorageQuery> query = null;
         try {
             query = this.controller.getStorageQuery();

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java Thu Aug 10 15:32:40 2006
@@ -26,11 +26,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
 import org.apache.lucene.gdata.data.GDataAccount;
 import org.apache.lucene.gdata.server.GDataEntityBuilder;
 import org.apache.lucene.gdata.server.registry.ProvidedService;
 import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.gdata.utils.ModifiedEntryFilter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
@@ -48,7 +48,7 @@
 import com.google.gdata.util.ParseException;
 
 /**
- * StorageQuery wrapps a Lucene {@link org.apache.lucene.search.IndexSearcher}
+ * StorageQuery wraps a Lucene {@link org.apache.lucene.search.IndexSearcher}
  * and a {@link org.apache.lucene.gdata.storage.lucenestorage.StorageBuffer} to
  * perform all request on the lucene storage. The wrapped components are thread -
  * safe.
@@ -109,7 +109,7 @@
         }
 
         return this.searcher.search(query, new ModifiedEntryFilter(this.buffer
-                .getExculdList()));
+                .getExculdList(),StorageEntryWrapper.FIELD_ENTRY_ID));
     }
 
     /*
@@ -120,7 +120,7 @@
         TermQuery query = new TermQuery(new Term(
                 StorageEntryWrapper.FIELD_FEED_REFERENCE, feedId));
         return this.searcher.search(query, new ModifiedEntryFilter(this.buffer
-                .getExculdList()), sort);
+                .getExculdList(),StorageEntryWrapper.FIELD_ENTRY_ID), sort);
 
     }
 
@@ -135,21 +135,21 @@
          * deleted entries. These entries must be found!!
          */
         return this.searcher.search(termQuery, new ModifiedEntryFilter(
-                this.buffer.getExculdList()));
+                this.buffer.getExculdList(),StorageEntryWrapper.FIELD_ENTRY_ID));
 
     }
 
     /**
      * This method fetches the latest feed entries from the storage. Feed
-     * ususaly requested via a search query or as a simple query to the REST
+     * usually requested via a search query or as a simple query to the REST
      * interface.
      * <p>
-     * The REST interface requestes all the entries from a Storage. The Storage
+     * The REST interface requests all the entries from a Storage. The Storage
      * retrieves the entries corresponding to the parameters specified. This
      * method first requests the latest entries or updated entries from the
-     * {@link StorageBuffer}. If the buffer already contains enought entries
-     * for the the specified result count the entires will be returned. If not,
-     * the underlaying lucene index will be searcher for all documents of the
+     * {@link StorageBuffer}. If the buffer already contains enough entries
+     * for the the specified result count the entries will be returned. If not,
+     * the underlying lucene index will be searcher for all documents of the
      * specified feed sorted by storing timestamp desc.
      * </p>
      * <p>
@@ -164,10 +164,10 @@
      * @param resultCount -
      *            how many entries are requested
      * @param startIndex -
-     *            the offset of the entriy to start from.
+     *            the offset of the entry to start from.
      * @param config -
-     *            the FeedInstanceConfiguration contaning extension profile used
-     *            to create the entriy instances
+     *            the FeedInstanceConfiguration containing extension profile used
+     *            to create the entry instances
      * @return - an ordered list of {@link BaseEntry} objects, or an empty list
      *         if no entries could be found
      * @throws IOException -
@@ -214,7 +214,7 @@
             }
         } else {
             /*
-             * if the buffersize is less than the startindex the buffersize must
+             * if the buffer size is less than the start index the buffer size must
              * be considered. Sublists would not be a repeatable read part of
              * the whole list
              */
@@ -251,7 +251,7 @@
     /**
      * This method retrieves a single entry from the storage. If the
      * {@link StorageBuffer} does not contain the requested entry the
-     * underlaying storage index will be searched.
+     * underlying storage index will be searched.
      * <p>
      * The Entry will be searched in a feed context specified by the given feed
      * ID
@@ -260,10 +260,10 @@
      * @param entryId -
      *            the entry to fetch
      * @param feedId -
-     *            the feedid eg. feed context
+     *            the feed id e.g. feed context
      * @param config -
-     *            the FeedInstanceConfiguration contaning extension profile used
-     *            to create the entriy instances
+     *            the FeedInstanceConfiguration containing extension profile used
+     *            to create the entry instances
      * @return - the requested {@link BaseEntry} or <code>null</code> if the
      *         entry can not be found
      * @throws IOException -
@@ -297,9 +297,9 @@
 
     /**
      * Fetches the requested entries from the storage. The given list contains
-     * entry ids to be looked up in the storage. First the {@link StorageBuffer}
-     * will be queried for the entry ids. If not all of the entries remain in
-     * the buffer the underlaying lucene index will be searched. The entries are
+     * entry id's to be looked up in the storage. First the {@link StorageBuffer}
+     * will be queried for the entry id's. If not all of the entries remain in
+     * the buffer the underlying lucene index will be searched. The entries are
      * not guaranteed to be in the same order as they are in the given id list.
      * Entry ID's not found in the index or the buffer will be omitted.
      * <p>
@@ -308,12 +308,12 @@
      * </p>
      * 
      * @param entryIds -
-     *            the entriy ids to fetch.
+     *            the entry id's to fetch.
      * @param feedId -
-     *            the feed id eg. feed context.
+     *            the feed id e.g. feed context.
      * @param config -
-     *            the FeedInstanceConfiguration contaning extension profile used
-     *            to create the entriy instances
+     *            the FeedInstanceConfiguration containing extension profile used
+     *            to create the entry instances
      * 
      * @return - the list of entries corresponding to the given entry id list.
      * @throws IOException -
@@ -395,7 +395,7 @@
      * not be reused after invoking this method.
      * 
      * @throws IOException -
-     *             if the resouces can not be closed
+     *             if the resources can not be closed
      */
     public void close() throws IOException {
         this.searcher.close();
@@ -419,7 +419,7 @@
     }
 
     /**
-     * Looks up the feedtype for the given feed ID
+     * Looks up the feed type for the given feed ID
      * 
      * @param feedID -
      *            the feed ID

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/util/ReferenceCounter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/util/ReferenceCounter.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/util/ReferenceCounter.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/util/ReferenceCounter.java Thu Aug 10 15:32:40 2006
@@ -1,77 +0,0 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
- * 
- * Licensed 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. 
- */ 
- 
-package org.apache.lucene.gdata.storage.lucenestorage.util; 
- 
-import java.util.concurrent.atomic.AtomicInteger; 
- 
-/** 
- * A reference counting utility. This is use to keep track of released objects 
- * of <code>Type</code>. 
- *  
- * @author Simon Willnauer 
- * @param <Type> - 
- *            the type of the object 
- *  
- */ 
-public abstract class ReferenceCounter<Type> { 
-    protected final Type resource; 
- 
-    private AtomicInteger refcounter = new AtomicInteger(); 
- 
-    /** 
-     * @param resource - 
-     *            the resouce to track 
-     *  
-     */ 
-    public ReferenceCounter(Type resource) { 
-        this.resource = resource; 
-    } 
- 
-    /** 
-     *  
-     * Decrements the reference. If no references remain the 
-     * {@link ReferenceCounter#close()} method will be inoked; 
-     */ 
-    public final void decrementRef() { 
-        if (this.refcounter.decrementAndGet() == 0) 
-            close(); 
-    } 
- 
-    /** 
-     * A custom implementation. Performs an action if no reference remaining 
-     *  
-     */ 
-    protected abstract void close(); 
- 
-    /** 
-     * Increments the reference 
-     *  
-     * @return the refernece object 
-     */ 
-    public final ReferenceCounter<Type> increamentReference() { 
-        this.refcounter.incrementAndGet(); 
-        return this; 
-    } 
- 
-    /** 
-     * @return - the resource to keep track of 
-     */ 
-    public final Type get() { 
-        return this.resource; 
-    } 
- 
-} 

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,81 @@
+/** 
+ * Copyright 2004 The Apache Software Foundation 
+ * 
+ * Licensed 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. 
+ */ 
+ 
+package org.apache.lucene.gdata.utils; 
+ 
+import java.io.IOException;
+import java.util.BitSet;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.search.Filter;
+ 
+/** 
+ * The {@link ModifiedEntryFilter} filters the given entryIds from the lucene 
+ * {@link org.apache.lucene.search.Hits} set. This filter is used to prevent the 
+ * storage from retrieving already deleted or updated entries still remaining in 
+ * the {@link org.apache.lucene.gdata.storage.lucenestorage.StorageBuffer}. 
+ *  
+ * @see org.apache.lucene.search.Filter 
+ *  
+ * @author Simon Willnauer 
+ *  
+ */ 
+public class ModifiedEntryFilter extends Filter { 
+    /*
+     * implements Serializable 
+     */ 
+    private static final long serialVersionUID = -1551686287704213591L; 
+ 
+    private final String[] entyIds; 
+    private final String searchField;
+    /** 
+     * Creates a new {@link ModifiedEntryFilter} 
+     * @param entryIds the entry id's to filter  
+     * @param field - the field, the id is stored 
+     *  
+     */ 
+    public ModifiedEntryFilter(final String[] entryIds,String field) { 
+        super(); 
+        this.searchField = field;
+        this.entyIds = entryIds; 
+    } 
+ 
+    /** 
+     * @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader) 
+     */ 
+    @Override 
+    public BitSet bits(IndexReader reader) throws IOException { 
+        BitSet bitSet = new BitSet(reader.maxDoc()); 
+        bitSet.flip(0, reader.maxDoc()); // set all documents  
+        int[] docs = new int[1]; 
+        int[] freq = new int[1]; 
+        for (String id : this.entyIds) { 
+            if (id != null) { 
+                TermDocs termDocs = reader.termDocs(new Term( 
+                        this.searchField, id)); 
+                int count = termDocs.read(docs, freq); 
+                if (count == 1) 
+                    bitSet.flip(docs[0]); 
+ 
+            } 
+        } 
+ 
+        return bitSet; 
+    } 
+ 
+} 

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ModifiedEntryFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,80 @@
+/** 
+ * Copyright 2004 The Apache Software Foundation 
+ * 
+ * Licensed 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. 
+ */ 
+ 
+package org.apache.lucene.gdata.utils; 
+ 
+import java.util.concurrent.atomic.AtomicInteger; 
+ 
+/** 
+ * A reference counting utility. This is use to keep track of released objects 
+ * of <code>Type</code>. 
+ *  
+ * @author Simon Willnauer 
+ * @param <Type> - 
+ *            the type of the object 
+ *  
+ */ 
+public abstract class ReferenceCounter<Type> { 
+    protected final Type resource; 
+ 
+    private AtomicInteger refcounter = new AtomicInteger(); 
+ 
+    /** 
+     * @param resource - 
+     *            the resource to track 
+     *  
+     */ 
+    public ReferenceCounter(Type resource) { 
+        this.resource = resource; 
+    } 
+ 
+    /** 
+     *  
+     * Decrements the reference. If no references remain the 
+     * {@link ReferenceCounter#close()} method will be invoked; 
+     */ 
+    public final void decrementRef() { 
+        /*
+         * close if less or equals 0
+         */
+        if (this.refcounter.decrementAndGet() <= 0) 
+            close(); 
+    } 
+ 
+    /** 
+     * A custom implementation. Performs an action if no reference remaining 
+     *  
+     */ 
+    protected abstract void close(); 
+ 
+    /** 
+     * Increments the reference 
+     *  
+     * @return the reference object 
+     */ 
+    public final ReferenceCounter<Type> increamentReference() { 
+        this.refcounter.incrementAndGet(); 
+        return this; 
+    } 
+ 
+    /** 
+     * @return - the resource to keep track of 
+     */ 
+    public final Type get() { 
+        return this.resource; 
+    } 
+ 
+} 

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReferenceCounter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,193 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+package org.apache.lucene.gdata.utils;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * A collection of static helper methods solve common reflection problems
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class ReflectionUtils {
+
+    /**
+     * Check if the given type implements a given super type
+     * @param typeToCheck - type supposed to implement an interface
+     * @param superType - the interface to be implemented by the type to check
+     * @return <code>true</code> if and only if the super type is above in the type hierarchy of the given type, otherwise <code>false</code>
+     */
+    public static boolean implementsType(Class typeToCheck, Class superType) {
+        if(superType == null)
+            return false;
+        if(!superType.isInterface())
+            return  false;
+        if (typeToCheck == null)
+            return false;
+        if (typeToCheck.equals(Object.class))
+            return false;
+        if (typeToCheck.equals(superType))
+            return true;
+        Class[] interfaces = typeToCheck.getInterfaces();
+        for (int i = 0; i < interfaces.length; i++) {
+            if (implementsType(interfaces[i], superType))
+                return true;
+        }
+        return implementsType(typeToCheck.getSuperclass(),superType);
+        
+    }
+    /**
+     * Check if the given type extends a given super type
+     * @param typeToCheck - type supposed to extend an specific type
+     * @param superType - the type to be extended by the type to check
+     * @return <code>true</code> if and only if the super type is above in the type hierarchy of the given type, otherwise <code>false</code>
+     */
+    public static boolean extendsType(Class typeToCheck, Class superType) {
+        if (typeToCheck == null)
+            return false;
+        if (typeToCheck.equals(Object.class))
+            return false;
+        if (typeToCheck.equals(superType))
+            return true;
+        
+        return extendsType(typeToCheck.getSuperclass(),superType);
+    }
+    /**
+     * This method combines the extendsType and implementsType and checks interfaces and classes
+     * @param typeToCheck - type supposed to extend / implement an specific type
+     * @param superType - the type to be extended / implemented by the type to check
+     * @return <code>true</code> if and only if the super type is above in the type hierarchy of the given type, otherwise <code>false</code>
+     */
+    public static boolean isTypeOf(Class typeToCheck, Class superType){
+        return extendsType(typeToCheck,superType)||implementsType(typeToCheck,superType);
+    }
+    
+    /**
+     * @param type - the type to check
+     * @param parameter - the constructor parameter
+     * @return <code>true</code> if and only if the type has a visible constructor with the desired parameters
+     */
+    public static boolean hasDesiredConstructor(Class type, Class[] parameter){
+        try{
+        return type.getConstructor(parameter) != null;
+        
+        }catch (Exception e) {
+            return false;
+        }
+    }
+  
+ 
+/**
+ * @param <T> the type of the class to instantiate 
+ * @param clazz - class object of the type
+ * @return a new instance of T
+
+ */
+@SuppressWarnings("unchecked")
+public  static <T> T getDefaultInstance(Class<T> clazz) {
+    if(clazz == null)
+        throw new ReflectionException("class must not be null");
+    
+    try{
+    Constructor constructor = clazz.getConstructor(new Class[]{});
+    return (T) constructor.newInstance(new Object[]{});
+    }catch (Exception e) {
+        throw new ReflectionException("can not instantiate type of class "+clazz.getName(),e);
+    }
+}
+
+
+/**
+ * This method calls {@link Class#newInstance()} to get a new instance. Use with care!
+ * @param clazz - the class to instantiate
+ * @return <code>true</code> if an instance could be created, otherwise false;
+ */
+public static boolean canCreateInstance(Class clazz){
+    if(clazz == null)
+        return false;
+    if(clazz.isPrimitive())
+        clazz = getPrimitiveWrapper(clazz);
+    try{
+        Object o = clazz.newInstance();
+        return o != null;
+    }catch (Throwable e) {
+        return false;
+    }
+}
+/**
+ * Returns the wrapper type for the given primitive type. Wrappers can be
+ * easily instantiated via reflection and will be boxed by the VM
+ * @param primitive - the primitive type 
+ * @return - the corresponding wrapper type
+ */
+public static final Class getPrimitiveWrapper(Class primitive) {
+    if(primitive == null )
+        throw new ReflectionException("primitive must not be null");
+    if(!primitive.isPrimitive())
+        throw new ReflectionException("given class is not a primitive");
+                
+    if (primitive == Integer.TYPE)
+        return Integer.class;
+    if (primitive == Float.TYPE)
+        return Float.class;
+    if (primitive == Long.TYPE)
+        return Long.class;
+    if (primitive == Short.TYPE)
+        return Short.class;
+    if (primitive == Byte.TYPE)
+        return Byte.class;
+    if (primitive == Double.TYPE)
+        return Double.class;
+    if (primitive == Boolean.TYPE)
+        return Boolean.class;
+
+    return primitive;
+}
+
+/**
+ * Exception wrapper for all thrown exception in the ReflectionUtils methods
+ * @author Simon Willnauer
+ *
+ */
+public static class ReflectionException extends RuntimeException{
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -4855060602565614280L;
+
+    /**
+     * @param message -  the exception message
+     * @param cause - the exception root cause
+     */
+    public ReflectionException(String message, Throwable cause) {
+        super(message, cause);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message - the exception message
+     */
+    public ReflectionException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+    
+}
+
+}

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java?rev=430568&r1=430567&r2=430568&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java Thu Aug 10 15:32:40 2006
@@ -1,18 +1,34 @@
+/** 
+ * Copyright 2004 The Apache Software Foundation 
+ * 
+ * Licensed 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. 
+ */
 package org.apache.lucene.gdata.data;
 
-import java.net.MalformedURLException;
-import java.net.URL;
+import junit.framework.TestCase;
 
 import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
 
-import junit.framework.TestCase;
-
+/**
+ * @author Simon Willnauer
+ *
+ */
 public class TestGDataUser extends TestCase {
     private GDataAccount user;
     @Override
     protected void setUp() throws Exception {
         this.user = new GDataAccount();
-        this.user.setName("simon");
+        this.user.setName("simonW");
         super.setUp();
     }
 
@@ -26,6 +42,7 @@
      * Test method for 'org.apache.lucene.gdata.data.GDataUser.isUserInRole(UserRole)'
      */
     public void testIsUserInRole() {
+        assertFalse(this.user.isUserInRole(null));
         assertTrue(this.user.isUserInRole(AccountRole.USER));
         assertFalse(this.user.isUserInRole(AccountRole.ENTRYAMINISTRATOR));
         this.user.setRole(AccountRole.ENTRYAMINISTRATOR);
@@ -44,6 +61,19 @@
         this.user.setRole(AccountRole.USERADMINISTRATOR);
         assertEquals(15,this.user.getRolesAsInt());
         
+        
+        
+    }
+    
+    public void testIsUserInRoleInt(){
+        assertFalse(GDataAccount.isInRole(1,AccountRole.ENTRYAMINISTRATOR));
+        assertFalse(GDataAccount.isInRole(1,AccountRole.FEEDAMINISTRATOR));
+        assertTrue(GDataAccount.isInRole(3,AccountRole.ENTRYAMINISTRATOR));
+        assertTrue(GDataAccount.isInRole(15,AccountRole.ENTRYAMINISTRATOR));
+        assertTrue(GDataAccount.isInRole(3,AccountRole.USER));
+        assertTrue(GDataAccount.isInRole(15,AccountRole.USERADMINISTRATOR));
+        assertFalse(GDataAccount.isInRole(7,AccountRole.USERADMINISTRATOR));
+        assertFalse(GDataAccount.isInRole(7,null));
     }
 
     /*
@@ -62,7 +92,40 @@
         assertEquals(4,this.user.getRoles().size());
         
     }
-
+    
+    public void testEquals(){
+        assertTrue(this.user.equals(this.user));
+        GDataAccount a = new GDataAccount();
+        a.setName(this.user.getName());
+        assertTrue(this.user.equals(a));
+        a.setName("someOtheraccount");
+        assertFalse(this.user.equals(a));
+        assertFalse(this.user.equals(null));
+        assertFalse(this.user.equals(new String()));
+        assertFalse(new GDataAccount().equals(new GDataAccount()));
+    }
+    public void testHashCode(){
+        assertEquals(this.user.hashCode(),this.user.hashCode());
+        assertFalse(this.user.hashCode()== this.user.getName().hashCode());
+        GDataAccount a = new GDataAccount();
+        a.setName(this.user.getName());
+        assertEquals(this.user.hashCode(),a.hashCode());
+        a.setName(null);
+        assertFalse(a.hashCode()== this.user.hashCode());
+    }
+    
+    public void testReqValuesSet(){
+        assertFalse(this.user.requiredValuesSet());
+        this.user.setPassword("hello");
+        assertFalse(this.user.requiredValuesSet());
+        this.user.setPassword("helloworld");
+        assertTrue(this.user.requiredValuesSet());
+        assertFalse(new GDataAccount().requiredValuesSet());
+    }
+    
+    public void testToStringPrevNulPEx(){
+        assertNotNull(this.user.toString());
+    }
     
     
 

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,222 @@
+/** 
+ * Copyright 2004 The Apache Software Foundation 
+ * 
+ * Licensed 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. 
+ */
+package org.apache.lucene.gdata.search;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.gdata.search.StandardGdataSearcher;
+import org.apache.lucene.gdata.search.index.IndexDocument;
+import org.apache.lucene.gdata.utils.ReferenceCounter;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class TestStandardGdataSearcher extends TestCase {
+    private Directory dir;
+
+    private int amountDocuments = 30;
+
+    private static final String FIELDNAME = "fname";
+
+    private static final String FIELDVALUE = "foobar";
+
+    private ReferenceCounter<IndexSearcher> searcher;
+
+    private StandardGdataSearcher gdataSearcher;
+
+    private List<String> idlist;
+    
+    private String feedId = "myFeed";
+
+    protected void setUp() throws Exception {
+        this.dir = new RAMDirectory();
+        IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true);
+        this.idlist = new ArrayList<String>();
+        for (int i = 0; i < this.amountDocuments; i++) {
+            Document doc = new Document();
+            doc.add(new Field(IndexDocument.FIELD_FEED_ID, this.feedId,
+                    Field.Store.YES, Field.Index.UN_TOKENIZED));
+            doc.add(new Field(IndexDocument.FIELD_ENTRY_ID, "" + i,
+                    Field.Store.YES, Field.Index.UN_TOKENIZED));
+            doc.add(new Field(FIELDNAME, FIELDVALUE, Field.Store.YES,
+                    Field.Index.UN_TOKENIZED));
+            writer.addDocument(doc);
+            this.idlist.add("" + i);
+        }
+        writer.close();
+        this.searcher = new TestRefcounter(new IndexSearcher(this.dir));
+        this.searcher.increamentReference();
+        this.gdataSearcher = new StandardGdataSearcher(this.searcher);
+    }
+
+    protected void tearDown() throws Exception {
+        this.searcher.decrementRef();
+        StandardGdataSearcher.flushFilterCache();
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.lucene.gdata.search.StandardGdataSearcher.StandardGdataSearcher(ReferenceCounter<IndexSearcher>)'
+     */
+    public void testStandardGdataSearcher() {
+        try {
+            new StandardGdataSearcher(null);
+            fail("searcher ref is null");
+        } catch (IllegalArgumentException e) {
+
+        }
+        new StandardGdataSearcher(this.searcher);
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.lucene.gdata.search.StandardGdataSearcher.search(Query, int,
+     * int)'
+     */
+    public void testSearch() throws IOException {
+        Query q = new TermQuery(new Term(FIELDNAME, FIELDVALUE));
+        Hits hits = this.searcher.get().search(q);
+        assertEquals(amountDocuments, hits.length());
+        List<String> returnValue = this.gdataSearcher.search(q,
+                this.amountDocuments, 0,this.feedId);
+        assertEquals(amountDocuments, returnValue.size());
+        assertTrue(returnValue.containsAll(this.idlist));
+        try {
+            this.gdataSearcher.search(null, 1, 0,this.feedId);
+            fail("searcher is null");
+        } catch (RuntimeException e) {
+        }
+
+        try {
+            this.gdataSearcher.search(q, -1, 5,this.feedId);
+            fail("hitcount is less than 0");
+        } catch (IllegalArgumentException e) {}
+        try {
+            this.gdataSearcher.search(q, 4, -1,this.feedId);
+            fail("offset is less than 0");
+        } catch (IllegalArgumentException e) {}
+        try {
+            this.gdataSearcher.search(q, 4, 5,null);
+            fail("feed id is null");
+        } catch (IllegalArgumentException e) {}
+      
+        returnValue = this.gdataSearcher.search(q,this.amountDocuments, 0,"SomeOtherFeed");
+        assertEquals(0,returnValue.size());
+        
+
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.lucene.gdata.search.StandardGdataSearcher.collectHits(Hits,
+     * int, int)'
+     */
+    public void testCollectHits() throws IOException {
+        Query q = new TermQuery(new Term(FIELDNAME, FIELDVALUE));
+        Hits hits = this.searcher.get().search(q);
+        assertEquals(amountDocuments, hits.length());
+        List<String> returnValue = this.gdataSearcher.collectHits(hits, 1, 0);
+        assertEquals(hits.doc(0).getField(IndexDocument.FIELD_ENTRY_ID)
+                .stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 1, 1);
+        assertEquals(hits.doc(0).getField(IndexDocument.FIELD_ENTRY_ID)
+                .stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 1,
+                this.amountDocuments);
+        assertEquals(1, returnValue.size());
+        assertEquals(hits.doc(this.amountDocuments - 1).getField(
+                IndexDocument.FIELD_ENTRY_ID).stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 10,
+                this.amountDocuments);
+        assertEquals(1, returnValue.size());
+        assertEquals(hits.doc(this.amountDocuments - 1).getField(
+                IndexDocument.FIELD_ENTRY_ID).stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 50, 0);
+        assertEquals(this.amountDocuments, returnValue.size());
+        assertTrue(returnValue.containsAll(this.idlist));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 1, 5);
+        assertEquals(1, returnValue.size());
+        assertEquals(hits.doc(4).getField(IndexDocument.FIELD_ENTRY_ID)
+                .stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 50,
+                this.amountDocuments);
+        assertEquals(1, returnValue.size());
+        assertEquals(hits.doc(this.amountDocuments - 1).getField(
+                IndexDocument.FIELD_ENTRY_ID).stringValue(), returnValue.get(0));
+
+        returnValue = this.gdataSearcher.collectHits(hits, 1,
+                this.amountDocuments + 1);
+        assertEquals(0, returnValue.size());
+
+    }
+
+    /*
+     * Test method for
+     * 'org.apache.lucene.gdata.search.StandardGdataSearcher.close()'
+     */
+    public void testClose() throws IOException {
+        StandardGdataSearcher s = new StandardGdataSearcher(new TestRefcounter(
+                new IndexSearcher(this.dir)));
+        s.close();
+        try {
+            s.search(null, 0, 0,this.feedId);
+            fail("searcher is closed");
+        } catch (IllegalStateException e) {
+        }
+
+    }
+
+    private static class TestRefcounter extends ReferenceCounter<IndexSearcher> {
+
+        public TestRefcounter(IndexSearcher resource) {
+            super(resource);
+            // TODO Auto-generated constructor stub
+        }
+
+        @Override
+        protected void close() {
+            try {
+                this.resource.close();
+            } catch (Exception e) {
+                // TODO: handle exception
+            }
+        }
+
+    }
+
+}

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/TestStandardGdataSearcher.java
------------------------------------------------------------------------------
    svn:executable = *

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package org.apache.lucene.gdata.search.analysis;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class IndexableStub extends Indexable {
+
+    private String content;
+    private boolean retNull;
+    int times = 1;
+    int count = 0;
+    IndexableStub() {
+        super(null);
+
+    }
+    public void returnProxyTimes(int times){
+        this.times = times;
+    }
+    public void setReturnNull(boolean returnNull){
+        this.retNull = returnNull;
+    }
+    public void setReturnValueTextContent(String content){
+        this.content = content;
+    }
+    @Override
+    public Node applyPath(String xPath) throws XPathExpressionException {
+        if(xPath == null)
+            throw new XPathExpressionException("path is null");
+        if(this.retNull)
+            return null;
+        if(times == count)
+            return null;
+        times++;
+        return (Node)Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[] {Node.class,NamedNodeMap.class},new Handler(this.content));
+        
+    }
+
+    private static class Handler implements InvocationHandler{
+        String returnValue;
+        public Handler(String toReturn){
+            this.returnValue = toReturn;
+        }
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+            if(method.getName().equals("getNextSibling")){
+                return null;
+            }
+            if(method.getReturnType() == String.class)
+                return this.returnValue;
+            if(method.getReturnType() == Node.class)
+                
+            return (Node)Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[] {Node.class,NamedNodeMap.class},new Handler(this.returnValue));
+            if(method.getReturnType() == NamedNodeMap.class)
+                return  (NamedNodeMap)Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[] {Node.class,NamedNodeMap.class},new Handler(this.returnValue));
+            return null;
+            
+        }
+        
+    }
+    
+
+
+}
+

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/IndexableStub.java
------------------------------------------------------------------------------
    svn:executable = *

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package org.apache.lucene.gdata.search.analysis;
+
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.search.config.IndexSchemaField;
+import org.apache.lucene.gdata.search.index.GdataIndexerException;
+import org.w3c.dom.Node;
+
+import junit.framework.TestCase;
+
+public class TestContentStrategy extends TestCase {
+    private static final String FIELD = "foo";
+    private static final float BOOST = 2.0f;
+    ContentStrategy strategy;
+    
+    protected void setUp() throws Exception {
+        IndexSchemaField field = new IndexSchemaField();
+        field.setName(FIELD);
+        field.setStore(Field.Store.YES);
+        field.setIndex(Field.Index.UN_TOKENIZED);
+        field.setBoost(BOOST);
+        this.strategy = new TestStrategy(field);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+    public void testContentStrategyIndexStoreField() throws NotIndexableException{
+        IndexSchemaField field = new IndexSchemaField();
+        field.setName(FIELD);
+        
+        
+        this.strategy = new TestStrategy(Field.Index.UN_TOKENIZED,Field.Store.YES,field);
+        this.strategy.processIndexable(null);
+        Field f = this.strategy.createLuceneField()[0];
+        assertEquals(FIELD,f.name());
+        assertEquals(TestStrategy.CONTENT,f.stringValue());
+        assertEquals(1.0f,f.getBoost());
+        assertTrue(f.isIndexed());
+        assertTrue(f.isStored());
+        assertFalse(f.isTokenized());
+        assertFalse(f.isCompressed());
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.search.analysis.ContentStrategy.ContentStrategy(Index, Store, IndexSchemaField)'
+     */
+    public void testContentStrategyIndexSchemaField() throws NotIndexableException {
+        IndexSchemaField field = new IndexSchemaField();
+        field.setName(FIELD);
+        
+        
+        this.strategy = new TestStrategy(field);
+        this.strategy.processIndexable(null);
+        Field f = this.strategy.createLuceneField()[0];
+        
+        assertEquals(FIELD,f.name());
+        assertEquals(TestStrategy.CONTENT,f.stringValue());
+        assertEquals(1.0f,f.getBoost());
+        assertTrue(f.isIndexed());
+        assertFalse(f.isStored());
+        assertTrue(f.isTokenized());
+        assertFalse(f.isCompressed());
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.search.analysis.ContentStrategy.createLuceneField()'
+     */
+    public void testCreateLuceneField() throws NotIndexableException {
+        try{
+        this.strategy.createLuceneField();
+        fail("processIndexable is not called");
+        }catch (GdataIndexerException e) {
+          //
+        }
+        this.strategy.processIndexable(null);
+        Field f = this.strategy.createLuceneField()[0];
+        
+        assertEquals(FIELD,f.name());
+        assertEquals(TestStrategy.CONTENT,f.stringValue());
+        assertEquals(BOOST,f.getBoost());
+        assertTrue(f.isIndexed());
+        assertTrue(f.isStored());
+        assertFalse(f.isTokenized());
+        assertFalse(f.isCompressed());
+       
+        
+        
+    }
+    
+    private static class TestStrategy extends ContentStrategy{
+
+        private static final String CONTENT = "someString";
+
+      
+        protected TestStrategy(Index index, Store store, IndexSchemaField fieldConfig) {
+            super(index, store, fieldConfig);
+      
+        }
+
+        protected TestStrategy(IndexSchemaField fieldConfiguration) {
+            super(fieldConfiguration);
+            
+        }
+
+        @Override
+        public void processIndexable(Indexable<? extends Node, ? extends ServerBaseEntry> indexable) throws NotIndexableException {
+            this.content = CONTENT;
+        }
+        
+    }
+
+}

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestContentStrategy.java
------------------------------------------------------------------------------
    svn:executable = *

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java?rev=430568&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java Thu Aug 10 15:32:40 2006
@@ -0,0 +1,84 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+package org.apache.lucene.gdata.search.analysis;
+
+import javax.xml.xpath.XPathExpressionException;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.server.registry.ProvidedServiceConfig;
+import org.apache.lucene.gdata.utils.ProvidedServiceStub;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
+import com.google.gdata.data.Category;
+import com.google.gdata.data.ExtensionProfile;
+import com.google.gdata.data.HtmlTextConstruct;
+import com.google.gdata.data.extensions.EventEntry;
+
+public class TestDomIndexable extends TestCase {
+
+   
+    public void testConstructor(){
+        try {
+            new DomIndexable(new ServerBaseEntry());
+            fail("no service config");
+        } catch (NotIndexableException e) {
+            
+            
+        }
+        ServerBaseEntry e = new ServerBaseEntry();
+        e.setServiceConfig(new ProvidedServiceConfig());
+        try {
+            new DomIndexable(e);
+            fail("no extension profile");
+        } catch (IllegalStateException e1) {
+            
+            
+        } catch (NotIndexableException e2) {
+            
+            fail("unexp. exception");   
+        }
+        e.setServiceConfig(new ProvidedServiceStub());
+        try {
+            new DomIndexable(e);
+        } catch (NotIndexableException e1) {
+         fail("unexp. exception");   
+         
+        }
+    }
+    /*
+     * Test method for 'org.apache.lucene.gdata.search.analysis.DomIndexable.applyPath(String)'
+     */
+    public void testApplyPath() throws NotIndexableException, XPathExpressionException {
+        String content = "fooo bar<br>";
+        ServerBaseEntry entry = new ServerBaseEntry();
+        entry.setContent(new HtmlTextConstruct(content));
+        entry.setServiceConfig(new ProvidedServiceStub());
+        
+            Indexable ind = new DomIndexable(entry);
+            Node n = ind.applyPath("/entry/content");
+            assertNotNull(n);
+            assertEquals(content,n.getTextContent());
+            Node attr = ind.applyPath("/entry/content/@type");
+            assertNotNull(attr);
+            assertEquals("html",attr.getTextContent());
+            assertTrue(attr instanceof Attr);
+            
+    }
+    
+}

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/search/analysis/TestDomIndexable.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message