de.enough.polish.browser
Class TagHandler

java.lang.Object
  extended by de.enough.polish.browser.TagHandler
Direct Known Subclasses:
HtmlTagHandler, RssTagHandler

public abstract class TagHandler
extends Object

This class provides the basic functionality for tag handlers. A tag handler is a responsible for handling domain-specific tags in the browser. E.g. you can support different micro formats in HTML with this.

See Also:
Browser

Constructor Summary
TagHandler()
           
 
Method Summary
 void addAttributeCommand(String tagName, String attributeName, String attributeValue, Command command)
          Adds a command to a specific tag/attribute combination.
protected  void addCommands(String tagName, Item item)
          Adds registered commands to the given item.
protected  void addCommands(String tagName, String attributeName, String attributeValue, Item item)
          Adds registered commands to the given item.
 void addTagCommand(String tagName, Command command)
          Adds a command to a specific tag.
protected  Command[] getCommandsForTag(String tag)
          Retrieves registered commands for the specified tag.
 boolean handleCommand(Command command)
          Handles all commands this tag handler is responsible for.
abstract  boolean handleTag(Container parentItem, SimplePullParser parser, String tagName, boolean opening, HashMap attributeMap, Style style)
           
abstract  void register(Browser browser)
          Register a given browser object for this TagHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagHandler

public TagHandler()
Method Detail

register

public abstract void register(Browser browser)
Register a given browser object for this TagHandler. This method is used to make a handler object aware of a browser in case the handler needs to call methods of the browser during its work.

Parameters:
browser - the browser to register.

handleTag

public abstract boolean handleTag(Container parentItem,
                                  SimplePullParser parser,
                                  String tagName,
                                  boolean opening,
                                  HashMap attributeMap,
                                  Style style)
Parameters:
parentItem - the container item the put the browser items into
parser - the parser
tagName - the name of the tag to handle
opening - true if this is an opening tag, false otherwise
attributeMap - all attributes for the tag
style - the style for the next item, can be null
Returns:
true if the tag was handled, false otherwise

handleCommand

public boolean handleCommand(Command command)
Handles all commands this tag handler is responsible for.

Parameters:
command - the command to handle
Returns:
true if the command was handled, false otherwise

addTagCommand

public void addTagCommand(String tagName,
                          Command command)
Adds a command to a specific tag.

Parameters:
tagName - the tag to add the command to
command - the command to add

addAttributeCommand

public void addAttributeCommand(String tagName,
                                String attributeName,
                                String attributeValue,
                                Command command)
Adds a command to a specific tag/attribute combination.

Parameters:
tagName - the tag to add the command to
attributeName - the attribute name to add the command to
attributeValue - the attribute value to add the command to
command - the command to add

addCommands

protected void addCommands(String tagName,
                           Item item)
Adds registered commands to the given item.

Parameters:
tagName - the name of the tag, e.g. div
item - the item used for visualising the tag

addCommands

protected void addCommands(String tagName,
                           String attributeName,
                           String attributeValue,
                           Item item)
Adds registered commands to the given item.

Parameters:
tagName - the name of the tag, e.g. div (can be null)
attributeName - the name of the attribute, e.g. class (can be null)
attributeValue - the value of the attribute, e.g. address (can be null)
item - the item used for visualising the tag

getCommandsForTag

protected Command[] getCommandsForTag(String tag)
Retrieves registered commands for the specified tag.

Parameters:
tag - the name of the tag
Returns:
null when there are no registered commands, otherwise an array of commands registered for the specified tag