예제 #1
0
        /// <summary>Constructor, given a category as a string from the URI.</summary>
        public QueryCategory(string strCategory, QueryCategoryOperator op)
        {
            Tracing.TraceMsg("Depersisting category from: " + strCategory);
            this.categoryOperator = op;
            strCategory           = FeedQuery.CleanPart(strCategory);

            // let's parse the string
            if (strCategory[0] == '-')
            {
                // negator
                this.isExcluded = true;
                // remove him
                strCategory = strCategory.Substring(1, strCategory.Length - 1);
            }

            // let's extract the scheme if there is one...
            int     iStart = strCategory.IndexOf('{');
            int     iEnd   = strCategory.IndexOf('}');
            AtomUri scheme = null;

            if (iStart != -1 && iEnd != -1)
            {
                iEnd++;
                iStart++;
                scheme = new AtomUri(strCategory.Substring(iStart, iEnd - iStart - 1));
                // the rest is then
                strCategory = strCategory.Substring(iEnd, strCategory.Length - iEnd);
            }

            Tracing.TraceMsg("Category found: " + strCategory + " - scheme: " + scheme);

            this.category = new AtomCategory(strCategory, scheme);
        }
예제 #2
0
        /// <summary>parses an xml stream to create an AtomCategory object</summary>
        /// <param name="reader">correctly positioned xmlreader</param>
        /// <param name="owner">the object containing the person</param>
        /// <returns> the created AtomCategory object</returns>
        protected AtomCategory ParseCategory(XmlReader reader, AtomBase owner)
        {
            Tracing.TraceCall();
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            AtomCategory category = owner.CreateAtomSubElement(reader, this) as AtomCategory;

            if (category != null)
            {
                bool noChildren = reader.IsEmptyElement;
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        object localname = reader.LocalName;
                        if (localname.Equals(this.nameTable.Term))
                        {
                            category.Term = Utilities.DecodedValue(reader.Value);
                        }
                        else if (localname.Equals(this.nameTable.Scheme))
                        {
                            category.Scheme = new AtomUri(reader.Value);
                        }
                        else if (localname.Equals(this.nameTable.Label))
                        {
                            category.Label = Utilities.DecodedValue(reader.Value);
                        }
                        else
                        {
                            ParseBaseAttributes(reader, category);
                        }
                    }
                }

                if (!noChildren)
                {
                    reader.MoveToElement();
                    int lvl = -1;
                    while (NextChildElement(reader, ref lvl))
                    {
                        ParseExtensionElements(reader, category);
                    }
                }
            }
            return(category);
        }
예제 #3
0
 /// <summary>
 /// helper to toggle categories
 /// </summary>
 /// <param name="cat"></param>
 /// <param name="value"></param>
 public void ToggleCategory(AtomCategory cat, bool value)
 {
     if (value)
     {
         if (!this.Categories.Contains(cat))
         {
             this.Categories.Add(cat);
         }
     }
     else
     {
         this.Categories.Remove(cat);
     }
 }
예제 #4
0
        /// <summary>tries to parse a category collection document</summary>
        /// <param name="reader"> xmlReader positioned at the start element</param>
        /// <param name="owner">the base object that the collection belongs to</param>
        /// <returns></returns>
        public AtomCategoryCollection ParseCategories(XmlReader reader, AtomBase owner)
        {
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            AtomCategoryCollection ret = new AtomCategoryCollection();

            MoveToStartElement(reader);

            Tracing.TraceCall("entering Categories Parser");
            object localname = reader.LocalName;

            Tracing.TraceInfo("localname is: " + reader.LocalName);

            if (IsCurrentNameSpace(reader, BaseNameTable.AppPublishingNamespace(owner)) &&
                localname.Equals(this.nameTable.Categories))
            {
                Tracing.TraceInfo("Found categories  document");
                int depth = -1;
                while (NextChildElement(reader, ref depth))
                {
                    localname = reader.LocalName;
                    if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom))
                    {
                        if (localname.Equals(this.nameTable.Category))
                        {
                            AtomCategory category = ParseCategory(reader, owner);
                            ret.Add(category);
                        }
                    }
                }
            }
            else
            {
                Tracing.TraceInfo("ParseCategories called and nothing was parsed" + localname);
                throw new ClientFeedException("An invalid Atom Document was passed to the parser. This was not an app:categories document: " + localname);
            }

            return(ret);
        }
예제 #5
0
 /// <summary>Constructor, given a category.</summary>
 public QueryCategory(AtomCategory category)
 {
     this.category         = category;
     this.categoryOperator = QueryCategoryOperator.AND;
 }
예제 #6
0
        /// <summary>reads one of the feed entries at a time</summary>
        /// <param name="reader"> XmlReader positioned at the entry element</param>
        /// <returns> notifies user using event mechanism</returns>
        public void ParseEntry(XmlReader reader)
        {
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            object localname = reader.LocalName;

            Tracing.TraceCall("Parsing atom entry");
            if (localname.Equals(this.nameTable.Entry) == false)
            {
                throw new ClientFeedException("trying to parse an atom entry, but reader is not at the right spot");
            }

            AtomEntry entry = OnCreateNewEntry();

            ParseBasicAttributes(reader, entry);

            // remember the depth of entry
            int depth = -1;

            while (NextChildElement(reader, ref depth))
            {
                localname = reader.LocalName;

                if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom))
                {
                    if (localname.Equals(this.nameTable.Id))
                    {
                        entry.Id = entry.CreateAtomSubElement(reader, this) as AtomId;
                        ParseBaseLink(reader, entry.Id);
                    }
                    else if (localname.Equals(this.nameTable.Link))
                    {
                        entry.Links.Add(ParseLink(reader, entry));
                    }
                    else if (localname.Equals(this.nameTable.Updated))
                    {
                        entry.Updated = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(this.nameTable.Published))
                    {
                        entry.Published = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(this.nameTable.Author))
                    {
                        entry.Authors.Add(ParsePerson(reader, entry));
                    }
                    else if (localname.Equals(this.nameTable.Contributor))
                    {
                        entry.Contributors.Add(ParsePerson(reader, entry));
                    }
                    else if (localname.Equals(this.nameTable.Rights))
                    {
                        entry.Rights = ParseTextConstruct(reader, entry);
                    }
                    else if (localname.Equals(this.nameTable.Category))
                    {
                        AtomCategory category = ParseCategory(reader, entry);
                        entry.Categories.Add(category);
                    }
                    else if (localname.Equals(this.nameTable.Summary))
                    {
                        entry.Summary = ParseTextConstruct(reader, entry);
                    }
                    else if (localname.Equals(this.nameTable.Content))
                    {
                        entry.Content = ParseContent(reader, entry);
                    }
                    else if (localname.Equals(this.nameTable.Source))
                    {
                        entry.Source = entry.CreateAtomSubElement(reader, this) as AtomSource;
                        ParseSource(reader, entry.Source);
                    }
                    else if (localname.Equals(this.nameTable.Title))
                    {
                        entry.Title = ParseTextConstruct(reader, entry);
                    }
                    // all parse methods should leave the reader at the end of their element
                    reader.Read();
                }
                else if (IsCurrentNameSpace(reader, BaseNameTable.gBatchNamespace))
                {
                    // parse the google batch extensions if they are there
                    ParseBatch(reader, entry);
                }
                else
                {
                    // default extension parsing
                    ParseExtensionElements(reader, entry);
                }
            }
            OnNewAtomEntry(entry);

            return;
        }