public TemplateGroupDirectory(string dirName, char delimiterStartChar, char delimiterStopChar)
            : base(delimiterStartChar, delimiterStopChar)
        {
            this.groupDirName = dirName;
            try
            {
                if (Directory.Exists(dirName))
                {
                    // we found the directory and it'll be file based
                    root = new Uri(dirName);
                }
                else
                {
                    throw new NotImplementedException();
#if false
                    ClassLoader cl = Thread.CurrentThread.getContextClassLoader();
                    root = cl.getResource(dirName);
                    if (root == null)
                    {
                        cl   = this.GetType().getClassLoader();
                        root = cl.getResource(dirName);
                    }
                    if (root == null)
                    {
                        throw new ArgumentException("No such directory: " + dirName);
                    }
#endif
                }
            }
            catch (Exception e)
            {
                ErrorManager.InternalError(null, "can't Load group dir " + dirName, e);
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void fixInternal() throws Throwable
        public static void fixInternal()
        {
            ClassLoader systemClassLoader = ClassLoader.SystemClassLoader;

            string[] libraries = LibrariesToLoad;

            try
            {
                File folder = new File(System.getProperty("java.io.tmpdir") + "/lwgl-2.9.3/" + System.getProperty("user.name"));
                folder.mkdirs();

                foreach (string library in libraries)
                {
                    URL    libUrl   = systemClassLoader.getResource(library);
                    string basename = FileUtil.getURLBaseName(libUrl);
                    File   outFile  = new File(folder, basename);

                    if (!outFile.exists())
                    {
                        FileUtil.writeBytes(outFile, FileUtil.readURL(libUrl));
                    }
                }

                System.setProperty("org.lwjgl.librarypath", folder.AbsolutePath);
                System.setProperty("net.java.games.input.librarypath", folder.AbsolutePath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
Exemple #3
0
        public static URL getResource(string name, ClassLoader classLoader)
        {
            if (classLoader == null)
            {
                // Try the current Thread context class loader
                classLoader = Thread.CurrentThread.ContextClassLoader;
            }
            URL url = classLoader.getResource(name);

            if (url == null)
            {
                // Finally, try the class loader for this class
                classLoader = typeof(ReflectUtil).ClassLoader;
                url         = classLoader.getResource(name);
            }

            return(url);
        }
Exemple #4
0
        public TemplateGroupFile(string fileName, char delimiterStartChar, char delimiterStopChar)
            : base(delimiterStartChar, delimiterStopChar)
        {
            if (!fileName.EndsWith(".stg"))
            {
                throw new ArgumentException("Group file names must end in .stg: " + fileName);
            }

            try
            {
                //File f = new File(fileName);
                if (File.Exists(fileName))
                {
                    url = new Uri(fileName);
                }
                else
                {
                    throw new NotImplementedException();
#if false
                    // try in classpath
                    ClassLoader cl = Thread.currentThread().getContextClassLoader();
                    url = cl.getResource(fileName);
                    if (url == null)
                    {
                        cl  = this.GetType().getClassLoader();
                        url = cl.getResource(fileName);
                    }
#endif
                }

                if (url == null)
                {
                    throw new ArgumentException("No such group file: " + fileName);
                }
            }
            catch (Exception e)
            {
                ErrorManager.InternalError(null, "can't Load group file " + fileName, e);
            }

            this.fileName = fileName;
        }
Exemple #5
0
        /// <summary>
        /// Returns the <seealso cref="File"/> for a filename.
        /// </summary>
        /// <param name="filename"> the filename to load </param>
        /// <param name="classLoader"> the classLoader to load file with, if null falls back to TCCL and then this class's classloader </param>
        /// <returns> the file object </returns>
        /// <exception cref="IoUtilException"> if the file cannot be loaded </exception>
        public static File getClasspathFile(string filename, ClassLoader classLoader)
        {
            if (string.ReferenceEquals(filename, null))
            {
                throw LOG.nullParameter("filename");
            }

            URL fileUrl = null;

            if (classLoader != null)
            {
                fileUrl = classLoader.getResource(filename);
            }
            if (fileUrl == null)
            {
                // Try the current Thread context classloader
                classLoader = Thread.CurrentThread.ContextClassLoader;
                fileUrl     = classLoader.getResource(filename);

                if (fileUrl == null)
                {
                    // Finally, try the classloader for this class
                    classLoader = typeof(IoUtil).ClassLoader;
                    fileUrl     = classLoader.getResource(filename);
                }
            }

            if (fileUrl == null)
            {
                throw LOG.fileNotFoundException(filename);
            }

            try
            {
                return(new File(fileUrl.toURI()));
            }
            catch (URISyntaxException e)
            {
                throw LOG.fileNotFoundException(filename, e);
            }
        }
        /// <summary>
        /// Creates an instance from a given classpath resource root location, using the given class loader
        /// to find the resource.
        /// <para>
        /// This is designed to handle resource roots which may physically correspond to a directory on
        /// disk, or be located within a jar file.
        ///
        /// </para>
        /// </summary>
        /// <param name="resourceRoot">  the resource root path </param>
        /// <param name="classLoader">  the class loader with which to find the resource </param>
        /// <returns> the market data builder </returns>
        public static ExampleMarketDataBuilder ofResource(string resourceRoot, ClassLoader classLoader)
        {
            // classpath resources are forward-slash separated
            string qualifiedRoot = resourceRoot;

            qualifiedRoot = qualifiedRoot.StartsWith("/", StringComparison.Ordinal) ? qualifiedRoot.Substring(1) : qualifiedRoot;
            qualifiedRoot = qualifiedRoot.StartsWith("\\", StringComparison.Ordinal) ? qualifiedRoot.Substring(1) : qualifiedRoot;
            qualifiedRoot = qualifiedRoot.EndsWith("/", StringComparison.Ordinal) ? qualifiedRoot : qualifiedRoot + "/";
            URL url = classLoader.getResource(qualifiedRoot);

            if (url == null)
            {
                throw new System.ArgumentException(Messages.format("Classpath resource not found: {}", qualifiedRoot));
            }
            if (url.Protocol != null && "jar".Equals(url.Protocol.ToLower(Locale.ENGLISH)))
            {
                // Inside a JAR
                int classSeparatorIdx = url.File.IndexOf("!");
                if (classSeparatorIdx == -1)
                {
                    throw new System.ArgumentException(Messages.format("Unexpected JAR file URL: {}", url));
                }
                string jarPath = StringHelper.SubstringSpecial(url.File, "file:".Length, classSeparatorIdx);
                File   jarFile;
                try
                {
                    jarFile = new File(jarPath);
                }
                catch (Exception e)
                {
                    throw new System.ArgumentException(Messages.format("Unable to create file for JAR: {}", jarPath), e);
                }
                return(new JarMarketDataBuilder(jarFile, resourceRoot));
            }
            else
            {
                // Resource is on disk
                File file;
                try
                {
                    file = new File(url.toURI());
                }
                catch (URISyntaxException e)
                {
                    throw new System.ArgumentException(Messages.format("Unexpected file location: {}", url), e);
                }
                return(new DirectoryMarketDataBuilder(file.toPath()));
            }
        }
Exemple #7
0
        /**
         * Evaluates the callback with 1 arguments.
         *
         * @param env the calling environment
         */
        public QuercusClass loadClass(Env env, string name)
        {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            URL         url    = loader.getResource(_prefix + name + ".php");

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

            string urlStr = url.ToString();

            // for JBoss, #5606
            // XXX: use this for resin and no-resin?
            if (!env.getQuercus().isResin() && urlStr.startsWith("vfs:"))
            {
                try {
                    InputStream @is = url.openStream();

                    try {
                        ReadStream rs = new ReadStream(new VfsStream(@is, null));

                        QuercusPage page = env.getQuercus().parse(rs);

                        page.execute(env);
                    }
                    finally {
                        try {
                            @is.close();
                        }
                        catch (Exception e) {
                        }
                    }
                }
                catch (Exception e) {
                    throw new QuercusException(e);
                }
            }
            else
            {
                string path = env.getPwd().lookup(urlStr);

                env.executePage(path);
            }

            return(env.findClass(name, -1, false, false, false));
        }