Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

Active Content Filtering: Custom filters

You can develop your own custom filter. There are two steps to create and use a new filter:

  1. Develop the filter by extending the com.ibm.trl.acf.api.Filter class. The Filter class defines two abstract methods that you need to implement: startElement2 and endElement2. These methods have the same semantics as startElement and endElement in the org.xm.sax.ContentHandler but they also require the scope declared in the configuration. You also need to implement the remaining methods in the org.xm.sax.ContentHandler. For example, to create a custom filter called ‘MyFilter’, you have to:
    1. Create a MyFilter class by extending the Filter class.
    2. Call the constructer of the super class in the constructer.
    3. Implement the actual process when each method is called.
      • Implement almost the same interface of the org.xm.sax.ContentHandler. Instead of startElement and endElement, startElement2 and endElement2 should be implemented.
      • The difference between startElement and startElement2 is that startElement2 has the additional argument ‘applicableRules’. A list of applicable rules specified in the configuration file is passed to the argument. List of rules not in the current scope will not be passed.
      • If you have nothing special to do in a method, you must propagate the events to the next handler.
  2. Add filter rules to the ACF configuration file. Please see Active content filtering to know how to write the configuration file. Afterwards these values can be accessed through the applicableRules attribute of startElement2.

The example code is as bellow.


public class MyFilter extends com.ibm.com.ibm.trl.acf.api.Filter {
        
        public MyFilter(
        org.xml.sax.ContentHandler next, com.ibm.trl.acf.impl.FilterRule filterRule,
        Boolean isProcess
        ) {
                // Call the constructor of the super class
                super(next, filterRule, isProcess);
        }
        
        public void startElement2(
        String uri, String localName, String qName, org.xml.sax.Attributes attributeList,
        java.util.List applicableRules
        ) throws org.xml.sax.SAXException {
                // Write the actual process for the start element.
                // The following example shows how to pass the SAX event to the next handler.
                if (next != null) {
                        next.startElement(uri, localName, qName, newAttributeList);
                }
        }
        
        public void endElement2(
        String uri, String localName, String qName
        ) throws org.xml.sax.SAXException {
                // Write the actual process for the start element.
                // The following example shows how to pass the SAX event to the next handler.
                if (next != null) {
                        next.endElement(uri, localName, qName);
                }
        }
        
        public void characters(
        char[] ch, int offset, int length
        ) throws org.xml.sax.SAXException {
                // Write the actual process for the start element.
                // The following example shows how to pass the SAX event to the next handler.
                if (next != null) {
                        next.characters(ch, offset, length);
                }
        }
        
        // Need to implement the other methods.
        
}

r2 - 26 Oct 2007 - 16:07:32 - rushall
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site