You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2005/05/25 20:39:12 UTC
svn commit: r178506 -
/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs
/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs
Author: gbayon
Date: Wed May 25 11:39:11 2005
New Revision: 178506
URL: http://svn.apache.org/viewcvs?rev=178506&view=rev
Log:
- Added fixed for JIRA-71
Modified:
incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs?rev=178506&r1=178505&r2=178506&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ResourcesTest.cs Wed May 25 11:39:11 2005
@@ -1,8 +1,6 @@
-using System;
+using System.IO;
using System.Xml;
-
using IBatisNet.Common.Utilities;
-
using NUnit.Framework;
namespace IBatisNet.Common.Test.NUnit.CommonTests.Utilities
@@ -51,8 +49,100 @@
Assert.AreEqual(doc.ChildNodes.Count,2);
Assert.AreEqual(doc.SelectNodes("/settings/add").Count, 4);
}
-
#endregion
+ #region GetFileInfo Tests
+
+ [Test]
+ public void GetFileInfoWithAbsolute()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo(Resources.ApplicationBase+Path.DirectorySeparatorChar+"IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+
+ [Test]
+ public void GetFileInfoWithRelative()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo("IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+
+ [Test]
+ public void GetFileInfoWithRelativeProtocole()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo("file://IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+
+ [Test]
+ public void GetFileInfoWithAbsoluteProtocole()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo("file://"+Resources.ApplicationBase+Path.DirectorySeparatorChar+"IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+
+ [Test]
+ public void GetFileInfoWithRelativeProtocolePlusSlash()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo("file:///IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+
+
+
+ [Test]
+ public void GetFileInfoWithAbsoluteProtocolePlusSlash()
+ {
+ FileInfo fileInfo = Resources.GetFileInfo("file:///"+Resources.ApplicationBase+Path.DirectorySeparatorChar+"IBatisNet.Common.Test.dll");
+ Assert.IsNotNull(fileInfo);
+ }
+ #endregion
+
+ #region GetConfigAsXmlDocument Tests
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithAbsolute()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument(Resources.ApplicationBase+Path.DirectorySeparatorChar+"SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithRelative()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument("SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithRelativeProtocole()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument("file://SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithAbsoluteProtocole()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument("file://"+Resources.ApplicationBase+Path.DirectorySeparatorChar+"SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithRelativeProtocolePlusSlash()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument("file:///SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+
+
+
+ [Test]
+ public void GetConfigAsXmlDocumentWithAbsoluteProtocolePlusSlash()
+ {
+ XmlDocument doc = Resources.GetConfigAsXmlDocument("file:///"+Resources.ApplicationBase+Path.DirectorySeparatorChar+"SqlMap_MSSQL_SqlClient.config");
+ Assert.IsNotNull(doc);
+ }
+ #endregion
}
}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs?rev=178506&r1=178505&r2=178506&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Resources.cs Wed May 25 11:39:11 2005
@@ -97,6 +97,37 @@
#region Methods
/// <summary>
+ /// Protocole separator
+ /// </summary>
+ public const string PROTOCOL_SEPARATOR = "://";
+
+ /// <summary>
+ /// Strips protocol name from the resource name
+ /// </summary>
+ /// <param name="filePath">Name of the resource</param>
+ /// <returns>Name of the resource without protocol name</returns>
+ public static string GetFileSystemResourceWithoutProtocol(string filePath)
+ {
+ int pos = filePath.IndexOf(PROTOCOL_SEPARATOR);
+ if (pos == -1)
+ {
+ return filePath;
+ }
+ else
+ {
+ // skip forward slashes after protocol name, if any
+ if (filePath.Length > pos + PROTOCOL_SEPARATOR.Length)
+ {
+ while (filePath[++pos] == '/')
+ {
+ ;
+ }
+ }
+ return filePath.Substring(pos);
+ }
+ }
+
+ /// <summary>
/// Get config file from from the base directory that the assembler
/// used for probe assemblies
/// </summary>
@@ -106,17 +137,16 @@
{
XmlDocument config = new XmlDocument();
XmlTextReader reader = null;
+ filePath = GetFileSystemResourceWithoutProtocol(filePath);
+ if (!Resources.FileExists(filePath))
+ {
+ filePath = Path.Combine(_baseDirectory, filePath);
+ }
+
try
{
- if (Resources.FileExists(filePath))
- {
- reader = new XmlTextReader( filePath );
- }
- else
- {
- reader = new XmlTextReader(Path.Combine(_baseDirectory, filePath));
- }
+ reader = new XmlTextReader( filePath );
config.Load(reader);
}
catch(Exception e)
@@ -158,7 +188,16 @@
// to read the specified file,
// no exception is thrown and the method returns false regardless of the existence of path.
// So we check permissiion and throw an exception if no permission
- FileIOPermission filePermission = new FileIOPermission(FileIOPermissionAccess.Read, filePath);
+ FileIOPermission filePermission = null;
+ try
+ {
+ // filePath must be the absolute path of the file.
+ filePermission = new FileIOPermission(FileIOPermissionAccess.Read, filePath);
+ }
+ catch
+ {
+ return false;
+ }
try
{
filePermission.Demand();
@@ -393,21 +432,18 @@
/// <returns>return a FileInfo</returns>
public static FileInfo GetFileInfo(string filePath)
{
- string file = string.Empty;
FileInfo fileInfo = null;
+ filePath = GetFileSystemResourceWithoutProtocol(filePath);
- if (Resources.FileExists(filePath))
- {
- file = filePath;
- }
- else
+ if ( !Resources.FileExists(filePath))
{
- file = Path.Combine(_applicationBase, filePath);
+ filePath = Path.Combine(_applicationBase, filePath);
}
try
{
- fileInfo = new FileInfo(file);
+ //argument : The fully qualified name of the new file, or the relative file name.
+ fileInfo = new FileInfo(filePath);
}
catch(Exception e)
{