提交 8d1fe65a 编写于 作者: M malenkov

8038962: KSS: javax.swing.text.html[.parser].ResourceLoader

Reviewed-by: alexsch, serb
上级 a9993d6f
...@@ -26,7 +26,6 @@ package javax.swing.text.html; ...@@ -26,7 +26,6 @@ package javax.swing.text.html;
import sun.awt.AppContext; import sun.awt.AppContext;
import java.lang.reflect.Method;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
...@@ -34,12 +33,13 @@ import java.net.MalformedURLException; ...@@ -34,12 +33,13 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import javax.swing.text.*; import javax.swing.text.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.plaf.TextUI; import javax.swing.plaf.TextUI;
import java.util.*; import java.util.*;
import javax.accessibility.*; import javax.accessibility.*;
import java.lang.ref.*; import java.lang.ref.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* The Swing JEditorPane text component supports different kinds * The Swing JEditorPane text component supports different kinds
...@@ -414,14 +414,13 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { ...@@ -414,14 +414,13 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* HTMLEditorKit class * HTMLEditorKit class
* @return a stream representing the resource * @return a stream representing the resource
*/ */
static InputStream getResourceAsStream(String name) { static InputStream getResourceAsStream(final String name) {
try { return AccessController.doPrivileged(
return ResourceLoader.getResourceAsStream(name); new PrivilegedAction<InputStream>() {
} catch (Throwable e) { public InputStream run() {
// If the class doesn't exist or we have some other return HTMLEditorKit.class.getResourceAsStream(name);
// problem we just try to call getResourceAsStream directly. }
return HTMLEditorKit.class.getResourceAsStream(name); });
}
} }
/** /**
......
/*
* 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;
}
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package javax.swing.text.html.parser; package javax.swing.text.html.parser;
import sun.awt.AppContext; import sun.awt.AppContext;
...@@ -35,6 +34,8 @@ import java.io.DataInputStream; ...@@ -35,6 +34,8 @@ import java.io.DataInputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Serializable; import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* Responsible for starting up a new DocumentParser * Responsible for starting up a new DocumentParser
...@@ -111,14 +112,13 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl ...@@ -111,14 +112,13 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
* ParserDelegator class. * ParserDelegator class.
* @returns a stream representing the resource * @returns a stream representing the resource
*/ */
static InputStream getResourceAsStream(String name) { static InputStream getResourceAsStream(final String name) {
try { return AccessController.doPrivileged(
return ResourceLoader.getResourceAsStream(name); new PrivilegedAction<InputStream>() {
} catch (Throwable e) { public InputStream run() {
// If the class doesn't exist or we have some other return ParserDelegator.class.getResourceAsStream(name);
// problem we just try to call getResourceAsStream directly. }
return ParserDelegator.class.getResourceAsStream(name); });
}
} }
private void readObject(ObjectInputStream s) private void readObject(ObjectInputStream s)
......
/*
* 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;
}
...@@ -27,9 +27,9 @@ package javax.swing.text.rtf; ...@@ -27,9 +27,9 @@ package javax.swing.text.rtf;
import java.lang.*; import java.lang.*;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.awt.Font;
import java.awt.Color; import java.awt.Color;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.text.*; import javax.swing.text.*;
/** /**
...@@ -558,16 +558,14 @@ getCharacterSet(final String name) ...@@ -558,16 +558,14 @@ getCharacterSet(final String name)
{ {
char[] set = characterSets.get(name); char[] set = characterSets.get(name);
if (set == null) { if (set == null) {
InputStream charsetStream; InputStream charsetStream = AccessController.doPrivileged(
charsetStream = java.security.AccessController. new PrivilegedAction<InputStream>() {
doPrivileged(new java.security.PrivilegedAction<InputStream>() { public InputStream run() {
public InputStream run() { return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt");
return RTFReader.class.getResourceAsStream }
("charsets/" + name + ".txt"); });
} set = readCharset(charsetStream);
}); defineCharacterSet(name, set);
set = readCharset(charsetStream);
defineCharacterSet(name, set);
} }
return set; return set;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册