Represents the HTML document that is constructed by defining the text and
other components (images, buttons, etc) in HTML language. This class can
becomes the default document for
JEditorPane
after setting its
content type to "text/html". HTML document also serves as an intermediate
data structure when it is needed to parse HTML and then obtain the content of
the certain types of tags. This class also has methods for modifying the HTML
content.
createLeafElement
protected Element createLeafElement(Element parent,
AttributeSet a,
int p0,
int p1)
This method returns an HTMLDocument.RunElement object attached to
parent representing a run of text from p0 to p1. The run has
attributes described by a.
- createLeafElement in interface AbstractDocument
parent
- - the parent elementa
- - the attributes for the elementp0
- - the beginning of the range >= 0p1
- - the end of the range >= p0
getBase
public URL getBase()
Returns the location against which to resolve relative URLs.
This is the document's URL if the document was loaded from a URL.
If a base
tag is found, it will be used.
getElement
public Element getElement(String attrId)
Returns the element that has the given id Attribute (for instance, <p id
='my paragraph >'). If it is not found, null is returned. The HTML tag,
having this attribute, is not checked by this method and can be any. The
method is not thread-safe.
attrId
- - the value of the attribute id to look for
- the element that has the given id.
getElement
public Element getElement(Element e,
Object attribute,
Object value)
Gets the child element that contains the attribute with the value or null.
Not thread-safe.
e
- - the element to begin search atattribute
- - the desired attributevalue
- - the desired value
- the element found with the attribute and value specified or null if
it is not found.
getInsertingReader
public HTMLEditorKit.ParserCallback getInsertingReader(int pos,
int popDepth,
int pushDepth,
HTML.Tag insertTag,
Element parent)
throws IllegalStateException
Gets the reader for the parser to use when inserting the HTML fragment into
the document. Checks if the parser is present, sets the parent in the
element stack and removes any actions for BODY (it can be only one body in
a HTMLDocument).
pos
- - the starting positionpopDepth
- - the number of EndTagTypes to generate before insertingpushDepth
- - the number of StartTagTypes with a direction of
JoinNextDirection that should be generated before inserting, but
after the end tags have been generated.insertTag
- - the first tag to start inserting into documentparent
- the element that will be the parent in the document. HTML
parsing includes checks for the parent, so it must be available.
getParser
public HTMLEditorKit.Parser getParser()
Returns the parser used by this HTMLDocument to insert HTML.
- the parser used by this HTMLDocument to insert HTML.
getPreservesUnknownTags
public boolean getPreservesUnknownTags()
Returns whether or not the parser preserves unknown HTML tags.
- true if the parser preserves unknown tags
getReader
public HTMLEditorKit.ParserCallback getReader(int pos,
int popDepth,
int pushDepth,
HTML.Tag insertTag)
Gets the reader for the parser to use when loading the document with HTML.
pos
- - the starting positionpopDepth
- - the number of EndTagTypes to generate before insertingpushDepth
- - the number of StartTagTypes with a direction
of JoinNextDirection that should be generated before inserting,
but after the end tags have been generated.insertTag
- - the first tag to start inserting into document
getStyleSheet
public StyleSheet getStyleSheet()
Gets the style sheet with the document display rules (CSS) that were specified
in the HTML document.
getTokenThreshold
public int getTokenThreshold()
Returns the number of tokens that are buffered before the document
is rendered.
- the number of tokens buffered
insertBeforeEnd
public void insertBeforeEnd(Element elem,
String htmlText)
throws BadLocationException,
IOException
Inserts the string at the end of the element. If elem's children are
leaves, and the character at elem.getEndOffset() - 1 is a newline, then it
will be inserted before the newline. The parser must be set.
elem
- - the element to be the root for the new texthtmlText
- - the text to insert
insertBeforeStart
public void insertBeforeStart(Element elem,
String htmlText)
throws BadLocationException,
IOException
Inserts the string before the start of the given element. The parser must
be set.
elem
- - the element to be the root for the new text.htmlText
- - the string to be parsed and assigned to elem
setBase
public void setBase(URL u)
Sets the location against which to resolve relative URLs.
setInnerHTML
public void setInnerHTML(Element elem,
String htmlText)
throws BadLocationException,
IOException
Replaces the children of the given element with the contents of
the string. The document must have an HTMLEditorKit.Parser set.
This will be seen as at least two events, n inserts followed by a remove.
elem
- - the brance element whose children will be replacedhtmlText
- - the string to be parsed and assigned to element.
setOuterHTML
public void setOuterHTML(Element elem,
String htmlText)
throws BadLocationException,
IOException
Replaces the given element in the parent with the string. When replacing a
leaf, this will attempt to make sure there is a newline present if one is
needed. This may result in an additional element being inserted. This will
be seen as at least two events, n inserts followed by a remove. The
HTMLEditorKit.Parser must be set.
elem
- - the branch element whose parent will be replacedhtmlText
- - the string to be parsed and assigned to elem
setPreservesUnknownTags
public void setPreservesUnknownTags(boolean preservesTags)
Sets the behaviour of the parser when it encounters unknown HTML tags.
preservesTags
- true if the parser should preserve unknown tags.
setTokenThreshold
public void setTokenThreshold(int n)
Sets the number of tokens to buffer before trying to display the
Document.
n
- the number of tokens to buffer
HTMLDocument.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.