~ubuntu-branches/ubuntu/gutsy/libjaxp1.3-java/gutsy

« back to all changes in this revision

Viewing changes to org/xml/sax/helpers/SecuritySupport12.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-08-03 10:30:58 UTC
  • Revision ID: james.westby@ubuntu.com-20060803103058-7jwwiqv9g8w9094d
Tags: upstream-1.3.03
ImportĀ upstreamĀ versionĀ 1.3.03

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002-2005 The Apache Software Foundation.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package org.xml.sax.helpers;
 
18
 
 
19
import java.io.File;
 
20
import java.io.FileInputStream;
 
21
import java.io.FileNotFoundException;
 
22
import java.io.InputStream;
 
23
import java.security.AccessController;
 
24
import java.security.PrivilegedAction;
 
25
import java.security.PrivilegedActionException;
 
26
import java.security.PrivilegedExceptionAction;
 
27
 
 
28
/**
 
29
 * This class is duplicated for each JAXP subpackage so keep it in sync.
 
30
 * It is package private and therefore is not exposed as part of the JAXP
 
31
 * API.
 
32
 *
 
33
 * Security related methods that only work on J2SE 1.2 and newer.
 
34
 */
 
35
class SecuritySupport12 extends SecuritySupport {
 
36
 
 
37
    public ClassLoader getContextClassLoader() {
 
38
        return (ClassLoader)
 
39
                AccessController.doPrivileged(new PrivilegedAction() {
 
40
            public Object run() {
 
41
                ClassLoader cl = null;
 
42
                try {
 
43
                    cl = Thread.currentThread().getContextClassLoader();
 
44
                } catch (SecurityException ex) { }
 
45
                return cl;
 
46
            }
 
47
        });
 
48
    }
 
49
 
 
50
    public String getSystemProperty(final String propName) {
 
51
        return (String)
 
52
            AccessController.doPrivileged(new PrivilegedAction() {
 
53
                public Object run() {
 
54
                    return System.getProperty(propName);
 
55
                }
 
56
            });
 
57
    }
 
58
 
 
59
    public FileInputStream getFileInputStream(final File file)
 
60
        throws FileNotFoundException
 
61
    {
 
62
        try {
 
63
            return (FileInputStream)
 
64
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
 
65
                    public Object run() throws FileNotFoundException {
 
66
                        return new FileInputStream(file);
 
67
                    }
 
68
                });
 
69
        } catch (PrivilegedActionException e) {
 
70
            throw (FileNotFoundException)e.getException();
 
71
        }
 
72
    }
 
73
 
 
74
    public InputStream getResourceAsStream(final ClassLoader cl,
 
75
                                           final String name)
 
76
    {
 
77
        return (InputStream)
 
78
            AccessController.doPrivileged(new PrivilegedAction() {
 
79
                public Object run() {
 
80
                    InputStream ris;
 
81
                    if (cl == null) {
 
82
                        ris = ClassLoader.getSystemResourceAsStream(name);
 
83
                    } else {
 
84
                        ris = cl.getResourceAsStream(name);
 
85
                    }
 
86
                    return ris;
 
87
                }
 
88
            });
 
89
    }
 
90
}