org.apache.jetspeed.rewriter
Class AbstractRewriter

java.lang.Object
  extended by org.apache.jetspeed.rewriter.AbstractRewriter
All Implemented Interfaces:
Rewriter
Direct Known Subclasses:
BasicRewriter

public abstract class AbstractRewriter
extends Object
implements Rewriter

AbstractRewriter

Version:
$Id: AbstractRewriter.java 516448 2007-03-09 16:25:47Z ate $
Author:
David Sean Taylor

Field Summary
private  String baseUrl
           
protected static org.apache.commons.logging.Log log
           
private  boolean useProxy
           
 
Constructor Summary
AbstractRewriter()
           
 
Method Summary
 void enterConvertTagEvent(String tag, MutableAttributes attrs)
          Rewriter event called back just before tag conversion (rewriter callbacks) begins by the ParserAdaptor.
 boolean enterEndTagEvent(String tag)
          Rewriter event called back on the leading edge of processing an end tag by the ParserAdaptor.
 boolean enterSimpleTagEvent(String tag, MutableAttributes attrs)
          Rewriter event called back on the leading edge of processing a simple tag by the ParserAdaptor.
 boolean enterStartTagEvent(String tag, MutableAttributes attrs)
          Rewriter event called back on the leading edge of processing a start tag by the ParserAdaptor.
 boolean enterText(char[] values, int param)
          Rewriter event called back when text is found for Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.
 String exitEndTagEvent(String tag)
          Rewriter event called back on the trailing edge of a end tag by the ParserAdaptor.
 String exitSimpleTagEvent(String tag, MutableAttributes attrs)
          Rewriter event called back on the trailing edge of a simple tag by the ParserAdaptor.
 String exitStartTagEvent(String tag, MutableAttributes attrs)
          Rewriter event called back on the trailing edge of a start tag by the ParserAdaptor.
 String getBaseRelativeUrl(String relativeUrl)
          Gets a new URL relative to Base according to the site / and URL rewriting rules of java.net.URL
 String getBaseUrl()
          Gets the base URL for rewriting.
 boolean getUseProxy()
          Gets whether this rewriter require a proxy server.
 void parse(ParserAdaptor adaptor, Reader reader)
          Parses the reader of content receiving call backs for rewriter events.
 void rewrite(ParserAdaptor adaptor, Reader reader, Writer writer)
          Parses the reader of content receiving call backs for rewriter events.
abstract  String rewriteUrl(String url, String tag, String attribute)
          This event is the inteface between the Rewriter and ParserAdaptor for rewriting URLs.
 void setBaseUrl(String base)
          Sets the base URL for rewriting.
 void setUseProxy(boolean useProxy)
          Set whether this rewriter require a proxy server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jetspeed.rewriter.Rewriter
shouldRemoveComments, shouldRemoveTag, shouldStripTag
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

baseUrl

private String baseUrl

useProxy

private boolean useProxy
Constructor Detail

AbstractRewriter

public AbstractRewriter()
Method Detail

parse

public void parse(ParserAdaptor adaptor,
                  Reader reader)
           throws RewriterException
Description copied from interface: Rewriter
Parses the reader of content receiving call backs for rewriter events. This method does not rewrite, but only parses. Useful for readonly operations. The configured parser can parse over different stream formats returning a normalized (org.sax.xml) attribute and element based events.

Specified by:
parse in interface Rewriter
Parameters:
adaptor - the parser adaptor which handles generating SAX-like events called back on this object.
reader - the input stream over the content to be parsed.
Throws:
RewriterException

rewrite

public void rewrite(ParserAdaptor adaptor,
                    Reader reader,
                    Writer writer)
             throws RewriterException
Description copied from interface: Rewriter
Parses the reader of content receiving call backs for rewriter events. The content is rewritten to the output stream. The configured parser can parse over different stream formats returning a normalized (org.sax.xml) attribute and element based events.

Specified by:
rewrite in interface Rewriter
Parameters:
adaptor - the parser adaptor which handles generating SAX-like events called back on this object.
reader - the input stream over the content to be parsed.
writer - the output stream where content is rewritten to.
Throws:
RewriterException

rewriteUrl

public abstract String rewriteUrl(String url,
                                  String tag,
                                  String attribute)
