コード例 #1
0
ファイル: CapabilitiesLoader.cs プロジェクト: yonder/mono
        static TextReader GetJavaTextReader(string filename)
        {
            try
            {
                java.lang.ClassLoader cl = (java.lang.ClassLoader)
                                           AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
                if (cl == null)
                {
                    return(null);
                }

                string custom = String.Concat("browscap/", filename);

                java.io.InputStream inputStream = cl.getResourceAsStream(custom);
                if (inputStream == null)
                {
                    inputStream = cl.getResourceAsStream(filename);
                }

                if (inputStream == null)
                {
                    return(null);
                }

                return(new StreamReader(new System.Web.J2EE.J2EEUtils.InputStreamWrapper(inputStream)));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #2
0
        public bool LoadFromFile(string fileName)
        {
            this.fileName = fileName;
            Stream fs = null;

            if (fileName == null || !File.Exists(fileName))
            {
#if TARGET_J2EE
                if (fileName != null && fileName.EndsWith("machine.config"))
                {
                    if (fileName.StartsWith("/"))
                    {
                        fileName = fileName.Substring(1);
                    }
                    java.lang.ClassLoader cl = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
                    if (cl == null)
                    {
                        return(false);
                    }
                    java.io.InputStream inputStream = cl.getResourceAsStream(fileName);
                    fs = (Stream)IOUtils.getStream(inputStream);
                }
                else
#endif
                return(false);
            }

            XmlTextReader reader = null;

            try {
                if (fs == null)
                {
                    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                }
                reader = new XmlTextReader(fs);
                InitRead(reader);
                ReadConfig(reader, false);
            } catch (ConfigurationException) {
                throw;
            } catch (Exception e) {
                throw new ConfigurationException("Error reading " + fileName, e);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(true);
        }
コード例 #3
0
ファイル: WebConfigurationHost.cs プロジェクト: yonder/mono
        public virtual string GetStreamName(string configPath)
        {
            if (configPath == MachinePath)
            {
                if (map == null)
                {
                    return(System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile);
                }
                else
                {
                    return(map.MachineConfigFilename);
                }
            }
            else if (configPath == MachineWebPath)
            {
                string mdir;

                if (map == null)
#if TARGET_J2EE
                {
                    // check META-INF/web.config exists
                    java.lang.ClassLoader cl = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
                    if (cl == null)
                    {
                        return(null);
                    }
                    java.io.InputStream wcs = cl.getResourceAsStream("META-INF/web.config");
                    if (wcs == null)
                    {
                        return(null);
                    }

                    wcs.close();

                    return("/META-INF/web.config");
                }
#else
                { mdir = Path.GetDirectoryName(System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile); }
#endif
                else
                {
                    mdir = Path.GetDirectoryName(map.MachineConfigFilename);
                }

                return(GetWebConfigFileName(mdir));
            }
コード例 #4
0
        protected void SetStringResourcePointer(object stringResourcePointer,
                                                int maxResourceOffset)
        {
            if (GetResourceBytes(this.GetType()) != null)
            {
                return;
            }

            java.lang.Class       c = vmw.common.TypeUtils.ToClass(stringResourcePointer);
            java.lang.ClassLoader contextClassLoader = c.getClassLoader();

            //TODO:move this code to page mapper
            string assemblyName = PageMapper.GetAssemblyResource(Context, VirtualPathUtility.ToAbsolute(AppRelativeVirtualPath));

            if (assemblyName == null)
            {
                throw new HttpException(404, "The requested resource (" + this.AppRelativeVirtualPath + ") is not available.");
            }

            java.io.InputStream inputStream = contextClassLoader.getResourceAsStream(assemblyName);

            System.IO.Stream strim = null;
            if (inputStream == null)
            {
                string descPath = String.Join("/", new string [] { "assemblies", this.GetType().Assembly.GetName().Name, assemblyName });
                try {
                    strim = new StreamReader(HttpContext.Current.Request.MapPath("/" + descPath)).BaseStream;
                }
                catch (Exception ex) {
                    throw new System.IO.IOException("couldn't open resource file:" + assemblyName, ex);
                }
                if (strim == null)
                {
                    throw new System.IO.IOException("couldn't open resource file:" + assemblyName);
                }
            }

            try {
                if (strim == null)
                {
                    strim = (System.IO.Stream)vmw.common.IOUtils.getStream(inputStream);
                }
                int     capacity      = (int)strim.Length;
                byte [] resourceBytes = new byte [capacity];
                strim.Read(resourceBytes, 0, capacity);
                SetResourceBytes(this.GetType(), resourceBytes);
            }
            catch (Exception e) {
                throw new HttpException("problem with dll.ghres file", e);
            }
            finally {
                if (strim != null)
                {
                    strim.Close();
                }
                if (inputStream != null)
                {
                    inputStream.close();
                }
            }
        }