Author: kostat
Date: 2006-12-20 12:24:30 -0500 (Wed, 20 Dec 2006)
New Revision: 69822

Modified:
   trunk/mcs/class/System.Web/System.Web.J2EE/BaseHttpServlet.cs
Log:
add ability to initialize DataDirectory from init parameter; read root folder 
from /WEB-INF/classes/appData.properties properties file

Modified: trunk/mcs/class/System.Web/System.Web.J2EE/BaseHttpServlet.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.J2EE/BaseHttpServlet.cs       
2006-12-20 17:22:36 UTC (rev 69821)
+++ trunk/mcs/class/System.Web/System.Web.J2EE/BaseHttpServlet.cs       
2006-12-20 17:24:30 UTC (rev 69822)
@@ -36,6 +36,7 @@
 using javax.servlet;
 using javax.servlet.http;
 using vmw.common;
+using java.util;
 
 namespace System.Web.J2EE
 {
@@ -187,15 +188,35 @@
                                
servletDomain.SetData(IAppDomainConfig.WEB_APP_DIR, rootPath);
 
                                //Set DataDirectory substitution string 
(http://blogs.msdn.com/dataaccess/archive/2005/10/28/486273.aspx)
-                               string realPath = config.getServletContext 
().getRealPath ("/");
-                               if (realPath == null)
-                                       realPath = String.Empty;
-                               string dataDirectory = Path.Combine (realPath, 
"App_Data");
-                               dataDirectory = dataDirectory.Replace ('\\', 
'/');
+                               string dataDirectory = 
config.getServletContext().getInitParameter ("DataDirectory");
+                               if (dataDirectory == null)
+                                       dataDirectory = "APP_DATA";
 
-                               if (dataDirectory [dataDirectory.Length - 1] != 
'/')
-                                       dataDirectory += "/";
+                               if (!Path.IsPathRooted (dataDirectory)) {
+                                       java.io.InputStream inputStream = 
config.getServletContext ().getResourceAsStream 
("/WEB-INF/classes/appData.properties");
+                                       string root;
+                                       if (inputStream != null) {
+                                               try {
+                                                       Properties props = new 
Properties ();
+                                                       props.load 
(inputStream);
+                                                       root = 
props.getProperty ("root.folder");
+                                               }
+                                               finally {
+                                                       inputStream.close ();
+                                               }
+                                       }
+                                       else
+                                               root = config.getServletContext 
().getRealPath ("/");
 
+                                       if (root == null)
+                                               root = String.Empty;
+
+                                       dataDirectory = Path.Combine (root, 
dataDirectory);
+                               }
+
+                               if (dataDirectory [dataDirectory.Length - 1] != 
Path.DirectorySeparatorChar)
+                                       dataDirectory += 
Path.DirectorySeparatorChar;
+
                                servletDomain.SetData ("DataDirectory", 
dataDirectory);
 
                                // The BaseDir is the full path to the physical 
dir of the app

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to