Imported GNU Classpath 0.19 + gcj-import-20051115.
[official-gcc.git] / libjava / classpath / javax / swing / text / html / HTMLDocument.java
blobd048a04e614ba15182ad08d83293d9836c9b25dc
1 /* HTMLDocument.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.text.html;
41 import java.net.URL;
43 import javax.swing.text.AbstractDocument;
44 import javax.swing.text.AttributeSet;
45 import javax.swing.text.DefaultStyledDocument;
46 import javax.swing.text.Element;
47 import javax.swing.text.ElementIterator;
48 import javax.swing.text.html.HTML.Tag;
50 /**
51 * TODO: This class is not yet completetely implemented.
53 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
55 public class HTMLDocument extends DefaultStyledDocument
57 /** A key for document properies. The value for the key is
58 * a Vector of Strings of comments not found in the body.
59 */
60 public static final String AdditionalComments = "AdditionalComments";
61 URL baseURL = null;
62 boolean preservesUnknownTags = true;
64 /**
65 * Returns the location against which to resolve relative URLs.
66 * This is the document's URL if the document was loaded from a URL.
67 * If a <code>base</code> tag is found, it will be used.
68 * @return the base URL
70 public URL getBase()
72 return baseURL;
75 /**
76 * Sets the location against which to resolve relative URLs.
77 * @param u the new base URL
79 public void setBase(URL u)
81 baseURL = u;
82 //TODO: also set the base of the StyleSheet
85 /**
86 * Returns whether or not the parser preserves unknown HTML tags.
87 * @return true if the parser preserves unknown tags
89 public boolean getPreservesUnknownTags()
91 return preservesUnknownTags;
94 /**
95 * Sets the behaviour of the parser when it encounters unknown HTML tags.
96 * @param preservesTags true if the parser should preserve unknown tags.
98 public void setPreservesUnknownTags(boolean preservesTags)
100 preservesUnknownTags = preservesTags;
104 * An iterator to iterate through LeafElements in the document.
106 class LeafIterator extends Iterator
108 HTML.Tag tag;
109 HTMLDocument doc;
110 ElementIterator it;
112 public LeafIterator (HTML.Tag t, HTMLDocument d)
114 doc = d;
115 tag = t;
116 it = new ElementIterator(doc);
120 * Return the attributes for the tag associated with this iteartor
121 * @return the AttributeSet
123 public AttributeSet getAttributes()
125 if (it.current() != null)
126 return it.current().getAttributes();
127 return null;
131 * Get the end of the range for the current occurrence of the tag
132 * being defined and having the same attributes.
133 * @return the end of the range
135 public int getEndOffset()
137 if (it.current() != null)
138 return it.current().getEndOffset();
139 return -1;
143 * Get the start of the range for the current occurrence of the tag
144 * being defined and having the same attributes.
145 * @return the start of the range (-1 if it can't be found).
148 public int getStartOffset()
150 if (it.current() != null)
151 return it.current().getStartOffset();
152 return -1;
156 * Advance the iterator to the next LeafElement .
158 public void next()
160 it.next();
161 while (it.current()!= null && !it.current().isLeaf())
162 it.next();
166 * Indicates whether or not the iterator currently represents an occurrence
167 * of the tag.
168 * @return true if the iterator currently represents an occurrence of the
169 * tag.
171 public boolean isValid()
173 return it.current() != null;
177 * Type of tag for this iterator.
179 public Tag getTag()
181 return tag;
186 public void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent event)
188 // TODO: Implement this properly.
192 * Gets an iterator for the given HTML.Tag.
193 * @param t the requested HTML.Tag
194 * @return the Iterator
196 public HTMLDocument.Iterator getIterator (HTML.Tag t)
198 return new HTMLDocument.LeafIterator(t, this);
202 * An iterator over a particular type of tag.
204 public abstract static class Iterator
207 * Return the attribute set for this tag.
208 * @return the <code>AttributeSet</code> (null if none found).
210 public abstract AttributeSet getAttributes();
213 * Get the end of the range for the current occurrence of the tag
214 * being defined and having the same attributes.
215 * @return the end of the range
217 public abstract int getEndOffset();
220 * Get the start of the range for the current occurrence of the tag
221 * being defined and having the same attributes.
222 * @return the start of the range (-1 if it can't be found).
224 public abstract int getStartOffset();
227 * Move the iterator forward.
229 public abstract void next();
232 * Indicates whether or not the iterator currently represents an occurrence
233 * of the tag.
234 * @return true if the iterator currently represents an occurrence of the
235 * tag.
237 public abstract boolean isValid();
240 * Type of tag this iterator represents.
241 * @return the tag.
243 public abstract HTML.Tag getTag();
246 public class BlockElement extends AbstractDocument.BranchElement
248 public BlockElement (Element parent, AttributeSet a)
250 super (parent, a);
254 * Gets the resolving parent. Since HTML attributes are not
255 * inherited at the model level, this returns null.
257 public AttributeSet getResolveParent()
259 return null;
262 public String getName()
264 //FIXME: this is supposed to do something different from the super class
265 return super.getName();