Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        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));
            }
Exemplo n.º 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();
                }
            }
        }