Home » openjdk-7 » javax » swing » text » html » [javadoc | source]
javax.swing.text.html
public class: HTMLDocument [javadoc | source]
java.lang.Object
   javax.swing.text.AbstractDocument
      javax.swing.text.DefaultStyledDocument
         javax.swing.text.html.HTMLDocument

All Implemented Interfaces:
    StyledDocument, Document, Serializable

Direct Known Subclasses:
    BasicDocument

A document that models HTML. The purpose of this model is to support both browsing and editing. As a result, the structure described by an HTML document is not exactly replicated by default. The element structure that is modeled by default, is built by the class HTMLDocument.HTMLReader, which implements the HTMLEditorKit.ParserCallback protocol that the parser expects. To change the structure one can subclass HTMLReader, and reimplement the method #getReader(int) to return the new reader implementation. The documentation for HTMLReader should be consulted for the details of the default structure created. The intent is that the document be non-lossy (although reproducing the HTML format may result in a different format).

The document models only HTML, and makes no attempt to store view attributes in it. The elements are identified by the StyleContext.NameAttribute attribute, which should always have a value of type HTML.Tag that identifies the kind of element. Some of the elements (such as comments) are synthesized. The HTMLFactory uses this attribute to determine what kind of view to build.

This document supports incremental loading. The TokenThreshold property controls how much of the parse is buffered before trying to update the element structure of the document. This property is set by the EditorKit so that subclasses can disable it.

The Base property determines the URL against which relative URLs are resolved. By default, this will be the Document.StreamDescriptionProperty if the value of the property is a URL. If a <BASE> tag is encountered, the base will become the URL specified by that tag. Because the base URL is a property, it can of course be set directly.

The default content storage mechanism for this document is a gap buffer (GapContent). Alternatives can be supplied by using the constructor that takes a Content implementation.

Modifying HTMLDocument

In addition to the methods provided by Document and StyledDocument for mutating an HTMLDocument, HTMLDocument provides a number of convenience methods. The following methods can be used to insert HTML content into an existing document.

The following examples illustrate using these methods. Each example assumes the HTML document is initialized in the following way:

JEditorPane p = new JEditorPane();
p.setContentType("text/html");
p.setText("..."); // Document text is provided below.
HTMLDocument d = (HTMLDocument) p.getDocument();

With the following HTML content:

<html>
  <head>
    <title>An example HTMLDocument</title>
    <style type="text/css">
      div { background-color: silver; }
      ul { color: red; }
    </style>
  </head>
  <body>
    <div id="BOX">
      <p>Paragraph 1</p>
      <p>Paragraph 2</p>
    </div>
  </body>
</html>

All the methods for modifying an HTML document require an Element . Elements can be obtained from an HTML document by using the method #getElement(Element e, Object attribute, Object value) . It returns the first descendant element that contains the specified attribute with the given value, in depth-first order. For example, d.getElement(d.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.P) returns the first paragraph element.

A convenient shortcut for locating elements is the method #getElement(String) ; returns an element whose ID attribute matches the specified value. For example, d.getElement("BOX") returns the DIV element.

The #getIterator(HTML.Tag t) method can also be used for finding all occurrences of the specified HTML tag in the document.

Inserting elements

Elements can be inserted before or after the existing children of any non-leaf element by using the methods insertAfterStart and insertBeforeEnd. For example, if e is the DIV element, d.insertAfterStart(e, "<ul><li>List Item</li></ul>") inserts the list before the first paragraph, and d.insertBeforeEnd(e, "<ul><li>List Item</li></ul>") inserts the list after the last paragraph. The DIV block becomes the parent of the newly inserted elements.

Sibling elements can be inserted before or after any element by using the methods insertBeforeStart and insertAfterEnd. For example, if e is the DIV element, d.insertBeforeStart(e, "<ul><li>List Item</li></ul>") inserts the list before the DIV element, and d.insertAfterEnd(e, "<ul><li>List Item</li></ul>") inserts the list after the DIV element. The newly inserted elements become siblings of the DIV element.

Replacing elements

Elements and all their descendants can be replaced by using the methods setInnerHTML and setOuterHTML. For example, if e is the DIV element, d.setInnerHTML(e, "<ul><li>List Item</li></ul>") replaces all children paragraphs with the list, and d.setOuterHTML(e, "<ul><li>List Item</li></ul>") replaces the DIV element itself. In latter case the parent of the list is the BODY element.

