summaryrefslogtreecommitdiff
path: root/sj2/stardiv/controller/SjSettings.java
blob: c4eb1f6e5eec66bc9daa615dceb3d470ce133c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*************************************************************************
 *
 *  $RCSfile: SjSettings.java,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: jl $ $Date: 2001-11-22 13:50:27 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

package stardiv.controller;

import java.util.Properties;
import java.util.Hashtable;
import java.util.Enumeration;

import com.sun.star.lib.sandbox.SandboxSecurity;

/**
 * ber diese Klasse werden alle globalen Einstellungen, die fr das Sj Projekt
 * wichtig sind, dokumentiert und modifiziert.
 *
 * @version    $Version: 1.0 $
 * @author     Markus Meyer
 *
 */
public class SjSettings {
    /**
     * The following properties are used to setup the environment for
     * the stardiv packages.<BR>
     * "appletviewer.security.mode"="unrestricted" | "host" | "none": Set the
     * security level of the default SecurityManager. The default is "host".<BR>
     * "stardiv.security.defaultSecurityManager"="true" | "false": Create and set
     * the stardiv.security.AppletSecurity, if the property is "true". This occures
     * only in the first call.<BR>
     * "stardiv.security.noExit"="true" | "false": no exit is allowed. Use this property
     * if you are running more than one java application in the virtual machine. This occures
     * only in the first call.<BR>
     * "stardiv.security.disableSecurity"="true" | "false": disable security checking. Only usefull
     * if a SecurityManager is installed. The default is "false".<BR>
     * if you are running more than one java application in the virtual machine. This occures
     * only in the first call.<BR>
     * "stardiv.controller.installConsole"="true" | "false": pipe the stdout and stderr
     * through a console. Show the console with stardiv.controller.Console.showConsole( true ).
     * This occures only in the first call.<BR>
     * "stardiv.js.debugOnError"="true" | "false": Start the javascript ide, if an error
     * occures. The default is "false".<BR>
     * "stardiv.js.debugImmediate"="true" | "false": Start the javascript ide, if a script
     * starts. The default is "false".<BR>
     * "stardiv.debug.trace"="messageBox" | "window" | "file" | "none": The trace pipe is
     * set to one of the four mediums. The Default is "none".<BR>
     * "stardiv.debug.error"="messageBox" | "window" | "file" | "none": The error pipe is
     * set to one of the four mediums. The Default is "none".<BR>
     * "stardiv.debug.warning"="messageBox" | "window" | "file" | "none": The warning pipe is
     * set to one of the four mediums. The Default is "none".<BR>
     * If the properties http.proxyHost, http.proxyPort, http.maxConnections,
     * http.keepAlive or http.nonProxyHosts are changed, the method
     * sun.net.www.http.HttpClient.resetProperties() is called.<BR>
     * If the properties ftpProxySet, ftpProxyHost or ftpProxyPort are changed,
     * the static variables useFtpProxy, ftpProxyHost and ftpProxyPort in the class
     * sun.net.ftp.FtpClient are set.<BR>
     * <B>If you are writing your own SecurityManager and ClassLoader, please implement the
     * interfaces stardiv.security.ClassLoaderExtension and
     * stardiv.security.SecurityManagerExtension. Be shure to set the
     * stardiv.security.ClassLoaderFactory, to enable dynamic class loading, otherwise
     * the stardiv.security.AppletClassLoader is used. Set the factory with
     * SjSettings.setClassLoaderFactory().</B>
     */
    static public synchronized void changeProperties( Properties pChangeProps )
    {
        SecurityManager pSM = System.getSecurityManager();
        if( pSM != null )
            pSM.checkPropertiesAccess();
        Properties props = new Properties( System.getProperties() );
        boolean bInited = Boolean.getBoolean( "stardiv.controller.SjSettings.inited" );


        if( !bInited )
        {
            // check the awt.toolkit property: if none is set use com.sun.star.comp.jawt.peer.Toolkit
            //if ( props.getProperty("awt.toolkit") == null )
            //  props.put("awt.toolkit", "com.sun.star.comp.jawt.peer.Toolkit");

            // Define a number of standard properties
            props.put("acl.read", "+");
            props.put("acl.read.default", "");
            props.put("acl.write", "+");
            props.put("acl.write.default", "");

            // Standard browser properties
            props.put("browser", "stardiv.applet.AppletViewerFrame");
            props.put("browser.version", "4.02");
            props.put("browser.vendor", "Sun Microsystems, Inc.");
            props.put("http.agent", "JDK/1.1");

            // Define which packages can be accessed by applets
            props.put("package.restrict.access.sun", "true");
            props.put("package.restrict.access.netscape", "true");
            props.put("package.restrict.access.stardiv", "true");

            // Define which packages can be extended by applets
            props.put("package.restrict.definition.java", "true");
            props.put("package.restrict.definition.sun", "true");
            props.put("package.restrict.definition.netscape", "true");
            props.put("package.restrict.definition.stardiv", "true");

            // Define which properties can be read by applets.
            // A property named by "key" can be read only when its twin
            // property "key.applet" is true.  The following ten properties
            // are open by default.  Any other property can be explicitly
            // opened up by the browser user setting key.applet=true in
            // ~/.hotjava/properties.   Or vice versa, any of the following can
            // be overridden by the user's properties.
            props.put("java.version.applet", "true");
            props.put("java.vendor.applet", "true");
            props.put("java.vendor.url.applet", "true");
            props.put("java.class.version.applet", "true");
            props.put("os.name.applet", "true");
            props.put("os.version.applet", "true");
            props.put("os.arch.applet", "true");
            props.put("file.separator.applet", "true");
            props.put("path.separator.applet", "true");
            props.put("line.separator.applet", "true");

            // das appletresourceprotokol
            props.put("java.protocol.handler.pkgs", "stardiv.net.protocol");
        }

        // put new and changed properties to the property table
        if( pChangeProps != null )
        {
            Enumeration aEnum = pChangeProps.propertyNames();
            while( aEnum.hasMoreElements() )
            {
                String aKey = (String)aEnum.nextElement();
                props.put( aKey, pChangeProps.getProperty( aKey ) );
            }
        }

        // Install a property list.
        if( !bInited )
            props.put( "stardiv.controller.SjSettings.inited", "true" );
        System.setProperties(props);
        if( !bInited )
        {
            // Security Manager setzten
            boolean bNoExit = Boolean.getBoolean( "stardiv.security.noExit" );
            //Create and install the security manager
            if (System.getSecurityManager() == null)
                System.setSecurityManager(new SandboxSecurity(bNoExit));

            if( Boolean.getBoolean("stardiv.controller.installConsole") )
                Console.installConsole();
        }
    }

    private static boolean equalsImpl( Object p1, Object p2 )
    {
        return p1 == p2 || (p1 != null && p2 != null && p1.equals( p2 ) );
    }
}