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.converters;
27
28 import com.sun.javafx.css.StyleConverterImpl;
29 import javafx.application.Application;
30 import javafx.css.ParsedValue;
31 import javafx.css.StyleConverter;
32 import javafx.scene.text.Font;
33 import sun.util.logging.PlatformLogger;
34
35 import java.net.MalformedURLException;
36 import java.net.URI;
37 import java.net.URISyntaxException;
38 import java.net.URL;
39 import java.security.AccessController;
40 import java.security.CodeSource;
41 import java.security.PrivilegedActionException;
42 import java.security.PrivilegedExceptionAction;
43 import java.security.ProtectionDomain;
44
45 /**
46 * Convert url("<path>") a URL string resolved relative to the location of the stylesheet.
47 */
48 public final class URLConverter extends StyleConverterImpl<ParsedValue[], String> {
49
50 // lazy, thread-safe instatiation
51 private static class Holder {
52 static final URLConverter INSTANCE = new URLConverter();
53 static final SequenceConverter SEQUENCE_INSTANCE = new SequenceConverter();
54 }
55
56 public static StyleConverter<ParsedValue[], String> getInstance() {
57 return Holder.INSTANCE;
58 }
59
60 private URLConverter() {
61 super();
62 }
63
64 @Override
65 public String convert(ParsedValue<ParsedValue[], String> value, Font font) {
66
67 String url = null;
68
218 //
219 // Put together a new URI from the pieces of rtJarURI. We cannot use resolve here since
220 // the scheme and path may have been munged.
221 //
222 URI resolved = new URI(scheme, rtJarUserInfo, rtJarHost, rtJarPort, rtJarPath, null, null);
223 return resolved.toURL();
224
225 } catch (URISyntaxException | MalformedURLException | PrivilegedActionException ignored) {
226 // Allow this method to return null so the caller will try to further resolve the path.
227 // If nothing else, an error message will result when the converted URL is consumed.
228 }
229 }
230 return null;
231 }
232
233 @Override
234 public String toString() {
235 return "URLType";
236 }
237
238 public static final class SequenceConverter extends StyleConverterImpl<ParsedValue<ParsedValue[], String>[], String[]> {
239
240 public static SequenceConverter getInstance() {
241 return Holder.SEQUENCE_INSTANCE;
242 }
243
244 private SequenceConverter() {
245 super();
246 }
247
248 @Override
249 public String[] convert(ParsedValue<ParsedValue<ParsedValue[], String>[], String[]> value, Font font) {
250 ParsedValue<ParsedValue[], String>[] layers = value.getValue();
251 String[] urls = new String[layers.length];
252 for (int layer = 0; layer < layers.length; layer++) {
253 urls[layer] = URLConverter.getInstance().convert(layers[layer], font);
254 }
255 return urls;
256 }
257
258 @Override
|
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.converter;
27
28 import javafx.application.Application;
29 import javafx.css.ParsedValue;
30 import javafx.css.StyleConverter;
31 import javafx.scene.text.Font;
32 import sun.util.logging.PlatformLogger;
33
34 import java.net.MalformedURLException;
35 import java.net.URI;
36 import java.net.URISyntaxException;
37 import java.net.URL;
38 import java.security.AccessController;
39 import java.security.CodeSource;
40 import java.security.PrivilegedActionException;
41 import java.security.PrivilegedExceptionAction;
42 import java.security.ProtectionDomain;
43
44 /**
45 * Convert url("<path>") a URL string resolved relative to the location of the stylesheet.
46 *
47 * @since 9
48 */
49 public final class URLConverter extends StyleConverter<ParsedValue[], String> {
50
51 // lazy, thread-safe instatiation
52 private static class Holder {
53 static final URLConverter INSTANCE = new URLConverter();
54 static final SequenceConverter SEQUENCE_INSTANCE = new SequenceConverter();
55 }
56
57 public static StyleConverter<ParsedValue[], String> getInstance() {
58 return Holder.INSTANCE;
59 }
60
61 private URLConverter() {
62 super();
63 }
64
65 @Override
66 public String convert(ParsedValue<ParsedValue[], String> value, Font font) {
67
68 String url = null;
69
219 //
220 // Put together a new URI from the pieces of rtJarURI. We cannot use resolve here since
221 // the scheme and path may have been munged.
222 //
223 URI resolved = new URI(scheme, rtJarUserInfo, rtJarHost, rtJarPort, rtJarPath, null, null);
224 return resolved.toURL();
225
226 } catch (URISyntaxException | MalformedURLException | PrivilegedActionException ignored) {
227 // Allow this method to return null so the caller will try to further resolve the path.
228 // If nothing else, an error message will result when the converted URL is consumed.
229 }
230 }
231 return null;
232 }
233
234 @Override
235 public String toString() {
236 return "URLType";
237 }
238
239 public static final class SequenceConverter extends StyleConverter<ParsedValue<ParsedValue[], String>[], String[]> {
240
241 public static SequenceConverter getInstance() {
242 return Holder.SEQUENCE_INSTANCE;
243 }
244
245 private SequenceConverter() {
246 super();
247 }
248
249 @Override
250 public String[] convert(ParsedValue<ParsedValue<ParsedValue[], String>[], String[]> value, Font font) {
251 ParsedValue<ParsedValue[], String>[] layers = value.getValue();
252 String[] urls = new String[layers.length];
253 for (int layer = 0; layer < layers.length; layer++) {
254 urls[layer] = URLConverter.getInstance().convert(layers[layer], font);
255 }
256 return urls;
257 }
258
259 @Override
|