Beispiel #1
0
        ///
        ///	 <summary> * remove any internal "../" "./" and "//" from a url
        ///	 *  </summary>
        ///	 * <param name="url"> the url to clean </param>
        ///	 * <returns> String - the clean path </returns>
        ///
        public static string cleanDots(string url)
        {
            if (url == null)
            {
                return(null);
            }
            string dummy     = url;
            int    posDouble = url.IndexOf("//");
            string prefix    = url.StartsWith("/") ? "/" : "";

            if (posDouble >= 0)
            {
                prefix = url.Substring(0, posDouble + 2);
                dummy  = url.Substring(posDouble + 2);
            }
            VString vs = new VString(StringUtil.tokenize(dummy, "/", false));

            for (int i = vs.Count - 1; i > 0; i--)
            {
                if (vs.stringAt(i).Equals("") || vs.stringAt(i).Equals("."))
                {
                    vs.RemoveAt(i);
                }
            }
            for (int i = vs.Count - 1; i > 0; i--)
            {
                if (vs.stringAt(i).Equals(".."))
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (!vs.stringAt(j).Equals(".."))
                        {
                            vs.RemoveAt(i--);
                            vs.RemoveAt(j);
                            break;
                        }
                    }
                }
            }

            return(prefix + (vs.IsEmpty() ? "." : StringUtil.setvString(vs, "/", null, null)));
        }
Beispiel #2
0
        ///
        ///	 <summary> * fitsCompleteList - tests whether <code>value</code> matches the
        ///	 * AllowedValueList/PresentValueList specified for this State
        ///	 * (ListType=CompleteList)
        ///	 *  </summary>
        ///	 * <param name="value">
        ///	 *            value to test </param>
        ///	 * <param name="list">
        ///	 *            ValueList </param>
        ///	 * <returns> boolean - true, if <code>value</code> matches the ValueList </returns>
        ///
        private bool fitsCompleteList(VString @value, VString list)
        {
            int v_size = @value.Count;
            int l_size = list.Count;

            if (v_size != l_size)
            {
                return(false);
            }

            if (!isUnique(@value))
            {
                return(false);
            }

            VString valueList = new VString(@value);

            bool bFound;

            for (int i = l_size - 1; i >= 0; i--)
            {
                bFound = false;
                for (int j = valueList.Count - 1; j >= 0; j--)
                {
                    if (list[i].Equals(valueList[j]))
                    {
                        valueList.RemoveAt(j);
                        bFound = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #3
0
        ///
        ///	 <summary> * returns the relative URL of a file relative to the current working directory<br>
        ///	 * this includes escaping of %20 etc.
        ///	 *  </summary>
        ///	 * <param name="f"> the file to get the relative path for </param>
        ///	 * <param name="fCWD"> the file that describes cwd, if <code>null</code> cwd is calculated
        ///	 * @return </param>
        ///
        public static string getRelativePath(FileInfo f, FileInfo fCWD)
        {
            FileInfo fCWDLocal = fCWD;

            if (fCWDLocal == null)
            {
                fCWDLocal = new FileInfo(System.Environment.CurrentDirectory);
            }

            string cPath = null;
            string cwd   = null;

            try
            {
                cPath = f.FullName;
                // just in case...
                cwd = fCWDLocal.FullName;
                if (cPath[0] != cwd[0])
                {
                    return(null); // incompatible abs paths
                }
            }
            catch (IOException)
            {
                return(null);
            }
            VString vCwd  = new VString(StringUtil.tokenize(cwd, Path.DirectorySeparatorChar.ToString(), false));
            VString vPath = new VString(StringUtil.tokenize(cPath, Path.DirectorySeparatorChar.ToString(), false));

            int lenPath = vPath.Count;
            int size    = vCwd.Count;

            if (lenPath < size)
            {
                size = lenPath;
            }
            for (int i = 0; i < size; i++)
            {
                if (vCwd.stringAt(0).Equals(vPath.stringAt(0)))
                {
                    vCwd.RemoveAt(0);
                    vPath.RemoveAt(0);
                }
                else
                {
                    break;
                }
            }
            lenPath = vPath.Count;
            size    = vCwd.Count;
            string prefix = (size == 0) ? "." : "..";

            for (int i = 1; i < size; i++)
            {
                prefix += "/..";
            }

            string s = lenPath == 0 ? prefix : StringUtil.setvString(vPath, Path.DirectorySeparatorChar.ToString(), prefix + Path.DirectorySeparatorChar.ToString(), null);

            return(cleanDots(s));
        }