diff options
author | malenkov <none@none> | 2014-04-18 14:15:42 +0400 |
---|---|---|
committer | malenkov <none@none> | 2014-04-18 14:15:42 +0400 |
commit | d56f16f6bd35dbfe0f454100aa07525e3bf6fc65 (patch) | |
tree | 31d2cfefb4f5952e28ac6782ac3288409fd7db80 /src/share/classes/javax | |
parent | 91b53cf5dfa8b304010d3ce37cca58d1b4f0c9cb (diff) |
8038962: KSS: javax.swing.text.html[.parser].ResourceLoader
Reviewed-by: alexsch, serb
Diffstat (limited to 'src/share/classes/javax')
5 files changed, 28 insertions, 151 deletions
diff --git a/src/share/classes/javax/swing/text/html/HTMLEditorKit.java b/src/share/classes/javax/swing/text/html/HTMLEditorKit.java index 29c753776..425ba5f0b 100644 --- a/src/share/classes/javax/swing/text/html/HTMLEditorKit.java +++ b/src/share/classes/javax/swing/text/html/HTMLEditorKit.java @@ -26,7 +26,6 @@ package javax.swing.text.html; import sun.awt.AppContext; -import java.lang.reflect.Method; import java.awt.*; import java.awt.event.*; import java.io.*; @@ -34,12 +33,13 @@ import java.net.MalformedURLException; import java.net.URL; import javax.swing.text.*; import javax.swing.*; -import javax.swing.border.*; import javax.swing.event.*; import javax.swing.plaf.TextUI; import java.util.*; import javax.accessibility.*; import java.lang.ref.*; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * The Swing JEditorPane text component supports different kinds @@ -414,14 +414,13 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { * HTMLEditorKit class * @return a stream representing the resource */ - static InputStream getResourceAsStream(String name) { - try { - return ResourceLoader.getResourceAsStream(name); - } catch (Throwable e) { - // If the class doesn't exist or we have some other - // problem we just try to call getResourceAsStream directly. - return HTMLEditorKit.class.getResourceAsStream(name); - } + static InputStream getResourceAsStream(final String name) { + return AccessController.doPrivileged( + new PrivilegedAction<InputStream>() { + public InputStream run() { + return HTMLEditorKit.class.getResourceAsStream(name); + } + }); } /** diff --git a/src/share/classes/javax/swing/text/html/ResourceLoader.java b/src/share/classes/javax/swing/text/html/ResourceLoader.java deleted file mode 100644 index 1fd230bea..000000000 --- a/src/share/classes/javax/swing/text/html/ResourceLoader.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.swing.text.html; - -import java.io.InputStream; - -/** - * Simple class to load resources using the 1.2 - * security model. Since the html support is loaded - * lazily, it's resources are potentially fetched with - * applet code in the call stack. By providing this - * functionality in a class that is only built on 1.2, - * reflection can be used from the code that is also - * built on 1.1 to call this functionality (and avoid - * the evils of preprocessing). This functionality - * is called from HTMLEditorKit.getResourceAsStream. - * - * @author Timothy Prinzing - */ -class ResourceLoader implements java.security.PrivilegedAction { - - ResourceLoader(String name) { - this.name = name; - } - - public Object run() { - Object o = HTMLEditorKit.class.getResourceAsStream(name); - return o; - } - - public static InputStream getResourceAsStream(String name) { - java.security.PrivilegedAction a = new ResourceLoader(name); - return (InputStream) java.security.AccessController.doPrivileged(a); - } - - private String name; -} diff --git a/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java b/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java index cdea9579f..fbf5e1734 100644 --- a/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java +++ b/src/share/classes/javax/swing/text/html/parser/ParserDelegator.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing.text.html.parser; import sun.awt.AppContext; @@ -35,6 +34,8 @@ import java.io.DataInputStream; import java.io.ObjectInputStream; import java.io.Reader; import java.io.Serializable; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Responsible for starting up a new DocumentParser @@ -111,14 +112,13 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl * ParserDelegator class. * @returns a stream representing the resource */ - static InputStream getResourceAsStream(String name) { - try { - return ResourceLoader.getResourceAsStream(name); - } catch (Throwable e) { - // If the class doesn't exist or we have some other - // problem we just try to call getResourceAsStream directly. - return ParserDelegator.class.getResourceAsStream(name); - } + static InputStream getResourceAsStream(final String name) { + return AccessController.doPrivileged( + new PrivilegedAction<InputStream>() { + public InputStream run() { + return ParserDelegator.class.getResourceAsStream(name); + } + }); } private void readObject(ObjectInputStream s) diff --git a/src/share/classes/javax/swing/text/html/parser/ResourceLoader.java b/src/share/classes/javax/swing/text/html/parser/ResourceLoader.java deleted file mode 100644 index 9b958f566..000000000 --- a/src/share/classes/javax/swing/text/html/parser/ResourceLoader.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.swing.text.html.parser; - -import java.io.InputStream; - -/** - * Simple class to load resources using the 1.2 - * security model. Since the html support is loaded - * lazily, it's resources are potentially fetched with - * applet code in the call stack. By providing this - * functionality in a class that is only built on 1.2, - * reflection can be used from the code that is also - * built on 1.1 to call this functionality (and avoid - * the evils of preprocessing). This functionality - * is called from ParserDelegator.getResourceAsStream. - * - * @author Timothy Prinzing - */ -class ResourceLoader implements java.security.PrivilegedAction { - - ResourceLoader(String name) { - this.name = name; - } - - public Object run() { - Object o = ParserDelegator.class.getResourceAsStream(name); - return o; - } - - public static InputStream getResourceAsStream(String name) { - java.security.PrivilegedAction a = new ResourceLoader(name); - return (InputStream) java.security.AccessController.doPrivileged(a); - } - - private String name; -} diff --git a/src/share/classes/javax/swing/text/rtf/RTFReader.java b/src/share/classes/javax/swing/text/rtf/RTFReader.java index ebef02d09..e7457584d 100644 --- a/src/share/classes/javax/swing/text/rtf/RTFReader.java +++ b/src/share/classes/javax/swing/text/rtf/RTFReader.java @@ -27,9 +27,9 @@ package javax.swing.text.rtf; import java.lang.*; import java.util.*; import java.io.*; -import java.awt.Font; import java.awt.Color; - +import java.security.AccessController; +import java.security.PrivilegedAction; import javax.swing.text.*; /** @@ -558,16 +558,14 @@ getCharacterSet(final String name) { char[] set = characterSets.get(name); if (set == null) { - InputStream charsetStream; - charsetStream = java.security.AccessController. - doPrivileged(new java.security.PrivilegedAction<InputStream>() { - public InputStream run() { - return RTFReader.class.getResourceAsStream - ("charsets/" + name + ".txt"); - } - }); - set = readCharset(charsetStream); - defineCharacterSet(name, set); + InputStream charsetStream = AccessController.doPrivileged( + new PrivilegedAction<InputStream>() { + public InputStream run() { + return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt"); + } + }); + set = readCharset(charsetStream); + defineCharacterSet(name, set); } return set; } |