Description copied from interface: Rewriter
This event is the inteface between the Rewriter and ParserAdaptor for rewriting URLs. The ParserAdaptor calls back the Rewriter when it finds a URL that is a candidate to be rewritten. The Rewriter rewrites the URL and returns it as the result of this function.

Specified by:
rewriteUrl in interface Rewriter
Parameters:
url - the URL to be rewritten
tag - The tag being processed
attribute - The current attribute being processsed

setBaseUrl

public void setBaseUrl(String base)
Description copied from interface: Rewriter
Sets the base URL for rewriting. This URL is the base from which other URLs are generated.

Specified by:
setBaseUrl in interface Rewriter
Parameters:
base - The base URL for this rewriter

getBaseUrl

public String getBaseUrl()
Description copied from interface: Rewriter
Gets the base URL for rewriting. This URL is the base from which other URLs are generated.

Specified by:
getBaseUrl in interface Rewriter
Returns:
The base URL for this rewriter

getBaseRelativeUrl

public String getBaseRelativeUrl(String relativeUrl)
Description copied from interface: Rewriter
Gets a new URL relative to Base according to the site / and URL rewriting rules of java.net.URL

Specified by:
getBaseRelativeUrl in interface Rewriter
Returns:
The new URL from path, relative to the base URL (or path, if path is absolute)

getUseProxy

public boolean getUseProxy()
Description copied from interface: Rewriter
Gets whether this rewriter require a proxy server.

Specified by:
getUseProxy in interface Rewriter
Returns:
true if it requires a proxy

setUseProxy

public void setUseProxy(boolean useProxy)
Description copied from interface: Rewriter
Set whether this rewriter require a proxy server.

Specified by:
setUseProxy in interface Rewriter
Parameters:
useProxy - true if it requires a proxy

enterSimpleTagEvent

public boolean enterSimpleTagEvent(String tag,
                                   MutableAttributes attrs)
Description copied from interface: Rewriter
Rewriter event called back on the leading edge of processing a simple tag by the ParserAdaptor. Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.

Specified by:
enterSimpleTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
attrs - The attribute list for the tag.
Returns:
Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.

exitSimpleTagEvent

public String exitSimpleTagEvent(String tag,
                                 MutableAttributes attrs)
Description copied from interface: Rewriter
Rewriter event called back on the trailing edge of a simple tag by the ParserAdaptor. Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

Specified by:
exitSimpleTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
attrs - The attribute list for the tag.
Returns:
Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

enterStartTagEvent

public boolean enterStartTagEvent(String tag,
                                  MutableAttributes attrs)
Description copied from interface: Rewriter
Rewriter event called back on the leading edge of processing a start tag by the ParserAdaptor. Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.

Specified by:
enterStartTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
attrs - The attribute list for the tag.
Returns:
Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.

exitStartTagEvent

public String exitStartTagEvent(String tag,
                                MutableAttributes attrs)
Description copied from interface: Rewriter
Rewriter event called back on the trailing edge of a start tag by the ParserAdaptor. Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

Specified by:
exitStartTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
attrs - The attribute list for the tag.
Returns:
Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

enterEndTagEvent

public boolean enterEndTagEvent(String tag)
Description copied from interface: Rewriter
Rewriter event called back on the leading edge of processing an end tag by the ParserAdaptor. Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.

Specified by:
enterEndTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
Returns:
Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.

exitEndTagEvent

public String exitEndTagEvent(String tag)
Description copied from interface: Rewriter
Rewriter event called back on the trailing edge of a end tag by the ParserAdaptor. Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

Specified by:
exitEndTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
Returns:
Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.

enterText

public boolean enterText(char[] values,
                         int param)
Description copied from interface: Rewriter
Rewriter event called back when text is found for Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.

Specified by:
enterText in interface Rewriter
Parameters:
values - an array of characters containing the text.
Returns:
Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.

enterConvertTagEvent

public void enterConvertTagEvent(String tag,
                                 MutableAttributes attrs)
Description copied from interface: Rewriter
Rewriter event called back just before tag conversion (rewriter callbacks) begins by the ParserAdaptor.

Specified by:
enterConvertTagEvent in interface Rewriter
Parameters:
tag - The name of the tag being processed.
attrs - The attribute list for the tag.


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.