harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [5/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/swing: make/ src/main/java/common/javax/swing/ src/main/java/common/javax/swing/text/ src/main/java/common/javax/swing/text/html/ src/main/java/common/javax/swing/text/h...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameTagView.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameTagView.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameTagView.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FrameTagView.java
Mon Jul 31 07:08:47 2006
@@ -0,0 +1,151 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Vadim L. Bogdanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.Component;
+import java.awt.Insets;
+import java.awt.Shape;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.swing.JEditorPane;
+import javax.swing.JScrollPane;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.border.Border;
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.ComponentView;
+import javax.swing.text.Element;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.ViewFactory;
+
+
+class FrameTagView extends ComponentView {
+    private JEditorPane editorPane;
+    private JScrollPane scrollPane;
+    private Border scrollPaneBorder;
+
+    public FrameTagView(final Element elem) {
+        super(elem);
+    }
+
+    protected Component createComponent() {
+        editorPane = new JEditorPane();
+        scrollPane = new JScrollPane(editorPane);
+
+        loadContent(editorPane);
+        updateAttributes();
+
+        return scrollPane;
+    }
+
+    public void changedUpdate(final DocumentEvent e, final Shape s,
+                              final ViewFactory f) {
+        super.changedUpdate(e, s, f);
+
+        updateAttributes();
+    }
+
+    private void updateAttributes() {
+        if (scrollPane == null) {
+            return;
+        }
+
+        installBorder();
+        installMargin();
+        installScrollBarPolicy();
+
+        editorPane.setEditable(((JTextComponent)getContainer()).isEditable());
+    }
+
+    private void installBorder() {
+        if (getFrameBorderAttr()) {
+            if (scrollPane.getBorder() == null && scrollPaneBorder != null) {
+                scrollPane.setBorder(scrollPaneBorder);
+            }
+        } else {
+            scrollPaneBorder = scrollPane.getBorder();
+            scrollPane.setBorder(null);
+        }
+    }
+
+    private void installMargin() {
+        int marginWidth = getMarginWidthAttr();
+        int marginHeight = getMarginHeightAttr();
+        editorPane.setMargin(new Insets(marginHeight, marginWidth,
+                                        marginHeight, marginWidth));
+    }
+
+    private void installScrollBarPolicy() {
+        String scrolling = getScrollingAttr();
+        if ("yes".equals(scrolling)) {
+            scrollPane.setHorizontalScrollBarPolicy(
+                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
+            scrollPane.setVerticalScrollBarPolicy(
+                    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
+        } else if ("no".equals(scrolling)) {
+            scrollPane.setHorizontalScrollBarPolicy(
+                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+            scrollPane.setVerticalScrollBarPolicy(
+                    ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        }
+    }
+
+    private void loadContent(final JEditorPane pane) {
+        try {
+            pane.setPage(getSourceURL());
+        } catch (final IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private URL getSourceURL() {
+        try {
+            return new URL(((HTMLDocument)getDocument()).getBase(), getSrcAttr());
+        } catch (final MalformedURLException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private String getSrcAttr() {
+        return getAttributes().getAttribute(HTML.Attribute.SRC).toString();
+    }
+
+    private String getScrollingAttr() {
+        Object value = getAttributes().getAttribute(HTML.Attribute.SCROLLING);
+        return value == null ? "auto" : value.toString();
+    }
+
+    private boolean getFrameBorderAttr() {
+        Object value = getAttributes().getAttribute(HTML.Attribute.FRAMEBORDER);
+        return !"0".equals(value);
+    }
+
+    private int getMarginWidthAttr() {
+        Object value = getAttributes().getAttribute(HTML.Attribute.MARGINWIDTH);
+        return value == null ? 2 : ((Integer)value).intValue();
+    }
+
+    private int getMarginHeightAttr() {
+        Object value = getAttributes().getAttribute(HTML.Attribute.MARGINHEIGHT);
+        return value == null ? 0 : ((Integer)value).intValue();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HRuleTagView.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HRuleTagView.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HRuleTagView.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HRuleTagView.java
Mon Jul 31 07:08:47 2006
@@ -0,0 +1,162 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Vadim L. Bogdanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.BoxView;
+import javax.swing.text.Element;
+import javax.swing.text.Position;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.Position.Bias;
+
+import org.apache.harmony.awt.text.TextUtils;
+
+class HRuleTagView extends View {
+    private static final int INSET = 3;
+    private static final int MINIMUM_SIZE = 2;
+    private static final Color SHADOW = Color.BLACK;
+    private static final Color LIGHT_SHADOW = Color.LIGHT_GRAY;
+
+    private AttributeSet attrs;
+
+    HRuleTagView(final Element elem) {
+        super(elem);
+    }
+
+    public float getPreferredSpan(final int axis) {
+        if (axis == Y_AXIS) {
+            return getSizeAttr() + 2 * INSET;
+        } else {
+            return Integer.MAX_VALUE;
+        }
+    }
+
+    public void paint(final Graphics g, final Shape allocation) {
+        Rectangle r = allocation.getBounds();
+        int totalWidth = r.width;
+        r.grow(0, -INSET);
+        r.width = getWidthAttr();
+        calculatePosition(r, totalWidth);
+
+        if (getNoshadeAttr()) {
+            g.setColor(SHADOW);
+            g.fillRect(r.x, r.y, r.width, r.height);
+        } else {
+            g.setColor(SHADOW);
+            g.drawLine(r.x, r.y, r.x + r.width, r.y);
+            int size = getSizeAttr() - 1;
+            g.drawLine(r.x, r.y, r.x, r.y + size);
+            g.setColor(LIGHT_SHADOW);
+            g.drawLine(r.x + 1, r.y + size, r.x + r.width, r.y + size);
+            g.drawLine(r.x + r.width, r.y + 1, r.x + r.width, r.y + size);
+        }
+    }
+
+    public int viewToModel(final float x, final float y,
+                           final Shape shape, final Bias[] biasReturn) {
+        final Rectangle bounds = shape.getBounds();
+        if (x > bounds.width / 2 + bounds.x - 1) {
+            biasReturn[0] = Position.Bias.Backward;
+            return getEndOffset();
+        }
+        biasReturn[0] = Position.Bias.Forward;
+        return getStartOffset();
+    }
+
+    public Shape modelToView(final int pos, final Shape shape,
+                             final Bias bias) throws BadLocationException {
+        return TextUtils.modelToIconOrComponentView(this, pos, shape, bias);
+    }
+
+    public int getBreakWeight(final int axis, final float pos, final float len) {
+        return ForcedBreakWeight;
+    }
+
+    public int getResizeWeight(final int axis) {
+        return axis == X_AXIS ? 1 : 0;
+    }
+
+    public AttributeSet getAttributes() {
+        if (attrs == null) {
+            attrs = ((HTMLDocument)getDocument()).getStyleSheet()
+                .getViewAttributes(this);
+        }
+        return attrs;
+    }
+
+    public void changedUpdate(final DocumentEvent event,
+                              final Shape shape,
+                              final ViewFactory factory) {
+        attrs = ((HTMLDocument)getDocument()).getStyleSheet()
+            .getViewAttributes(this);
+        super.changedUpdate(event, shape, factory);
+    }
+
+    private int getSizeAttr() {
+        Object value = getElement().getAttributes()
+            .getAttribute(HTML.Attribute.SIZE);
+
+        if (value != null) {
+            int size = Integer.parseInt((String)value);
+            if (size > MINIMUM_SIZE) {
+                return size;
+            }
+        }
+        return MINIMUM_SIZE;
+    }
+
+    private boolean getNoshadeAttr() {
+        Object value = getElement().getAttributes()
+            .getAttribute(HTML.Attribute.NOSHADE);
+        return value != null;
+    }
+
+    private int getWidthAttr() {
+        Object value = getAttributes().getAttribute(CSS.Attribute.WIDTH);
+        return value != null
+            ? ((CSS.FloatValue)value).intValue(this)
+            : ((BoxView)getParent().getParent()).getWidth();
+    }
+
+    private int getAlignAttr() {
+        Object value = getAttributes().getAttribute(StyleConstants.Alignment);
+        return value != null
+            ? ((Integer)value).intValue()
+            : StyleConstants.ALIGN_CENTER;
+    }
+
+    private void calculatePosition(final Rectangle r, final int totalWidth) {
+        int align = getAlignAttr();
+        if (align == StyleConstants.ALIGN_CENTER) {
+            r.x += (totalWidth - r.width) / 2;
+        } else if (align == StyleConstants.ALIGN_RIGHT) {
+            r.x += totalWidth - r.width;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
Mon Jul 31 07:08:47 2006
@@ -0,0 +1,590 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+*/
+package javax.swing.text.html;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.StyleContext;
+
+import org.apache.harmony.x.swing.Utilities;
+
+/**
+ * Attributes and Tags of this class are defined by HTML 4.01 specification,
+ * see <a href="http://www.w3.org/TR/html401/">HTML 4.01 Specification</a>.
+ */
+public class HTML {
+
+    public static final class Attribute {
+        public static final Attribute ACTION = new Attribute("action");
+        public static final Attribute ALIGN = new Attribute("align");
+        public static final Attribute ALINK = new Attribute("alink");
+        public static final Attribute ALT = new Attribute("alt");
+        public static final Attribute ARCHIVE = new Attribute("archive");
+        public static final Attribute BACKGROUND = new Attribute("background");
+        public static final Attribute BGCOLOR = new Attribute("bgcolor");
+        public static final Attribute BORDER = new Attribute("border");
+        public static final Attribute CELLPADDING =
+                                            new Attribute("cellpadding");
+        public static final Attribute CELLSPACING =
+                                            new Attribute("cellspacing");
+        public static final Attribute CHECKED = new Attribute("checked");
+        public static final Attribute CLASS = new Attribute("class");
+        public static final Attribute CLASSID = new Attribute("classid");
+        public static final Attribute CLEAR = new Attribute("clear");
+        public static final Attribute CODE = new Attribute("code");
+        public static final Attribute CODEBASE = new Attribute("codebase");
+        public static final Attribute CODETYPE = new Attribute("codetype");
+        public static final Attribute COLOR = new Attribute("color");
+        public static final Attribute COLS = new Attribute("cols");
+        public static final Attribute COLSPAN = new Attribute("colspan");
+        public static final Attribute COMMENT = new Attribute("comment");
+        public static final Attribute COMPACT = new Attribute("compact");
+        public static final Attribute CONTENT = new Attribute("content");
+        public static final Attribute COORDS = new Attribute("coords");
+        public static final Attribute DATA = new Attribute("data");
+        public static final Attribute DECLARE = new Attribute("declare");
+        public static final Attribute DIR = new Attribute("dir");
+        public static final Attribute DUMMY = new Attribute("dummy");
+        public static final Attribute ENCTYPE = new Attribute("enctype");
+        public static final Attribute ENDTAG = new Attribute("endtag");
+        public static final Attribute FACE = new Attribute("face");
+        public static final Attribute FRAMEBORDER =
+                                            new Attribute("frameborder");
+        public static final Attribute HALIGN = new Attribute("halign");
+        public static final Attribute HEIGHT = new Attribute("height");
+        public static final Attribute HREF = new Attribute("href");
+        public static final Attribute HSPACE = new Attribute("hspace");
+        public static final Attribute HTTPEQUIV = new Attribute("http-equiv");
+        public static final Attribute ID = new Attribute("id");
+        public static final Attribute ISMAP = new Attribute("ismap");
+        public static final Attribute LANG = new Attribute("lang");
+        public static final Attribute LANGUAGE = new Attribute("language");
+        public static final Attribute LINK = new Attribute("link");
+        public static final Attribute LOWSRC = new Attribute("lowsrc");
+        public static final Attribute MARGINHEIGHT =
+                                            new Attribute("marginheight");
+        public static final Attribute MARGINWIDTH =
+                                            new Attribute("marginwidth");
+        public static final Attribute MAXLENGTH = new Attribute("maxlength");
+        public static final Attribute METHOD = new Attribute("method");
+        public static final Attribute MULTIPLE = new Attribute("multiple");
+        public static final Attribute N = new Attribute("n");
+        public static final Attribute NAME = new Attribute("name");
+        public static final Attribute NOHREF = new Attribute("nohref");
+        public static final Attribute NORESIZE = new Attribute("noresize");
+        public static final Attribute NOSHADE = new Attribute("noshade");
+        public static final Attribute NOWRAP = new Attribute("nowrap");
+        public static final Attribute PROMPT = new Attribute("prompt");
+        public static final Attribute REL = new Attribute("rel");
+        public static final Attribute REV = new Attribute("rev");
+        public static final Attribute ROWS = new Attribute("rows");
+        public static final Attribute ROWSPAN = new Attribute("rowspan");
+        public static final Attribute SCROLLING = new Attribute("scrolling");
+        public static final Attribute SELECTED = new Attribute("selected");
+        public static final Attribute SHAPE = new Attribute("shape");
+        public static final Attribute SHAPES = new Attribute("shapes");
+        public static final Attribute SIZE = new Attribute("size");
+        public static final Attribute SRC = new Attribute("src");
+        public static final Attribute STANDBY = new Attribute("standby");
+        public static final Attribute START = new Attribute("start");
+        public static final Attribute STYLE = new Attribute("style");
+        public static final Attribute TARGET = new Attribute("target");
+        public static final Attribute TEXT = new Attribute("text");
+        public static final Attribute TITLE = new Attribute("title");
+        public static final Attribute TYPE = new Attribute("type");
+        public static final Attribute USEMAP = new Attribute("usemap");
+        public static final Attribute VALIGN = new Attribute("valign");
+        public static final Attribute VALUE = new Attribute("value");
+        public static final Attribute VALUETYPE = new Attribute("valuetype");
+        public static final Attribute VERSION = new Attribute("version");
+        public static final Attribute VLINK = new Attribute("vlink");
+        public static final Attribute VSPACE = new Attribute("vspace");
+        public static final Attribute WIDTH = new Attribute("width");
+
+        static final Attribute ACCESSKEY = new Attribute("accesskey");
+        static final Attribute DISABLED = new Attribute("disabled");
+        static final Attribute LABEL = new Attribute("label");
+        static final Attribute READONLY = new Attribute("readonly");
+
+        static final String IMPLIED_NEW_LINE = "CR";
+
+        private final String id;
+
+        private Attribute(final String id) {
+            this.id = id;
+        }
+
+        public String toString() {
+            return id;
+        }
+    }
+
+    public static class Tag {
+        public static final Tag A = new Tag("a", false, false);
+        public static final Tag ADDRESS = new Tag("address", false, false);
+        public static final Tag APPLET = new Tag("applet", false, false);
+        public static final Tag AREA = new Tag("area", false, false);
+        public static final Tag B = new Tag("b", false, false);
+        public static final Tag BASE = new Tag("base", false, false);
+        public static final Tag BASEFONT = new Tag("basefont", false, false);
+        public static final Tag BIG = new Tag("big", false, false);
+        public static final Tag BLOCKQUOTE = new Tag("blockquote", true, true);
+        public static final Tag BODY = new Tag("body", true, true);
+        public static final Tag BR = new Tag("br", true, false);
+        public static final Tag CAPTION = new Tag("caption", false, false);
+        public static final Tag CENTER = new Tag("center", true, false);
+        public static final Tag CITE = new Tag("cite", false, false);
+        public static final Tag CODE = new Tag("code", false, false);
+        public static final Tag COMMENT = new Tag("comment", false, false);
+        public static final Tag CONTENT = new Tag("content", false, false);
+        public static final Tag DD = new Tag("dd", true, true);
+        public static final Tag DFN = new Tag("dfn", false, false);
+        public static final Tag DIR = new Tag("dir", true, true);
+        public static final Tag DIV = new Tag("div", true, true);
+        public static final Tag DL = new Tag("dl", true, true);
+        public static final Tag DT = new Tag("dt", true, true);
+        public static final Tag EM = new Tag("em", false, false);
+        public static final Tag FONT = new Tag("font", false, false);
+        public static final Tag FORM = new Tag("form", true, false);
+        public static final Tag FRAME = new Tag("frame", false, false);
+        public static final Tag FRAMESET = new Tag("frameset", false, false);
+        public static final Tag H1 = new Tag("h1", true, true);
+        public static final Tag H2 = new Tag("h2", true, true);
+        public static final Tag H3 = new Tag("h3", true, true);
+        public static final Tag H4 = new Tag("h4", true, true);
+        public static final Tag H5 = new Tag("h5", true, true);
+        public static final Tag H6 = new Tag("h6", true, true);
+        public static final Tag HEAD = new Tag("head", true, true);
+        public static final Tag HR = new Tag("hr", true, false);
+        public static final Tag HTML = new Tag("html", true, false);
+        public static final Tag I = new Tag("i", false, false);
+        public static final Tag IMG = new Tag("img", false, false);
+        public static final Tag IMPLIED = new Tag("p-implied", false, false);
+        public static final Tag INPUT = new Tag("input", false, false);
+        public static final Tag ISINDEX = new Tag("isindex", true, false);
+        public static final Tag KBD = new Tag("kbd", false, false);
+        public static final Tag LI = new Tag("li", true, true);
+        public static final Tag LINK = new Tag("link", false, false);
+        public static final Tag MAP = new Tag("map", false, false);
+        public static final Tag MENU = new Tag("menu", true, true);
+        public static final Tag META = new Tag("meta", false, false);
+        public static final Tag NOFRAMES = new Tag("noframes", true, true);
+        public static final Tag OBJECT = new Tag("object", false, false);
+        public static final Tag OL = new Tag("ol", true, true);
+        public static final Tag OPTION = new Tag("option", false, false);
+        public static final Tag P = new Tag("p", true, true);
+        public static final Tag PARAM = new Tag("param", false, false);
+        public static final Tag PRE = new Tag("pre", true, true);
+        public static final Tag S = new Tag("s", false, false);
+        public static final Tag SAMP = new Tag("samp", false, false);
+        public static final Tag SCRIPT = new Tag("script", false, false);
+        public static final Tag SELECT = new Tag("select", false, false);
+        public static final Tag SMALL = new Tag("small", false, false);
+        public static final Tag SPAN = new Tag("span", false, false);
+        public static final Tag STRIKE = new Tag("strike", false, false);
+        public static final Tag STRONG = new Tag("strong", false, false);
+        public static final Tag STYLE = new Tag("style", false, false);
+        public static final Tag SUB = new Tag("sub", false, false);
+        public static final Tag SUP = new Tag("sup", false, false);
+        public static final Tag TABLE = new Tag("table", false, true);
+        public static final Tag TD = new Tag("td", true, true);
+        public static final Tag TEXTAREA = new Tag("textarea", false, false);
+        public static final Tag TH = new Tag("th", true, true);
+        public static final Tag TITLE = new Tag("title", true, true);
+        public static final Tag TR = new Tag("tr", false, true);
+        public static final Tag TT = new Tag("tt", false, false);
+        public static final Tag U = new Tag("u", false, false);
+        public static final Tag UL = new Tag("ul", true, true);
+        public static final Tag VAR = new Tag("var", false, false);
+
+        static final Tag ABBR = new Tag("abbr", false, false);
+        static final Tag ACRONYM = new Tag("acronym", false, false);
+        static final Tag BDO = new Tag("bdo", false, false);
+        static final Tag BUTTON = new Tag("button", false, false);
+        static final Tag COL = new Tag("col", false, false);
+        static final Tag COLGROUP = new Tag("colgroup", false, false);
+        static final Tag DEL = new Tag("del", false, false);
+        static final Tag FIELDSET = new Tag("fieldset", false, false);
+        static final Tag IFRAME = new Tag("iframe", true, true);
+        static final Tag INS = new Tag("ins", false, false);
+        static final Tag LABEL = new Tag("label", false, false);
+        static final Tag LEGEND = new Tag("legend", false, false);
+        static final Tag NOSCRIPT = new Tag("noscript", true, true);
+        static final Tag OPTGROUP = new Tag("optgroup", false, false);
+        static final Tag Q = new Tag("q", false, false);
+        static final Tag TBODY = new Tag("tbody", true, true);
+        static final Tag TFOOT = new Tag("tfoot", true, true);
+        static final Tag THEAD = new Tag("thead", true, true);
+
+        String id;
+        boolean causesBreak;
+        boolean isBlock;
+
+        public Tag() {
+            this(null, false, false);
+        }
+
+        protected Tag(final String id) {
+            this(id, false, false);
+        }
+
+        protected Tag(final String id, final boolean causesBreak,
+                      final boolean isBlock) {
+            this.id = id;
+            this.causesBreak = causesBreak;
+            this.isBlock = isBlock;
+        }
+
+        public boolean breaksFlow() {
+            return causesBreak;
+        }
+
+        public boolean isBlock() {
+            return isBlock;
+        }
+
+        public boolean isPreformatted() {
+            return this == PRE || this == TEXTAREA;
+        }
+
+        public String toString() {
+            return id;
+        }
+    }
+
+    public static class UnknownTag extends Tag implements Serializable {
+        public UnknownTag(final String id) {
+            super(id);
+        }
+
+        public boolean equals(final Object obj) {
+            return obj instanceof UnknownTag
+                   && toString().equals(obj.toString());
+        }
+
+        public int hashCode() {
+            return toString().hashCode();
+        }
+
+        private void writeObject(final ObjectOutputStream out)
+            throws IOException {
+
+            out.defaultWriteObject();
+            out.writeObject(toString());
+            out.writeBoolean(breaksFlow());
+            out.writeBoolean(isBlock());
+        }
+
+        private void readObject(final ObjectInputStream in)
+            throws IOException, ClassNotFoundException {
+
+            in.defaultReadObject();
+            id = (String)in.readObject();
+            causesBreak = in.readBoolean();
+            isBlock = in.readBoolean();
+        }
+    }
+
+    public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
+
+    private static final Map attrMap = new HashMap();
+    private static final Map tagMap = new HashMap();
+
+    private static final Attribute[] attrs = {
+        Attribute.ACTION,
+        Attribute.ALIGN,
+        Attribute.ALINK,
+        Attribute.ALT,
+        Attribute.ARCHIVE,
+        Attribute.BACKGROUND,
+        Attribute.BGCOLOR,
+        Attribute.BORDER,
+        Attribute.CELLPADDING,
+        Attribute.CELLSPACING,
+        Attribute.CHECKED,
+        Attribute.CLASS,
+        Attribute.CLASSID,
+        Attribute.CLEAR,
+        Attribute.CODE,
+        Attribute.CODEBASE,
+        Attribute.CODETYPE,
+        Attribute.COLOR,
+        Attribute.COLS,
+        Attribute.COLSPAN,
+        Attribute.COMMENT,
+        Attribute.COMPACT,
+        Attribute.CONTENT,
+        Attribute.COORDS,
+        Attribute.DATA,
+        Attribute.DECLARE,
+        Attribute.DIR,
+        Attribute.DUMMY,
+        Attribute.ENCTYPE,
+        Attribute.ENDTAG,
+        Attribute.FACE,
+        Attribute.FRAMEBORDER,
+        Attribute.HALIGN,
+        Attribute.HEIGHT,
+        Attribute.HREF,
+        Attribute.HSPACE,
+        Attribute.HTTPEQUIV,
+        Attribute.ID,
+        Attribute.ISMAP,
+        Attribute.LANG,
+        Attribute.LANGUAGE,
+        Attribute.LINK,
+        Attribute.LOWSRC,
+        Attribute.MARGINHEIGHT,
+        Attribute.MARGINWIDTH,
+        Attribute.MAXLENGTH,
+        Attribute.METHOD,
+        Attribute.MULTIPLE,
+        Attribute.N,
+        Attribute.NAME,
+        Attribute.NOHREF,
+        Attribute.NORESIZE,
+        Attribute.NOSHADE,
+        Attribute.NOWRAP,
+        Attribute.PROMPT,
+        Attribute.REL,
+        Attribute.REV,
+        Attribute.ROWS,
+        Attribute.ROWSPAN,
+        Attribute.SCROLLING,
+        Attribute.SELECTED,
+        Attribute.SHAPE,
+        Attribute.SHAPES,
+        Attribute.SIZE,
+        Attribute.SRC,
+        Attribute.STANDBY,
+        Attribute.START,
+        Attribute.STYLE,
+        Attribute.TARGET,
+        Attribute.TEXT,
+        Attribute.TITLE,
+        Attribute.TYPE,
+        Attribute.USEMAP,
+        Attribute.VALIGN,
+        Attribute.VALUE,
+        Attribute.VALUETYPE,
+        Attribute.VERSION,
+        Attribute.VLINK,
+        Attribute.VSPACE,
+        Attribute.WIDTH,
+
+        // HTML 4.01-specific attributes
+        Attribute.ACCESSKEY,
+        Attribute.DISABLED,
+        Attribute.LABEL,
+        Attribute.READONLY
+    };
+
+    private static final Tag[] tags = {
+        Tag.A,
+        Tag.ADDRESS,
+        Tag.APPLET,
+        Tag.AREA,
+        Tag.B,
+        Tag.BASE,
+        Tag.BASEFONT,
+        Tag.BIG,
+        Tag.BLOCKQUOTE,
+        Tag.BODY,
+        Tag.BR,
+        Tag.CAPTION,
+        Tag.CENTER,
+        Tag.CITE,
+        Tag.CODE,
+        //Tag.COMMENT,
+        //Tag.CONTENT,
+        Tag.DD,
+        Tag.DFN,
+        Tag.DIR,
+        Tag.DIV,
+        Tag.DL,
+        Tag.DT,
+        Tag.EM,
+        Tag.FONT,
+        Tag.FORM,
+        Tag.FRAME,
+        Tag.FRAMESET,
+        Tag.H1,
+        Tag.H2,
+        Tag.H3,
+        Tag.H4,
+        Tag.H5,
+        Tag.H6,
+        Tag.HEAD,
+        Tag.HR,
+        Tag.HTML,
+        Tag.I,
+        Tag.IMG,
+        //Tag.IMPLIED,
+        Tag.INPUT,
+        Tag.ISINDEX,
+        Tag.KBD,
+        Tag.LI,
+        Tag.LINK,
+        Tag.MAP,
+        Tag.MENU,
+        Tag.META,
+        Tag.NOFRAMES,
+        Tag.OBJECT,
+        Tag.OL,
+        Tag.OPTION,
+        Tag.P,
+        Tag.PARAM,
+        Tag.PRE,
+        Tag.S,
+        Tag.SAMP,
+        Tag.SCRIPT,
+        Tag.SELECT,
+        Tag.SMALL,
+        Tag.SPAN,
+        Tag.STRIKE,
+        Tag.STRONG,
+        Tag.STYLE,
+        Tag.SUB,
+        Tag.SUP,
+        Tag.TABLE,
+        Tag.TD,
+        Tag.TEXTAREA,
+        Tag.TH,
+        Tag.TITLE,
+        Tag.TR,
+        Tag.TT,
+        Tag.U,
+        Tag.UL,
+        Tag.VAR,
+        // HTML 4.01-specific tags
+        Tag.ABBR,
+        Tag.ACRONYM,
+        Tag.BDO,
+        Tag.BUTTON,
+        Tag.COL,
+        Tag.COLGROUP,
+        Tag.DEL,
+        Tag.FIELDSET,
+        Tag.IFRAME,
+        Tag.INS,
+        Tag.LABEL,
+        Tag.LEGEND,
+        Tag.NOSCRIPT,
+        Tag.OPTGROUP,
+        Tag.Q,
+        Tag.TBODY,
+        Tag.TFOOT,
+        Tag.THEAD
+    };
+
+    static {
+        for (int i = 0; i < attrs.length; i++) {
+            attrMap.put(attrs[i].toString(), attrs[i]);
+            StyleContext.registerStaticAttributeKey(attrs[i]);
+        }
+
+        for (int i = 0; i < tags.length; i++) {
+            tagMap.put(tags[i].toString(), tags[i]);
+            StyleContext.registerStaticAttributeKey(tags[i]);
+        }
+    }
+
+    public HTML() {
+    }
+
+    public static Tag[] getAllTags() {
+        return tags;
+    }
+
+    public static Tag getTag(final String tagName) {
+        return (Tag)tagMap.get(tagName);
+    }
+
+    public static Attribute[] getAllAttributeKeys() {
+        return attrs;
+    }
+
+    public static Attribute getAttributeKey(final String attrName) {
+        return (Attribute)attrMap.get(attrName);
+    }
+
+    public static int getIntegerAttributeValue(final AttributeSet attr,
+                                               final Attribute key,
+                                               final int def) {
+        final Object value = attr.getAttribute(key);
+        if (value != null) {
+            try {
+                return Integer.parseInt((String)value);
+            } catch (NumberFormatException e) {
+                return def;
+            }
+        }
+        return def;
+    }
+
+    static URL resolveURL(final URL url, final URL base) {
+        if (url == null) {
+            return null;
+        }
+        return resolveURL(url.toString(), base != null ? base.toString() : null);
+    }
+
+    static URL resolveURL(final String url, final URL base) {
+        if (Utilities.isEmptyString(url)) {
+            return null;
+        }
+        return resolveURL(url, base != null ? base.toString() : null);
+    }
+
+    static URL resolveURL(final String url, final String base) {
+        if (Utilities.isEmptyString(url)) {
+            return null;
+        }
+
+        URI uri = null;
+        if (base != null) {
+            try {
+                uri = new URI(base).resolve(url);
+            } catch (URISyntaxException e) { }
+        }
+
+        URL result = null;
+        try {
+            if (uri != null) {
+                result = uri.toURL();
+            } else {
+                result = new URL(url);
+            }
+        } catch (final MalformedURLException e) { }
+
+        return result;
+    }
+}
+



Mime
View raw message