cmlenz      02/04/23 04:16:35

  Modified:    src/share/org/apache/slide/content ContentInterceptor.java
                        ContentImpl.java
               src/share/org/apache/slide/common NamespaceConfig.java
  Added:       src/share/org/apache/slide/content
                        AbstractContentInterceptor.java
  Log:
  Port ContentInterceptor improvements to the HEAD branch
  
  Revision  Changes    Path
  1.5       +244 -23   
jakarta-slide/src/share/org/apache/slide/content/ContentInterceptor.java
  
  Index: ContentInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContentInterceptor.java   28 Mar 2002 06:23:14 -0000      1.4
  +++ ContentInterceptor.java   23 Apr 2002 11:16:35 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentInterceptor.java,v 
1.4 2002/03/28 06:23:14 jericho Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/03/28 06:23:14 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentInterceptor.java,v 
1.5 2002/04/23 11:16:35 cmlenz Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/04/23 11:16:35 $
    *
    * ====================================================================
    *
  @@ -29,7 +29,7 @@
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
  - * 4. the names "The Jakarta Project", "Slide", and "Apache Software
  + * 4. The names "The Jakarta Project", "Slide", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
    *    from this software without prior written permission. For written 
    *    permission, please contact [EMAIL PROTECTED]
  @@ -64,50 +64,271 @@
   package org.apache.slide.content;
   
   import java.util.Hashtable;
  +import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.SlideToken;
  +import org.apache.slide.common.ServiceAccessException;
  +import org.apache.slide.lock.ObjectLockedException;
  +import org.apache.slide.security.AccessDeniedException;
  +import org.apache.slide.structure.LinkedObjectNotFoundException;
  +import org.apache.slide.structure.ObjectNotFoundException;
   
   /**
  - * Slide content interceptor class.
  + * An interface that allows custom components to observe and intercept 
  + * storage, retrieval and removal of content.
  + * 
  + * <p>
  + *   Multiple <code>ContentInterceptors</code> can be associated with a single 
  + *   <code>Namespace</code>. They are typically configured in the 
  + *   <code>&lt;configuration&gt;</code> section of the domain configuration 
  + *   file like this:
  + * </p>
  + * <p><code>
  + * &nbsp;&lt;content-interceptor class="com.acme.MyContentInterceptor"&gt;
  + * <br>
  + * &nbsp;&nbsp;&lt;parameter name="myParam1"&gt;someValue&lt;/parameter&gt;
  + * <br>
  + * &nbsp;&nbsp;&lt;parameter name="myParam2"&gt;anotherValue&lt;/parameter&gt;
  + * <br>
  + * &nbsp;&lt;/content-interceptor&gt;
  + * </code></p>
  + * <p>
  + *   As you can see, <code>ContentInterceptors</code> can be configured with 
  + *   parameters. This is optional, and exactly which parameters are available 
  + *   depends on the specific  <code>ContentInterceptor</code> implementation.
  + * </p>
  + * <p>
  + *   <code>ContentInterceptor</code> implementations must provide a public 
  + *   constructor without arguments, so that instances of the class can be 
  + *   instantiated at startup. In addition, implementors should pay attention 
  + *   to this minimal lifecycle definition:
  + *   <ul>
  + *     <li>When the namespace is being configured, <code>setParameters</code> 
  + *     will be called with a <code>java.util.Hashtable</code> containing the 
  + *     parameter names and values as specified in the configuration.</li>
  + *     <li>When configuration is completed, <code>setNamespace</code> will be 
  + *     called, passing in a <code>NamespaceAccessToken</code> than can later 
  + *     be used by the <code>ContentInterceptor</code> to perform its deeds 
  + *     (like logging to the namespace logger).</li>
  + *     <li>After that, any of the <code>preXXX</code> and <code>postXXX</code> 
  + *     methods will be called as soon as the associated event occurs.</li>
  + *  </ul>
  + * </p>
  + * <p>
  + *   The signatures of the <code>preXXX</code> and <code>postXXX</code> specify
  + *   a wide range of exceptions that can be thrown. If such an exception is 
  + *   thrown it will be propagated up to the the API client. In the case of the 
  + *   <code>preXXX</code> the started operation will be terminated. So be sure 
  + *   to handle all exceptions that shouldn't be propagated back into the core 
  + *   core API - and thus possibly influence success of the operation - 
  + *   yourself.
  + * </p>
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Christopher Lenz</a>
  + * @author Jean-Philippe Courson
    */
  -public class ContentInterceptor {
  +public interface ContentInterceptor {
       
       
       // ---------------------------------------------------------------- Methods
       
       
       /**
  -     * That method will be called just before storing content.
  +     * This method will be called just before the content of a node is stored.
  +     * 
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the content to be stored
  +     * @param revisionDescriptor    revision descriptor of the content to be 
  +     *                              stored
  +     * @param revisionContent       the actual content to be stored
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
  +     */
  +    public void preStoreContent
  +        (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
  +         NodeRevisionDescriptor revisionDescriptor,
  +         NodeRevisionContent revisionContent)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
  +    
  +    
  +    /**
  +     * This method will be called just after the content of a node was stored.
  +     * 
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the content that has been 
  +     *                              stored
  +     * @param revisionDescriptor    revision descriptor of the content that 
  +     *                              has  been stored
  +     * @param revisionContent       the actual content that has been stored
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
        */
  -    public void preStoreContent(SlideToken token, 
  -                                NodeRevisionDescriptors revisionDescriptors,
  -                                NodeRevisionDescriptor revisionDescriptor,
  -                                NodeRevisionContent revisionContent) {
  -    }
  +    public void postStoreContent
  +        (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
  +         NodeRevisionDescriptor revisionDescriptor,
  +         NodeRevisionContent revisionContent)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
       
       
       /**
  -     * That method will be called just after storing content.
  +     * This method will be called just before content is retrieved, or the 
  +     * descriptor of a particular revision is retrieved.
  +     * 
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the descriptor that 
  +     *                              should be retrieved, or <code>null</code> 
  +     *                              if the content should be retrieved
  +     * @param revisionNumber        revision number of the descriptor that 
  +     *                              should be retrieved, or <code>null</code> 
  +     *                              if the content should be retrieved
  +     * @param revisionDescriptor    revision descriptor of the content that 
  +     *                              should be retrieved, or <code>null</code> 
  +     *                              if the descriptor will be retrieved
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
        */
  -    public void postStoreContent(SlideToken token, 
  -                                 NodeRevisionDescriptors revisionDescriptors,
  -                                 NodeRevisionDescriptor revisionDescriptor,
  -                                 NodeRevisionContent revisionContent) {
  -    }
  +    public void preRetrieveContent
  +        (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
  +         NodeRevisionNumber revisionNumber,
  +         NodeRevisionDescriptor revisionDescriptor)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
       
       
       /**
  -     * That method will be called just after retrieving content.
  +     * This method will be called just after retrieving content, or the 
  +     * descriptor of a particular revision.
        * 
  -     * @param revisionContent null when the descriptor is retrieved
  -     * @param revisionDescriptors null when the content is retrieved
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the descriptor that has 
  +     *                              been retrieved, or <code>null</code> when 
  +     *                              the content has been retrieved
  +     * @param revisionDescriptor    revision descriptor of the content that has
  +     *                              been retrieved, or the descriptor itself 
  +     *                              has been retrieved
  +     * @param revisionContent       the actual content that has been retrieved,
  +     *                              or <code>null</code> when the descriptor 
  +     *                              has been retrieved
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
        */
       public void postRetrieveContent
           (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
            NodeRevisionDescriptor revisionDescriptor,
  -         NodeRevisionContent revisionContent) {
  -    }
  +         NodeRevisionContent revisionContent)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
  +    
  +    
  +    /**
  +     * This method will be called just before content will get removed, either 
  +     * of all revisions of a node, or of only one particular revision.
  +     * 
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the content that will be 
  +     *                              removed, or <code>null</code> if a only a 
  +     *                              particular revision should be removed
  +     * @param revisionDescriptor    revision descriptor of the content that 
  +     *                              will be removed, or <code>null</code> if 
  +     *                              all revisions of a node should be removed
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
  +     */
  +    public void preRemoveContent   
  +        (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
  +         NodeRevisionDescriptor revisionDescriptor)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
  +    
  +    
  +    /**
  +     * This method will be called just after content has been removed, either 
  +     * of all revisions of a node, or of only one particular revision.
  +     * 
  +     * @param token                 the SlideToken
  +     * @param revisionDescriptors   revision tree of the content that has been 
  +     *                              removed, or <code>null</code> if a only a 
  +     *                              particular revision has been removed
  +     * @param revisionDescriptor    revision descriptor of the content that 
  +     *                              has been removed, or <code>null</code> if 
  +     *                              all revisions of a node have been removed
  +     * @throws AccessDeniedException            if access to a resource has 
  +     *                                          been denied
  +     * @throws ObjectNotFoundException          if an object could not be found
  +     * @throws LinkedObjectNotFoundException    if an object linked to by 
  +     *                                          another object could not be 
  +     *                                          found
  +     * @throws ObjectLockedException            if an object is locked
  +     * @throws ServiceAccessException           low-level service failure
  +     */
  +    public void postRemoveContent   
  +        (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
  +         NodeRevisionDescriptor revisionDescriptor)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException;
  +    
  +    
  +    /**
  +     * The <code>setNamespace</code> method will be called during 
  +     * initialization of the ContextInterceptor.
  +     * 
  +     * @param nat   the access token to the namespace this ContentInterceptor 
  +     *              has been associated with
  +     */
  +    public void setNamespace
  +        (NamespaceAccessToken nat);
  +    
  +    
  +    /**
  +     * This method is called during initialization of the ContentInterceptor 
  +     * to allow parameterization from the configuration. If no parameters have 
  +     * been specified, the Hashtable will be empty
  +     *
  +     * @param parameters    Hashtable containing the parameters' names as keys 
  +     *                      and the associated parameter values as values, 
  +     *                      both of type <code>java.lang.String</code>
  +     */
  +    public void setParameters
  +        (Hashtable parameters);
       
       
   }
  +
  
  
  
  1.33      +32 -5     
jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java
  
  Index: ContentImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ContentImpl.java  10 Apr 2002 08:08:15 -0000      1.32
  +++ ContentImpl.java  23 Apr 2002 11:16:35 -0000      1.33
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java,v 1.32 
2002/04/10 08:08:15 juergen Exp $
  - * $Revision: 1.32 $
  - * $Date: 2002/04/10 08:08:15 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java,v 1.33 
2002/04/23 11:16:35 cmlenz Exp $
  + * $Revision: 1.33 $
  + * $Date: 2002/04/23 11:16:35 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,10 @@
    * Implementation of the content interface.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.32 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Christopher Lenz</a>
  + * @author Jean-Philippe Courson
  + * @version $Revision: 1.33 $
  + * @version $Revision: 1.33 $
    */
   public final class ContentImpl implements Content {
       
  @@ -88,6 +91,8 @@
       protected static final int PRE_STORE = 0;
       protected static final int POST_STORE = 1;
       protected static final int POST_RETRIEVE = 2;
  +    protected static final int PRE_REMOVE = 3;
  +    protected static final int POST_REMOVE = 4;
       
       
       // ----------------------------------------------------------- Constructors
  @@ -969,6 +974,9 @@
           LinkedObjectNotFoundException, ServiceAccessException,
           RevisionDescriptorNotFoundException, ObjectLockedException {
           
  +        // Invoke interceptors
  +        invokeInterceptors(token, revisionDescriptors, null, null, PRE_REMOVE);
  +        
           // Retrieve the associated object
           ObjectNode associatedObject = structureHelper.retrieve
               (token, revisionDescriptors.getUri(), false);
  @@ -990,6 +998,9 @@
           
           objectUri.getStore().removeRevisionDescriptors(objectUri);
           
  +        // Invoke interceptors
  +        invokeInterceptors(token, revisionDescriptors, null, null,
  +                           POST_REMOVE);
       }
       
       
  @@ -1045,11 +1056,16 @@
               objectUri.getStore().retrieveRevisionDescriptor
               (objectUri, revisionNumber);
           
  +        // Invoke interceptors
  +        invokeInterceptors(token, null, revisionDescriptor, null, PRE_REMOVE);
  +        
           objectUri.getStore().removeRevisionContent
               (objectUri, revisionDescriptor);
           objectUri.getStore()
               .removeRevisionDescriptor(objectUri, revisionNumber);
           
  +        // Invoke interceptors
  +        invokeInterceptors(token, null, revisionDescriptor, null, POST_REMOVE);
       }
       
       
  @@ -1269,7 +1285,10 @@
       protected void invokeInterceptors
           (SlideToken token, NodeRevisionDescriptors revisionDescriptors,
            NodeRevisionDescriptor revisionDescriptor,
  -         NodeRevisionContent revisionContent, int type) {
  +         NodeRevisionContent revisionContent, int type)
  +        throws AccessDeniedException, ObjectNotFoundException,
  +               LinkedObjectNotFoundException, ObjectLockedException,
  +               ServiceAccessException {
           ContentInterceptor[] contentInterceptors =
               namespace.getContentInterceptors();
           for (int i = 0; i < contentInterceptors.length; i++) {
  @@ -1288,6 +1307,14 @@
                       contentInterceptors[i].postRetrieveContent
                           (token, revisionDescriptors,
                            revisionDescriptor, revisionContent);
  +                    break;
  +                case PRE_REMOVE:
  +                    contentInterceptors[i].preRemoveContent
  +                        (token, revisionDescriptors, revisionDescriptor);
  +                    break;
  +                case POST_REMOVE:
  +                    contentInterceptors[i].postRemoveContent
  +                        (token, revisionDescriptors, revisionDescriptor);
                       break;
               }
           }
  
  
  
  1.2       +268 -0    
