APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.xml.internal

public Class SecuritySupport

extends Object
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, java.net.URL, .URLConnection, java.nio.file.Paths, java.security.CodeSource, java.text.MessageFormat, java.util.Locale, .MissingResourceException, .Properties, .ResourceBundle

This class contains utility methods for reading resources in the JAXP packages

Field Summary

Modifier and TypeField and Description
pack-priv static final Properties
cacheProps

Cache for properties in java.home/conf/jaxp.properties

pack-priv static volatile boolean
firstTime

Flag indicating whether java.home/conf/jaxp.properties has been read

public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the name of the protocol if rejected, null otherwise
checkAccess
(String
the Id of the URI
systemId
,
String
a list of allowed protocols separated by comma
allowedProtocols
,
String
keyword to indicate allowing any protocol
accessAny
)

Check the protocol used in the systemId against allowed protocols

public static boolean

Returns:

true if the file exists, false otherwise
doesFileExist
(final File
the specified file
f
)

Checks whether the file exists.

public static ClassLoader

Returns:

the current thread's context class loader, or the system class loader
getClassLoader
()

Returns the current thread's context class loader, or the system class loader if the context class loader is null.

public static String
public static ClassLoader
public static String
getErrorMessage(Locale locale, String bundle, String key, Object[] arguments)

public static FileInputStream

Returns:

the FileInputStream
getFileInputStream
(final File
the specified file
file
)

Creates and returns a new FileInputStream from a file.

public static InputStream

Returns:

the InputStream
getInputStream
(final URLConnection
the URLConnection
uc
)

Returns an InputStream from a URLConnection.

public static <
the type of the property value
T
>
T

Returns:

the value of the property, or the default value if no system property is found
getJAXPSystemProperty
(Class<T>
the type of the property value
type
,
String
the name of the property
propName
,
String
the default value
defValue
)

Reads JAXP system property in this order: system property, $java.home/conf/jaxp.properties if the system property is not specified

public static String

Returns:

the value of the property
getJAXPSystemProperty
(String
the name of the property
propName
)

Reads JAXP system property in this order: system property, $java.home/conf/jaxp.properties if the system property is not specified

public static ClassLoader
public static URL

Returns:

the resource
getResource
(final String
the resource name
name
)

Returns the resource by the name.

public static InputStream

Returns:

the resource stream
getResourceAsStream
(final String
the resource name
name
)

Returns the resource as a stream.

public static InputStream
getResourceAsStream(final ClassLoader cl, final String name)

public static ResourceBundle

Returns:

a resource bundle for the given base name and the default locale
getResourceBundle
(String
the base name of the resource bundle, a fully qualified class name
bundle
)

Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.

public static ResourceBundle

Returns:

a resource bundle for the given base name and locale
getResourceBundle
(final String
the base name of the resource bundle, a fully qualified class name
bundle
,
final Locale
the locale for which a resource bundle is desired
locale
)

Gets a resource bundle using the specified base name and locale, and the caller's class loader.

public static ClassLoader
public static boolean

Returns:

true if it is a directory, false otherwise
isDirectory
(final File
the file to be tested
f
)

Tests whether the file denoted by this abstract pathname is a directory.

public static boolean

Returns:

true if the input is file, false otherwise
isFile
(final File
the file to be tested
f
)

Tests whether the input is file.

public static boolean

Returns:

true if the file exists, false otherwise
isFileExists
(final File
the file to be tested
f
)

Tests whether the file exists.

private static boolean

Returns:

true if the protocol is in the list
isProtocolAllowed
(String
a protocol
protocol
,
String
a list of allowed protocols
allowedProtocols
)

Check if the protocol is in the allowed list of protocols.

public static String

Returns:

the value of the specified property, null if the property is not found
readConfig
(String
the specified property
propName
)

Returns the value of the specified property from the Configuration file.

public static String

Returns:

the value of the specified property, null if the property is not found
readConfig
(String
the specified property
propName
,
boolean
a flag indicating whether to read stax.properties
stax
)

Returns the value of the specified property from the Configuration file.

public static String

Returns:

the file name only
sanitizePath
(String
a URI or file path
input
)

Strips off path from a URI or file path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachePropsback to summary
pack-priv static final Properties cacheProps

Cache for properties in java.home/conf/jaxp.properties

firstTimeback to summary
pack-priv static volatile boolean firstTime

Flag indicating whether java.home/conf/jaxp.properties has been read

NEWLINEback to summary
public static final String NEWLINE

Constructor Detail

SecuritySupportback to summary
private SecuritySupport()

Method Detail

checkAccessback to summary
public static String checkAccess(String systemId, String allowedProtocols, String accessAny) throws IOException

Check the protocol used in the systemId against allowed protocols

Parameters
systemId:String

the Id of the URI

allowedProtocols:String

a list of allowed protocols separated by comma

accessAny:String

keyword to indicate allowing any protocol

Returns:String

the name of the protocol if rejected, null otherwise

doesFileExistback to summary
public static boolean doesFileExist(final File f)

Checks whether the file exists.

