/// <summary>
/// Evaulate the path string in relation to the current item
/// </summary>
/// <param name="context">The Revolver context to evaluate the path against</param>
/// <param name="path">The path to evaulate. Can either be absolute or relative</param>
/// <returns>The full sitecore path to the target item</returns>
public static string EvaluatePath(Context context, string path)
{
if (ID.IsID(path))
return path;
string workingPath = string.Empty;
if (!path.StartsWith("/"))
workingPath = context.CurrentItem.Paths.FullPath + "/" + path;
else
workingPath = path;
// Strip any language and version tags
if (workingPath.IndexOf(':') >= 0)
workingPath = workingPath.Substring(0, workingPath.IndexOf(':'));
// Make relative paths absolute
string[] parts = workingPath.Split('/');
StringCollection targetParts = new StringCollection();
targetParts.AddRange(parts);
while (targetParts.Contains(".."))
{
int ind = targetParts.IndexOf("..");
targetParts.RemoveAt(ind);
if (ind > 0)
{
targetParts.RemoveAt(ind - 1);
}
}
if (targetParts[targetParts.Count - 1] == ".")
targetParts.RemoveAt(targetParts.Count - 1);
// Remove empty elements
while (targetParts.Contains(""))
{
targetParts.RemoveAt(targetParts.IndexOf(""));
}
string[] toRet = new string[targetParts.Count];
targetParts.CopyTo(toRet, 0);
return "/" + string.Join("/", toRet);
}