Exemple #1
0
 /// <summary>
 /// Create new instance with given URL
 /// </summary>
 /// <param name="url"></param>
 protected internal Connection(java.net.URL url) : base(url)
 {
     this.url = url;
     this.requestProperties = new java.util.Properties();
     this.addRequestProperty("User-Agent", "Vampire/" + java.lang.SystemJ.getProperty("java.version"));
     this.addRequestProperty("Referer", "http://www.Ritter.biz");
 }
Exemple #2
0
        /// <summary>
        /// Create a new URLConnection for http protocol
        /// </summary>
        /// <param name="u">URL</param>
        /// <returns></returns>
        /// <see cref="java.net.URL"/>
        protected internal override java.net.URLConnection openConnection(java.net.URL u)
        {
            switch (u.getProtocol())
            {
            case "http":
                return(new biz.ritter.net.protocol.http.Connection(u));

            default:
                return(default(java.net.URLConnection));
            }
        }
Exemple #3
0
        /// <summary>
        /// Find the resource with given name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        protected java.net.URL findResource(String name)
        {
            Trace.AutoFlush = true;
            Trace.Indent();
            java.net.URL result = null;

            //Steps:
            // * 1. Look in self assembly...
            // * 2. Locate Directory...
            // * 3. List Directory
            // * 4. Load Assembly
            // * 5. Look for Resource
            // * 6.1 If resource not found - unload
            // * 6.2 If resource found - create URL and return

            System.IO.Stream stream = null;

            // Look simple...
            Trace.TraceInformation("Look simple with LoadResource...");
            // Look in ${JAVAPI_HOME}/lib/endorsed for assemblies
            Trace.TraceInformation("Look in ${JAVAPI_HOME}/lib/endorsed...");
            // Look in sun.boot.class.path specific directories for assemblies
            Trace.TraceInformation("Look in sun.boot.class.path...");
            // Look in JavApi assembly for resource
            Trace.TraceInformation("Look in " + this.GetType().Assembly.FullName);
            stream = this.getStreamFromAssembly(name, this.GetType().Assembly);
            if (null != stream)
            {
                stream.Close();
                result = new java.net.URL("assembly://" + this.GetType().Assembly.GetName() + "/" + name);
            }
            else
            {
                // Look in ${JAVAPI_HOME}/lib/ext path for assemblies
                Trace.TraceInformation("Look in ${JAVAPI_HOME}/lib/ext...");
                // Look in java.ext.dirs specific directories for assemblies
                Trace.TraceInformation("Look in java.ext.dirs...");
                // Look in java.class.path specific directories for assemblies
                Trace.TraceInformation("Look in java.class.path...");
                // Look in run directory for assembles
                Trace.TraceInformation("Look in execution directory...");
            }

            if (result == null)
            {
                Trace.TraceWarning("Resource locating not fully implemented!");
            }

            Trace.TraceInformation("Found resource at " + result.ToString());
            Trace.Unindent();
            return(result);
        }
Exemple #4
0
 /// <summary>
 /// Creates an InputStream for given resource. Resources are define as path with slash separator /.
 /// Returns null if no resource found.
 /// </summary>
 /// <param name="name"></param>
 /// <returns>InputSteam or null</returns>
 public java.io.InputStream getResourceAsStream(String name)
 {
     java.io.InputStream result = null;
     if (null != getParent())
     {
         result = getParent().getResourceAsStream(name);
     }
     if (null == result)
     {
         java.net.URL url = this.findResource(name);
     }
     return(result);
 }
        private static String getPath(String url)
        {
            java.net.URL parsedUrl;
            try {
                parsedUrl = new java.net.URL(url);
            } catch (java.net.MalformedURLException e) {
                //FIXIT: later logging
                //logger.atWarning().log("Malformed URL: \"%s\", replaced with \"/\"", url);
                return("/");
            }
            String path = parsedUrl.getPath();
            String args = parsedUrl.getQuery();

            if (args != null)
            {
                path += "?" + args;
            }

            return(path);
        }
Exemple #6
0
            /*
             * Parse the provider-configuration file as specified
             * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider Configuration File">JAR File Specification</a>
             */
            private java.util.Set <String> parse(java.net.URL u)
            {
                java.io.InputStream    input  = null;
                java.io.BufferedReader reader = null;
                java.util.Set <String> names  = new java.util.HashSet <String>();
                try
                {
                    input  = u.openStream();
                    reader = new java.io.BufferedReader(new java.io.InputStreamReader(input, "utf-8")); //$NON-NLS-1$

                    String line;
                    while ((line = reader.readLine()) != null)
                    {
                        // The comment character is '#' (0x23)
                        // on each line all characters following the first comment character are ignored
                        int sharpIndex = line.indexOf('#');
                        if (sharpIndex >= 0)
                        {
                            line = line.substring(0, sharpIndex);
                        }

                        // Whitespaces are ignored
                        line = line.trim();

                        if (line.length() > 0)
                        {
                            // a java class name, check if identifier correct
                            char[] namechars = line.toCharArray();
                            for (int i = 0; i < namechars.Length; i++)
                            {
                                if (!(java.lang.Character.isJavaIdentifierPart(namechars[i]) || namechars[i] == '.'))
                                {
                                    throw new ServiceConfigurationError(Messages.getString("imageio.99", line));
                                }
                            }
                            names.add(line);
                        }
                    }
                }
                catch (java.io.IOException e)
                {
                    throw new ServiceConfigurationError(e.toString());
                }
                finally
                {
                    try
                    {
                        if (reader != null)
                        {
                            reader.close();
                        }
                        if (input != null)
                        {
                            input.close();
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        throw new ServiceConfigurationError(e.toString());
                    }
                }

                return(names);
            }
Exemple #7
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;
            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home") //$NON-NLS-1$
                    + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                    + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException e)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops = new java.util.Properties();
                        loaded = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException e)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException e)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }
Exemple #8
0
 public java.io.InputStream getResourceAsStream(String name)
 {
     java.net.URL url = getResource(name);
     return(url.openStream());
 }
 public void setURL(int column, java.net.URL url)
 {
     throw new java.sql.SQLFeatureNotSupportedException();
 }
Exemple #10
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;

            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home")                //$NON-NLS-1$
                                              + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                                              + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream   fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            {                                                                                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops     = new java.util.Properties();
                        loaded       = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }