org.apache.jetspeed.rewriter
Interface Rewriter

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

public interface Rewriter

Rewriter

Version:
$Id: Rewriter.java 188328 2005-02-08 19:08:40Z rogerrut $
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 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

public 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

public 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

public 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

public 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

public 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

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

Returns:
true If all comments should be removed.

setBaseUrl

public 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

public 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

getUseProxy

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

Returns:
true if it requires a proxy

setUseProxy

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

Parameters:
useProxy - true if it requires a proxy

enterSimpleTagEvent

public 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

public 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

public 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

public 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

public 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.
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)
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.
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)
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

public 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-2005 Apache Software Foundation. All Rights Reserved.