summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-11 11:02:07 +0000
committerRoman Kennke <roman@kennke.org>2006-11-11 11:02:07 +0000
commitd6468560da4a79c4d09bbf7b62598ad2bf7d9b99 (patch)
tree21e62cde57cb8a6728c8a5f56da10deb1eb0847a /javax
parent5a7231e58f2b64cd18389479181b89e8da7e1bae (diff)
downloadclasspath-d6468560da4a79c4d09bbf7b62598ad2bf7d9b99.tar.gz
2006-11-11 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/css/CSSColor.java (isValidColor): New helper method. Checks strings if they form a valid color value. * gnu/javax/swing/text/html/css/Length.java (Length): Catch number format exceptions. * javax/swing/text/html/CSS.java (addInternal): New method. Checks for shorthand CSS attributes and parses them. (parseBackgroundShorthand): New method. Parses the background shorthand attribute. * javax/swing/text/html/HTMLDocument.java (HTMLReader.LinkAction): Made class a subclass of HiddenAction. (HTMLReader.LinkAction.start): Implemented to load the linked stylesheet. (HTMLReader.LinkAction.end): Removed. This is not needed. * javax/swing/text/html/StyleSheet.java (CSSStyleSheetParserCallback.declaration): Push declaration through CSS.addInternal() to parse shorthand attributes. (addCSSAttribute): Push declaration through CSS.addInternal() to parse shorthand attributes. (importStyleSheet): Implemented. This adds a stylesheet from an URL. * javax/swing/text/html/TableView.java (calculateColumnRequirements): Increase column index for non CellView children to avoid endless loop. * javax/swing/text/CompositeView.java (setParent): Comparen with numChildren not with real arraylength.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/text/CompositeView.java2
-rw-r--r--javax/swing/text/html/CSS.java22
-rw-r--r--javax/swing/text/html/HTMLDocument.java69
-rw-r--r--javax/swing/text/html/StyleSheet.java24
-rw-r--r--javax/swing/text/html/TableView.java2
5 files changed, 103 insertions, 16 deletions
diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java
index ab587a9e1..d4467f314 100644
--- a/javax/swing/text/CompositeView.java
+++ b/javax/swing/text/CompositeView.java
@@ -134,7 +134,7 @@ public abstract class CompositeView
public void setParent(View parent)
{
super.setParent(parent);
- if (parent != null && ((children == null) || children.length == 0))
+ if (parent != null && numChildren == 0)
loadChildren(getViewFactory());
}
diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java
index a91394d4d..6461dca9a 100644
--- a/javax/swing/text/html/CSS.java
+++ b/javax/swing/text/html/CSS.java
@@ -46,6 +46,9 @@ import gnu.javax.swing.text.html.css.Length;
import java.io.Serializable;
import java.util.HashMap;
+import java.util.StringTokenizer;
+
+import javax.swing.text.MutableAttributeSet;
/**
* Provides CSS attributes to be used by the HTML view classes. The constants
@@ -524,4 +527,23 @@ public class CSS implements Serializable
o = v;
return o;
}
+
+ static void addInternal(MutableAttributeSet atts, Attribute a, String v)
+ {
+ if (a == Attribute.BACKGROUND)
+ parseBackgroundShorthand(atts, v);
+ }
+
+ private static void parseBackgroundShorthand(MutableAttributeSet atts,
+ String v)
+ {
+ StringTokenizer tokens = new StringTokenizer(v, " ");
+ while (tokens.hasMoreElements())
+ {
+ String token = tokens.nextToken();
+ if (CSSColor.isValidColor(token))
+ atts.addAttribute(Attribute.BACKGROUND_COLOR,
+ getValue(Attribute.BACKGROUND_COLOR, token));
+ }
+ }
}
diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java
index 93397f2e5..418607309 100644
--- a/javax/swing/text/html/HTMLDocument.java
+++ b/javax/swing/text/html/HTMLDocument.java
@@ -42,6 +42,7 @@ import gnu.classpath.NotImplementedException;
import java.io.IOException;
import java.io.StringReader;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -992,27 +993,71 @@ public class HTMLDocument extends DefaultStyledDocument
}
}
- class LinkAction extends TagAction
+ class LinkAction extends HiddenAction
{
/**
* This method is called when a start tag is seen for one of the types
* of tags associated with this Action.
*/
public void start(HTML.Tag t, MutableAttributeSet a)
- throws NotImplementedException
{
- // FIXME: Implement.
+ super.start(t, a);
+ String type = (String) a.getAttribute(HTML.Attribute.TYPE);
+ if (type == null)
+ type = "text/css";
+ if (type.equals("text/css"))
+ {
+ String rel = (String) a.getAttribute(HTML.Attribute.REL);
+ String media = (String) a.getAttribute(HTML.Attribute.MEDIA);
+ String title = (String) a.getAttribute(HTML.Attribute.TITLE);
+ if (media == null)
+ media = "all";
+ else
+ media = media.toLowerCase();
+ if (rel != null)
+ {
+ rel = rel.toLowerCase();
+ if ((media.indexOf("all") != -1
+ || media.indexOf("screen") != -1)
+ && (rel.equals("stylesheet")))
+ {
+ String href = (String) a.getAttribute(HTML.Attribute.HREF);
+ URL url = null;
+ try
+ {
+ url = new URL(baseURL, href);
+ }
+ catch (MalformedURLException ex)
+ {
+ try
+ {
+ url = new URL(href);
+ }
+ catch (MalformedURLException ex2)
+ {
+ url = null;
+ }
+ }
+ if (url != null)
+ {
+ try
+ {
+ getStyleSheet().importStyleSheet(url);
+ }
+ catch (Exception ex)
+ {
+ // Don't let exceptions and runtime exceptions
+ // in CSS parsing disprupt the HTML parsing
+ // process. But inform the user/developer
+ // on the console about it.
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
}
- /**
- * Called when an end tag is seen for one of the types of tags associated
- * with this Action.
- */
- public void end(HTML.Tag t)
- throws NotImplementedException
- {
- // FIXME: Implement.
- }
}
class MapAction extends TagAction
diff --git a/javax/swing/text/html/StyleSheet.java b/javax/swing/text/html/StyleSheet.java
index 9f626e3f9..450682f68 100644
--- a/javax/swing/text/html/StyleSheet.java
+++ b/javax/swing/text/html/StyleSheet.java
@@ -50,7 +50,10 @@ import gnu.javax.swing.text.html.css.Selector;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
@@ -154,6 +157,7 @@ public class StyleSheet extends StyleContext
{
CSS.Attribute cssAtt = CSS.getAttribute(property);
Object val = CSS.getValue(cssAtt, value);
+ CSS.addInternal(style, cssAtt, value);
if (cssAtt != null)
style.addAttribute(cssAtt, val);
}
@@ -596,13 +600,26 @@ public class StyleSheet extends StyleContext
/**
* Imports a style sheet from the url. The rules are directly added to the
- * receiver.
+ * receiver. This is usually called when a <link> tag is resolved in an
+ * HTML document.
*
- * @param url - the URL to import the StyleSheet from.
+ * @param url the URL to import the StyleSheet from
*/
public void importStyleSheet(URL url)
{
- // FIXME: Not implemented
+ try
+ {
+ InputStream in = url.openStream();
+ Reader r = new BufferedReader(new InputStreamReader(in));
+ CSSStyleSheetParserCallback cb =
+ new CSSStyleSheetParserCallback(CSSStyle.PREC_AUTHOR_NORMAL);
+ CSSParser parser = new CSSParser(r, cb);
+ parser.parse();
+ }
+ catch (IOException ex)
+ {
+ // We can't do anything about it I guess.
+ }
}
/**
@@ -638,6 +655,7 @@ public class StyleSheet extends StyleContext
String value)
{
Object val = CSS.getValue(key, value);
+ CSS.addInternal(attr, key, value);
attr.addAttribute(key, val);
}
diff --git a/javax/swing/text/html/TableView.java b/javax/swing/text/html/TableView.java
index ba959b589..2bd11ffcf 100644
--- a/javax/swing/text/html/TableView.java
+++ b/javax/swing/text/html/TableView.java
@@ -467,6 +467,8 @@ class TableView
}
c += colSpan;
}
+ else
+ c++;
}
// Update the total requirements as follows: