You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by un...@apache.org on 2003/11/21 12:41:44 UTC

cvs commit: cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository RepositoryInterceptor.java RepositoryInterceptorBase.java SourceRepositoryImpl.java SourceRepository.java

unico       2003/11/21 03:41:44

  Modified:    src/blocks/repository/java/org/apache/cocoon/components/repository
                        SourceRepositoryImpl.java SourceRepository.java
  Added:       src/blocks/repository/java/org/apache/cocoon/components/repository
                        RepositoryInterceptor.java
                        RepositoryInterceptorBase.java
  Log:
  repository interception mechanism for repository auditing
  
  Revision  Changes    Path
  1.4       +17 -2     cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/SourceRepositoryImpl.java
  
  Index: SourceRepositoryImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/SourceRepositoryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SourceRepositoryImpl.java	4 Nov 2003 16:58:11 -0000	1.3
  +++ SourceRepositoryImpl.java	21 Nov 2003 11:41:44 -0000	1.4
  @@ -79,6 +79,7 @@
   public class SourceRepositoryImpl extends AbstractLogEnabled 
   implements Serviceable, ThreadSafe, SourceRepository {
       
  +    private RepositoryInterceptor m_interceptor = new RepositoryInterceptorBase(){};
       private SourceResolver m_resolver;
       
       
  @@ -89,9 +90,13 @@
       
       /**
        * @avalon.dependency type="SourceResolver"
  +     * @avalon.dependency type="RepositoryInterceptor" optional="true"
        */
       public void service(ServiceManager manager) throws ServiceException {
           m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
  +        if (manager.hasService(RepositoryInterceptor.ROLE)) {
  +            m_interceptor = (RepositoryInterceptor) manager.lookup(RepositoryInterceptor.ROLE);
  +        }
       }
       
       
  @@ -144,8 +149,9 @@
               }
               
               source = m_resolver.resolveURI(in);
  +            m_interceptor.preStoreSource(destination);
               SourceUtil.copy(source,destination);
  -            
  +            m_interceptor.postStoreSource(destination);
               return status;
           }
           catch (IOException e) {
  @@ -195,7 +201,9 @@
                   return STATUS_CONFLICT;
               }
               
  +            m_interceptor.preStoreSource(source);
               ((ModifiableTraversableSource) source).makeCollection();
  +            m_interceptor.postStoreSource(source);
               return STATUS_CREATED;
           }
           catch (IOException e) {
  @@ -277,7 +285,9 @@
                   }
               }
           }
  +        m_interceptor.preRemoveSource(source);
           ((ModifiableSource) source).delete();
  +        m_interceptor.postRemoveSource(source);
           return STATUS_OK;
       }
       
  @@ -395,7 +405,9 @@
                   }
                   // TODO: copy properties
                   target = ((ModifiableTraversableSource) destination);
  +                m_interceptor.preStoreSource(target);
                   target.makeCollection();
  +                m_interceptor.postStoreSource(target);
                   if (recurse) {
                       Iterator children = origin.getChildren().iterator();
                       while (children.hasNext()) {
  @@ -411,7 +423,9 @@
           }
           if (destination instanceof ModifiableSource) {
               // TODO: copy properties
  -            SourceUtil.copy(source, destination);
  +            m_interceptor.preStoreSource(destination);
  +            SourceUtil.copy(source,destination);
  +            m_interceptor.postStoreSource(destination);
           }
           else {
               final String message = "copy() is forbidden: " +
  @@ -435,4 +449,5 @@
           }
           return null;
       }
  +
   }
  
  
  
  1.4       +3 -3      cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/SourceRepository.java
  
  Index: SourceRepository.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/SourceRepository.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SourceRepository.java	4 Nov 2003 16:58:11 -0000	1.3
  +++ SourceRepository.java	21 Nov 2003 11:41:44 -0000	1.4
  @@ -55,13 +55,13 @@
   import org.apache.excalibur.source.SourceException;
   
   /**
  - * A stateless utitlity service intended to be used by flowscripts to help
  + * A stateless utility service intended to be used by flowscripts to help
    * them with persistent operations on sources.
    * 
    * <p>
  - * Each operation return a status code that is based on RFC 2518 (WebDAV).
  + * Each operation returns a status code that is based on RFC 2518 (WebDAV).
    * This does not mean to it cannot be used outside of a WebDAV context.
  - * It is reusing a standard to enable richer communication between
  + * It is reusing a standard to enable rich communication between
    * the flow layer and the service layer.
    * </p>
    * 
  
  
  
  1.1                  cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/RepositoryInterceptor.java
  
  Index: RepositoryInterceptor.java
  ===================================================================
  /* Created on Oct 18, 2003 7:00:43 PM by unico */
  package org.apache.cocoon.components.repository;
  
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceException;
  
  /**
   * TODO describe class
   * 
   * Instances must be thread safe.
   * 
   * @author <a href="mailto:unico@apache.org">Unico Hommes</a> 
   */
  public interface RepositoryInterceptor {
      
      public static final String ROLE = RepositoryInterceptor.class.getName();
      
      /** called before a source is removed */
      public abstract void preRemoveSource(Source source) throws SourceException;
      
      /** called before a source was successfully removed */
      public abstract void postRemoveSource(Source source) throws SourceException;
      
      /** called before a source is stored */
      public abstract void preStoreSource(Source source) throws SourceException;
      
      /** called after a source was successfully stored */
      public abstract void postStoreSource(Source source) throws SourceException;
      
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/repository/RepositoryInterceptorBase.java
  
  Index: RepositoryInterceptorBase.java
  ===================================================================
  /* Created on Oct 18, 2003 7:00:43 PM by unico */
  package org.apache.cocoon.components.repository;
  
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceException;
  
  /**
   * NOP implementation of RepositoryInterceptor.
   * 
   * @author <a href="mailto:unico@apache.org">Unico Hommes</a> 
   */
  public abstract class RepositoryInterceptorBase implements RepositoryInterceptor {
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.components.repository.RepositoryInterceptor#postRemoveSource(org.apache.excalibur.source.Source)
       */
      public void postRemoveSource(Source source) throws SourceException {
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.components.repository.RepositoryInterceptor#postStoreSource(org.apache.excalibur.source.Source)
       */
      public void postStoreSource(Source source) throws SourceException {
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.components.repository.RepositoryInterceptor#preRemoveSource(org.apache.excalibur.source.Source)
       */
      public void preRemoveSource(Source source) throws SourceException {
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.components.repository.RepositoryInterceptor#preStoreSource(org.apache.excalibur.source.Source)
       */
      public void preStoreSource(Source source) throws SourceException {
      }
  
  }