Java Code Examples for com.sun.org.apache.xalan.internal.utils.SecuritySupport#getSystemProperty()

The following examples show how to use com.sun.org.apache.xalan.internal.utils.SecuritySupport#getSystemProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Encodings.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 2
Source File: Encodings.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 3
Source File: TemplatesImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    is.defaultReadObject();
    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 4
Source File: Encodings.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 5
Source File: Encodings.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 6
Source File: Encodings.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 7
Source File: Encodings.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
    String urlString = null;
    InputStream is = null;

    try {
        urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
    } catch (SecurityException e) {
    }

    if (urlString != null && urlString.length() > 0) {
        URL url = new URL(urlString);
        is = url.openStream();
    }

    if (is == null) {
        is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
    }
    return is;
}
 
Example 8
Source File: TemplatesImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    is.defaultReadObject();
    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 9
Source File: XalanConstants.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isJavaVersionAtLeast(int compareTo) {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");
    String versions[] = javaVersion.split("\\.", 3);
    if (Integer.parseInt(versions[0]) >= compareTo ||
        Integer.parseInt(versions[1]) >= compareTo) {
        return true;
    }
    return false;
}
 
Example 10
Source File: TemplatesImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
@SuppressWarnings("unchecked")
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = is.readFields();
    _name = (String)gf.get("_name", null);
    _bytecodes = (byte[][])gf.get("_bytecodes", null);
    _class = (Class[])gf.get("_class", null);
    _transletIndex = gf.get("_transletIndex", -1);

    _outputProperties = (Properties)gf.get("_outputProperties", null);
    _indentNumber = gf.get("_indentNumber", 0);

    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 11
Source File: XalanConstants.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isJavaVersionAtLeast(int compareTo) {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");
    String versions[] = javaVersion.split("\\.", 3);
    if (Integer.parseInt(versions[0]) >= compareTo ||
        Integer.parseInt(versions[1]) >= compareTo) {
        return true;
    }
    return false;
}
 
Example 12
Source File: TemplatesImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
@SuppressWarnings("unchecked")
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = is.readFields();
    _name = (String)gf.get("_name", null);
    _bytecodes = (byte[][])gf.get("_bytecodes", null);
    _class = (Class[])gf.get("_class", null);
    _transletIndex = gf.get("_transletIndex", -1);

    _outputProperties = (Properties)gf.get("_outputProperties", null);
    _indentNumber = gf.get("_indentNumber", 0);

    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 13
Source File: TemplatesImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
@SuppressWarnings("unchecked")
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = is.readFields();
    _name = (String)gf.get("_name", null);
    _bytecodes = (byte[][])gf.get("_bytecodes", null);
    _class = (Class[])gf.get("_class", null);
    _transletIndex = gf.get("_transletIndex", -1);

    _outputProperties = (Properties)gf.get("_outputProperties", null);
    _indentNumber = gf.get("_indentNumber", 0);

    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 14
Source File: XalanConstants.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isJavaVersionAtLeast(int compareTo) {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");
    String versions[] = javaVersion.split("\\.", 3);
    if (Integer.parseInt(versions[0]) >= compareTo ||
        Integer.parseInt(versions[1]) >= compareTo) {
        return true;
    }
    return false;
}
 
Example 15
Source File: TemplatesImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Overrides the default readObject implementation since we decided
 *  it would be cleaner not to serialize the entire tranformer
 *  factory.  [ ref bugzilla 12317 ]
 *  We need to check if the user defined class for URIResolver also
 *  implemented Serializable
 *  if yes then we need to deserialize the URIResolver
 *  Fix for bugzilla bug 22438
 */
@SuppressWarnings("unchecked")
private void  readObject(ObjectInputStream is)
  throws IOException, ClassNotFoundException
{
    SecurityManager security = System.getSecurityManager();
    if (security != null){
        String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
        if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
            throw new UnsupportedOperationException(err.toString());
        }
    }

    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = is.readFields();
    _name = (String)gf.get("_name", null);
    _bytecodes = (byte[][])gf.get("_bytecodes", null);
    _class = (Class[])gf.get("_class", null);
    _transletIndex = gf.get("_transletIndex", -1);

    _outputProperties = (Properties)gf.get("_outputProperties", null);
    _indentNumber = gf.get("_indentNumber", 0);

    if (is.readBoolean()) {
        _uriResolver = (URIResolver) is.readObject();
    }

    _tfactory = new TransformerFactoryImpl();
}
 
Example 16
Source File: XalanConstants.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isJavaVersionAtLeast(int compareTo) {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");
    String versions[] = javaVersion.split("\\.", 3);
    if (Integer.parseInt(versions[0]) >= compareTo ||
        Integer.parseInt(versions[1]) >= compareTo) {
        return true;
    }
    return false;
}
 
