com.inet.html.css
Class Styles

java.lang.Object
  extended by com.inet.html.css.Styles
All Implemented Interfaces:
java.lang.Cloneable

public class Styles
extends java.lang.Object
implements java.lang.Cloneable

This class represents the complete style sheet of a website, including all linked style information.


Nested Class Summary
static class Styles.StyleSheetEntry
          Simple data container for style sheet entries
 
Constructor Summary
Styles(java.lang.String filename)
          Creates a new style container
Styles(java.lang.String filename, Styles base)
          Creates a new style container, copies all styles from base to this container
 
Method Summary
 void addInitialRule(java.lang.String selectors, javax.swing.text.AttributeSet attrs, java.lang.String fileName)
          Adds an initial rule with several attributes to this container.
 void addRule(java.lang.String selectors, javax.swing.text.AttributeSet attrs, java.lang.Object source, boolean skipIfKnown, boolean isInline)
          Adds a rule with several attributes to this container
 void clear()
          Removes all rules from this styles.
 void compile()
          THIS FUNCTION SHOULD BE USED ONLY FOR THE LOWEST-PRIO STYLESHEET!
 java.util.List<Selector> createMatchList(javax.swing.text.Element targetElement, HTML.Tag tag)
          Creates a list of all selectors, that match the element.
 java.lang.Object getClassName(java.lang.Object identifier)
          Returns the generated class name for an identifier.
 com.inet.html.parser.converter.AttributeValue getCssAttribute(javax.swing.text.Element elemAttrs, CSS.Attribute searchAttr, boolean important)
          Search an AttributValue in the styles for the described element.
 com.inet.html.parser.converter.AttributeValue getCssAttribute(javax.swing.text.Element elemAttrs, CSS.Attribute searchAttr, boolean important, java.util.List<Selector> matchList)
          Search an AttributValue in the styles for the described element.
 javax.swing.text.MutableAttributeSet getDefaultSet(java.lang.Object tag)
          Returns the default set, which applies to any element with the given tag
 java.util.Set<CSS.Attribute> getDescribedAttributes()
          Returns a list of all CSS attributes described by the matchlists of this stylesheet.
 java.util.List<Styles.StyleSheetEntry> getEntries(java.lang.Object sourceIdentifier)
          Returns all entries of a CSS source.
 int getInitialCount()
          This is the number of attribute sets, which where defined by the base style sheet given in the constructor.
 java.lang.String getName()
          Returns the internal name of this stylesheet, may be null
 int getRuleCount()
          Get the count of added Rules.
 java.util.List<java.lang.Object> getSourceIdentifiers()
          Returns a list of all known source identifiers
 boolean isCompiled()
          Returns true, if the selectors were compiled
 boolean isExternal(java.lang.Object identifier)
          Checks, if the source referenced by the identifier is an external source.
 java.lang.Object register(java.lang.Object source, boolean isInline, boolean isForeign)
          Registers a new style source, required to add rules of this source to the document
 void setResolver(CSSChangeListener resolver)
          Set the resolver of this stylesheet.
 void updateIndex()
          Checks and updates the class generator index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Styles

public Styles(java.lang.String filename)
Creates a new style container

Parameters:
filename - The name for this stylesheet (currently not used)

Styles

public Styles(java.lang.String filename,
              Styles base)
Creates a new style container, copies all styles from base to this container

Parameters:
filename - The name for this stylesheet (currently not used)
base - the base styles to copy
Method Detail

addInitialRule

public void addInitialRule(java.lang.String selectors,
                           javax.swing.text.AttributeSet attrs,
                           java.lang.String fileName)
Adds an initial rule with several attributes to this container.
NOTE: Only allowed before anything is changed on this document!

Parameters:
selectors - String with one or more comma separated selectors
attrs - the referenced attribute set
fileName - the name of an external CSS file or null

register

public java.lang.Object register(java.lang.Object source,
                                 boolean isInline,
                                 boolean isForeign)
Registers a new style source, required to add rules of this source to the document

Parameters:
source - the source identifier
isInline - set to true, if the styles are part of the STYLE element
isForeign - set to true, if the styles were pasted into the current document
Returns:
the generated CSS class name for this style source

updateIndex

public void updateIndex()
Checks and updates the class generator index. This has to be done once for every document after it was parsed.


addRule

public void addRule(java.lang.String selectors,
                    javax.swing.text.AttributeSet attrs,
                    java.lang.Object source,
                    boolean skipIfKnown,
                    boolean isInline)
Adds a rule with several attributes to this container

