Пример #1
0
        //
        // Public methods
        //

        /// <summary> Add a new Tag Scanner.
        /// In typical situations where you require a no-frills parser, use the RegisterScanners() method to add the most
        /// common parsers. But when you wish to either compose a parser with only certain scanners registered, use this method.
        /// It is advantageous to register only the scanners you want, in order to achieve faster parsing speed. This method
        /// would also be of use when you have developed custom scanners, and need to register them into the parser.
        /// </summary>
        /// <param name="scanner">TagScanner object (or derivative) to be added to the list of registered scanners
        ///
        /// </param>
        public virtual void AddScanner(TagScanner scanner)
        {
            foreach (string id in scanner.ID)
            {
                scanners[id] = scanner;
            }
            scanner.Feedback = feedback;
        }
Пример #2
0
 public static bool EvaluateTag(TagScanner pTagScanner, string pTagString, string pTagName)
 {
     pTagString = TagScanner.AbsorbLeadingBlanks(pTagString);
     if (pTagString.ToUpper().IndexOf(pTagName) == 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        /// <summary> Scan the tag to see using the scanners, and attempt identification.
        /// </summary>
        /// <param name="url">URL at which HTML page is located
        /// </param>
        /// <param name="reader">The NodeReader that is to be used for reading the url
        ///
        /// </param>
        public virtual AbstractNode Scan(IDictionary scanners, string url, NodeReader reader)
        {
            if (tagContents.Length == 0)
            {
                return(this);
            }
            try
            {
                bool         found  = false;
                AbstractNode retVal = null;
                // Find the first word in the scanners
                string firstWord = ExtractWord(tagContents.ToString());
                // Now, get the scanner associated with this.
                TagScanner scanner = (TagScanner)scanners[firstWord];

                // Now do a deep check
                if (scanner != null && scanner.Evaluate(tagContents.ToString(), reader.PreviousOpenScanner))
                {
                    found = true;
                    TagScanner save;
                    save = reader.PreviousOpenScanner;
                    reader.PreviousOpenScanner = scanner;
                    retVal = scanner.CreateScannedNode(this, url, reader, tagLine);
                    reader.PreviousOpenScanner = save;
                }

                if (!found)
                {
                    return(this);
                }
                else
                {
                    return(retVal);
                }
            }
            catch (System.Exception e)
            {
                string errorMsg;
                if (tagContents != null)
                {
                    errorMsg = tagContents.ToString();
                }
                else
                {
                    errorMsg = "null";
                }
                throw new ParserException(
                          "Tag.scan() : Error while scanning tag, tag contents = " + errorMsg + ", tagLine = " + tagLine, e);
            }
        }