Summary

The following table shows the example document and the results of various methods described above.

Example insertAfterStart insertBeforeEnd insertBeforeStart insertAfterEnd setInnerHTML setOuterHTML

Paragraph 1

Paragraph 2

  • List Item

Paragraph 1

Paragraph 2

Paragraph 1

Paragraph 2

  • List Item
  • List Item

Paragraph 1

Paragraph 2

Paragraph 1

Paragraph 2

  • List Item
  • List Item
  • List Item

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder .

Nested Class Summary:
abstract public static class  HTMLDocument.Iterator  An iterator to iterate over a particular type of tag. The iterator is not thread safe. If reliable access to the document is not already ensured by the context under which the iterator is being used, its use should be performed under the protection of Document.render. 
static class  HTMLDocument.LeafIterator  An iterator to iterate over a particular type of tag. 
public class  HTMLDocument.HTMLReader  An HTML reader to load an HTML document with an HTML element structure. This is a set of callbacks from the parser, implemented to create a set of elements tagged with attributes. The parse builds up tokens (ElementSpec) that describe the element subtree desired, and burst it into the document under the protection of a write lock using the insert method on the document outer class.

The reader can be configured by registering actions (of type HTMLDocument.HTMLReader.TagAction) that describe how to handle the action. The idea behind the actions provided is that the most natural text editing operations can be provided if the element structure boils down to paragraphs with runs of some kind of style in them. Some things are more naturally specified structurally, so arbitrary structure should be allowed above the paragraphs, but will need to be edited with structural actions. The implication of this is that some of the HTML elements specified in the stream being parsed will be collapsed into attributes, and in some cases paragraphs will be synthesized. When HTML elements have been converted to attributes, the attribute key will be of type HTML.Tag, and the value will be of type AttributeSet so that no information is lost. This enables many of the existing actions to work so that the user can type input, hit the return key, backspace, delete, etc and have a reasonable result. Selections can be created, and attributes applied or removed, etc. With this in mind, the work done by the reader can be categorized into the following kinds of tasks:

Block
Build the structure like it's specified in the stream. This produces elements that contain other elements.
Paragraph
Like block except that it's expected that the element will be used with a paragraph view so a paragraph element won't need to be synthesized.
Character
Contribute the element as an attribute that will start and stop at arbitrary text locations. This will ultimately be mixed into a run of text, with all of the currently flattened HTML character elements.
Special
Produce an embedded graphical element.
Form
Produce an element that is like the embedded graphical element, except that it also has a component model associated with it.
Hidden
Create an element that is hidden from view when the document is being viewed read-only, and visible when the document is being edited. This is useful to keep the model from losing information, and used to store things like comments and unrecognized tags.

Currently, <APPLET>, <PARAM>, <MAP>, <AREA>, <LINK>, <SCRIPT> and <STYLE> are unsupported.

The assignment of the actions described is shown in the following table for the tags defined in HTML.Tag.

TagAction
HTML.Tag.A CharacterAction
HTML.Tag.ADDRESS CharacterAction
HTML.Tag.APPLET HiddenAction
HTML.Tag.AREA AreaAction
HTML.Tag.B CharacterAction
HTML.Tag.BASE BaseAction
HTML.Tag.BASEFONT CharacterAction
HTML.Tag.BIG CharacterAction
HTML.Tag.BLOCKQUOTEBlockAction
HTML.Tag.BODY BlockAction
HTML.Tag.BR SpecialAction
HTML.Tag.CAPTION BlockAction
HTML.Tag.CENTER BlockAction
HTML.Tag.CITE CharacterAction
HTML.Tag.CODE CharacterAction
HTML.Tag.DD BlockAction
HTML.Tag.DFN CharacterAction
HTML.Tag.DIR BlockAction
HTML.Tag.DIV BlockAction
HTML.Tag.DL BlockAction
HTML.Tag.DT ParagraphAction
HTML.Tag.EM CharacterAction
HTML.Tag.FONT CharacterAction
HTML.Tag.FORM As of 1.4 a BlockAction
HTML.Tag.FRAME SpecialAction
HTML.Tag.FRAMESET BlockAction
HTML.Tag.H1 ParagraphAction
HTML.Tag.H2 ParagraphAction
HTML.Tag.H3 ParagraphAction
HTML.Tag.H4 ParagraphAction
HTML.Tag.H5 ParagraphAction
HTML.Tag.H6 ParagraphAction
HTML.Tag.HEAD HeadAction
HTML.Tag.HR SpecialAction
HTML.Tag.HTML BlockAction
HTML.Tag.I CharacterAction
HTML.Tag.IMG SpecialAction
HTML.Tag.INPUT FormAction
HTML.Tag.ISINDEX IsndexAction
HTML.Tag.KBD CharacterAction
HTML.Tag.LI BlockAction
HTML.Tag.LINK LinkAction
HTML.Tag.MAP MapAction
HTML.Tag.MENU BlockAction
HTML.Tag.META MetaAction
HTML.Tag.NOFRAMES BlockAction
HTML.Tag.OBJECT SpecialAction
HTML.Tag.OL BlockAction
HTML.Tag.OPTION FormAction
HTML.Tag.P ParagraphAction
HTML.Tag.PARAM HiddenAction
HTML.Tag.PRE PreAction
HTML.Tag.SAMP CharacterAction
HTML.Tag.SCRIPT HiddenAction
HTML.Tag.SELECT FormAction
HTML.Tag.SMALL CharacterAction
HTML.Tag.STRIKE CharacterAction
HTML.Tag.S CharacterAction
HTML.Tag.STRONG CharacterAction
HTML.Tag.STYLE StyleAction
HTML.Tag.SUB CharacterAction
HTML.Tag.SUP CharacterAction
HTML.Tag.TABLE BlockAction
HTML.Tag.TD BlockAction
HTML.Tag.TEXTAREA FormAction
HTML.Tag.TH BlockAction
HTML.Tag.TITLE TitleAction
HTML.Tag.TR BlockAction
HTML.Tag.TT CharacterAction
HTML.Tag.U CharacterAction
HTML.Tag.UL BlockAction
HTML.Tag.VAR CharacterAction

Once </html> is encountered, the Actions are no longer notified. 

static class  HTMLDocument.TaggedAttributeSet  Used by StyleSheet to determine when to avoid removing HTML.Tags matching StyleConstants. 
public class  HTMLDocument.RunElement  An element that represents a chunk of text that has a set of HTML character level attributes assigned to it. 
public class  HTMLDocument.BlockElement  An element that represents a structural block of HTML. 
Field Summary
static final  String TokenThreshold    Document property for the number of tokens to buffer before building an element subtree to represent them. 
public static final  String AdditionalComments    Document property key value. The value for the key will be a Vector of Strings that are comments not found in the body. 
static final  String StyleType    Document property key value. The value for the key will be a String indicating the default type of stylesheet links. 
 URL base    The location to resolve relative URLs against. By default this will be the document's URL if the document was loaded from a URL. If a base tag is found and can be parsed, it will be used as the base location. 
 boolean hasBaseTag    does the document have base tag 
static  String MAP_PROPERTY    Property Maps are registered under, will be a Hashtable. 
Fields inherited from javax.swing.text.DefaultStyledDocument:
BUFFER_SIZE_DEFAULT,  buffer
Fields inherited from javax.swing.text.AbstractDocument:
listenerList,  BAD_LOCATION,  ParagraphElementName,  ContentElementName,  SectionElementName,  BidiElementName,  ElementNameAttribute,  I18NProperty,  MultiByteProperty,  AsyncLoadPriority
Constructor:
 public HTMLDocument() 
 public HTMLDocument(StyleSheet styles) 
    Constructs an HTML document with the default content storage implementation and the specified style/attribute storage mechanism. This is a convenience method for the constructor HTMLDocument(Content, StyleSheet).
    Parameters:
    styles - the styles
 public HTMLDocument(Content c,
    StyleSheet styles) 
    Constructs an HTML document with the given content storage implementation and the given style/attribute storage mechanism.
    Parameters:
    c - the container for the content
    styles - the styles
