Back to index

lightning-sunbird  0.9+nobinonly
MRJSession.java
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the MRJ Carbon OJI Plugin.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Patrick C. Beard <beard@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 package netscape.oji;
00039 
00040 import java.io.*;
00041 import java.awt.*;
00042 import java.awt.event.*;
00043 import java.util.Date;
00044 import java.util.Properties;
00045 import java.net.URL;
00046 
00053 public class MRJSession {
00054     // Save primordial System streams.
00055     private static PrintStream out;
00056     private static PrintStream err;
00057     private static PrintStream console;
00058 
00059     private static Properties loadProperties(String pluginHome) {
00060         Properties props = new Properties();
00061         try {
00062             InputStream propsStream = new FileInputStream(pluginHome + "/MRJPlugin.properties");
00063             props.load(propsStream);
00064             propsStream.close();
00065         } catch (IOException ex) {
00066         }
00067         return props;
00068     }
00069 
00070     public static void open(String consolePath) throws IOException {
00071         String pluginHome = System.getProperty("netscape.oji.plugin.home");
00072         Properties props = loadProperties(pluginHome);
00073         boolean append = Boolean.valueOf(props.getProperty("netscape.oji.plugin.console.append")).booleanValue();
00074     
00075         // Make sure the parent directories exist.
00076         File consoleFile = new File(consolePath);
00077         File parentFile = consoleFile.getParentFile();
00078         if (!parentFile.exists()) {
00079             parentFile.mkdirs();
00080         }
00081     
00082         // redirect console I/O to specified file.
00083         MRJSession.out = System.out;
00084         MRJSession.err = System.err;
00085         console = new PrintStream(new FileOutputStream(consolePath, append));
00086         System.setOut(console);
00087         System.setErr(console);
00088 
00089         Date date = new Date();
00090         String version = props.getProperty("netscape.oji.plugin.version");
00091         System.out.println("MRJ Plugin for Mac OS X v" + version);
00092         System.out.println("[starting up Java Applet Security @ " + date + "]");
00093 
00094         // bring up MRJ Applet Security.
00095         if (System.getSecurityManager() == null) {
00096             try {
00097                 // make sure that the classes in MRJPlugin.jar are granted all permissions.
00098                 // see p. 117 of "Inside Java 2 Platform Security" for more information.
00099                 System.setProperty("java.security.policy", "file:" + pluginHome + "/MRJPlugin.policy");
00100                 String name = props.getProperty("netscape.oji.plugin.security");
00101                 SecurityManager securityManager = (SecurityManager) Class.forName(name).newInstance();
00102                 System.setSecurityManager(securityManager);
00103             } catch (Exception ex) {
00104             }
00105         }
00106     }
00107 
00108     public static void close() throws IOException {
00109         System.setOut(MRJSession.out);
00110         System.setErr(MRJSession.err);
00111         console.close();
00112     }
00113 }