38 |
|
|
39 |
package javax.swing.text.html; |
package javax.swing.text.html; |
40 |
|
|
41 |
|
import java.net.URL; |
42 |
|
|
43 |
|
import javax.swing.text.AbstractDocument; |
44 |
import javax.swing.text.AttributeSet; |
import javax.swing.text.AttributeSet; |
45 |
import javax.swing.text.DefaultStyledDocument; |
import javax.swing.text.DefaultStyledDocument; |
46 |
|
import javax.swing.text.Element; |
47 |
import javax.swing.text.ElementIterator; |
import javax.swing.text.ElementIterator; |
48 |
|
import javax.swing.text.AbstractDocument.BranchElement; |
49 |
import javax.swing.text.html.HTML.Tag; |
import javax.swing.text.html.HTML.Tag; |
50 |
|
|
51 |
/** |
/** |
55 |
*/ |
*/ |
56 |
public class HTMLDocument extends DefaultStyledDocument |
public class HTMLDocument extends DefaultStyledDocument |
57 |
{ |
{ |
58 |
|
URL baseURL = null; |
59 |
|
boolean preservesUnknownTags = true; |
60 |
|
|
61 |
|
/** |
62 |
|
* Returns the location against which to resolve relative URLs. |
63 |
|
* This is the document's URL if the document was loaded from a URL. |
64 |
|
* If a <code>base</code> tag is found, it will be used. |
65 |
|
* @return the base URL |
66 |
|
*/ |
67 |
|
public URL getBase() |
68 |
|
{ |
69 |
|
return baseURL; |
70 |
|
} |
71 |
|
|
72 |
|
/** |
73 |
|
* Sets the location against which to resolve relative URLs. |
74 |
|
* @param u the new base URL |
75 |
|
*/ |
76 |
|
public void setBase(URL u) |
77 |
|
{ |
78 |
|
baseURL = u; |
79 |
|
//TODO: also set the base of the StyleSheet |
80 |
|
} |
81 |
|
|
82 |
|
/** |
83 |
|
* Returns whether or not the parser preserves unknown HTML tags. |
84 |
|
* @return true if the parser preserves unknown tags |
85 |
|
*/ |
86 |
|
public boolean getPreservesUnknownTags() |
87 |
|
{ |
88 |
|
return preservesUnknownTags; |
89 |
|
} |
90 |
|
|
91 |
|
/** |
92 |
|
* Sets the behaviour of the parser when it encounters unknown HTML tags. |
93 |
|
* @param preservesTags true if the parser should preserve unknown tags. |
94 |
|
*/ |
95 |
|
public void setPreservesUnknownTags(boolean preservesTags) |
96 |
|
{ |
97 |
|
preservesUnknownTags = preservesTags; |
98 |
|
} |
99 |
|
|
100 |
/** |
/** |
101 |
* An iterator to iterate through LeafElements in the document. |
* An iterator to iterate through LeafElements in the document. |
102 |
*/ |
*/ |
238 |
*/ |
*/ |
239 |
public abstract HTML.Tag getTag(); |
public abstract HTML.Tag getTag(); |
240 |
} |
} |
241 |
|
|
242 |
|
public class BlockElement extends AbstractDocument.BranchElement |
243 |
|
{ |
244 |
|
public BlockElement (Element parent, AttributeSet a) |
245 |
|
{ |
246 |
|
super (parent, a); |
247 |
|
} |
248 |
|
|
249 |
|
/** |
250 |
|
* Gets the resolving parent. Since HTML attributes are not |
251 |
|
* inherited at the model level, this returns null. |
252 |
|
*/ |
253 |
|
public AttributeSet getResolveParent() |
254 |
|
{ |
255 |
|
return null; |
256 |
|
} |
257 |
|
|
258 |
|
public String getName() |
259 |
|
{ |
260 |
|
//FIXME: this is supposed to do something different from the super class |
261 |
|
return super.getName(); |
262 |
|
} |
263 |
|
} |
264 |
} |
} |