Exemplo n.º 1
0
        ///<summary>
        /// This function returns the whole matching path which you have
        /// followed to reach the PrefixPhrase.
        ///</summary>
        public void getMatchingPhrase(StringBuilder buffy, String purl, char seperator)
        {
            String returnValue    = "";
            int    seperatorIndex = purl.IndexOf(seperator);

            if (seperatorIndex > 0)
            {
                String           key               = purl.Substring(0, seperatorIndex);
                String           phrase            = purl.Substring(seperatorIndex + 1, purl.Length - (seperatorIndex + 1));
                PrefixPhrase <O> childPrefixPhrase = childPhraseMap.Get(key);

                // now handled inside ChildPrefixMap
                //			if(childPrefixPhrase==null)
                //			{
                //				// try getting it using wildcard as key
                //				childPrefixPhrase = childPhraseMap.get("*");
                //				key="*";
                //			}

                if (childPrefixPhrase != null)
                {
                    buffy.Append(returnValue).Append(key).Append(seperator);
                    buffy.Append(childPrefixPhrase.GetMatchingPhrase(phrase, seperator));
                }
            }
        }
Exemplo n.º 2
0
        ///<summary>
        ///For put, checks to see if String key is WILDCARD.
        ///If so, sets special wildcardMatch slot instead of adding to HashMap.
        ///</summary>
        public new PrefixPhrase <O> Add(String key, PrefixPhrase <O> value)
        {
            PrefixPhrase <O> result;

            if (WILDCARD.Equals(key))
            {
                result        = wildcardMatch;
                wildcardMatch = value;
                return(result);
            }

            TryGetValue(key, out result);
            if (result == null)
            {
                base.Add(key, value);
                result = value;
            }
            else
            {
                base.Remove(key);
                base.Add(key, value);
            }

            return(result);
        }
Exemplo n.º 3
0
        public bool Match(ParsedUri purl)
        {
            String host = purl.Host;
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = LookupChild(host);

            // children of hostPrefix
            return((hostPrefix == null) ? false : hostPrefix.Match(purl.LocalPath, separator));       //edit
        }
Exemplo n.º 4
0
        public PrefixPhrase <O> getMatchingPrefix(ParsedUri purl)
        {
            String host = purl.Host;
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = LookupChild(host);

            // children of hostPrefix
            String path = purl.AbsolutePath;

            return((hostPrefix == null) ? null : hostPrefix.GetMatchingPrefix(path, 1, separator));             // skip over starting '/'
        }
Exemplo n.º 5
0
        public PrefixPhrase <O> Add(ParsedUri purl)
        {
            String host = purl.Host;        //edit
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = GetPrefix(null, host);

            // children of hostPrefix
            String pathStringToParse = usePathFile ? purl.ToString() : purl.LocalPath;        //.pathDirectoryString;

            return((hostPrefix != null) ? hostPrefix.Add(pathStringToParse, separator) : LookupChild(host));
        }
Exemplo n.º 6
0
        /**
         * Seek the PrefixPhrase corresponding to the argument.
         * If it does not exist, return it.
         * <p/>
         * If it does exist, does it have 0 children?
         *      If so, return null. No need to insert for the argument's phrase.
         *      If not, return it.
         *
         * @param prefixPhrase
         * @return
         */
        protected PrefixPhrase <O> GetPrefix(PrefixPhrase <O> parent, String prefixPhrase)
        {
            PrefixPhrase <O> preexistingPrefix = childPhraseMap.Get(prefixPhrase);              // will match wildcard specially, if this is called for
            bool             createNew         = false;

            if (preexistingPrefix == null)
            {
                preexistingPrefix = new PrefixPhrase <O>(parent, prefixPhrase);
                childPhraseMap.Add(prefixPhrase, preexistingPrefix);
                createNew = true;
            }
            if (!createNew && preexistingPrefix.IsTerminal())
            {
                return(null);
            }

            return(preexistingPrefix);
        }
