From bd7549bfbc57975772cacbbe2a79da35c805edec Mon Sep 17 00:00:00 2001 From: prrace Date: Tue, 4 Mar 2025 15:29:29 -0800 Subject: [PATCH 1/3] 8319192 --- .../swing/plaf/synth/SynthLookAndFeel.java | 50 +------------------ .../javax/swing/plaf/synth/SynthParser.java | 43 +++------------- 2 files changed, 7 insertions(+), 86 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java index ca58ca7968bd1..9cfb29ac43cd6 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java @@ -604,55 +604,7 @@ public void load(InputStream input, Class resourceBase) throws } new SynthParser().parse(input, (DefaultSynthStyleFactory) factory, - null, resourceBase, defaultsMap); - } - - /** - * Loads the set of SynthStyles that will be used by - * this SynthLookAndFeel. Path based resources are resolved - * relatively to the specified URL of the style. For example - * an Image would be resolved by - * new URL(synthFile, path). Refer to - * Synth File Format for more - * information. - *

- * Whilst this API may be safe for loading local resources that are - * delivered with a {@code LookAndFeel} or application, and so have an - * equal level of trust with application code, using it to load from - * remote resources, particularly any which may have a lower level of - * trust, is strongly discouraged. - * The alternative mechanisms to load styles from an {@code InputStream} - * {@linkplain #load(InputStream, Class)} - * using resources co-located with the application or by providing a - * {@code SynthStyleFactory} to - * {@linkplain #setStyleFactory setStyleFactory(SynthStyleFactory)} - * are preferred. - * Consequently this method is deprecated and will be removed in a future - * release. - * - * @param url the URL to load the set of - * SynthStyle from - * @throws ParseException if there is an error in parsing - * @throws IllegalArgumentException if synthSet is null - * @throws IOException if synthSet cannot be opened as an InputStream - * @since 1.6 - * @deprecated Use {@link #load(InputStream, Class)} or - * {@link #setStyleFactory setStyleFactory(SynthStyleFactory)} instead - */ - @Deprecated(since = "21", forRemoval = true) - public void load(URL url) throws ParseException, IOException { - if (url == null) { - throw new IllegalArgumentException( - "You must supply a valid Synth set URL"); - } - - if (defaultsMap == null) { - defaultsMap = new HashMap(); - } - - InputStream input = url.openStream(); - new SynthParser().parse(input, (DefaultSynthStyleFactory) factory, - url, null, defaultsMap); + resourceBase, defaultsMap); } /** diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java index 6334c0649bfd3..fcd7fdc92dd16 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java @@ -165,11 +165,6 @@ class SynthParser extends DefaultHandler { */ private Map _mapping; - /** - * Based URL used to resolve paths. - */ - private URL _urlResourceBase; - /** * Based class used to resolve paths. */ @@ -213,26 +208,23 @@ class SynthParser extends DefaultHandler { * * @param inputStream XML document containing the styles to read * @param factory DefaultSynthStyleFactory that new styles are added to - * @param urlResourceBase the URL used to resolve any resources, such as Images * @param classResourceBase the Class used to resolve any resources, such as Images * @param defaultsMap Map that UIDefaults properties are placed in */ public void parse(InputStream inputStream, DefaultSynthStyleFactory factory, - URL urlResourceBase, Class classResourceBase, + Class classResourceBase, Map defaultsMap) throws ParseException, IllegalArgumentException { - if (inputStream == null || factory == null || - (urlResourceBase == null && classResourceBase == null)) { + if (inputStream == null || factory == null || classResourceBase == null) { throw new IllegalArgumentException( - "You must supply an InputStream, StyleFactory and Class or URL"); + "You must supply an InputStream, StyleFactory and Class"); } - assert(!(urlResourceBase != null && classResourceBase != null)); + assert(classResourceBase != null); _factory = factory; _classResourceBase = classResourceBase; - _urlResourceBase = urlResourceBase; _defaultsMap = defaultsMap; try { try { @@ -255,17 +247,7 @@ public void parse(InputStream inputStream, * Returns the path to a resource. */ private URL getResource(String path) { - if (_classResourceBase != null) { - return _classResourceBase.getResource(path); - } else { - try { - @SuppressWarnings("deprecation") - var result = new URL(_urlResourceBase, path); - return result; - } catch (MalformedURLException mue) { - return null; - } - } + return _classResourceBase.getResource(path); } /** @@ -294,20 +276,7 @@ private boolean isForwarding() { private DocumentHandler getHandler() { if (_handler == null) { _handler = new DocumentHandler(); - if (_urlResourceBase != null) { - // getHandler() is never called before parse() so it is safe - // to create a URLClassLoader with _resourceBase. - // - // getResource(".") is called to ensure we have the directory - // containing the resources in the case the resource base is a - // .class file. - URL[] urls = new URL[] { getResource(".") }; - ClassLoader parent = Thread.currentThread().getContextClassLoader(); - ClassLoader urlLoader = new URLClassLoader(urls, parent); - _handler.setClassLoader(urlLoader); - } else { - _handler.setClassLoader(_classResourceBase.getClassLoader()); - } + _handler.setClassLoader(_classResourceBase.getClassLoader()); for (String key : _mapping.keySet()) { _handler.setVariable(key, _mapping.get(key)); From 6656254c346ef505a48652fdf4dedd6edc020e33 Mon Sep 17 00:00:00 2001 From: prrace Date: Tue, 4 Mar 2025 17:17:04 -0800 Subject: [PATCH 2/3] 8319192 --- .../share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java | 1 - .../share/classes/javax/swing/plaf/synth/SynthParser.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java index 9cfb29ac43cd6..6cb4803c65f12 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java @@ -45,7 +45,6 @@ import java.io.Serializable; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.net.URL; import java.text.ParseException; import java.util.HashMap; import java.util.Locale; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java index fcd7fdc92dd16..e4cd421290bb1 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java @@ -34,7 +34,6 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.text.ParseException; From f0b771b59790f56d0250dbefbbaf09834d8531a3 Mon Sep 17 00:00:00 2001 From: prrace Date: Wed, 5 Mar 2025 15:03:34 -0800 Subject: [PATCH 3/3] 8319192 --- .../javax/swing/plaf/synth/SynthParser.java | 2 - .../plaf/synth/doc-files/synthFileFormat.html | 41 ++----------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java index e4cd421290bb1..869460d59b88c 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java @@ -220,8 +220,6 @@ public void parse(InputStream inputStream, "You must supply an InputStream, StyleFactory and Class"); } - assert(classResourceBase != null); - _factory = factory; _classResourceBase = classResourceBase; _defaultsMap = defaultsMap; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/doc-files/synthFileFormat.html b/src/java.desktop/share/classes/javax/swing/plaf/synth/doc-files/synthFileFormat.html index b3c8118b40496..87c5e74737482 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/doc-files/synthFileFormat.html +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/doc-files/synthFileFormat.html @@ -53,9 +53,7 @@

File Format

necessary to create your own look and feel. A synth file is loaded by way of the - SynthLookAndFeel.load(InputStream, Class) or - - SynthLookAndFeel.load(URL) methods. + SynthLookAndFeel.load(InputStream, Class) method. The following example uses the load method to configure a SynthLookAndFeel and sets it as the current look and feel: @@ -71,36 +69,6 @@

File Format

This example loads the look and feel from an input stream, using the specified class as the resource base to resolve paths.

-

- It is also possible to load a look and feel from an arbitrary URL - as in the following example. -

-
-
-  SynthLookAndFeel laf = new SynthLookAndFeel();
-  laf.load(new URL("file:///C:/java/synth/laf/laf.xml"));
-  UIManager.setLookAndFeel(laf);
-      
-
-

- The method - SynthLookAndFeel.load(URL) can be used, for instance, to load a look - and feel from any of the following: -

- -

Note: Synth's file format allows for the definition of code to be executed. - Loading any code from a remote location should be used only - with extreme caution from a trusted source over a secure connection. - It is strongly discouraged for an application or a LookAndFeel to do so. -

While the DTD for synth is specified, the parser is not validating. Parsing will fail only if a necessary attribute is not @@ -880,10 +848,9 @@

The imagePainter element

a direction or orientation. If this is not specified the image is used for all directions.
path
-
Path to the image. If SynthLookAndFeel.load is - passed a Class this will use the Class method getResource (with the - Class supplied to the load method). If load is passed a URL this will use the - URL constructor URL(context, path) to resolve the path.
+
Path to the image. SynthLookAndFeel.load + will use the Class method getResource (with the + Class supplied to the load method) to resolve the path.
sourceInsets
Insets on the source image. This is top, left, bottom, right with each component separated by a space.