jakarta-slide/src/share/org/apache/slide/content/AbstractContentInterceptor.java
  
  
  
  
  1.21      +29 -4     
jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java
  
  Index: NamespaceConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- NamespaceConfig.java      5 Apr 2002 16:10:15 -0000       1.20
  +++ NamespaceConfig.java      23 Apr 2002 11:16:35 -0000      1.21
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.20 
2002/04/05 16:10:15 pnever Exp $
  - * $Revision: 1.20 $
  - * $Date: 2002/04/05 16:10:15 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.21 
2002/04/23 11:16:35 cmlenz Exp $
  + * $Revision: 1.21 $
  + * $Date: 2002/04/23 11:16:35 $
    *
    * ====================================================================
    *
  @@ -81,7 +81,7 @@
    * Configuration of the Namespace.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    */
   public final class NamespaceConfig {
       
  @@ -963,12 +963,28 @@
                   Configuration contentInterceptorDef =
                       (Configuration) contentInteceptorsDef.nextElement();
                   String classname = contentInterceptorDef.getAttribute("class");
  +                
  +                // Load contentInterceptor parameters
  +                Enumeration contentInterceptorParametersDef =
  +                    contentInterceptorDef.getConfigurations("parameter");
  +                Hashtable contentInterceptorParameters = new Hashtable();
  +                while (contentInterceptorParametersDef.hasMoreElements()) {
  +                    Configuration parameterDefinition = (Configuration)
  +                        contentInterceptorParametersDef.nextElement();
  +                    String parameterName = 
  +                            parameterDefinition.getAttribute("name");
  +                    String parameterValue = parameterDefinition.getValue();
  +                    contentInterceptorParameters.put(parameterName,
  +                                                     parameterValue);
  +                }
  +                
                   try {
                       Class contentInterceptorClass =
                           Class.forName(classname);
                       ContentInterceptor contentInterceptor = 
                           (ContentInterceptor) 
                           contentInterceptorClass.newInstance();
  +                    contentInterceptor.setParameters(contentInterceptorParameters);
                       ContentInterceptor[] tempArray = 
                           new ContentInterceptor[contentInterceptors.length + 1];
                       for (int i = 0; i < contentInterceptors.length; i++) {
  @@ -982,6 +998,15 @@
                            ("org.apache.slide.common.InvalidContentInterceptor",
                             classname, e.getMessage()), Logger.WARNING);
                   }
  +            }
  +            
  +            // Initialize the content interceptors with the 
  +            // NamespaceAccessToken
  +            NamespaceAccessToken nat = new NamespaceAccessTokenImpl(namespace);
  +            ContentInterceptor[] contentInterceptors =
  +                namespace.getContentInterceptors();
  +            for (int i = 0; i < contentInterceptors.length; i++) {
  +                contentInterceptors[i].setNamespace(nat);
               }
           } catch (ConfigurationException e) {
               throw new InvalidNamespaceConfigurationException
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to