Exemplo n.º 7
0
        public PrefixPhrase <O> GetMatchingPrefix(String input, int start, char seperator)
        {
            if (IsTerminal())
            {
                return(this);
            }
            int seperatorIndex = input.IndexOf(seperator, start);

            if (seperatorIndex > 0)
            {
                String           key = input.Substring(start, seperatorIndex - start);
                PrefixPhrase <O> childPrefixPhrase = childPhraseMap.Get(key);
                if (childPrefixPhrase != null)
                {
                    return((seperatorIndex < input.Length) ? childPrefixPhrase.GetMatchingPrefix(input, seperatorIndex + 1, seperator) : this);
                }
            }
            return(null);
        }
Exemplo n.º 8
0
        /**
         * Match child prefix by iterating, instead of using HashMap, to avoid allocating substring keys.
         *
         * @param source	String to get key from.
         * @param start		start of substring for key in string
         * @param end		end of substring for key in string
         *
         * @return			Matching PrefixPhrase for the substring key from source, or null if there is no match.
         */
        private PrefixPhrase <O> MatchChild(String source, int start, int end)
        {
            // FIXME concurrent modification exception :-(
            PrefixPhrase <O> wildcardPhrase = childPhraseMap.WildcardMatch;

            if (wildcardPhrase != null)
            {
                return(wildcardPhrase);
            }

            foreach (String thatPhrase in childPhraseMap.Keys)
            {
                if (Match(thatPhrase, source, start, end))
                {
                    return(childPhraseMap.Get(thatPhrase));
                }
            }
            return(null);
        }
Exemplo n.º 9
0
        protected bool Match(String str, int start, char separator)
        {
            if (IsTerminal())
            {
                return(true);
            }

            int  end       = str.Length;
            bool terminate = false;

            if (start == end)
            {
                terminate = true;
            }
            else
            {
                if (str[start] == separator)
                {
                    start++;
                }
                if (start == end)
                {
                    terminate = true;
                }
            }
            if (terminate)
            {
                return(false);
            }

            int nextSeparator = str.IndexOf(separator, start);

            if (nextSeparator == -1)
            {
                nextSeparator = end;
            }

            //		String phraseString	= string.substring(start, nextSeparator);
            //		PrefixPhrase nextPrefixPhrase	= lookupChild(phraseString);
            PrefixPhrase <O> nextPrefixPhrase = MatchChild(str, start, nextSeparator);

            return((nextPrefixPhrase != null) && nextPrefixPhrase.Match(str, nextSeparator, separator));
        }
Exemplo n.º 10
0
        protected PrefixPhrase <O> Add(String str, int start, char separator)
        {
            int  end       = str.Length;
            bool terminate = false;

            if (start == end)
            {
                terminate = true;
            }
            else
            {
                if (str[start] == separator)
                {
                    start++;
                }
                if (start == end)
                {
                    terminate = true;
                }
            }
            if (terminate)
            {
                Clear();
                return(this);
            }
            int nextSeparator = str.IndexOf(separator, start);

            if (nextSeparator == -1)
            {
                nextSeparator = end;
            }

            if (nextSeparator > -1)
            {
                String phraseString = str.Substring(start, nextSeparator - start);
                // extra round of messing with synch, because we need to know if we
                // are creating a new Phrase
                PrefixPhrase <O> nextPrefixPhrase = GetPrefix(this, phraseString);
                if (nextPrefixPhrase != null)
                {
                    return(nextPrefixPhrase.Add(str, nextSeparator, separator));
                }
                else
                {
                    // done!
                    PrefixPhrase <O> newTerminal = LookupChild(phraseString);
                    //newTerminal.clear();
                    return(newTerminal);
                    //				synchronized (this)
                    //				{
                    //					nextPrefixPhrase	= getPrefix(this, phraseString);
                    //					if (nextPrefixPhrase == null)
                    //					{
                    //						nextPrefixPhrase	= childPhraseMap.getOrCreateAndPutIfNew(phraseString, this);
                    //						result				= nextPrefixPhrase;
                    //					}
                    //				}
                }
            }
            else
            {
                Debug.WriteLine("help! wrong block!!!");
                // last segment
                return(null);
            }
        }
Exemplo n.º 11
0
 public PrefixPhrase(PrefixPhrase <O> parent, String phrase)
 {
     this.parent = parent;
     this.phrase = phrase;
 }