PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer
Class Token

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.pagemixer.Token
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CDATAToken, CommentToken, DocTypeToken, PIToken, ScriptToken, TagToken, TextToken

public abstract class Token
extends java.lang.Object
implements java.io.Serializable

Abstraction of HTML page element.

HTML page is recognized as the sequence of Token (or derived classes from it) objects.

Though concept "name"/"start tag"/"end tag"/"attribute" are not needed at this abstraction level in fact, accessing/examination methods are provided for efficiency at execution (e.g.: eliminating cost of "instanceof"/narrowing).

You must concretize below method(s) to have this function.

See Also:
Attribute, Serialized Form

Constructor Summary
Token()
          Constructor.
 
Method Summary
 Token createFixed()
          Create inmutable LOGICALY equal one.
 boolean equals(java.lang.Object object)
          Examine object equality.
 Attribute findAttribute(Symbol name)
          Find attribute named as specified name.
 Attribute[] findAttributes(Symbol name)
          Find attributes named as specified name.
 Attribute[] getAttributes()
          Get array of all attributes owned by token.
 java.lang.String getAttributeValue(Symbol name, java.lang.String defaultValue)
          Get attribute value directly.
 Symbol getName()
          Get name of token.
 boolean hasAttribute(Symbol name, java.lang.String expected)
          Examine attribute value.
 int hashCode()
           
 boolean isEmpty()
          Examine whether token is "HTML empty tag" token.
 boolean isEnd()
          Examine whether token is "HTML end tag" token.
 boolean isNamedAs(Symbol name)
          Examine whether token is named as specified name or not.
 boolean isStart()
          Examine whether token is "HTML start tag" token.
abstract  void render(SafeWriter writer)
          Render own text image on specified writer.
abstract  void resolve(SymbolSet symbolSet)
          Resolve own name symbol with specified set.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Token

public Token()
Constructor.
Method Detail

getName

public Symbol getName()
Get name of token.
Returns:
name of token(may be null)

isNamedAs

public boolean isNamedAs(Symbol name)
Examine whether token is named as specified name or not.
Parameters:
name - expected name of token
Returns:
true if token is named as specified name

isStart

public boolean isStart()
Examine whether token is "HTML start tag" token.
Returns:
true if token is "HTML start tag"

isEnd

public boolean isEnd()
Examine whether token is "HTML end tag" token.
Returns:
true if token is "HTML end tag"

isEmpty

public boolean isEmpty()
Examine whether token is "HTML empty tag" token.
Returns:
true if token is "HTML empty tag"

findAttribute

public Attribute findAttribute(Symbol name)
Find attribute named as specified name.
Parameters:
name - name of attribute
Returns:
attribute named as specified name if found. otherwise null.

getAttributeValue

public final java.lang.String getAttributeValue(Symbol name,
                                                java.lang.String defaultValue)
Get attribute value directly.

This returns "defaultValue" at least, even though specified attribute is not found.

Parameters:
name - of attribute
defaultValue - to be returned
Since:
PageMixer 3.1

hasAttribute

public final boolean hasAttribute(Symbol name,
                                  java.lang.String expected)
Examine attribute value.

This only examines the attribute found by findAttribute(jp.ne.dti.lares.foozy.pagemixer.Symbol).

Parameters:
name - of attribute
expected - value(or null, if examine only attribute existance)
Returns:
whether specified attribute has expecged value
Since:
PageMixer 3.1

findAttributes

public Attribute[] findAttributes(Symbol name)
Find attributes named as specified name.

This returns non-null array object, even if no attribute has specified name.

Parameters:
name - name of attribute
Returns:
array of found attribute named as specified name.

getAttributes

public Attribute[] getAttributes()
Get array of all attributes owned by token.
Returns:
array of all attributes owned by token.

createFixed

public Token createFixed()
Create inmutable LOGICALY equal one.

Mutable token costs much more to keep mutablity (e.g.: having java.util.ArrrayList object, iterative processing on each elements is not cheap) than inmutable one.

Mutablity has less need at token processing, even though it is needed at HTML page tokenization.

So, after tokenization, this method will be invoked to re-produce inmutable and LOGICALY equal one from another.

Returns:
inmutable one

render

public abstract void render(SafeWriter writer)
                     throws MixingIOException
Render own text image on specified writer.
Parameters:
writer - writer written on
Throws:
MixingIOException - IOException is thrown

resolve

public abstract void resolve(SymbolSet symbolSet)
Resolve own name symbol with specified set.

Symbol of name may not be unified in some situations (e.g.: after objec deserialization). It causes comparation mistakes, because one of Symbol implementations uses pointer comparation to examine string equalitiy.

This method gives the chance to unify Symbol by resolving with specified SymbolSet (= invoking SymbolSet.lookup(Symbol))

This method in derived class may cause invocation Attribute.resolve(SymbolSet) on own attributes.

Parameters:
symbolSet - set to resolve with

equals

public boolean equals(java.lang.Object object)
Examine object equality.

This examines:

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

PageMixer API - 3.1