create
protected void create(DefaultStyledDocument.ElementSpec[] data)
Replaces the contents of the document with the given element specifications.
This is called before insert if the loading is done in bursts. This is the
only method called if loading the document entirely in one burst.
- create in interface DefaultStyledDocument
data
- - the date that replaces the content of the document
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. If it is not found,
null is returned. This method works on an Attribute, not a character tag.
This is not thread-safe.
attrId
- - 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.
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
insert
protected void insert(int offset,
DefaultStyledDocument.ElementSpec[] data)
throws BadLocationException
Inserts new elements in bulk. This is how elements get created in the
document. The parsing determines what structure is needed and creates the
specification as a set of tokens that describe the edit while leaving the
document free of a write-lock. This method can then be called in bursts by
the reader to acquire a write-lock for a shorter duration (i.e. while the
document is actually being altered).
- insert in interface DefaultStyledDocument
offset
- - the starting offsetdata
- - the element data
BadLocationException
- - if the given position does not
represent a valid location in the associated document.
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
setParagraphAttributes
public void setParagraphAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
This method sets the attributes associated with the paragraph containing
offset. If replace is false, s is merged with existing attributes. The
length argument determines how many characters are affected by the new
attributes. This is often the entire paragraph.
- setParagraphAttributes in interface StyledDocument
- setParagraphAttributes in interface DefaultStyledDocument
offset
- -
the offset into the paragraph (must be at least 0)length
- -
the number of characters affected (must be at least 0)s
- -
the attributesreplace
- -
whether to replace existing attributes, or merge them
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.