1 /*******************************************************************************
\r
2 * Copyright (c) 2006 Sybase, Inc. and others.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Sybase, Inc. - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.eclipse.jst.pagedesigner.css2.property;
\r
14 import org.eclipse.jst.pagedesigner.IHTMLConstants;
\r
15 import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
\r
16 import org.eclipse.jst.pagedesigner.utils.DOMUtil;
\r
17 import org.w3c.dom.Element;
\r
18 import org.w3c.dom.Node;
\r
23 public class BorderStyleMeta extends CSSPropertyMeta {
\r
24 static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NONE,
\r
25 ICSSPropertyID.VAL_HIDDEN, ICSSPropertyID.VAL_DOTTED,
\r
26 ICSSPropertyID.VAL_DASHED, ICSSPropertyID.VAL_SOLID,
\r
27 ICSSPropertyID.VAL_DOUBLE, ICSSPropertyID.VAL_GROOVE,
\r
28 ICSSPropertyID.VAL_RIDGE, ICSSPropertyID.VAL_INSET,
\r
29 ICSSPropertyID.VAL_OUTSET };
\r
33 public BorderStyleMeta() {
\r
34 super(false, ICSSPropertyID.VAL_NONE);
\r
40 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
\r
42 protected String[] getKeywordValues() {
\r
49 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element,
\r
50 * java.lang.String, java.lang.String,
\r
51 * org.eclipse.jst.pagedesigner.css2.ICSSStyle)
\r
53 public Object calculateHTMLAttributeOverride(Element element,
\r
54 String htmltag, String propertyName, ICSSStyle style) {
\r
55 if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(htmltag)) {
\r
56 return calculateTableOverride(element, propertyName);
\r
57 } else if (IHTMLConstants.TAG_TD.equalsIgnoreCase(htmltag)
\r
58 || IHTMLConstants.TAG_TH.equalsIgnoreCase(htmltag)) {
\r
59 return calculateTDOverride(element, propertyName, style);
\r
60 } else if (IHTMLConstants.TAG_IMG.equalsIgnoreCase(htmltag)) {
\r
61 String border = DOMUtil.getAttributeIgnoreCase(element,
\r
62 IHTMLConstants.ATTR_BORDER);
\r
63 if (border != null) {
\r
64 return ICSSPropertyID.VAL_SOLID;
\r
67 return super.calculateHTMLAttributeOverride(element, htmltag,
\r
68 propertyName, style);
\r
73 * @param propertyName
\r
76 private Object calculateTDOverride(Element element, String propertyName,
\r
78 // if element is empty, and "empty-cells" property is hide, then we
\r
79 // don't display border.
\r
80 Object obj = style.getStyleProperty(ICSSPropertyID.ATTR_EMPTY_CELLS);
\r
81 if (EmptyCellsMeta.HIDE.equals(obj) && TableUtil.isEmptyCell(element)) {
\r
82 return ICSSPropertyID.VAL_NONE;
\r
85 // find containing table first
\r
86 Node parent = element;
\r
87 Element tableEle = null;
\r
88 while ((parent = parent.getParentNode()) != null
\r
89 && parent instanceof Element) {
\r
90 if (((Element) parent).getTagName().equalsIgnoreCase(
\r
91 IHTMLConstants.TAG_TABLE)) {
\r
92 tableEle = (Element) parent;
\r
97 if (tableEle != null) {
\r
98 String rules = DOMUtil.getAttributeIgnoreCase(tableEle,
\r
99 IHTMLConstants.ATTR_RULES);
\r
100 String borderstr = DOMUtil.getAttributeIgnoreCase(tableEle,
\r
101 IHTMLConstants.ATTR_BORDER);
\r
102 if (rules == null || rules.length() == 0) {
\r
103 if (borderstr == null || "0".equals(borderstr.trim())) { //$NON-NLS-1$
\r
104 return ICSSPropertyID.VAL_NONE;
\r
106 return ICSSPropertyID.VAL_TDBORDERSTYLE;
\r
108 // ok, we got a value for rules
\r
109 if (TableUtil.matchRules(extractEdge(propertyName), rules)) {
\r
110 return ICSSPropertyID.VAL_TDBORDERSTYLE;
\r
112 return ICSSPropertyID.VAL_NONE;
\r
119 * @param propertyName
\r
122 private Object calculateTableOverride(Element element, String propertyName) {
\r
123 String frame = DOMUtil.getAttributeIgnoreCase(element,
\r
124 IHTMLConstants.ATTR_FRAME);
\r
125 String borderstr = DOMUtil.getAttributeIgnoreCase(element,
\r
126 IHTMLConstants.ATTR_BORDER);
\r
127 // border="0" implies frame="void"
\r
128 if ("0".equals(borderstr)) { //$NON-NLS-1$
\r
129 return ICSSPropertyID.VAL_NONE;
\r
131 if (frame == null || frame.length() == 0) {
\r
132 if (borderstr == null) {
\r
133 return ICSSPropertyID.VAL_NONE;
\r
134 } else if (borderstr.trim().length() == 0) {
\r
135 frame = IHTMLConstants.ATTR_BORDER;
\r
138 Integer.parseInt(borderstr);
\r
139 frame = IHTMLConstants.ATTR_BORDER;
\r
140 } catch (Exception ex) {
\r
145 // ok, we got a value for frame.
\r
146 if (TableUtil.matchFrame(extractEdge(propertyName), frame)) {
\r
147 return ICSSPropertyID.VAL_OUTSET;
\r
149 return ICSSPropertyID.VAL_NONE;
\r
152 static String extractEdge(String propertyName) {
\r
153 if (ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE
\r
154 .equalsIgnoreCase(propertyName)) {
\r
155 return "bottom"; //$NON-NLS-1$
\r
156 } else if (ICSSPropertyID.ATTR_BORDER_LEFT_STYLE
\r
157 .equalsIgnoreCase(propertyName)) {
\r
158 return "left"; //$NON-NLS-1$
\r
159 } else if (ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE
\r
160 .equalsIgnoreCase(propertyName)) {
\r
161 return "right"; //$NON-NLS-1$
\r
163 return "top"; //$NON-NLS-1$
\r
168 * @param propertyName
\r
169 * @return true if property name is a border style
\r
171 public static boolean isBorderStyle(String propertyName) {
\r
172 return ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE
\r
173 .equalsIgnoreCase(propertyName)
\r
174 || ICSSPropertyID.ATTR_BORDER_LEFT_STYLE
\r
175 .equalsIgnoreCase(propertyName)
\r
176 || ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE
\r
177 .equalsIgnoreCase(propertyName)
\r
178 || ICSSPropertyID.ATTR_BORDER_TOP_STYLE
\r
179 .equalsIgnoreCase(propertyName);
\r