3261N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A document that models HTML. The purpose of this model is to 0N/A * support both browsing and editing. As a result, the structure 0N/A * described by an HTML document is not exactly replicated by default. 0N/A * The element structure that is modeled by default, is built by the 0N/A * <code>HTMLEditorKit.ParserCallback</code> protocol that the parser 0N/A * expects. To change the structure one can subclass 0N/A * <code>HTMLReader</code>, and reimplement the method {@link 0N/A * #getReader(int)} to return the new reader implementation. The 0N/A * documentation for <code>HTMLReader</code> should be consulted for 0N/A * the details of the default structure created. The intent is that 0N/A * the document be non-lossy (although reproducing the HTML format may 0N/A * result in a different format). 0N/A * <p>The document models only HTML, and makes no attempt to store 0N/A * view attributes in it. The elements are identified by the 0N/A * <code>StyleContext.NameAttribute</code> attribute, which should 0N/A * always have a value of type <code>HTML.Tag</code> that identifies 0N/A * the kind of element. Some of the elements (such as comments) are 0N/A * synthesized. The <code>HTMLFactory</code> uses this attribute to 0N/A * determine what kind of view to build.</p> 0N/A * <p>This document supports incremental loading. The 0N/A * <code>TokenThreshold</code> property controls how much of the parse 0N/A * is buffered before trying to update the element structure of the 0N/A * document. This property is set by the <code>EditorKit</code> so 0N/A * that subclasses can disable it.</p> 0N/A * <p>The <code>Base</code> property determines the URL against which 0N/A * relative URLs are resolved. By default, this will be the 0N/A * <code>Document.StreamDescriptionProperty</code> if the value of the 0N/A * property is a URL. If a <BASE> tag is encountered, the base 0N/A * will become the URL specified by that tag. Because the base URL is 0N/A * a property, it can of course be set directly.</p> 0N/A * <p>The default content storage mechanism for this document is a gap 0N/A * buffer (<code>GapContent</code>). Alternatives can be supplied by 0N/A * using the constructor that takes a <code>Content</code> 0N/A * implementation.</p> 0N/A * <h2>Modifying HTMLDocument</h2> 0N/A * <p>In addition to the methods provided by Document and 0N/A * StyledDocument for mutating an HTMLDocument, HTMLDocument provides 0N/A * a number of convenience methods. The following methods can be used 0N/A * to insert HTML content into an existing document.</p> 0N/A * <li>{@link #setInnerHTML(Element, String)}</li> 0N/A * <li>{@link #setOuterHTML(Element, String)}</li> 0N/A * <li>{@link #insertBeforeStart(Element, String)}</li> 0N/A * <li>{@link #insertAfterStart(Element, String)}</li> 0N/A * <li>{@link #insertBeforeEnd(Element, String)}</li> 0N/A * <li>{@link #insertAfterEnd(Element, String)}</li> 0N/A * <p>The following examples illustrate using these methods. Each 0N/A * example assumes the HTML document is initialized in the following 0N/A * JEditorPane p = new JEditorPane(); 0N/A * p.setText("..."); // Document text is provided below. 0N/A * HTMLDocument d = (HTMLDocument) p.getDocument(); 0N/A * <p>With the following HTML content:</p> 0N/A * <title>An example HTMLDocument</title> 0N/A * div { background-color: silver; } 0N/A * ul { color: red; } 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <p>All the methods for modifying an HTML document require an {@link 0N/A * Element}. Elements can be obtained from an HTML document by using 0N/A * the method {@link #getElement(Element e, Object attribute, Object 0N/A * value)}. It returns the first descendant element that contains the 0N/A * specified attribute with the given value, in depth-first order. 0N/A * For example, <code>d.getElement(d.getDefaultRootElement(), 0N/A * StyleConstants.NameAttribute, HTML.Tag.P)</code> returns the first 0N/A * paragraph element.</p> 0N/A * <p>A convenient shortcut for locating elements is the method {@link 0N/A * #getElement(String)}; returns an element whose <code>ID</code> 0N/A * attribute matches the specified value. For example, 0N/A * <code>d.getElement("BOX")</code> returns the <code>DIV</code> 0N/A * <p>The {@link #getIterator(HTML.Tag t)} method can also be used for 0N/A * finding all occurrences of the specified HTML tag in the 0N/A * <h3>Inserting elements</h3> 0N/A * <p>Elements can be inserted before or after the existing children 0N/A * of any non-leaf element by using the methods 0N/A * <code>insertAfterStart</code> and <code>insertBeforeEnd</code>. 0N/A * For example, if <code>e</code> is the <code>DIV</code> element, 0N/A * <code>d.insertAfterStart(e, "<ul><li>List 0N/A * Item</li></ul>")</code> inserts the list before the first 0N/A * paragraph, and <code>d.insertBeforeEnd(e, "<ul><li>List 0N/A * Item</li></ul>")</code> inserts the list after the last 0N/A * paragraph. The <code>DIV</code> block becomes the parent of the 0N/A * newly inserted elements.</p> 0N/A * <p>Sibling elements can be inserted before or after any element by 0N/A * using the methods <code>insertBeforeStart</code> and 0N/A * <code>insertAfterEnd</code>. For example, if <code>e</code> is the 0N/A * <code>DIV</code> element, <code>d.insertBeforeStart(e, 0N/A * "<ul><li>List Item</li></ul>")</code> inserts the list 0N/A * before the <code>DIV</code> element, and <code>d.insertAfterEnd(e, 0N/A * "<ul><li>List Item</li></ul>")</code> inserts the list 0N/A * after the <code>DIV</code> element. The newly inserted elements 0N/A * become siblings of the <code>DIV</code> element.</p> 0N/A * <h3>Replacing elements</h3> 0N/A * <p>Elements and all their descendants can be replaced by using the 0N/A * methods <code>setInnerHTML</code> and <code>setOuterHTML</code>. 0N/A * For example, if <code>e</code> is the <code>DIV</code> element, 0N/A * <code>d.setInnerHTML(e, "<ul><li>List 0N/A * Item</li></ul>")</code> replaces all children paragraphs with 0N/A * the list, and <code>d.setOuterHTML(e, "<ul><li>List 0N/A * Item</li></ul>")</code> replaces the <code>DIV</code> element 0N/A * itself. In latter case the parent of the list is the 0N/A * <code>BODY</code> element. 0N/A * <p>The following table shows the example document and the results 0N/A * of various methods described above.</p> 0N/A * <table border=1 cellspacing=0> 0N/A * <th><code>insertAfterStart</code></th> 0N/A * <th><code>insertBeforeEnd</code></th> 0N/A * <th><code>insertBeforeStart</code></th> 0N/A * <th><code>insertAfterEnd</code></th> 0N/A * <th><code>setInnerHTML</code></th> 0N/A * <th><code>setOuterHTML</code></th> 0N/A * <td nowrap="nowrap"> 0N/A * <div style="background-color: silver;"> 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <!--insertAfterStart--> 0N/A * <td nowrap="nowrap"> 0N/A * <div style="background-color: silver;"> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <!--insertBeforeEnd--> 0N/A * <td nowrap="nowrap"> 0N/A * <div style="background-color: silver;"> 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <!--insertBeforeStart--> 0N/A * <td nowrap="nowrap"> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <div style="background-color: silver;"> 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <!--insertAfterEnd--> 0N/A * <td nowrap="nowrap"> 0N/A * <div style="background-color: silver;"> 0N/A * <p>Paragraph 1</p> 0N/A * <p>Paragraph 2</p> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <!--setInnerHTML--> 0N/A * <td nowrap="nowrap"> 0N/A * <div style="background-color: silver;"> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <!--setOuterHTML--> 0N/A * <td nowrap="nowrap"> 0N/A * <ul style="color: red;"> 0N/A * <li>List Item</li> 0N/A * <p><strong>Warning:</strong> Serialized objects of this class will 0N/A * not be compatible with future Swing releases. The current 0N/A * serialization support is appropriate for short term storage or RMI 0N/A * between applications running the same version of Swing. As of 1.4, 0N/A * support for long term storage of all JavaBeans<sup><font 0N/A * size="-2">TM</font></sup> has been added to the 0N/A * <code>java.beans</code> package. Please see {@link 0N/A * @author Timothy Prinzing 0N/A * @author Scott Violet 0N/A * @author Sunita Mani 0N/A * Constructs an HTML document using the default buffer size 0N/A * and a default <code>StyleSheet</code>. This is a convenience 0N/A * method for the constructor 0N/A * <code>HTMLDocument(Content, StyleSheet)</code>. 0N/A * Constructs an HTML document with the default content 0N/A * storage mechanism. This is a convenience method for the 0N/A * <code>HTMLDocument(Content, StyleSheet)</code>. 0N/A * @param styles the styles 0N/A * Constructs an HTML document with the given content 0N/A * storage mechanism. 0N/A * @param c the container for the content 0N/A * @param styles the styles 0N/A * Fetches the reader for the parser to use when loading the document 0N/A * with HTML. This is implemented to return an instance of 0N/A * Subclasses can reimplement this 0N/A * method to change how the document gets structured if desired. 0N/A * (For example, to handle custom tags, or structurally represent character 0N/A * @param pos the starting position 0N/A * @return the reader used by the parser to load the document 0N/A * Returns the reader for the parser to use to load the document 0N/A * with HTML. This is implemented to return an instance of 0N/A * Subclasses can reimplement this 0N/A * method to change how the document gets structured if desired. 0N/A * (For example, to handle custom tags, or structurally represent character 0N/A * <p>This is a convenience method for 0N/A * <code>getReader(int, int, int, HTML.Tag, TRUE)</code>. 0N/A * @param popDepth the number of <code>ElementSpec.EndTagTypes</code> 0N/A * to generate before inserting 0N/A * @param pushDepth the number of <code>ElementSpec.StartTagTypes</code> 0N/A * with a direction of <code>ElementSpec.JoinNextDirection</code> 0N/A * that should be generated before inserting, 0N/A * but after the end tags have been generated 0N/A * @param insertTag the first tag to start inserting into document 0N/A * @return the reader used by the parser to load the document 0N/A * Fetches the reader for the parser to use to load the document 0N/A * with HTML. This is implemented to return an instance of 0N/A * method to change how the document get structured if desired 0N/A * (e.g. to handle custom tags, structurally represent character 0N/A * style elements, etc.). 0N/A * @param popDepth the number of <code>ElementSpec.EndTagTypes</code> 0N/A * to generate before inserting 0N/A * @param pushDepth the number of <code>ElementSpec.StartTagTypes</code> 0N/A * with a direction of <code>ElementSpec.JoinNextDirection</code> 0N/A * that should be generated before inserting, 0N/A * but after the end tags have been generated 0N/A * @param insertTag the first tag to start inserting into document 0N/A * @param insertInsertTag false if all the Elements after insertTag should 0N/A * be inserted; otherwise insertTag will be inserted 0N/A * @return the reader used by the parser to load the document 0N/A * Returns the location to resolve relative URLs against. By 0N/A * default this will be the document's URL if the document 0N/A * was loaded from a URL. If a base tag is found and 0N/A * can be parsed, it will be used as the base location. 0N/A * @return the base location 0N/A * Sets the location to resolve relative URLs against. By 0N/A * default this will be the document's URL if the document 0N/A * was loaded from a URL. If a base tag is found and 0N/A * can be parsed, it will be used as the base location. 0N/A * <p>This also sets the base of the <code>StyleSheet</code> 0N/A * to be <code>u</code> as well as the base of the document. 0N/A * @param u the desired base URL 0N/A * Inserts new elements in bulk. This is how elements get created 0N/A * in the document. The parsing determines what structure is needed 0N/A * and creates the specification as a set of tokens that describe the 0N/A * edit while leaving the document free of a write-lock. This method 0N/A * can then be called in bursts by the reader to acquire a write-lock 0N/A * for a shorter duration (i.e. while the document is actually being 0N/A * @param offset the starting offset 0N/A * @param data the element data 0N/A * @exception BadLocationException if the given position does not 0N/A * represent a valid location in the associated document. 0N/A * Updates document structure as a result of text insertion. This 0N/A * will happen within a write lock. This implementation simply 0N/A * parses the inserted content for line breaks and builds up a set 0N/A * of instructions for the element buffer. 0N/A * @param chng a description of the document change 0N/A * @param attr the attributes 0N/A // If this is the composed text element, merge the content attribute to it 0N/A * Replaces the contents of the document with the given 0N/A * element specifications. This is called before insert if 0N/A * the loading is done in bursts. This is the only method called 0N/A * if loading the document entirely in one burst. 0N/A * @param data the new contents of the document 0N/A * Sets attributes for a paragraph. 0N/A * This method is thread safe, although most Swing methods 0N/A * are not. Please see 0N/A * to Use Threads</A> for more information. 0N/A * @param offset the offset into the paragraph (must be at least 0) 0N/A * @param length the number of characters affected (must be at least 0) 0N/A * @param s the attributes 0N/A * @param replace whether to replace existing attributes, or merge them 0N/A // Make sure we send out a change for the length of the paragraph. 0N/A * Fetches the <code>StyleSheet</code> with the document-specific display 0N/A * rules (CSS) that were specified in the HTML document itself. 0N/A * @return the <code>StyleSheet</code> 0N/A * Fetches an iterator for the specified HTML tag. 0N/A * This can be used for things like iterating over the 0N/A * set of anchors contained, or iterating over the input 0N/A * @param t the requested <code>HTML.Tag</code> 0N/A * @return the <code>Iterator</code> for the given HTML tag 0N/A * Creates a document leaf element that directly represents 0N/A * text (doesn't have any children). This is implemented 0N/A * to return an element of type 0N/A * <code>HTMLDocument.RunElement</code>. 0N/A * @param parent the parent element 0N/A * @param a the attributes for the element 0N/A * @param p0 the beginning of the range (must be at least 0) 0N/A * @param p1 the end of the range (must be at least p0) 0N/A * @return the new element 0N/A * Creates a document branch element, that can contain other elements. 0N/A * This is implemented to return an element of type 0N/A * <code>HTMLDocument.BlockElement</code>. 0N/A * @param parent the parent element 0N/A * @param a the attributes 0N/A * @return the element 0N/A * Creates the root element to be used to represent the 0N/A * default document structure. 0N/A * @return the element base 0N/A // grabs a write-lock for this initialization and 0N/A // abandon it during initialization so in normal 0N/A // operation we can detect an illegitimate attempt 0N/A // to mutate attributes. 0N/A * Sets the number of tokens to buffer before trying to update 0N/A * the documents element structure. 0N/A * @param n the number of tokens to buffer 0N/A * Gets the number of tokens to buffer before trying to update 0N/A * the documents element structure. The default value is 0N/A * <code>Integer.MAX_VALUE</code>. 0N/A * @return the number of tokens to buffer 0N/A * Determines how unknown tags are handled by the parser. 0N/A * If set to true, unknown 0N/A * tags are put in the model, otherwise they are dropped. 0N/A * @param preservesTags true if unknown tags should be 0N/A * saved in the model, otherwise tags are dropped 0N/A * Returns the behavior the parser observes when encountering 0N/A * @return true if unknown tags are to be preserved when parsing 0N/A * Processes <code>HyperlinkEvents</code> that 0N/A * are generated by documents in an HTML frame. 0N/A * The <code>HyperlinkEvent</code> type, as the parameter suggests, 0N/A * is <code>HTMLFrameHyperlinkEvent</code>. 0N/A * In addition to the typical information contained in a 0N/A * <code>HyperlinkEvent</code>, 0N/A * this event contains the element that corresponds to the frame in 0N/A * which the click happened (the source element) and the 0N/A * target name. The target name has 4 possible values: 0N/A * <li> a named frame 0N/A * If target is _self, the action is to change the value of the 0N/A * <code>HTML.Attribute.SRC</code> attribute and fires a 0N/A * <code>ChangedUpdate</code> event. 0N/A * If the target is _parent, then it deletes the parent element, 0N/A * which is a <FRAMESET> element, and inserts a new <FRAME> 0N/A * element, and sets its <code>HTML.Attribute.SRC</code> attribute 0N/A * to have a value equal to the destination URL and fire a 0N/A * <code>RemovedUpdate</code> and <code>InsertUpdate</code>. 0N/A * If the target is _top, this method does nothing. In the implementation 0N/A * of the view for a frame, namely the <code>FrameView</code>, 0N/A * the processing of _top is handled. Given that _top implies 0N/A * replacing the entire document, it made sense to handle this outside 0N/A * of the document that it will replace. 0N/A * If the target is a named frame, then the element hierarchy is searched 0N/A * for an element with a name equal to the target, its 0N/A * <code>HTML.Attribute.SRC</code> attribute is updated and a 0N/A * <code>ChangedUpdate</code> event is fired. 0N/A * @param e the event 0N/A The source and destination elements 0N/A The destination is the parent of the frame. 0N/A locate a named frame 0N/A * Searches the element hierarchy for an FRAME element 0N/A * that has its name attribute equal to the <code>frameName</code>. 0N/A * @return the element whose NAME attribute has a value of 0N/A * <code>frameName</code>; returns <code>null</code> 0N/A * Returns true if <code>StyleConstants.NameAttribute</code> is 0N/A * equal to the tag that is passed in as a parameter. 0N/A * @param attr the attributes to be matched 0N/A * @param tag the value to be matched 0N/A * @return true if there is a match, false otherwise 0N/A * Replaces a frameset branch Element with a frame leaf element. 0N/A * @param element the frameset element to remove 0N/A * @param url the value for the SRC attribute for the 0N/A * new frame that will replace the frameset 0N/A // Should handle this better 0N/A // Should handle this better 0N/A * Updates the Frame elements <code>HTML.Attribute.SRC attribute</code> 0N/A * and fires a <code>ChangedUpdate</code> event. 0N/A * @param element a FRAME element whose SRC attribute will be updated 0N/A * @param url a string specifying the new value for the SRC attribute 0N/A * Returns true if the document will be viewed in a frame. 0N/A * @return true if document will be viewed in a frame, otherwise false 0N/A * Sets a boolean state about whether the document will be 0N/A * viewed in a frame. 0N/A * @param frameDoc true if the document will be viewed in a frame, 0N/A * Adds the specified map, this will remove a Map that has been 0N/A * previously registered with the same name. 0N/A * @param map the <code>Map</code> to be registered 0N/A * Removes a previously registered map. 0N/A * @param map the <code>Map</code> to be removed 0N/A * Returns the Map associated with the given name. 611N/A * @param name the name of the desired <code>Map</code> 0N/A * @return the <code>Map</code> or <code>null</code> if it can't 0N/A * be found, or if <code>name</code> is <code>null</code> 0N/A * Returns an <code>Enumeration</code> of the possible Maps. 0N/A * @return the enumerated list of maps, or <code>null</code> 0N/A * if the maps are not an instance of <code>Hashtable</code> 0N/A * Sets the content type language used for style sheets that do not 0N/A * explicitly specify the type. The default is text/css. 0N/A * @param contentType the content type language for the style sheets 0N/A * Returns the content type language used for style sheets. The default 0N/A * @return the content type language used for the style sheets 0N/A * Sets the parser that is used by the methods that insert html 0N/A * into the existing document, such as <code>setInnerHTML</code>, 0N/A * and <code>setOuterHTML</code>. 0N/A * <code>HTMLEditorKit.createDefaultDocument</code> will set the parser 0N/A * for you. If you create an <code>HTMLDocument</code> by hand, 0N/A * be sure and set the parser accordingly. 0N/A * @param parser the parser to be used for text insertion 0N/A * Returns the parser that is used when inserting HTML into the existing 0N/A * @return the parser used for text insertion 0N/A * Replaces the children of the given element with the contents 0N/A * specified as an HTML string. 0N/A * <p>This will be seen as at least two events, n inserts followed by 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>setInnerHTML(elem, "<ul><li>")</code> 0N/A * results in the following structure (new elements are <font 0N/A * color="red">in red</font>).</p> 0N/A * <font color="red"><ul></font> 0N/A * <font color="red"><li></font> 0N/A * <p>Parameter <code>elem</code> must not be a leaf element, 0N/A * otherwise an <code>IllegalArgumentException</code> is thrown. 0N/A * If either <code>elem</code> or <code>htmlText</code> parameter 0N/A * is <code>null</code>, no changes are made to the document.</p> 0N/A * <p>For this to work correcty, the document must have an 0N/A * <code>HTMLEditorKit.Parser</code> set. This will be the case 0N/A * if the document was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the branch element whose children will be replaced 0N/A * @param htmlText the string to be parsed and assigned to <code>elem</code> 0N/A * @throws IllegalArgumentException if <code>elem</code> is a leaf 0N/A * @throws IllegalStateException if an <code>HTMLEditorKit.Parser</code> 0N/A * has not been defined 0N/A (
"Can not set inner HTML of a leaf");
0N/A // Elements were inserted, do the cleanup. 0N/A * Replaces the given element in the parent with the contents 0N/A * specified as an HTML string. 0N/A * <p>This will be seen as at least two events, n inserts followed by 0N/A * <p>When replacing a leaf this will attempt to make sure there is 0N/A * a newline present if one is needed. This may result in an additional 0N/A * element being inserted. Consider, if you were to replace a character 0N/A * element that contained a newline with <img> this would create 0N/A * two elements, one for the image, ane one for the newline.</p> 0N/A * <p>If you try to replace the element at length you will most 0N/A * likely end up with two elements, eg 0N/A * <code>setOuterHTML(getCharacterElement (getLength()), 0N/A * "blah")</code> will result in two leaf elements at the end, one 0N/A * representing 'blah', and the other representing the end 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>setOuterHTML(elem, "<ul><li>")</code> 0N/A * results in the following structure (new elements are <font 0N/A * color="red">in red</font>).</p> 0N/A * <font color="red"><ul></font> 0N/A * <font color="red"><li></font> 0N/A * <p>If either <code>elem</code> or <code>htmlText</code> 0N/A * parameter is <code>null</code>, no changes are made to the 0N/A * <p>For this to work correcty, the document must have an 0N/A * HTMLEditorKit.Parser set. This will be the case if the document 0N/A * was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the element to replace 0N/A * @param htmlText the string to be parsed and inserted in place of <code>elem</code> 0N/A * @throws IllegalStateException if an HTMLEditorKit.Parser has not 0N/A // We don't want a newline if elem is a leaf, and doesn't contain 0N/A * Inserts the HTML specified as a string at the start 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>insertAfterStart(elem, 0N/A * "<ul><li>")</code> results in the following structure 0N/A * (new elements are <font color="red">in red</font>).</p> 0N/A * <font color="red"><ul></font> <p> <p> 0N/A * <font color="red"><li></font> 0N/A * <p>Unlike the <code>insertBeforeStart</code> method, new 0N/A * elements become <em>children</em> of the specified element, 0N/A * <p>Parameter <code>elem</code> must not be a leaf element, 0N/A * otherwise an <code>IllegalArgumentException</code> is thrown. 0N/A * If either <code>elem</code> or <code>htmlText</code> parameter 0N/A * is <code>null</code>, no changes are made to the document.</p> 0N/A * <p>For this to work correcty, the document must have an 0N/A * <code>HTMLEditorKit.Parser</code> set. This will be the case 0N/A * if the document was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the branch element to be the root for the new text 0N/A * @param htmlText the string to be parsed and assigned to <code>elem</code> 0N/A * @throws IllegalArgumentException if <code>elem</code> is a leaf 0N/A * @throws IllegalStateException if an HTMLEditorKit.Parser has not 0N/A * been set on the document 0N/A (
"Can not insert HTML after start of a leaf");
0N/A * Inserts the HTML specified as a string at the end of 0N/A * <p> If <code>elem</code>'s children are leaves, and the 0N/A * character at a <code>elem.getEndOffset() - 1</code> is a newline, 0N/A * this will insert before the newline so that there isn't text after 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>insertBeforeEnd(elem, "<ul><li>")</code> 0N/A * results in the following structure (new elements are <font 0N/A * color="red">in red</font>).</p> 0N/A * <p> <p> <font color="red"><ul></font> 0N/A * <font color="red"><li></font> 0N/A * <p>Unlike the <code>insertAfterEnd</code> method, new elements 0N/A * become <em>children</em> of the specified element, not 0N/A * <p>Parameter <code>elem</code> must not be a leaf element, 0N/A * otherwise an <code>IllegalArgumentException</code> is thrown. 0N/A * If either <code>elem</code> or <code>htmlText</code> parameter 0N/A * is <code>null</code>, no changes are made to the document.</p> 0N/A * <p>For this to work correcty, the document must have an 0N/A * <code>HTMLEditorKit.Parser</code> set. This will be the case 0N/A * if the document was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the element to be the root for the new text 0N/A * @param htmlText the string to be parsed and assigned to <code>elem</code> 0N/A * @throws IllegalArgumentException if <code>elem</code> is a leaf 0N/A * @throws IllegalStateException if an HTMLEditorKit.Parser has not 0N/A * been set on the document 0N/A (
"Can not set inner HTML before end of leaf");
0N/A * Inserts the HTML specified as a string before the start of 0N/A * the given element. 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>insertBeforeStart(elem, 0N/A * "<ul><li>")</code> results in the following structure 0N/A * (new elements are <font color="red">in red</font>).</p> 0N/A * <font color="red"><ul></font> <b><div></b> 0N/A * <font color="red"><li></font> <p> <p> 0N/A * <p>Unlike the <code>insertAfterStart</code> method, new 0N/A * elements become <em>siblings</em> of the specified element, not 0N/A * <p>If either <code>elem</code> or <code>htmlText</code> 0N/A * parameter is <code>null</code>, no changes are made to the 0N/A * <p>For this to work correcty, the document must have an 0N/A * <code>HTMLEditorKit.Parser</code> set. This will be the case 0N/A * if the document was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the element the content is inserted before 0N/A * @param htmlText the string to be parsed and inserted before <code>elem</code> 0N/A * @throws IllegalStateException if an HTMLEditorKit.Parser has not 0N/A * been set on the document 0N/A * Inserts the HTML specified as a string after the the end of the 0N/A * <p>Consider the following structure (the <code>elem</code> 0N/A * parameter is <b>in bold</b>).</p> 0N/A * <p>Invoking <code>insertAfterEnd(elem, "<ul><li>")</code> 0N/A * results in the following structure (new elements are <font 0N/A * color="red">in red</font>).</p> 0N/A * <b><div></b> <font color="red"><ul></font> 0N/A * <p> <p> <font color="red"><li></font> 0N/A * <p>Unlike the <code>insertBeforeEnd</code> method, new elements 0N/A * become <em>siblings</em> of the specified element, not 0N/A * <p>If either <code>elem</code> or <code>htmlText</code> 0N/A * parameter is <code>null</code>, no changes are made to the 0N/A * <p>For this to work correcty, the document must have an 0N/A * <code>HTMLEditorKit.Parser</code> set. This will be the case 0N/A * if the document was created from an HTMLEditorKit via the 0N/A * <code>createDefaultDocument</code> method.</p> 0N/A * @param elem the element the content is inserted after 0N/A * @param htmlText the string to be parsed and inserted after <code>elem</code> 0N/A * @throws IllegalStateException if an HTMLEditorKit.Parser has not 0N/A * been set on the document 0N/A * Returns the element that has the given id <code>Attribute</code>. 0N/A * If the element can't be found, <code>null</code> is returned. 0N/A * Note that this method works on an <code>Attribute</code>, 0N/A * <i>not</i> a character tag. In the following HTML snippet: 0N/A * <code><a id="HelloThere"></code> the attribute is 0N/A * 'id' and the character tag is 'a'. 0N/A * This is a convenience method for 0N/A * <code>getElement(RootElement, HTML.Attribute.id, id)</code>. 0N/A * This is not thread-safe. 0N/A * @param id the string representing the desired <code>Attribute</code> 0N/A * @return the element with the specified <code>Attribute</code> 0N/A * or <code>null</code> if it can't be found, 0N/A * or <code>null</code> if <code>id</code> is <code>null</code> 0N/A * Returns the child element of <code>e</code> that contains the 0N/A * attribute, <code>attribute</code> with value <code>value</code>, or 0N/A * <code>null</code> if one isn't found. This is not thread-safe. 0N/A * @param e the root element where the search begins 0N/A * @param attribute the desired <code>Attribute</code> 0N/A * @param value the values for the specified <code>Attribute</code> 0N/A * @return the element with the specified <code>Attribute</code> 0N/A * and the specified <code>value</code>, or <code>null</code> 0N/A * if it can't be found 0N/A * Returns the child element of <code>e</code> that contains the 0N/A * attribute, <code>attribute</code> with value <code>value</code>, or 0N/A * <code>null</code> if one isn't found. This is not thread-safe. 0N/A * If <code>searchLeafAttributes</code> is true, and <code>e</code> is 0N/A * a leaf, any attributes that are instances of <code>HTML.Tag</code> 0N/A * with a value that is an <code>AttributeSet</code> will also be checked. 0N/A * @param e the root element where the search begins 0N/A * @param attribute the desired <code>Attribute</code> 0N/A * @param value the values for the specified <code>Attribute</code> 0N/A * @return the element with the specified <code>Attribute</code> 0N/A * and the specified <code>value</code>, or <code>null</code> 0N/A * if it can't be found 0N/A // For some leaf elements we store the actual attributes inside 0N/A // the AttributeSet of the Element (such as anchors). 0N/A * Verifies the document has an <code>HTMLEditorKit.Parser</code> set. 0N/A * If <code>getParser</code> returns <code>null</code>, this will throw an 0N/A * IllegalStateException. 0N/A * @throws IllegalStateException if the document does not have a Parser 0N/A * Installs a default Parser if one has not been installed yet. 0N/A * Inserts a string of HTML into the document at the given position. 0N/A * <code>parent</code> is used to identify the location to insert the 0N/A * <code>html</code>. If <code>parent</code> is a leaf this can have 0N/A * unexpected results. 0N/A // Found it, do the insert. 0N/A * Removes child Elements of the passed in Element <code>e</code>. This 0N/A * will do the necessary cleanup to ensure the element representing the 0N/A * end character is correctly created. 0N/A * <p>This is not a general purpose method, it assumes that <code>e</code> 0N/A * will still have at least one child after the remove, and it assumes 0N/A * the character at <code>e.getStartOffset() - 1</code> is a newline and 0N/A * Called to remove child elements of <code>e</code> when one of the 0N/A * elements to remove is representing the end character. 0N/A * <p>Since the Content will not allow a removal to the end character 0N/A * this will do a remove from <code>start - 1</code> to <code>end</code>. 0N/A * The end Element(s) will be removed, and the element representing 0N/A * <code>start - 1</code> to <code>start</code> will be recreated. This 0N/A * Element has to be recreated as after the content removal its offsets 0N/A * become <code>start - 1</code> to <code>start - 1</code>. 0N/A // index must be > 0 otherwise no insert would have happened. 0N/A // e.getElement(index - 1) should represent the newline. 0N/A // The hiearchies don't match, we'll have to manually 0N/A // recreate the leaf at e.getElement(index - 1) 0N/A // The hierarchies for the end Element and 0N/A // e.getElement(index - 1), match, we can safely remove 0N/A // the Elements and the end content will be aligned 0N/A // Not a leaf, descend until we find the leaf representing 0N/A // start - 1 and remove it. 0N/A * This is used by <code>removeElementsAtEnd</code>, it removes 0N/A * <code>count</code> elements starting at <code>start</code> from 0N/A * <code>e</code>. If <code>remove</code> is true text of length 0N/A * <code>start - 1</code> to <code>end - 1</code> is removed. If 0N/A * <code>create</code> is true a new leaf is created of length 1. 0N/A * Called to remove child Elements when the end is not touched. 0N/A // These two are provided for inner class access. The are named different 0N/A // than the super class as the super class implementations are final. 0N/A // Provided for inner class access. 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. The event instance 0N/A * is lazily created using the parameters passed into 0N/A * @param e the event 0N/A * @see EventListenerList 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. The event instance 0N/A * is lazily created using the parameters passed into 0N/A * @param e the event 0N/A * @see EventListenerList 0N/A * state defines whether the document is a frame document 0N/A * Used to store button groups for radio buttons in 0N/A * Document property for the number of tokens to buffer 0N/A * before building an element subtree to represent them. 0N/A * Document property key value. The value for the key will be a Vector 0N/A * of Strings that are comments not found in the body. 0N/A * Document property key value. The value for the key will be a 0N/A * String indicating the default type of stylesheet links. 0N/A * The location to resolve relative URLs against. By 0N/A * default this will be the document's URL if the document 0N/A * was loaded from a URL. If a base tag is found and 0N/A * can be parsed, it will be used as the base location. 0N/A * does the document have base tag 0N/A * BASE tag's TARGET attribute value 0N/A * The parser that is used when inserting html into the existing 0N/A * Used for inserts when a null AttributeSet is supplied. 0N/A * Property Maps are registered under, will be a Hashtable. 0N/A * I18N property key. 611N/A * @see AbstractDocument#I18NProperty 0N/A * An iterator to iterate over a particular type of 0N/A * tag. The iterator is not thread safe. If reliable 0N/A * access to the document is not already ensured by 0N/A * the context under which the iterator is being used, 0N/A * its use should be performed under the protection of 0N/A * Return the attributes for this tag. 0N/A * @return the <code>AttributeSet</code> for this tag, or 0N/A * <code>null</code> if none can be found 0N/A * Returns the start of the range for which the current occurrence of 0N/A * the tag is defined and has the same attributes. 0N/A * @return the start of the range, or -1 if it can't be found 0N/A * Returns the end of the range for which the current occurrence of 0N/A * the tag is defined and has the same attributes. 0N/A * @return the end of the range 0N/A * Move the iterator forward to the next occurrence 0N/A * of the tag it represents. 0N/A * Indicates if the iterator is currently 0N/A * representing an occurrence of a tag. If 0N/A * false there are no more tags for this iterator. 0N/A * @return true if the iterator is currently representing an 0N/A * occurrence of a tag, otherwise returns false 0N/A * Type of tag this iterator represents. 0N/A * An iterator to iterate over a particular type of tag. 0N/A * Returns the attributes for this tag. 0N/A * @return the <code>AttributeSet</code> for this tag, 0N/A * or <code>null</code> if none can be found 0N/A * Returns the start of the range for which the current occurrence of 0N/A * the tag is defined and has the same attributes. 0N/A * @return the start of the range, or -1 if it can't be found 0N/A * Returns the end of the range for which the current occurrence of 0N/A * the tag is defined and has the same attributes. 0N/A * @return the end of the range 0N/A * Moves the iterator forward to the next occurrence 0N/A * of the tag it represents. 0N/A // we found the next one 0N/A * Returns the type of tag this iterator represents. 0N/A * @return the <code>HTML.Tag</code> that this iterator represents. 0N/A * Returns true if the current position is not <code>null</code>. 0N/A * @return true if current position is not <code>null</code>, 0N/A * otherwise returns false 0N/A * Moves the given iterator to the next leaf element. 0N/A * @param iter the iterator to be scanned 0N/A * Marches a cloned iterator forward to locate the end 0N/A * of the run. This sets the value of <code>endOffset</code>. 0N/A * An HTML reader to load an HTML document with an HTML 0N/A * element structure. This is a set of callbacks from 0N/A * the parser, implemented to create a set of elements 0N/A * tagged with attributes. The parse builds up tokens 0N/A * (ElementSpec) that describe the element subtree desired, 0N/A * and burst it into the document under the protection of 0N/A * a write lock using the insert method on the document 0N/A * The reader can be configured by registering actions 0N/A * that describe how to handle the action. The idea behind 0N/A * the actions provided is that the most natural text editing 0N/A * operations can be provided if the element structure boils 0N/A * down to paragraphs with runs of some kind of style 0N/A * in them. Some things are more naturally specified 0N/A * structurally, so arbitrary structure should be allowed 0N/A * above the paragraphs, but will need to be edited with structural 0N/A * actions. The implication of this is that some of the 0N/A * HTML elements specified in the stream being parsed will 0N/A * be collapsed into attributes, and in some cases paragraphs 0N/A * will be synthesized. When HTML elements have been 0N/A * converted to attributes, the attribute key will be of 0N/A * type HTML.Tag, and the value will be of type AttributeSet 0N/A * so that no information is lost. This enables many of the 0N/A * existing actions to work so that the user can type input, 0N/A * hit the return key, backspace, delete, etc and have a 0N/A * reasonable result. Selections can be created, and attributes 0N/A * applied or removed, etc. With this in mind, the work done 0N/A * by the reader can be categorized into the following kinds 0N/A * <dd>Build the structure like it's specified in the stream. 0N/A * This produces elements that contain other elements. 0N/A * <dd>Like block except that it's expected that the element 0N/A * will be used with a paragraph view so a paragraph element 0N/A * won't need to be synthesized. 0N/A * <dd>Contribute the element as an attribute that will start 0N/A * and stop at arbitrary text locations. This will ultimately 0N/A * be mixed into a run of text, with all of the currently 0N/A * flattened HTML character elements. 0N/A * <dd>Produce an embedded graphical element. 0N/A * <dd>Produce an element that is like the embedded graphical 0N/A * element, except that it also has a component model associated 0N/A * <dd>Create an element that is hidden from view when the 0N/A * document is being viewed read-only, and visible when the 0N/A * document is being edited. This is useful to keep the 0N/A * model from losing information, and used to store things 0N/A * like comments and unrecognized tags. 0N/A * Currently, <APPLET>, <PARAM>, <MAP>, <AREA>, <LINK>, 0N/A * <SCRIPT> and <STYLE> are unsupported. 0N/A * The assignment of the actions described is shown in the 0N/A * following table for the tags defined in <code>HTML.Tag</code>.<P> 0N/A * <table border=1 summary="HTML tags and assigned actions"> 0N/A * <tr><th>Tag</th><th>Action</th></tr> 0N/A * <tr><td><code>HTML.Tag.A</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.ADDRESS</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.APPLET</code> <td>HiddenAction 0N/A * <tr><td><code>HTML.Tag.AREA</code> <td>AreaAction 0N/A * <tr><td><code>HTML.Tag.B</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.BASE</code> <td>BaseAction 0N/A * <tr><td><code>HTML.Tag.BASEFONT</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.BIG</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.BLOCKQUOTE</code><td>BlockAction 0N/A * <tr><td><code>HTML.Tag.BODY</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.BR</code> <td>SpecialAction 0N/A * <tr><td><code>HTML.Tag.CAPTION</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.CENTER</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.CITE</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.CODE</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.DD</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.DFN</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.DIR</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.DIV</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.DL</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.DT</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.EM</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.FONT</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.FORM</code> <td>As of 1.4 a BlockAction 0N/A * <tr><td><code>HTML.Tag.FRAME</code> <td>SpecialAction 0N/A * <tr><td><code>HTML.Tag.FRAMESET</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.H1</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.H2</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.H3</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.H4</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.H5</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.H6</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.HEAD</code> <td>HeadAction 0N/A * <tr><td><code>HTML.Tag.HR</code> <td>SpecialAction 0N/A * <tr><td><code>HTML.Tag.I</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.IMG</code> <td>SpecialAction 0N/A * <tr><td><code>HTML.Tag.INPUT</code> <td>FormAction 0N/A * <tr><td><code>HTML.Tag.ISINDEX</code> <td>IsndexAction 0N/A * <tr><td><code>HTML.Tag.KBD</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.LI</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.LINK</code> <td>LinkAction 0N/A * <tr><td><code>HTML.Tag.MAP</code> <td>MapAction 0N/A * <tr><td><code>HTML.Tag.MENU</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.META</code> <td>MetaAction 0N/A * <tr><td><code>HTML.Tag.NOFRAMES</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.OBJECT</code> <td>SpecialAction 0N/A * <tr><td><code>HTML.Tag.OL</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.OPTION</code> <td>FormAction 0N/A * <tr><td><code>HTML.Tag.P</code> <td>ParagraphAction 0N/A * <tr><td><code>HTML.Tag.PARAM</code> <td>HiddenAction 0N/A * <tr><td><code>HTML.Tag.PRE</code> <td>PreAction 0N/A * <tr><td><code>HTML.Tag.SAMP</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.SCRIPT</code> <td>HiddenAction 0N/A * <tr><td><code>HTML.Tag.SELECT</code> <td>FormAction 0N/A * <tr><td><code>HTML.Tag.SMALL</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.STRIKE</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.S</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.STRONG</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.STYLE</code> <td>StyleAction 0N/A * <tr><td><code>HTML.Tag.SUB</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.SUP</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.TABLE</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.TD</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.TEXTAREA</code> <td>FormAction 0N/A * <tr><td><code>HTML.Tag.TH</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.TITLE</code> <td>TitleAction 0N/A * <tr><td><code>HTML.Tag.TR</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.TT</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.U</code> <td>CharacterAction 0N/A * <tr><td><code>HTML.Tag.UL</code> <td>BlockAction 0N/A * <tr><td><code>HTML.Tag.VAR</code> <td>CharacterAction 0N/A * Once </html> is encountered, the Actions are no longer notified. 0N/A * Generates a RuntimeException (will eventually generate 0N/A * a BadLocationException when API changes are alloced) if inserting 0N/A * into non empty document, <code>insertTag</code> is 0N/A * non-<code>null</code>, and <code>offset</code> is not in the body. 0N/A // PENDING(sky): Add throws BadLocationException and remove 0N/A // register handlers for the well known tags 0N/A * This block initializes the <code>inParagraph</code> flag. 0N/A * It is left in <code>false</code> value automatically 0N/A * if the target document is empty or future inserts 0N/A * were positioned into the 'body' tag. 0N/A /* Going up by the left document structure path */ 0N/A /* Going down by the right document structure path */ 0N/A * Generates an initial batch of end <code>ElementSpecs</code> 0N/A * in parseBuffer to position future inserts into the body. 0N/A // Previous isn't in body, but current is. Have to 0N/A // do some end specs, followed by join next. 0N/A // Insert a newline, if necessary. 0N/A // Should never throw, but will catch anyway. 0N/A // We should probably throw an exception if (count == -1) 0N/A // Or look for the body and reset the offset. 0N/A * @return number of parents to reach the child at offset. 0N/A * @return number of parents of the leaf at <code>offset</code> 0N/A * until a parent with name, <code>name</code> has been 0N/A * found. -1 indicates no matching parent with 0N/A * <code>name</code>. 0N/A * This will make sure there aren't two BODYs (the second is 0N/A * typically created when you do a remove all, and then an insert). 0N/A // Remove the fake second body. 0N/A // Insert a new element to represent the end that the 0N/A // second body was representing. 0N/A // We now have two \n's, one part of the Document. 0N/A // We need to remove one 0N/A // Mark the edit as done. 0N/A // -- HTMLEditorKit.ParserCallback methods -------------------- 0N/A * The last method called on the reader. It allows 0N/A * any pending changes to be flushed into the document. 0N/A * Since this is currently loading synchronously, the entire 0N/A * set of changes are pushed in at this point. 0N/A // We won't insert when 0N/A * Called by the parser to indicate a block of text was 0N/A // see if complex glyph layout support is needed 0N/A // if a default direction of right-to-left has been specified, 0N/A // we want complex layout even if the text is all left to right. 0N/A // Assume content should be added. 0N/A * Callback from the parser. Route to the appropriate 0N/A * handler for the tag. 0N/A // Increment inBlock since we know we are in the body, 0N/A // this is needed incase an implied-p is needed. If 0N/A // inBlock isn't incremented, and an implied-p is 0N/A // encountered, addContent won't be called! 0N/A // Map the style attributes. 0N/A // Comment outside of body, will not be able to show it, 0N/A // but can add it as a property on the Document. 0N/A * Adds the comment <code>comment</code> to the set of comments 0N/A * maintained outside of the scope of elements. 0N/A // No place to put comment. 0N/A * Callback from the parser. Route to the appropriate 0N/A * handler for the tag. 0N/A * Callback from the parser. Route to the appropriate 0N/A * handler for the tag. 0N/A // Map the style attributes. 0N/A // unknown tag, only add if should preserve it. 0N/A * This is invoked after the stream has been parsed, but before 0N/A * <code>flush</code>. <code>eol</code> will be one of \n, \r 0N/A * or \r\n, which ever is encountered the most in parsing the 0N/A // ---- tag handling support ------------------------------ 0N/A * Registers a handler for the given tag. By default 0N/A * all of the well-known tags will have been registered. 0N/A * This can be used to change the handling of a particular 0N/A * tag or to add support for custom tags. 0N/A * An action to be performed in response 0N/A * to parsing a tag. This allows customization 0N/A * of how each tag is handled and avoids a large 0N/A * Called when a start tag is seen for the 0N/A * type of tag this action was registered 0N/A * to. The tag argument indicates the actual 0N/A * tag for those actions that are shared across 0N/A * many tags. By default this does nothing and 0N/A * completely ignores the tag. 0N/A * Called when an end tag is seen for the 0N/A * type of tag this action was registered 0N/A * to. The tag argument indicates the actual 0N/A * tag for those actions that are shared across 0N/A * many tags. By default this does nothing and 0N/A * completely ignores the tag. 0N/A * Action used for the actual element form tag. This is named such 0N/A * as there was already a public class named FormAction. 0N/A // initialize a ButtonGroupsMap when 0N/A // FORM tag is encountered. This will 0N/A // be used for any radio buttons that 0N/A // might be defined in the FORM. 0N/A // for new group new ButtonGroup will be created (fix for 4529702) 0N/A // group name is a key in radioButtonGroupsMap 0N/A // reset the button group to null since 0N/A // the form has ended. 0N/A * Subclass of HiddenAction to set the content type for style sheets, 0N/A * and to set the name of the default style sheet. 0N/A * End if overridden to create the necessary stylesheets that 0N/A * are referenced via the link tag. It is done in this manner 0N/A * as the meta tag can be used to specify an alternate style sheet, 0N/A * and is not guaranteed to come before the link tags. 0N/A // This check of the insertTag is put in to avoid considering 0N/A // the implied-p that is generated for the head. This allows 0N/A // inserts for HR to work correctly. 0N/A // See if there is a StyleSheet to link to. 0N/A // First element gives type. 0N/A // Select link if rel==stylesheet. 0N/A // Otherwise if rel==alternate stylesheet and 0N/A // title matches default style. 0N/A * A subclass to add the AttributeSet to styles if the 0N/A * attributes contains an attribute for 'rel' with value 0N/A * 'stylesheet' or 'alternate stylesheet'. 0N/A // set inPre to false after closing, so that if a newline 0N/A // is added it won't generate a blockOpen. 0N/A // Note that the third argument should really be based off 0N/A // inParagraph and impliedP. If we're wrong (that is 0N/A // insertTagDepthDelta shouldn't be changed), we'll end up 0N/A // removing an extra EndSpec, which won't matter anyway. 0N/A * mappings that have a corresponding StyleConstants 0N/A * and CSS mapping. The conversion is to CSS attributes. 0N/A // Note that the third argument should really be based off 0N/A // inParagraph and impliedP. If we're wrong (that is 0N/A // insertTagDepthDelta shouldn't be changed), we'll end up 0N/A // removing an extra EndSpec, which won't matter anyway. 0N/A // We also need to add attr, otherwise we lose custom 0N/A // attributes, including class/id for style lookups, and 0N/A // further confuse style lookup (doesn't have tag). 0N/A // set flag to catch empty anchors 0N/A // if the anchor was empty it was probably a 0N/A // named anchor point and we don't want to throw 0N/A * Action to support forms by building all of the elements 0N/A * used to represent form controls. This will process 0N/A * the <INPUT>, <TEXTAREA>, <SELECT>, 0N/A * and <OPTION> tags. The element created by 0N/A * this action is expected to have the attribute 0N/A * <code>StyleConstants.ModelAttribute</code> set to 0N/A * the model that holds the state for the form control. 0N/A * This enables multiple views, and allows document to 0N/A * be iterated over picking up the data of the form. 0N/A * The following are the model assignments for the 0N/A * various type of form elements. 0N/A * <table summary="model assignments for the various types of form elements"> 0N/A * <td>input, type button 0N/A * <td>{@link DefaultButtonModel} 0N/A * <td>input, type checkbox 0N/A * <td>{@link javax.swing.JToggleButton.ToggleButtonModel} 0N/A * <td>input, type image 0N/A * <td>{@link DefaultButtonModel} 0N/A * <td>input, type password 0N/A * <td>{@link PlainDocument} 0N/A * <td>input, type radio 0N/A * <td>{@link javax.swing.JToggleButton.ToggleButtonModel} 0N/A * <td>input, type reset 0N/A * <td>{@link DefaultButtonModel} 0N/A * <td>input, type submit 0N/A * <td>{@link DefaultButtonModel} 0N/A * <td>input, type text or type is null. 0N/A * <td>{@link PlainDocument} 0N/A * <td>{@link DefaultComboBoxModel} or an {@link DefaultListModel}, with an item type of Option 0N/A * <td>{@link PlainDocument} 0N/A * if type is not defined teh default is 0N/A * assumed to be text. 0N/A // build the element, unless this is an option. 0N/A /* Now that the textarea has ended, 0N/A * store the entire initial text 0N/A * of the text area. This will 0N/A * enable us to restore the initial 0N/A * state if a reset is requested. 0N/A * If a <SELECT> tag is being processed, this 0N/A * model will be a reference to the model being filled 0N/A * with the <OPTION> elements (which produce 0N/A * objects of type <code>Option</code>. 0N/A // --- utility methods used by the reader ------------------ 0N/A * Pushes the current character style on a stack in preparation 0N/A * for forming a new nested character style. 0N/A * Pops a previously pushed character style off the stack 0N/A * to return to a previous style. 0N/A * Adds the given content to the textarea document. 0N/A * This method gets called when we are in a textarea 0N/A * context. Therefore all text that is seen belongs 0N/A * to the text area and is hence added to the 0N/A * TextAreaDocument associated with the text area. 0N/A // Should do something reasonable 0N/A * Adds the given content that was encountered in a 0N/A * PRE element. This synthesizes lines to hold the 0N/A * runs of text, and makes calls to addContent to 0N/A * actually add the text. 0N/A * Adds an instruction to the parse buffer to create a 0N/A * block element with the given attributes. 0N/A * Adds an instruction to the parse buffer to close out 0N/A * a block element of the given type. 0N/A // Add a new line, if the last character wasn't one. This is 0N/A // needed for proper positioning of the cursor. addContent 0N/A // with true will force an implied paragraph to be generated if 0N/A // there isn't one. This may result in a rather bogus structure 0N/A // (perhaps a table with a child pargraph), but the paragraph 0N/A // is needed for proper positioning and display. 0N/A // add a space of content to keep the element being formed. 0N/A * Adds some text with the current character attributes. 0N/A * @param data the content to add 0N/A * @param offs the initial offset 0N/A * @param length the length 0N/A * Adds some text with the current character attributes. 0N/A * @param data the content to add 0N/A * @param offs the initial offset 0N/A * @param length the length 0N/A * @param generateImpliedPIfNecessary whether to generate implied 0N/A * Adds content that is basically specified entirely 0N/A * in the attribute set. 0N/A // Set this to avoid generating a newline for frames, frames 0N/A // shouldn't have any content, and shouldn't need a newline. 0N/A * Flushes the current parse buffer into the document. 0N/A * @param endOfStream true if there is no more content to parser 0N/A * This will be invoked for the last flush, if <code>insertTag</code> 0N/A // When inserting via an insertTag, the depths (of the tree 0N/A // being read in, and existing hiearchy) may not match up. 0N/A // This attemps to clean it up. 0N/A // If this starts with content (or popDepth > 0 && 0N/A // pushDepth > 0) and ends with EndTagTypes, make sure 0N/A // the last content isn't a \n, otherwise will end up with 0N/A // an extra \n in the middle of content. 0N/A // Make sure there is in fact a newline 0N/A * Adds the CSS rules in <code>rules</code>. 0N/A * Adds the CSS stylesheet at <code>href</code> to the known list 0N/A * Returns true if can insert starting at <code>t</code>. This 0N/A * will return false if the insert tag is set, and hasn't been found 0N/A * If insertTag == null then just proceed to 0N/A * foundInsertTag() call below and return true. 0N/A * Proceed to foundInsertTag() call... 0N/A // Allow the insert if t matches the insert tag, or 0N/A // insertAfterImplied is true and the element is implied. 0N/A // Need to insert a newline. 0N/A // Determine if we can use JoinPrevious, we can't 0N/A // if the Element has some attributes that are 0N/A // not meant to be duplicated. 0N/A // If not joining with the previous element, be 0N/A // sure and set the name (otherwise it will be 0N/A // A start spec will be added (for this tag), so we account 0N/A // An implied paragraph close (end spec) is going to be added, 0N/A // so we account for it here. 0N/A * This is set to true when and end is invoked for <html>. 0N/A /** Number of times <code>flushBuffer</code> has been invoked. */ 0N/A /** If true, behavior is similiar to insertTag, but instead of 0N/A * waiting for insertTag will wait for first Element without 0N/A * an 'implied' attribute and begin inserting then. */ 0N/A /** This is only used if insertAfterImplied is true. If false, only 0N/A * inserting content, and there is a trailing newline it is removed. */ 0N/A /** True if (!emptyDocument && insertTag == null), this is used so 0N/A * much it is cached. */ 0N/A /** True when the body has been encountered. */ 0N/A /** If non null, gives parent Tag that insert is to happen at. */ 0N/A /** If true, the insertTag is inserted, otherwise elements after 0N/A * the insertTag is found are inserted. */ 0N/A /** Set to true when insertTag has been found. */ 0N/A /** When foundInsertTag is set to true, this will be updated to 0N/A * reflect the delta between the two structures. That is, it 0N/A * will be the depth the inserts are happening at minus the 0N/A * depth of the tags being passed in. A value of 0 (the common 0N/A * case) indicates the structures match, a value greater than 0 indicates 0N/A * the insert is happening at a deeper depth than the stream is 0N/A * parsing, and a value less than 0 indicates the insert is happening earlier 0N/A * in the tree that the parser thinks and that we will need to remove 0N/A * EndTagType specs in the flushBuffer method. 0N/A /** How many parents to ascend before insert new elements. */ 0N/A /** How many parents to descend (relative to popDepth) before 0N/A /** Last Map that was encountered. */ 0N/A /** Set to true when a style element is encountered. */ 0N/A /** Name of style to use. Obtained from Meta tag. */ 0N/A /** Vector describing styles that should be include. Will consist 0N/A * of a bunch of HTML.Tags, which will either be: 0N/A * <p>LINK: in which case it is followed by an AttributeSet 0N/A * <p>STYLE: in which case the following element is a String 0N/A * indicating the type (may be null), and the elements following 0N/A * it until the next HTML.Tag are the rules as Strings. 0N/A /** True if inside the head tag. */ 0N/A /** Set to true if the style language is text/css. Since this is 0N/A * used alot, it is cached. */ 0N/A /** True if inserting into an empty document. */ 0N/A /** Attributes from a style Attribute. */ 0N/A * Current option, if in an option element (needed to 0N/A * This attribute is sometimes used to refer to next tag 0N/A * to be handled after p-implied when the latter is 0N/A * the current tag which is being handled. 0N/A * Used by StyleSheet to determine when to avoid removing HTML.Tags 0N/A * matching StyleConstants. 0N/A * An element that represents a chunk of text that has 0N/A * a set of HTML character level attributes assigned to 0N/A * Constructs an element that represents content within the 0N/A * document (has no children). 0N/A * @param parent the parent element 0N/A * @param a the element attributes 0N/A * @param offs0 the start offset (must be at least 0) 0N/A * @param offs1 the end offset (must be at least offs0) 0N/A * Gets the name of the element. 0N/A * @return the name, null if none 0N/A * Gets the resolving parent. HTML attributes are not inherited 0N/A * at the model level so we override this to return null. 0N/A * @return null, there are none 0N/A * @see AttributeSet#getResolveParent 0N/A * An element that represents a structural <em>block</em> of 0N/A * Constructs a composite element that initially contains 0N/A * @param parent the parent element 0N/A * @param a the attributes for the element 0N/A * Gets the name of the element. 0N/A * @return the name, null if none 0N/A * Gets the resolving parent. HTML attributes are not inherited 0N/A * at the model level so we override this to return null. 0N/A * @return null, there are none 0N/A * @see AttributeSet#getResolveParent 0N/A * Document that allows you to set the maximum length of the text.