cmlenz 02/04/23 04:23:48
Added: src/examples/interceptors SimpleContentInterceptor.java
readme.txt
Log:
Add a simple example implementation of the ContentInterceptor interface
that logs all calls of the hook methods to the namespace logger
Revision Changes Path
1.1
jakarta-slide/src/examples/interceptors/SimpleContentInterceptor.java
Index: SimpleContentInterceptor.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/examples/interceptors/SimpleContentInterceptor.java,v 1.1
2002/04/23 11:23:48 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2002/04/23 11:23:48 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", 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]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.slide.examples;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideToken;
import org.apache.slide.content.AbstractContentInterceptor;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.structure.LinkedObjectNotFoundException;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.util.logger.Logger;
/**
* Simple implementation of the ContentInterceptor interface that logs calls to
* the hook methods to the namespace logger.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
* @version $Revision: 1.1 $
*/
public class SimpleContentInterceptor
extends AbstractContentInterceptor {
// -------------------------------------- ContentInterceptor Implementation
/**
* Generates log output.
*/
public void preStoreContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
getNamespace().getLogger().log("preStoreContent(" +
revisionDescriptors.getUri() + " " +
revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() +
")", Logger.INFO);
}
/**
* Generates log output.
*/
public void postStoreContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
getNamespace().getLogger().log("postStoreContent(" +
revisionDescriptors.getUri() + " " +
revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() +
")", Logger.INFO);
}
/**
* Generates log output.
*/
public void preRetrieveContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionNumber revisionNumber,
NodeRevisionDescriptor revisionDescriptor)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
if (revisionDescriptors != null) {
// descriptor to be retrieved
getNamespace().getLogger().log
("preRetrieveContent(" + revisionDescriptors.getUri() + " " +
revisionNumber + ")",
Logger.INFO);
} else {
// descriptor retrieved
getNamespace().getLogger().log
("preRetrieveContent(" + revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() + ")",
Logger.INFO);
}
}
/**
* Generates log output.
*/
public void postRetrieveContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
if (revisionDescriptors != null) {
// descriptor retrieved
getNamespace().getLogger().log
("postRetrieveContent(" + revisionDescriptors.getUri() + " " +
revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() + ")",
Logger.INFO);
} else {
// content retrieved
getNamespace().getLogger().log
("postRetrieveContent(" + revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() + ")",
Logger.INFO);
}
}
/**
* Generates log output.
*/
public void preRemoveContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
if (revisionDescriptors != null) {
getNamespace().getLogger().log
("preRemoveContent(" + revisionDescriptors.getUri() + ")",
Logger.INFO);
} else {
getNamespace().getLogger().log
("preRemoveContent(" + revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() + ")", Logger.INFO);
}
}
/**
* Generates log output.
*/
public void postRemoveContent
(SlideToken token, NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor)
throws AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException, ObjectLockedException,
ServiceAccessException {
if (revisionDescriptors != null) {
getNamespace().getLogger().log
("postRemoveContent(" + revisionDescriptors.getUri() + ")",
Logger.INFO);
} else {
getNamespace().getLogger().log
("postRemoveContent(" + revisionDescriptor.getName() + " " +
revisionDescriptor.getRevisionNumber() + ")", Logger.INFO);
}
}
/**
* Generates log output.
*/
public void setNamespace(NamespaceAccessToken nat) {
System.out.println("SimpleContentInterceptor.setNamespace()");
super.setNamespace(nat);
}
/**
* Generates log output.
*/
public void setParameters(Hashtable parameters) {
System.out.println("SimpleContentInterceptor.setParameters():");
Enumeration keys = parameters.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
System.out.println(" " + key + " : " + parameters.get(key));
}
super.setParameters(parameters);
}
}
1.1 jakarta-slide/src/examples/interceptors/readme.txt
Index: readme.txt
===================================================================
This example provides a simple implementation of the
ContentInterceptor interface, which simply logs all calls to the
defined hook methods.
To use this class, compile it using
$ ant examples
from the home directory of the Slide source distribution.
You'll then find the class in
build/examples/org/apache/slide/examples/SimpleContentInterceptor.class
copy the entire org directory into the WEB-INF/classes path of the Slide
web application, and edit Domain.xml to include this fragment:
<content-interceptor
class="org.apache.slide.examples.SimpleContentInterceptor">
<parameter name="exampleParamName">exampleParamValue</parameter>
</content-interceptor>
... just before the end of the <configuration> section.
If everything goes well, log messages from the interceptor should start
appearing in the namespace log (which defaults to system console output).
Good luck!
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>