Skip to content

Commit 86eefca

Browse files
author
duke
committedMar 13, 2025
Automatic merge of jdk:master into master
2 parents f934774 + aa047ee commit 86eefca

File tree

3 files changed

+10
-126
lines changed

3 files changed

+10
-126
lines changed
 

‎src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java

+1-50
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.io.Serializable;
4646
import java.lang.ref.ReferenceQueue;
4747
import java.lang.ref.WeakReference;
48-
import java.net.URL;
4948
import java.text.ParseException;
5049
import java.util.HashMap;
5150
import java.util.Locale;
@@ -604,55 +603,7 @@ public void load(InputStream input, Class<?> resourceBase) throws
604603
}
605604

606605
new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
607-
null, resourceBase, defaultsMap);
608-
}
609-
610-
/**
611-
* Loads the set of <code>SynthStyle</code>s that will be used by
612-
* this <code>SynthLookAndFeel</code>. Path based resources are resolved
613-
* relatively to the specified <code>URL</code> of the style. For example
614-
* an <code>Image</code> would be resolved by
615-
* <code>new URL(synthFile, path)</code>. Refer to
616-
* <a href="doc-files/synthFileFormat.html">Synth File Format</a> for more
617-
* information.
618-
* <p>
619-
* Whilst this API may be safe for loading local resources that are
620-
* delivered with a {@code LookAndFeel} or application, and so have an
621-
* equal level of trust with application code, using it to load from
622-
* remote resources, particularly any which may have a lower level of
623-
* trust, is strongly discouraged.
624-
* The alternative mechanisms to load styles from an {@code InputStream}
625-
* {@linkplain #load(InputStream, Class)}
626-
* using resources co-located with the application or by providing a
627-
* {@code SynthStyleFactory} to
628-
* {@linkplain #setStyleFactory setStyleFactory(SynthStyleFactory)}
629-
* are preferred.
630-
* Consequently this method is deprecated and will be removed in a future
631-
* release.
632-
*
633-
* @param url the <code>URL</code> to load the set of
634-
* <code>SynthStyle</code> from
635-
* @throws ParseException if there is an error in parsing
636-
* @throws IllegalArgumentException if synthSet is <code>null</code>
637-
* @throws IOException if synthSet cannot be opened as an <code>InputStream</code>
638-
* @since 1.6
639-
* @deprecated Use {@link #load(InputStream, Class)} or
640-
* {@link #setStyleFactory setStyleFactory(SynthStyleFactory)} instead
641-
*/
642-
@Deprecated(since = "21", forRemoval = true)
643-
public void load(URL url) throws ParseException, IOException {
644-
if (url == null) {
645-
throw new IllegalArgumentException(
646-
"You must supply a valid Synth set URL");
647-
}
648-
649-
if (defaultsMap == null) {
650-
defaultsMap = new HashMap<String, Object>();
651-
}
652-
653-
InputStream input = url.openStream();
654-
new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
655-
url, null, defaultsMap);
606+
resourceBase, defaultsMap);
656607
}
657608

658609
/**

‎src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java

+5-39
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.BufferedInputStream;
3535
import java.io.IOException;
3636
import java.io.InputStream;
37-
import java.net.MalformedURLException;
3837
import java.net.URL;
3938
import java.net.URLClassLoader;
4039
import java.text.ParseException;
@@ -165,11 +164,6 @@ class SynthParser extends DefaultHandler {
165164
*/
166165
private Map<String,Object> _mapping;
167166