Example 17
Source File: Encodings.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the proper mime encoding.  From the XSLT recommendation: "The encoding
 * attribute specifies the preferred encoding to use for outputting the result
 * tree. XSLT processors are required to respect values of UTF-8 and UTF-16.
 * For other values, if the XSLT processor does not support the specified
 * encoding it may signal an error; if it does not signal an error it should
 * use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding
 * whose name does not match the EncName production of the XML Recommendation
 * [XML]. If no encoding attribute is specified, then the XSLT processor should
 * use either UTF-8 or UTF-16."
 *
 * @param encoding Reference to java-style encoding string, which may be null,
 * in which case a default will be found.
 *
 * @return The ISO-style encoding string, or null if failure.
 */
static String getMimeEncoding(String encoding)
{

    if (null == encoding)
    {
        try
        {

            // Get the default system character encoding.  This may be
            // incorrect if they passed in a writer, but right now there
            // seems to be no way to get the encoding from a writer.
            encoding = SecuritySupport.getSystemProperty("file.encoding", "UTF8");

            if (null != encoding)
            {

                /*
                * See if the mime type is equal to UTF8.  If you don't
                * do that, then  convertJava2MimeEncoding will convert
                * 8859_1 to "ISO-8859-1", which is not what we want,
                * I think, and I don't think I want to alter the tables
                * to convert everything to UTF-8.
                */
                String jencoding =
                    (encoding.equalsIgnoreCase("Cp1252")
                        || encoding.equalsIgnoreCase("ISO8859_1")
                        || encoding.equalsIgnoreCase("8859_1")
                        || encoding.equalsIgnoreCase("UTF8"))
                        ? DEFAULT_MIME_ENCODING
                        : convertJava2MimeEncoding(encoding);

                encoding =
                    (null != jencoding) ? jencoding : DEFAULT_MIME_ENCODING;
            }
            else
            {
                encoding = DEFAULT_MIME_ENCODING;
            }
        }
        catch (SecurityException se)
        {
            encoding = DEFAULT_MIME_ENCODING;
        }
    }
    else
    {
        encoding = convertJava2MimeEncoding(encoding);
    }

    return encoding;
}
 
Example 18
Source File: Encodings.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the proper mime encoding.  From the XSLT recommendation: "The encoding
 * attribute specifies the preferred encoding to use for outputting the result
 * tree. XSLT processors are required to respect values of UTF-8 and UTF-16.
 * For other values, if the XSLT processor does not support the specified
 * encoding it may signal an error; if it does not signal an error it should
 * use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding
 * whose name does not match the EncName production of the XML Recommendation
 * [XML]. If no encoding attribute is specified, then the XSLT processor should
 * use either UTF-8 or UTF-16."
 *
 * @param encoding Reference to java-style encoding string, which may be null,
 * in which case a default will be found.
 *
 * @return The ISO-style encoding string, or null if failure.
 */
static String getMimeEncoding(String encoding)
{

    if (null == encoding)
    {
        try
        {

            // Get the default system character encoding.  This may be
            // incorrect if they passed in a writer, but right now there
            // seems to be no way to get the encoding from a writer.
            encoding = SecuritySupport.getSystemProperty("file.encoding", "UTF8");

            if (null != encoding)
            {

                /*
                * See if the mime type is equal to UTF8.  If you don't
                * do that, then  convertJava2MimeEncoding will convert
                * 8859_1 to "ISO-8859-1", which is not what we want,
                * I think, and I don't think I want to alter the tables
                * to convert everything to UTF-8.
                */
                String jencoding =
                    (encoding.equalsIgnoreCase("Cp1252")
                        || encoding.equalsIgnoreCase("ISO8859_1")
                        || encoding.equalsIgnoreCase("8859_1")
                        || encoding.equalsIgnoreCase("UTF8"))
                        ? DEFAULT_MIME_ENCODING
                        : convertJava2MimeEncoding(encoding);

                encoding =
                    (null != jencoding) ? jencoding : DEFAULT_MIME_ENCODING;
            }
            else
            {
                encoding = DEFAULT_MIME_ENCODING;
            }
        }
        catch (SecurityException se)
        {
            encoding = DEFAULT_MIME_ENCODING;
        }
    }
    else
    {
        encoding = convertJava2MimeEncoding(encoding);
    }

    return encoding;
}
 
Example 19
Source File: EnvironmentCheck.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Fillin hash with info about SystemProperties.
 *
 * Logs java.class.path and other likely paths; then attempts
 * to search those paths for .jar files with Xalan-related classes.
 *
 * //@todo NOTE: We don't actually search java.ext.dirs for
 * //  *.jar files therein! This should be updated
 *
 * @param h Map to put information in
 * @see #jarNames
 * @see #checkPathForJars(String, String[])
 */