Parameters
f:File

the specified file

Returns:boolean

true if the file exists, false otherwise

getClassLoaderback to summary
public static ClassLoader getClassLoader()

Returns the current thread's context class loader, or the system class loader if the context class loader is null.

Returns:ClassLoader

the current thread's context class loader, or the system class loader

getClassSourceback to summary
public static String getClassSource(Class<?> cls)
getContextClassLoaderback to summary
public static ClassLoader getContextClassLoader()
getErrorMessageback to summary
public static String getErrorMessage(Locale locale, String bundle, String key, Object[] arguments)
getFileInputStreamback to summary
public static FileInputStream getFileInputStream(final File file) throws FileNotFoundException

Creates and returns a new FileInputStream from a file.

Parameters
file:File

the specified file

Returns:FileInputStream

the FileInputStream

Exceptions
FileNotFoundException:
if the file is not found
getInputStreamback to summary
public static InputStream getInputStream(final URLConnection uc) throws IOException

Returns an InputStream from a URLConnection.

Parameters
uc:URLConnection

the URLConnection

Returns:InputStream

the InputStream

Exceptions
IOException:
if an I/O error occurs while creating the input stream
getJAXPSystemPropertyback to summary
public static <T> T getJAXPSystemProperty(Class<T> type, String propName, String defValue)

Reads JAXP system property in this order: system property, $java.home/conf/jaxp.properties if the system property is not specified

Parameters
<T>
the type of the property value
type:Class<T>

the type of the property value

propName:String

the name of the property

defValue:String

the default value

Returns:T

the value of the property, or the default value if no system property is found

getJAXPSystemPropertyback to summary
public static String getJAXPSystemProperty(String propName)

Reads JAXP system property in this order: system property, $java.home/conf/jaxp.properties if the system property is not specified

Parameters
propName:String

the name of the property

Returns:String

the value of the property

getParentClassLoaderback to summary
public static ClassLoader getParentClassLoader(final ClassLoader cl)
getResourceback to summary
public static URL getResource(final String name)

Returns the resource by the name.

Parameters
name:String

the resource name

Returns:URL

the resource

getResourceAsStreamback to summary
public static InputStream getResourceAsStream(final String name)

Returns the resource as a stream.

Parameters
name:String

the resource name

Returns:InputStream

the resource stream

getResourceAsStreamback to summary
public static InputStream getResourceAsStream(final ClassLoader cl, final String name)
getResourceBundleback to summary
public static ResourceBundle getResourceBundle(String bundle)

Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.

Parameters
bundle:String

the base name of the resource bundle, a fully qualified class name

Returns:ResourceBundle

a resource bundle for the given base name and the default locale

getResourceBundleback to summary
public static ResourceBundle getResourceBundle(final String bundle, final Locale locale)

Gets a resource bundle using the specified base name and locale, and the caller's class loader.

Parameters
bundle:String

the base name of the resource bundle, a fully qualified class name

locale:Locale

the locale for which a resource bundle is desired

Returns:ResourceBundle

a resource bundle for the given base name and locale

getSystemClassLoaderback to summary
public static ClassLoader getSystemClassLoader()
isDirectoryback to summary
public static boolean isDirectory(final File f)

Tests whether the file denoted by this abstract pathname is a directory.

Parameters
f:File

the file to be tested

Returns:boolean

true if it is a directory, false otherwise

isFileback to summary
public static boolean isFile(final File f)

Tests whether the input is file.

Parameters
f:File

the file to be tested

Returns:boolean

true if the input is file, false otherwise

isFileExistsback to summary
public static boolean isFileExists(final File f)

Tests whether the file exists.

Parameters
f:File

the file to be tested

Returns:boolean

true if the file exists, false otherwise

isProtocolAllowedback to summary
private static boolean isProtocolAllowed(String protocol, String allowedProtocols)

Check if the protocol is in the allowed list of protocols. The check is case-insensitive while ignoring whitespaces.

Parameters
protocol:String

a protocol

allowedProtocols:String

a list of allowed protocols

Returns:boolean

true if the protocol is in the list

readConfigback to summary
public static String readConfig(String propName)

Returns the value of the specified property from the Configuration file. The method reads the System Property "java.xml.config.file" for a custom configuration file, if doesn't exist, falls back to the JDK default that is typically located at $java.home/conf/jaxp.properties.

Parameters
propName:String

the specified property

Returns:String

the value of the specified property, null if the property is not found

readConfigback to summary
public static String readConfig(String propName, boolean stax)

Returns the value of the specified property from the Configuration file. The method reads the JDK default configuration that is typically located at $java.home/conf/jaxp.properties. On top of the default, if the System Property "java.xml.config.file" exists, the configuration file it points to will also be read. Any settings in it will then override those in the default.

Parameters
propName:String

the specified property

stax:boolean

a flag indicating whether to read stax.properties

Returns:String

the value of the specified property, null if the property is not found

sanitizePathback to summary
public static String sanitizePath(String input)

Strips off path from a URI or file path.

Parameters
input:String

a URI or file path

Returns:String

the file name only