168-
/**
169-
* Based URL used to resolve paths.
170-
*/
171-
private URL _urlResourceBase;
172-
173167
/**
174168
* Based class used to resolve paths.
175169
*/
@@ -213,26 +207,21 @@ class SynthParser extends DefaultHandler {
213207
*
214208
* @param inputStream XML document containing the styles to read
215209
* @param factory DefaultSynthStyleFactory that new styles are added to
216-
* @param urlResourceBase the URL used to resolve any resources, such as Images
217210
* @param classResourceBase the Class used to resolve any resources, such as Images
218211
* @param defaultsMap Map that UIDefaults properties are placed in
219212
*/
220213
public void parse(InputStream inputStream,
221214
DefaultSynthStyleFactory factory,
222-
URL urlResourceBase, Class<?> classResourceBase,
215+
Class<?> classResourceBase,
223216
Map<String, Object> defaultsMap)
224217
throws ParseException, IllegalArgumentException {
225-
if (inputStream == null || factory == null ||
226-
(urlResourceBase == null && classResourceBase == null)) {
218+
if (inputStream == null || factory == null || classResourceBase == null) {
227219
throw new IllegalArgumentException(
228-
"You must supply an InputStream, StyleFactory and Class or URL");
220+
"You must supply an InputStream, StyleFactory and Class");
229221
}
230222

231-
assert(!(urlResourceBase != null && classResourceBase != null));
232-
233223
_factory = factory;
234224
_classResourceBase = classResourceBase;
235-
_urlResourceBase = urlResourceBase;
236225
_defaultsMap = defaultsMap;
237226
try {
238227
try {
@@ -255,17 +244,7 @@ public void parse(InputStream inputStream,
255244
* Returns the path to a resource.
256245
*/
257246
private URL getResource(String path) {
258-
if (_classResourceBase != null) {
259-
return _classResourceBase.getResource(path);
260-
} else {
261-
try {
262-
@SuppressWarnings("deprecation")
263-
var result = new URL(_urlResourceBase, path);
264-
return result;
265-
} catch (MalformedURLException mue) {
266-
return null;
267-
}
268-
}
247+
return _classResourceBase.getResource(path);
269248
}
270249

271250
/**
@@ -294,20 +273,7 @@ private boolean isForwarding() {
294273
private DocumentHandler getHandler() {
295274
if (_handler == null) {
296275
_handler = new DocumentHandler();
297-
if (_urlResourceBase != null) {
298-
// getHandler() is never called before parse() so it is safe
299-
// to create a URLClassLoader with _resourceBase.
300-
//
301-
// getResource(".") is called to ensure we have the directory
302-
// containing the resources in the case the resource base is a
303-
// .class file.
304-
URL[] urls = new URL[] { getResource(".") };
305-
ClassLoader parent = Thread.currentThread().getContextClassLoader();
306-
ClassLoader urlLoader = new URLClassLoader(urls, parent);
307-
_handler.setClassLoader(urlLoader);
308-
} else {
309-
_handler.setClassLoader(_classResourceBase.getClassLoader());
310-
}
276+
_handler.setClassLoader(_classResourceBase.getClassLoader());
311277

312278
for (String key : _mapping.keySet()) {
313279
_handler.setVariable(key, _mapping.get(key));

‎src/java.desktop/share/classes/javax/swing/plaf/synth/doc-files/synthFileFormat.html

+4-37
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ <h1><a id="file">File Format</a></h1>
5353
necessary to create your own look and feel. A synth file is
5454
loaded by way of the <A
5555
HREF="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.io.InputStream,java.lang.Class)">
56-
SynthLookAndFeel.load(InputStream, Class)</a> or
57-
<a href="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.net.URL)">
58-
SynthLookAndFeel.load(URL)</a> methods.
56+
SynthLookAndFeel.load(InputStream, Class)</a> method.
5957
The following example uses the <code>load</code> method to configure
6058
a <code>SynthLookAndFeel</code> and sets it as the current look
6159
and feel:
@@ -71,36 +69,6 @@ <h1><a id="file">File Format</a></h1>
7169
This example loads the look and feel from an input stream, using
7270
the specified class as the resource base to resolve paths.
7371
</p>
74-
<p>
75-
It is also possible to load a look and feel from an arbitrary URL
76-
as in the following example.
77-
</p>
78-
<div class="example">
79-
<pre>
80-
SynthLookAndFeel laf = new SynthLookAndFeel();
81-
laf.load(new URL("file:///C:/java/synth/laf/laf.xml"));
82-
UIManager.setLookAndFeel(laf);
83-
</pre>
84-
</div>
85-
<p>
86-
The method <a
87-
href="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.net.URL)">
88-
SynthLookAndFeel.load(URL)</a> can be used, for instance, to load a look
89-
and feel from any of the following:
90-
</p>
91-
<ul>
92-
<li>File, e.g. <code>file:///C:/java/synth/laf/laf.xml</code></li>
93-
<li>Web server, e.g. <code>http://host/laf.xml</code></li>
94-
<li>JAR file, e.g.
95-
<code>jar:file:///C:/synth-laf.jar!/laf.xml</code></li>
96-
<li>Remote JAR file, e.g.
97-
<code>jar:http://host/synth-laf.jar!/laf.xml</code></li>
98-
</ul>
99-
<p>Note: Synth's file format allows for the definition of code to be executed.
100-
Loading any code from a remote location should be used only
101-
with extreme caution from a trusted source over a secure connection.
102-
It is strongly discouraged for an application or a LookAndFeel to do so.
103-
</p>
10472
<p>
10573
While the DTD for synth is specified, the parser is not validating.
10674
Parsing will fail only if a necessary attribute is not
@@ -880,10 +848,9 @@ <h2>The imagePainter element</h2>
880848
a direction or orientation. If this is not specified the image is
881849
used for all directions.</dd>
882850
<dt><a id="imagePainter.path"><samp>path</samp></a></dt>
883-
<dd>Path to the image. If SynthLookAndFeel.load is
884-
passed a Class this will use the Class method getResource (with the
885-
Class supplied to the load method). If load is passed a URL this will use the
886-
URL constructor URL(context, path) to resolve the path.</dd>
851+
<dd>Path to the image. SynthLookAndFeel.load
852+
will use the Class method getResource (with the
853+
Class supplied to the load method) to resolve the path.
887854
<dt><a id="imagePainter.sourceInsets"><samp>sourceInsets</samp></a></dt>
888855
<dd>Insets on the source image. This is top, left, bottom, right with
889856
each component separated by a space.</dd>

0 commit comments

Comments
 (0)
Please sign in to comment.