Method from javax.swing.text.html.HTMLDocument Summary:
addMap,   create,   createBranchElement,   createDefaultRoot,   createLeafElement,   fireChangedUpdate,   fireUndoableEditUpdate,   getBase,   getBaseTarget,   getDefaultStyleSheetType,   getElement,   getElement,   getIterator,   getMap,   getMaps,   getParser,   getPreservesUnknownTags,   getReader,   getReader,   getReader,   getStyleSheet,   getTokenThreshold,   hasBaseTag,   insert,   insertAfterEnd,   insertAfterStart,   insertBeforeEnd,   insertBeforeStart,   insertUpdate,   isFrameDocument,   matchNameAttribute,   obtainLock,   processHTMLFrameHyperlinkEvent,   releaseLock,   removeMap,   setBase,   setDefaultStyleSheetType,   setFrameDocumentState,   setInnerHTML,   setOuterHTML,   setParagraphAttributes,   setParser,   setPreservesUnknownTags,   setTokenThreshold
Methods from javax.swing.text.DefaultStyledDocument:
addDocumentListener,   addStyle,   create,   createDefaultRoot,   createSpecsForInsertAfterNewline,   createStyleChangeListener,   createStyleContextChangeListener,   getBackground,   getCharacterElement,   getDefaultRootElement,   getFont,   getForeground,   getLogicalStyle,   getParagraphElement,   getStyle,   getStyleNames,   insert,   insertUpdate,   removeDocumentListener,   removeElement,   removeStyle,   removeUpdate,   setCharacterAttributes,   setLogicalStyle,   setParagraphAttributes,   styleChanged,   updateStylesListeningTo
Methods from javax.swing.text.AbstractDocument:
addDocumentListener,   addUndoableEditListener,   createBranchElement,   createLeafElement,   createPosition,   dump,   fireChangedUpdate,   fireInsertUpdate,   fireRemoveUpdate,   fireUndoableEditUpdate,   getAsynchronousLoadPriority,   getAttributeContext,   getBidiRootElement,   getContent,   getCurrentWriter,   getDefaultRootElement,   getDocumentFilter,   getDocumentListeners,   getDocumentProperties,   getEndPosition,   getLength,   getListeners,   getParagraphElement,   getProperty,   getRootElements,   getStartPosition,   getText,   getText,   getUndoableEditListeners,   handleInsertString,   handleRemove,   insertString,   insertUpdate,   isLeftToRight,   postRemoveUpdate,   putProperty,   readLock,   readUnlock,   remove,   removeDocumentListener,   removeUndoableEditListener,   removeUpdate,   render,   replace,   setAsynchronousLoadPriority,   setDocumentFilter,   setDocumentProperties,   updateBidi,   writeLock,   writeUnlock
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.html.HTMLDocument Detail:
  void addMap(Map map) 
    Adds the specified map, this will remove a Map that has been previously registered with the same name.
 protected  void create(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.
 protected Element createBranchElement(Element parent,
    AttributeSet a) 
    Creates a document branch element, that can contain other elements. This is implemented to return an element of type HTMLDocument.BlockElement.
 protected AbstractElement createDefaultRoot() 
    Creates the root element to be used to represent the default document structure.
 protected Element createLeafElement(Element parent,
    AttributeSet a,
    int p0,
    int p1) 
    Creates a document leaf element that directly represents text (doesn't have any children). This is implemented to return an element of type HTMLDocument.RunElement.
 protected  void fireChangedUpdate(DocumentEvent e) 
    Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
 protected  void fireUndoableEditUpdate(UndoableEditEvent e) 
    Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
 public URL getBase() 
    Returns the location to resolve relative URLs against. By default this will be the document's URL if the document was loaded from a URL. If a base tag is found and can be parsed, it will be used as the base location.
 String getBaseTarget() 
 String getDefaultStyleSheetType() 
    Returns the content type language used for style sheets. The default is text/css.
 public Element getElement(String id) 
    Returns the element that has the given id Attribute. If the element can't be found, null is returned. Note that this method works on an Attribute, not a character tag. In the following HTML snippet: <a id="HelloThere"> the attribute is 'id' and the character tag is 'a'. This is a convenience method for getElement(RootElement, HTML.Attribute.id, id). This is not thread-safe.
 public Element getElement(Element e,
    Object attribute,
    Object value) 
    Returns the child element of e that contains the attribute, attribute with value value, or null if one isn't found. This is not thread-safe.
 public Iterator getIterator(Tag t) 
    Fetches an iterator for the specified HTML tag. This can be used for things like iterating over the set of anchors contained, or iterating over the input elements.
 Map getMap(String name) 
    Returns the Map associated with the given name.
 Enumeration getMaps() 
    Returns an Enumeration of the possible Maps.
 public Parser getParser() 
    Returns the parser that is used when inserting HTML into the existing document.
 public boolean getPreservesUnknownTags() 
    Returns the behavior the parser observes when encountering unknown tags.
 public ParserCallback getReader(int pos) 
    Fetches the reader for the parser to use when loading the document with HTML. This is implemented to return an instance of HTMLDocument.HTMLReader. Subclasses can reimplement this method to change how the document gets structured if desired. (For example, to handle custom tags, or structurally represent character style elements.)
 public ParserCallback getReader(int pos,
    int popDepth,
    int pushDepth,
    Tag insertTag) 
    Returns the reader for the parser to use to load the document with HTML. This is implemented to return an instance of HTMLDocument.HTMLReader. Subclasses can reimplement this method to change how the document gets structured if desired. (For example, to handle custom tags, or structurally represent character style elements.)

    This is a convenience method for getReader(int, int, int, HTML.Tag, TRUE).

 ParserCallback getReader(int pos,
    int popDepth,
    int pushDepth,
    Tag insertTag,
    boolean insertInsertTag) 
    Fetches the reader for the parser to use to load the document with HTML. This is implemented to return an instance of HTMLDocument.HTMLReader. Subclasses can reimplement this method to change how the document get structured if desired (e.g. to handle custom tags, structurally represent character style elements, etc.).
 public StyleSheet getStyleSheet() 
    Fetches the StyleSheet with the document-specific display rules (CSS) that were specified in the HTML document itself.
 public int getTokenThreshold() 
    Gets the number of tokens to buffer before trying to update the documents element structure. The default value is Integer.MAX_VALUE.
 boolean hasBaseTag() 
 protected  void insert(int offset,
    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).
 public  void insertAfterEnd(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Inserts the HTML specified as a string after the the end of the given element.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking insertAfterEnd(elem, "<ul><li>") results in the following structure (new elements are in red).

           <body>
            /  \
         <div> <ul>
          / \    \
        <p> <p>  <li>
    

    Unlike the insertBeforeEnd method, new elements become siblings of the specified element, not children.

    If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 public  void insertAfterStart(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Inserts the HTML specified as a string at the start of the element.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking insertAfterStart(elem, "<ul><li>") results in the following structure (new elements are in red).

           <body>
             |
           <div>
          /  |  \
       <ul> <p> <p>
        /
     <li>
    

    Unlike the insertBeforeStart method, new elements become children of the specified element, not siblings.

    Parameter elem must not be a leaf element, otherwise an IllegalArgumentException is thrown. If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 public  void insertBeforeEnd(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Inserts the HTML specified as a string at the end of the element.

    If elem's children are leaves, and the character at a elem.getEndOffset() - 1 is a newline, this will insert before the newline so that there isn't text after the newline.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking insertBeforeEnd(elem, "<ul><li>") results in the following structure (new elements are in red).

           <body>
             |
           <div>
          /  |  \
        <p> <p> <ul>
                  \
                  <li>
    

    Unlike the insertAfterEnd method, new elements become children of the specified element, not siblings.

    Parameter elem must not be a leaf element, otherwise an IllegalArgumentException is thrown. If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 public  void insertBeforeStart(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Inserts the HTML specified as a string before the start of the given element.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking insertBeforeStart(elem, "<ul><li>") results in the following structure (new elements are in red).

           <body>
            /  \
         <ul> <div>
          /    /  \
        <li> <p>  <p>
    

    Unlike the insertAfterStart method, new elements become siblings of the specified element, not children.

    If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 protected  void insertUpdate(DefaultDocumentEvent chng,
    AttributeSet attr) 
    Updates document structure as a result of text insertion. This will happen within a write lock. This implementation simply parses the inserted content for line breaks and builds up a set of instructions for the element buffer.
 boolean isFrameDocument() 
    Returns true if the document will be viewed in a frame.
 static boolean matchNameAttribute(AttributeSet attr,
    Tag tag) 
    Returns true if StyleConstants.NameAttribute is equal to the tag that is passed in as a parameter.
  void obtainLock() 
 public  void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent e) 
    Processes HyperlinkEvents that are generated by documents in an HTML frame. The HyperlinkEvent type, as the parameter suggests, is HTMLFrameHyperlinkEvent. In addition to the typical information contained in a HyperlinkEvent, this event contains the element that corresponds to the frame in which the click happened (the source element) and the target name. The target name has 4 possible values:
    • _self
    • _parent
    • _top
    • a named frame
    If target is _self, the action is to change the value of the HTML.Attribute.SRC attribute and fires a ChangedUpdate event.

    If the target is _parent, then it deletes the parent element, which is a <FRAMESET> element, and inserts a new <FRAME> element, and sets its HTML.Attribute.SRC attribute to have a value equal to the destination URL and fire a RemovedUpdate and InsertUpdate.

    If the target is _top, this method does nothing. In the implementation of the view for a frame, namely the FrameView, the processing of _top is handled. Given that _top implies replacing the entire document, it made sense to handle this outside of the document that it will replace.

    If the target is a named frame, then the element hierarchy is searched for an element with a name equal to the target, its HTML.Attribute.SRC attribute is updated and a ChangedUpdate event is fired.

  void releaseLock() 
  void removeMap(Map map) 
    Removes a previously registered map.
 public  void setBase(URL u) 
    Sets the location to resolve relative URLs against. By default this will be the document's URL if the document was loaded from a URL. If a base tag is found and can be parsed, it will be used as the base location.

    This also sets the base of the StyleSheet to be u as well as the base of the document.

  void setDefaultStyleSheetType(String contentType) 
    Sets the content type language used for style sheets that do not explicitly specify the type. The default is text/css.
  void setFrameDocumentState(boolean frameDoc) 
    Sets a boolean state about whether the document will be viewed in a frame.
 public  void setInnerHTML(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Replaces the children of the given element with the contents specified as an HTML string.

    This will be seen as at least two events, n inserts followed by a remove.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking setInnerHTML(elem, "<ul><li>") results in the following structure (new elements are in red).

        <body>
          |
        <div>
            \
            <ul>
              \
              <li>
    

    Parameter elem must not be a leaf element, otherwise an IllegalArgumentException is thrown. If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 public  void setOuterHTML(Element elem,
    String htmlText) throws BadLocationException, IOException 
    Replaces the given element in the parent with the contents specified as an HTML string.

    This will be seen as at least two events, n inserts followed by a remove.

    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. Consider, if you were to replace a character element that contained a newline with <img> this would create two elements, one for the image, ane one for the newline.

    If you try to replace the element at length you will most likely end up with two elements, eg setOuterHTML(getCharacterElement (getLength()), "blah") will result in two leaf elements at the end, one representing 'blah', and the other representing the end element.

    Consider the following structure (the elem parameter is in bold).

        <body>
          |
        <div>
         /  \
       <p>   <p>
    

    Invoking setOuterHTML(elem, "<ul><li>") results in the following structure (new elements are in red).

       <body>
         |
        <ul>
          \
          <li>
    

    If either elem or htmlText parameter is null, no changes are made to the document.

    For this to work correcty, the document must have an HTMLEditorKit.Parser set. This will be the case if the document was created from an HTMLEditorKit via the createDefaultDocument method.

 public  void setParagraphAttributes(int offset,
    int length,
    AttributeSet s,
    boolean replace) 
    Sets attributes for a paragraph.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public  void setParser(Parser parser) 
    Sets the parser that is used by the methods that insert html into the existing document, such as setInnerHTML, and setOuterHTML.

    HTMLEditorKit.createDefaultDocument will set the parser for you. If you create an HTMLDocument by hand, be sure and set the parser accordingly.

 public  void setPreservesUnknownTags(boolean preservesTags) 
    Determines how unknown tags are handled by the parser. If set to true, unknown tags are put in the model, otherwise they are dropped.
 public  void setTokenThreshold(int n) 
    Sets the number of tokens to buffer before trying to update the documents element structure.