Exemple #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);
            _categoryOperator = op;
            strCategory       = FeedQuery.CleanPart(strCategory);

            // let's parse the string
            if (strCategory[0] == '-')
            {
                // negator
                _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);

            _category = new AtomCategory(strCategory, scheme);
        }
        /// <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(_nameTable.Term))
                        {
                            category.Term = Utilities.DecodedValue(reader.Value);
                        }
                        else if (localname.Equals(_nameTable.Scheme))
                        {
                            category.Scheme = new AtomUri(reader.Value);
                        }
                        else if (localname.Equals(_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);
        }
 /// <summary>
 /// helper to toggle categories
 /// </summary>
 /// <param name="cat"></param>
 /// <param name="value"></param>
 public void ToggleCategory(AtomCategory cat, bool value)
 {
     if (value)
     {
         if (!Categories.Contains(cat))
         {
             Categories.Add(cat);
         }
     }
     else
     {
         Categories.Remove(cat);
     }
 }
        /// <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(_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(_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);
        }
Exemple #5
0
 /// <summary>Constructor, given a category.</summary>
 public QueryCategory(AtomCategory category)
 {
     _category         = category;
     _categoryOperator = QueryCategoryOperator.AND;
 }
        /// <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(_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(_nameTable.Id))
                    {
                        entry.Id = entry.CreateAtomSubElement(reader, this) as AtomId;
                        ParseBaseLink(reader, entry.Id);
                    }
                    else if (localname.Equals(_nameTable.Link))
                    {
                        entry.Links.Add(ParseLink(reader, entry));
                    }
                    else if (localname.Equals(_nameTable.Updated))
                    {
                        entry.Updated = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(_nameTable.Published))
                    {
                        entry.Published = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(_nameTable.Author))
                    {
                        entry.Authors.Add(ParsePerson(reader, entry));
                    }
                    else if (localname.Equals(_nameTable.Contributor))
                    {
                        entry.Contributors.Add(ParsePerson(reader, entry));
                    }
                    else if (localname.Equals(_nameTable.Rights))
                    {
                        entry.Rights = ParseTextConstruct(reader, entry);
                    }
                    else if (localname.Equals(_nameTable.Category))
                    {
                        AtomCategory category = ParseCategory(reader, entry);
                        entry.Categories.Add(category);
                    }
                    else if (localname.Equals(_nameTable.Summary))
                    {
                        entry.Summary = ParseTextConstruct(reader, entry);
                    }
                    else if (localname.Equals(_nameTable.Content))
                    {
                        entry.Content = ParseContent(reader, entry);
                    }
                    else if (localname.Equals(_nameTable.Source))
                    {
                        entry.Source = entry.CreateAtomSubElement(reader, this) as AtomSource;
                        ParseSource(reader, entry.Source);
                    }
                    else if (localname.Equals(_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;
        }