6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.css;
27
28 import com.sun.javafx.css.converters.URLConverter;
29 import javafx.css.ParsedValue;
30 import javafx.css.StyleConverter;
31 import javafx.css.StyleOrigin;
32
33 import java.io.DataInputStream;
34 import java.io.DataOutputStream;
35 import java.io.IOException;
36
37 final public class Declaration {
38 final String property;
39 final ParsedValueImpl parsedValue;
40 final boolean important;
41 // The Rule to which this Declaration belongs.
42 Rule rule;
43
44 public Declaration(final String propertyName, final ParsedValueImpl parsedValue,
45 final boolean important) {
46 this.property = propertyName;
47 this.parsedValue = parsedValue;
48 this.important = important;
49 if (propertyName == null) {
50 throw new IllegalArgumentException("propertyName cannot be null");
51 }
52 if (parsedValue == null) {
53 throw new IllegalArgumentException("parsedValue cannot be null");
54 }
55 }
56
57 /** @return ParsedValue contains the parsed declaration. */
58 public ParsedValue getParsedValue() {
59 return parsedValue;
60 }
61
62 /** @return ParsedValue contains the parsed declaration. */
63 ParsedValueImpl getParsedValueImpl() {
64 return parsedValue;
65 }
66
67 /** @return The CSS property name */
68 public String getProperty() {
69 return property;
70 }
71
72 /** @return The Rule to which this Declaration belongs. */
73 public Rule getRule() {
74 return rule;
75 }
76
77 public boolean isImportant() {
78 return important;
79 }
80
81 /** Helper */
82 private StyleOrigin getOrigin() {
83 Rule rule = getRule();
84 if (rule != null) {
85 return rule.getOrigin();
86 }
87 return null;
88 }
89 /**
90 * One declaration is the equal to another regardless of the Rule to which
91 * the Declaration belongs. Only the property, value and importance are
92 * considered.
93 */
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj) {
97 return true;
98 }
99 if (obj == null) {
100 return false;
101 }
102 if (getClass() != obj.getClass()) {
103 return false;
104 }
105 final Declaration other = (Declaration) obj;
106 if (this.important != other.important) {
107 return false;
108 }
109 if (this.getOrigin() != other.getOrigin()) {
110 return false;
111 }
112 if ((this.property == null) ? (other.property != null) : !this.property.equals(other.property)) {
113 return false;
114 }
115 if (this.parsedValue != other.parsedValue && (this.parsedValue == null || !this.parsedValue.equals(other.parsedValue))) {
116 return false;
117 }
118 return true;
119 }
120
121 @Override
122 public int hashCode() {
123 int hash = 5;
124 hash = 89 * hash + (this.property != null ? this.property.hashCode() : 0);
125 hash = 89 * hash + (this.parsedValue != null ? this.parsedValue.hashCode() : 0);
126 hash = 89 * hash + (this.important ? 1 : 0);
127 return hash;
128 }
129
130 @Override public String toString() {
131 StringBuilder sbuf = new StringBuilder(property);
132 sbuf.append(": ");
133 sbuf.append(parsedValue);
134 if (important) sbuf.append(" !important");
135 return sbuf.toString();
136 }
137
138 //
139 // RT-21964
140 //
141 // We know when the .css file is parsed what the stylesheet URL is,
142 // but that might not be the URL of the deployed file. So for URL
153 // code is tightly coupled to the way URLConverter works
154 if (converter == URLConverter.getInstance()) {
155
156 final ParsedValue[] values = (ParsedValue[])parsedValue.getValue();
157 values[1] = new ParsedValueImpl<String,String>(stylesheetUrl, null);
158
159 } else if (converter == URLConverter.SequenceConverter.getInstance()) {
160
161 final ParsedValue<ParsedValue[], String>[] layers =
162 (ParsedValue<ParsedValue[], String>[])parsedValue.getValue();
163
164 for (int layer = 0; layer < layers.length; layer++) {
165 final ParsedValue[] values = layers[layer].getValue();
166 values[1] = new ParsedValueImpl<String,String>(stylesheetUrl, null);
167 }
168
169 }
170
171 }
172
173 final void writeBinary(final DataOutputStream os, final StringStore stringStore)
174 throws IOException
175 {
176 os.writeShort(stringStore.addString(getProperty()));
177 getParsedValueImpl().writeBinary(os,stringStore);
178 os.writeBoolean(isImportant());
179 }
180
181 static Declaration readBinary(int bssVersion, DataInputStream is, String[] strings)
182 throws IOException
183 {
184 final String propertyName = strings[is.readShort()];
185 final ParsedValueImpl parsedValue = ParsedValueImpl.readBinary(bssVersion,is,strings);
186 final boolean important = is.readBoolean();
187 return new Declaration(propertyName, parsedValue, important);
188
189 }
190 }
191
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.css;
27
28 import com.sun.javafx.css.ParsedValueImpl;
29 import javafx.css.converter.URLConverter;
30
31 import java.io.DataInputStream;
32 import java.io.DataOutputStream;
33 import java.io.IOException;
34
35 /**
36 * @since 9
37 */
38 final public class Declaration {
39 final String property;
40 final ParsedValue parsedValue;
41 final boolean important;
42 // The Rule to which this Declaration belongs.
43 Rule rule;
44
45 Declaration(final String propertyName, final ParsedValue parsedValue,
46 final boolean important) {
47 this.property = propertyName;
48 this.parsedValue = parsedValue;
49 this.important = important;
50 if (propertyName == null) {
51 throw new IllegalArgumentException("propertyName cannot be null");
52 }
53 if (parsedValue == null) {
54 throw new IllegalArgumentException("parsedValue cannot be null");
55 }
56 }
57
58 /** @return ParsedValue contains the parsed declaration. */
59 public ParsedValue getParsedValue() {
60 return parsedValue;
61 }
62
63 /** @return The CSS property name */
64 public String getProperty() {
65 return property;
66 }
67
68 /** @return The Rule to which this Declaration belongs. */
69 public Rule getRule() {
70 return rule;
71 }
72
73 boolean isImportant() {
74 return important;
75 }
76
77 /** Helper */
78 private StyleOrigin getOrigin() {
79 Rule rule = getRule();
80 if (rule != null) {
81 return rule.getOrigin();
82 }
83 return null;
84 }
85 /**
86 * One declaration is the equal to another regardless of the Rule to which
87 * the Declaration belongs. Only the property, value and importance are
88 * considered.
89 */
90 @Override public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj == null) {
95 return false;
96 }
97 if (getClass() != obj.getClass()) {
98 return false;
99 }
100 final Declaration other = (Declaration) obj;
101 if (this.important != other.important) {
102 return false;
103 }
104 if (this.getOrigin() != other.getOrigin()) {
105 return false;
106 }
107 if ((this.property == null) ? (other.property != null) : !this.property.equals(other.property)) {
108 return false;
109 }
110 if (this.parsedValue != other.parsedValue && (this.parsedValue == null || !this.parsedValue.equals(other.parsedValue))) {
111 return false;
112 }
113 return true;
114 }
115
116 @Override public int hashCode() {
117 int hash = 5;
118 hash = 89 * hash + (this.property != null ? this.property.hashCode() : 0);
119 hash = 89 * hash + (this.parsedValue != null ? this.parsedValue.hashCode() : 0);
120 hash = 89 * hash + (this.important ? 1 : 0);
121 return hash;
122 }
123
124 @Override public String toString() {
125 StringBuilder sbuf = new StringBuilder(property);
126 sbuf.append(": ");
127 sbuf.append(parsedValue);
128 if (important) sbuf.append(" !important");
129 return sbuf.toString();
130 }
131
132 //
133 // RT-21964
134 //
135 // We know when the .css file is parsed what the stylesheet URL is,
136 // but that might not be the URL of the deployed file. So for URL
147 // code is tightly coupled to the way URLConverter works
148 if (converter == URLConverter.getInstance()) {
149
150 final ParsedValue[] values = (ParsedValue[])parsedValue.getValue();
151 values[1] = new ParsedValueImpl<String,String>(stylesheetUrl, null);
152
153 } else if (converter == URLConverter.SequenceConverter.getInstance()) {
154
155 final ParsedValue<ParsedValue[], String>[] layers =
156 (ParsedValue<ParsedValue[], String>[])parsedValue.getValue();
157
158 for (int layer = 0; layer < layers.length; layer++) {
159 final ParsedValue[] values = layers[layer].getValue();
160 values[1] = new ParsedValueImpl<String,String>(stylesheetUrl, null);
161 }
162
163 }
164
165 }
166
167 final void writeBinary(final DataOutputStream os, final StyleConverter.StringStore stringStore)
168 throws IOException
169 {
170 if (parsedValue instanceof ParsedValueImpl) {
171 os.writeShort(stringStore.addString(getProperty()));
172 ((ParsedValueImpl)parsedValue).writeBinary(os,stringStore);
173 os.writeBoolean(isImportant());
174 }
175 }
176
177 static Declaration readBinary(int bssVersion, DataInputStream is, String[] strings)
178 throws IOException
179 {
180 final String propertyName = strings[is.readShort()];
181 final ParsedValueImpl parsedValue = ParsedValueImpl.readBinary(bssVersion,is,strings);
182 final boolean important = is.readBoolean();
183 return new Declaration(propertyName, parsedValue, important);
184
185 }
186 }
187
|