diff options
author | Roman Kennke <roman@kennke.org> | 2006-11-03 11:24:05 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-11-03 11:24:05 +0000 |
commit | 5944b30c24f002b0ebdb66106110dede2cb4ed36 (patch) | |
tree | ef80bcf97a5fc41b6713c7ab841cad4a738b0e2d /javax/swing/text | |
parent | 4c09f7d17324679eeff2a7aa7ccf4d5c6a3e8761 (diff) | |
download | classpath-5944b30c24f002b0ebdb66106110dede2cb4ed36.tar.gz |
2006-11-03 Roman Kennke <kennke@aicas.com>
* javax/swing/text/html/StyleSheet.java
(addRule): Implemented.
* javax/swing/text/html/HTMLDocument.java
(HTMLReader.inStyleTag): New field.
(HTMLReader.styles): New field.
(HTMLReader.HeadAction.end): Implemented to read all stylesheets,
if any.
(HTMLReader.StyleAction.start): Set inStyleTag flag.
(HTMLReader.StyleAction.end): Set inStyleTag flag.
(HTMLReader.handleText): When inside a style tag, add
content to the styles array.
Diffstat (limited to 'javax/swing/text')
-rw-r--r-- | javax/swing/text/html/HTMLDocument.java | 46 | ||||
-rw-r--r-- | javax/swing/text/html/StyleSheet.java | 21 |
2 files changed, 53 insertions, 14 deletions
diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java index 2ff0fd097..b2342944f 100644 --- a/javax/swing/text/html/HTMLDocument.java +++ b/javax/swing/text/html/HTMLDocument.java @@ -44,6 +44,7 @@ import gnu.javax.swing.text.html.parser.htmlAttributeSet; import java.io.IOException; import java.io.StringReader; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; import java.util.Stack; import java.util.Vector; @@ -568,6 +569,21 @@ public class HTMLDocument extends DefaultStyledDocument */ boolean inPreTag = false; + /** + * This is true when we are inside a style tag. This will add text + * content inside this style tag beeing parsed as CSS. + * + * This is package private to avoid accessor methods. + */ + boolean inStyleTag = false; + + /** + * This contains all stylesheets that are somehow read, either + * via embedded style tags, or via linked stylesheets. The + * elements will be String objects containing a stylesheet each. + */ + ArrayList styles; + void print (String line) { if (debug) @@ -932,9 +948,17 @@ public class HTMLDocument extends DefaultStyledDocument public void end(HTML.Tag t) throws NotImplementedException { - // FIXME: Implement. - print ("HeadAction.end not implemented: "+t); - super.end(t); + // We read in all the stylesheets that are embedded or referenced + // inside the header. + if (styles != null) + { + int numStyles = styles.size(); + for (int i = 0; i < numStyles; i++) + { + String style = (String) styles.get(i); + getStyleSheet().addRule(style); + } + } } } @@ -1012,7 +1036,7 @@ public class HTMLDocument extends DefaultStyledDocument print ("MetaAction.end not implemented"); } } - + class StyleAction extends TagAction { /** @@ -1020,10 +1044,8 @@ public class HTMLDocument extends DefaultStyledDocument * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) - throws NotImplementedException { - // FIXME: Implement. - print ("StyleAction.start not implemented"); + inStyleTag = true; } /** @@ -1031,10 +1053,8 @@ public class HTMLDocument extends DefaultStyledDocument * with this Action. */ public void end(HTML.Tag t) - throws NotImplementedException { - // FIXME: Implement. - print ("StyleAction.end not implemented"); + inStyleTag = false; } } @@ -1240,6 +1260,12 @@ public class HTMLDocument extends DefaultStyledDocument { if (inPreTag) preContent(data); + else if (inStyleTag) + { + if (styles == null) + styles = new ArrayList(); + styles.add(new String(data)); + } else addContent(data, 0, data.length); diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java index c21fc064a..562203e75 100644 --- a/javax/swing/text/html/StyleSheet.java +++ b/javax/swing/text/html/StyleSheet.java @@ -38,7 +38,6 @@ exception statement from your version. */ package javax.swing.text.html; -import gnu.classpath.NotImplementedException; import gnu.javax.swing.text.html.css.CSSColor; import gnu.javax.swing.text.html.css.CSSParser; import gnu.javax.swing.text.html.css.CSSParserCallback; @@ -53,6 +52,7 @@ import java.awt.Graphics; import java.io.IOException; import java.io.Reader; import java.io.Serializable; +import java.io.StringReader; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; @@ -94,8 +94,10 @@ public class StyleSheet extends StyleContext /** * Parses CSS stylesheets using the parser in gnu/javax/swing/html/css. + * + * This is package private to avoid accessor methods. */ - private class CSSStyleSheetParserCallback + class CSSStyleSheetParserCallback implements CSSParserCallback { /** @@ -405,9 +407,20 @@ public class StyleSheet extends StyleContext * @param rule - the rule to add to the sheet */ public void addRule(String rule) - throws NotImplementedException { - // FIXME: Implement. + CSSStyleSheetParserCallback cb = new CSSStyleSheetParserCallback(); + // FIXME: Handle ref. + StringReader in = new StringReader(rule); + CSSParser parser = new CSSParser(in, cb); + try + { + parser.parse(); + } + catch (IOException ex) + { + // Shouldn't happen. And if, then we + assert false; + } } /** |