Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8319192: Remove javax.swing.plaf.synth.SynthLookAndFeel.load(URL url) #23909

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -604,55 +603,7 @@ public void load(InputStream input, Class<?> resourceBase) throws
}

new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
null, resourceBase, defaultsMap);
}

/**
* Loads the set of <code>SynthStyle</code>s that will be used by
* this <code>SynthLookAndFeel</code>. Path based resources are resolved
* relatively to the specified <code>URL</code> of the style. For example
* an <code>Image</code> would be resolved by
* <code>new URL(synthFile, path)</code>. Refer to
* <a href="doc-files/synthFileFormat.html">Synth File Format</a> for more
* information.
* <p>
* 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 <code>URL</code> to load the set of
* <code>SynthStyle</code> from
* @throws ParseException if there is an error in parsing
* @throws IllegalArgumentException if synthSet is <code>null</code>
* @throws IOException if synthSet cannot be opened as an <code>InputStream</code>
* @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<String, Object>();
}

InputStream input = url.openStream();
new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
url, null, defaultsMap);
resourceBase, defaultsMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is URLClassLoader no longer used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems so. I'll remove it.

import java.text.ParseException;
Expand Down Expand Up @@ -165,11 +164,6 @@ class SynthParser extends DefaultHandler {
*/
private Map<String,Object> _mapping;

/**
* Based URL used to resolve paths.
*/
private URL _urlResourceBase;

/**
* Based class used to resolve paths.
*/
Expand Down Expand Up @@ -213,26 +207,21 @@ 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<String, Object> 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));

_factory = factory;
_classResourceBase = classResourceBase;
_urlResourceBase = urlResourceBase;
_defaultsMap = defaultsMap;
try {
try {
Expand All @@ -255,17 +244,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);
}

/**
Expand Down Expand Up @@ -294,20 +273,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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ <h1><a id="file">File Format</a></h1>
necessary to create your own look and feel. A synth file is
loaded by way of the <A
HREF="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.io.InputStream,java.lang.Class)">
SynthLookAndFeel.load(InputStream, Class)</a> or
<a href="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.net.URL)">
SynthLookAndFeel.load(URL)</a> methods.
SynthLookAndFeel.load(InputStream, Class)</a> method.
The following example uses the <code>load</code> method to configure
a <code>SynthLookAndFeel</code> and sets it as the current look
and feel:
Expand All @@ -71,36 +69,6 @@ <h1><a id="file">File Format</a></h1>
This example loads the look and feel from an input stream, using
the specified class as the resource base to resolve paths.
</p>
<p>
It is also possible to load a look and feel from an arbitrary URL
as in the following example.
</p>
<div class="example">
<pre>
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(new URL("file:///C:/java/synth/laf/laf.xml"));
UIManager.setLookAndFeel(laf);
</pre>
</div>
<p>
The method <a
href="../../../../../javax/swing/plaf/synth/SynthLookAndFeel.html#load(java.net.URL)">
SynthLookAndFeel.load(URL)</a> can be used, for instance, to load a look
and feel from any of the following:
</p>
<ul>
<li>File, e.g. <code>file:///C:/java/synth/laf/laf.xml</code></li>
<li>Web server, e.g. <code>http://host/laf.xml</code></li>
<li>JAR file, e.g.
<code>jar:file:///C:/synth-laf.jar!/laf.xml</code></li>
<li>Remote JAR file, e.g.
<code>jar:http://host/synth-laf.jar!/laf.xml</code></li>
</ul>
<p>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.
</p>
<p>
While the DTD for synth is specified, the parser is not validating.
Parsing will fail only if a necessary attribute is not
Expand Down Expand Up @@ -880,10 +848,9 @@ <h2>The imagePainter element</h2>
a direction or orientation. If this is not specified the image is
used for all directions.</dd>
<dt><a id="imagePainter.path"><samp>path</samp></a></dt>
<dd>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.</dd>
<dd>Path to the image. SynthLookAndFeel.load
will use the Class method getResource (with the
Class supplied to the load method) to resolve the path.
<dt><a id="imagePainter.sourceInsets"><samp>sourceInsets</samp></a></dt>
<dd>Insets on the source image. This is top, left, bottom, right with
each component separated by a space.</dd>
Expand Down