Parameters:
selectors - String with one or more comma separated selectors
attrs - the referenced attribute set
source - the source identifier, may be an URI or any other identifiable object
skipIfKnown - if there is already an equal selector with an equal set of attributes the current selector will NOT be added, although it would have a higher priority. This can be used to avoid duplicate style-entries on inserts
isInline - this has to be set to true, if the style is part of the STYLE element of the primary document. Only these styles will be checked for auto generates classes!

getRuleCount

public int getRuleCount()
Get the count of added Rules.

Returns:
the count.
See Also:
#addRule(String, AttributeSet, String)

getSourceIdentifiers

public java.util.List<java.lang.Object> getSourceIdentifiers()
Returns a list of all known source identifiers

Returns:
a list of all known source identifiers, never null

isExternal

public boolean isExternal(java.lang.Object identifier)
Checks, if the source referenced by the identifier is an external source. This will only return true, if the source is known and external

Parameters:
identifier - the identifier to check
Returns:
true, if the source is external

getEntries

public java.util.List<Styles.StyleSheetEntry> getEntries(java.lang.Object sourceIdentifier)
Returns all entries of a CSS source.

Parameters:
sourceIdentifier - the identifier of the source
Returns:
the entries or null, if the source is unknown

getCssAttribute

public com.inet.html.parser.converter.AttributeValue getCssAttribute(javax.swing.text.Element elemAttrs,
                                                                     CSS.Attribute searchAttr,
                                                                     boolean important)
Search an AttributValue in the styles for the described element.

Parameters:
elemAttrs - the attributes that descibed the element
searchAttr - The attribute to search for
important - if true, the important selectors will be checkt, if false the normal selectors will be checked
Returns:
the requested AttributValue or NULL if none was found

getCssAttribute

public com.inet.html.parser.converter.AttributeValue getCssAttribute(javax.swing.text.Element elemAttrs,
                                                                     CSS.Attribute searchAttr,
                                                                     boolean important,
                                                                     java.util.List<Selector> matchList)
Search an AttributValue in the styles for the described element.

Parameters:
elemAttrs - the attributes that described the element
searchAttr - The attribute to search for
important - if true, the important selectors will be checked, if false the normal selectors will be checked
matchList - A list of selectors, which match this element
Returns:
the requested AttributValue or NULL if none was found

createMatchList

public java.util.List<Selector> createMatchList(javax.swing.text.Element targetElement,
                                                HTML.Tag tag)
Creates a list of all selectors, that match the element. This list ignores important and inline styles or html tags!

Parameters:
targetElement - the element to match
tag - is passed for performance, it eqals to targetElement.getAttributes().getAttribute( StyleConstants.NameAttribute ) and can be null if the type is another
Returns:
a list of all selectors, that match the element

clear

public void clear()
Removes all rules from this styles.


getName

public java.lang.String getName()
Returns the internal name of this stylesheet, may be null

Returns:
Returns the internal name of this stylesheet, may be null

getInitialCount

public int getInitialCount()
This is the number of attribute sets, which where defined by the base style sheet given in the constructor. The styles up to this index WERE NOT set by the HTML code, which was read! It's up to the implementation of the writer etc. how to deal with this information.

Returns:
number of styles defined by the constructor

setResolver

public void setResolver(CSSChangeListener resolver)
Set the resolver of this stylesheet. The resolver must be set to null, if this stylesheet is not active on the document.

Parameters:
resolver - the current resolver or null

compile

public void compile()
THIS FUNCTION SHOULD BE USED ONLY FOR THE LOWEST-PRIO STYLESHEET! (in most cases the default.css)
Compile generates default attribute sets for every known html element and one for the ALL-Selector. This information may be used to speed up the attribute fill


isCompiled

public boolean isCompiled()
Returns true, if the selectors were compiled

Returns:
true, if the selectors were compiled

getDescribedAttributes

public java.util.Set<CSS.Attribute> getDescribedAttributes()
Returns a list of all CSS attributes described by the matchlists of this stylesheet. If this stylesheet was compiled, the attributes described by the default attribute sets will not appear in this list!

Returns:
a list of attributes described by this stylesheet

getDefaultSet

public javax.swing.text.MutableAttributeSet getDefaultSet(java.lang.Object tag)
Returns the default set, which applies to any element with the given tag

Parameters:
tag - the tag of the element
Returns:
the default styles of elements of this type

getClassName

public java.lang.Object getClassName(java.lang.Object identifier)
Returns the generated class name for an identifier. This assumes that the the identifier was already registered

Parameters:
identifier - the identifier
Returns:
it's generated class name or null