protected void checkSystemProperties(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  // Grab java version for later use
  try
  {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");

    h.put("java.version", javaVersion);
  }
  catch (SecurityException se)
  {

    // For applet context, etc.
    h.put(
      "java.version",
      "WARNING: SecurityException thrown accessing system version properties");
  }

  // Printout jar files on classpath(s) that may affect operation
  //  Do this in order
  try
  {

    // This is present in all JVM's
    String cp = SecuritySupport.getSystemProperty("java.class.path");

    h.put("java.class.path", cp);

    List<Map> classpathJars = checkPathForJars(cp, jarNames);

    if (null != classpathJars) {
        h.put(FOUNDCLASSES + "java.class.path", classpathJars);
    }

    // Also check for JDK 1.2+ type classpaths
    String othercp = SecuritySupport.getSystemProperty("sun.boot.class.path");

    if (null != othercp) {
        h.put("sun.boot.class.path", othercp);
        classpathJars = checkPathForJars(othercp, jarNames);

        if (null != classpathJars) {
            h.put(FOUNDCLASSES + "sun.boot.class.path", classpathJars);
        }
    }

    //@todo NOTE: We don't actually search java.ext.dirs for
    //  *.jar files therein! This should be updated
    othercp = SecuritySupport.getSystemProperty("java.ext.dirs");

    if (null != othercp)
    {
      h.put("java.ext.dirs", othercp);

      classpathJars = checkPathForJars(othercp, jarNames);

      if (null != classpathJars)
        h.put(FOUNDCLASSES + "java.ext.dirs", classpathJars);
    }

    //@todo also check other System properties' paths?
    //  v2 = checkPathForJars(System.getProperty("sun.boot.library.path"), jarNames);   // ?? may not be needed
    //  v3 = checkPathForJars(System.getProperty("java.library.path"), jarNames);   // ?? may not be needed
  }
  catch (SecurityException se2)
  {
    // For applet context, etc.
    h.put(
      "java.class.path",
      "WARNING: SecurityException thrown accessing system classpath properties");
  }
}
 
Example 20
Source File: EnvironmentCheck.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Fillin hash with info about SystemProperties.
 *
 * Logs java.class.path and other likely paths; then attempts
 * to search those paths for .jar files with Xalan-related classes.
 *
 * //@todo NOTE: We don't actually search java.ext.dirs for
 * //  *.jar files therein! This should be updated
 *
 * @param h Map to put information in
 * @see #jarNames
 * @see #checkPathForJars(String, String[])
 */
protected void checkSystemProperties(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  // Grab java version for later use
  try
  {
    String javaVersion = SecuritySupport.getSystemProperty("java.version");

    h.put("java.version", javaVersion);
  }
  catch (SecurityException se)
  {

    // For applet context, etc.
    h.put(
      "java.version",
      "WARNING: SecurityException thrown accessing system version properties");
  }

  // Printout jar files on classpath(s) that may affect operation
  //  Do this in order
  try
  {

    // This is present in all JVM's
    String cp = SecuritySupport.getSystemProperty("java.class.path");

    h.put("java.class.path", cp);

    List<Map> classpathJars = checkPathForJars(cp, jarNames);

    if (null != classpathJars) {
        h.put(FOUNDCLASSES + "java.class.path", classpathJars);
    }

    // Also check for JDK 1.2+ type classpaths
    String othercp = SecuritySupport.getSystemProperty("sun.boot.class.path");

    if (null != othercp) {
        h.put("sun.boot.class.path", othercp);
        classpathJars = checkPathForJars(othercp, jarNames);

        if (null != classpathJars) {
            h.put(FOUNDCLASSES + "sun.boot.class.path", classpathJars);
        }
    }

    //@todo NOTE: We don't actually search java.ext.dirs for
    //  *.jar files therein! This should be updated
    othercp = SecuritySupport.getSystemProperty("java.ext.dirs");

    if (null != othercp)
    {
      h.put("java.ext.dirs", othercp);

      classpathJars = checkPathForJars(othercp, jarNames);

      if (null != classpathJars)
        h.put(FOUNDCLASSES + "java.ext.dirs", classpathJars);
    }

    //@todo also check other System properties' paths?
    //  v2 = checkPathForJars(System.getProperty("sun.boot.library.path"), jarNames);   // ?? may not be needed
    //  v3 = checkPathForJars(System.getProperty("java.library.path"), jarNames);   // ?? may not be needed
  }
  catch (SecurityException se2)
  {
    // For applet context, etc.
    h.put(
      "java.class.path",
      "WARNING: SecurityException thrown accessing system classpath properties");
  }
}