コード例 #1
0
        /// <summary>
        /// Specify the dir containing your docx4j properties file
        /// </summary>
        /// <param name="dir"></param>
        public static void setDocx4jPropertiesDir(string dir)
        {
            ILog log = LogManager.GetCurrentClassLogger();

            java.net.URL url = (new java.io.File(dir)).toURL();
            //java.net.URL url = new java.net.URL("file:///C:/Users/jharrop/Documents/Visual%20Studio%202010/Projects/docx4j.NET/docx4j.NET/src/samples/resources/"); // also OK

            java.lang.ClassLoader contextCL = java.lang.Thread.currentThread().getContextClassLoader();
            java.lang.ClassLoader urlCL     = java.net.URLClassLoader.newInstance(new java.net.URL[] { url }, contextCL);
            java.lang.Thread.currentThread().setContextClassLoader(urlCL);

            //java.lang.Class clazz = typeof(org.docx4j.utils.ResourceUtils);
            //java.lang.ClassLoader contextCL = clazz.getClassLoader();
            //log.Warn(contextCL.getClass().getName()); // ikvm.runtime.AssemblyClassLoader
            //ikvm.runtime.AssemblyClassLoader acl = contextCL as ikvm.runtime.AssemblyClassLoader;

            // you can delete the below if the properties file is being found
            if (urlCL.getResource("docx4j.properties") == null)
            {
                log.Warn(url.toString() + " dir does not appear to contain docx4j.properties!");
            }
            else
            {
                log.Info(url.toString() + " dir contains docx4j.properties!");
            }
        }
コード例 #2
0
ファイル: ClassLoader.cs プロジェクト: zhouweiaccp/XobotOS
 /// <summary>Returns the URL of the resource with the specified name.</summary>
 /// <remarks>
 /// Returns the URL of the resource with the specified name. This
 /// implementation first tries to use the parent class loader to find the
 /// resource; if this fails then
 /// <see cref="findResource(string)">findResource(string)</see>
 /// is called to
 /// find the requested resource.
 /// </remarks>
 /// <param name="resName">the name of the resource to find.</param>
 /// <returns>
 /// the
 /// <code>URL</code>
 /// object for the requested resource or
 /// <code>null</code>
 /// if the resource can not be found
 /// </returns>
 /// <seealso cref="Type{T}.getResource(string)">Type&lt;T&gt;.getResource(string)</seealso>
 public virtual java.net.URL getResource(string resName)
 {
     java.net.URL resource = parent.getResource(resName);
     if (resource == null)
     {
         resource = findResource(resName);
     }
     return(resource);
 }
コード例 #3
0
        /// <summary>
        /// Specify the dir containing your docx4j properties file
        /// </summary>
        /// <param name="dir"></param>
        public static void setDocx4jPropertiesDir(string dir)
        {
            ILog log = LogManager.GetCurrentClassLogger();

            java.net.URL url = (new java.io.File(dir)).toURL();
            //java.net.URL url = new java.net.URL("file:///C:/Users/jharrop/Documents/Visual%20Studio%202010/Projects/docx4j.NET/docx4j.NET/src/samples/resources/"); // also OK
            java.lang.ClassLoader contextCL = java.lang.Thread.currentThread().getContextClassLoader();
            java.lang.ClassLoader urlCL     = java.net.URLClassLoader.newInstance(new java.net.URL[] { url }, contextCL);
            java.lang.Thread.currentThread().setContextClassLoader(urlCL);
            // you can delete the below if the properties file is being found
            if (log.IsWarnEnabled && urlCL.getResource("docx4j.properties") == null)
            {
                log.Warn(url.toString() + " dir does not appear to contain docx4j.properties!");
            }
        }