org.apache.jetspeed.rewriter
Interface Rewriter

All Known Subinterfaces:
RulesetRewriter
All Known Implementing Classes:
AbstractRewriter, BasicRewriter, RulesetRewriterImpl, TicketParamRewriter, WebContentRewriter

public interface Rewriter

Rewriter

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

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 path)
          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.
 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.
 boolean shouldRemoveComments()
          Returns true if all comments should be removed.
 boolean shouldRemoveTag(String tag)
          Returns true if the tag should be removed, otherwise false.
 boolean shouldStripTag(String tag)
          Returns true if the tag should be stripped, otherwise false.
 

Method Detail

parse

void parse(ParserAdaptor adaptor,
           Reader reader)
           throws RewriterException
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.

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:
RewriteException - when a parsing error occurs or unexpected content is found.
RewriterException

rewrite

void rewrite(ParserAdaptor adaptor,
             Reader reader,
             Writer writer)
             throws RewriterException
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.

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:
RewriteException - when a parsing error occurs or unexpected content is found.
RewriterException

rewriteUrl

String rewriteUrl(String url,
                  String tag,
                  String attribute)
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.

Parameters:
url - the URL to be rewritten
tag - The tag being processed
attribute - The current attribute being processsed

shouldRemoveTag

boolean shouldRemoveTag(String tag)
Returns true if the tag should be removed, otherwise false. Removing a tag only removes the tag but not the contents in between the start and end tag.

Returns:
true if the tag should be removed.

shouldStripTag

boolean shouldStripTag(String tag)
Returns true if the tag should be stripped, otherwise false. Stripping tags removes the start and end tag, plus all tags and content in between the start and end tag.

Returns:
true if the tag should be stripped.

shouldRemoveComments

boolean shouldRemoveComments()
Returns true if all comments should be removed.

Returns:
true If all comments should be removed.

setBaseUrl

void setBaseUrl(String base)
Sets the base URL for rewriting. This URL is the base from which other URLs are generated.

Parameters:
base - The base URL for this rewriter

getBaseUrl

String getBaseUrl()
Gets the base URL for rewriting. This URL is the base from which other URLs are generated.

Returns:
The base URL for this rewriter

getBaseRelativeUrl

String getBaseRelativeUrl(String path)
Gets a new URL relative to Base according to the site / and URL rewriting rules of java.net.URL

Returns:
The new URL from path, relative to the base URL (or path, if path is absolute)

getUseProxy

boolean getUseProxy()
Gets whether this rewriter require a proxy server.

Returns:
true if it requires a proxy

setUseProxy

void setUseProxy(boolean useProxy)
Set whether this rewriter require a proxy server.

Parameters:
useProxy - true if it requires a proxy

enterSimpleTagEvent

boolean enterSimpleTagEvent(String tag,
                            MutableAttributes attrs)
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.

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

String exitSimpleTagEvent(String tag,
                          MutableAttributes attrs)
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.

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

boolean enterStartTagEvent(String tag,
                           MutableAttributes attrs)
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.

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

String exitStartTagEvent(String tag,
                         MutableAttributes attrs)
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.

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

boolean enterEndTagEvent(String tag)
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.

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.

exitEndTagEvent

String exitEndTagEvent(String tag)
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.

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.

enterText

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.

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

enterConvertTagEvent

void enterConvertTagEvent(String tag,
                          MutableAttributes attrs)
Rewriter event called back just before tag conversion (rewriter callbacks) begins by the ParserAdaptor.

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.