Пример #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
        /////////////////////////////////////////////////////////////////////////////
        #endregion


        #region overloaded for property changes, xml:base
        //////////////////////////////////////////////////////////////////////
        /// <summary>just go down the child collections</summary>
        /// <param name="uriBase"> as currently calculated</param>
        //////////////////////////////////////////////////////////////////////
        internal override void BaseUriChanged(AtomUri uriBase)
        {
            base.BaseUriChanged(uriBase);

            foreach (AtomPerson person in this.Authors)
            {
                person.BaseUriChanged(uriBase);
            }
            // saving Contributors
            foreach (AtomPerson person in this.Contributors)
            {
                person.BaseUriChanged(uriBase);
            }
            // saving Categories
            foreach (AtomCategory category in this.Categories)
            {
                category.BaseUriChanged(uriBase);
            }
            // saving the generator
            if (this.Generator != null)
            {
                this.Generator.BaseUriChanged(uriBase);
            }
            // save the icon
            if (this.Icon != null)
            {
                this.Icon.BaseUriChanged(uriBase);
            }
            // save the logo
            if (this.Logo != null)
            {
                this.Logo.BaseUriChanged(uriBase);
            }
            // save the ID
            if (this.Id != null)
            {
                this.Id.BaseUriChanged(uriBase);
            }
            // save the Links
            foreach (AtomLink link in this.Links)
            {
                link.BaseUriChanged(uriBase);
            }

            if (this.Rights != null)
            {
                this.Rights.BaseUriChanged(uriBase);
            }
            if (this.Subtitle != null)
            {
                this.Subtitle.BaseUriChanged(uriBase);
            }
            if (this.Title != null)
            {
                this.Title.BaseUriChanged(uriBase);
            }
        }
Пример #3
0
 /// <summary>comparison method similar to strings</summary>
 public static int Compare(AtomUri oneAtomUri, AtomUri anotherAtomUri)
 {
     if (oneAtomUri != null)
     {
         return(oneAtomUri.CompareTo(anotherAtomUri));
     }
     else if (anotherAtomUri == null)
     {
         return(0);
     }
     return(-1);
 }
Пример #4
0
        /////////////////////////////////////////////////////////////////////////////

        #region overloaded for property changes, xml:base
        //////////////////////////////////////////////////////////////////////
        /// <summary>just go down the child collections</summary>
        /// <param name="uriBase"> as currently calculated</param>
        //////////////////////////////////////////////////////////////////////
        internal override void BaseUriChanged(AtomUri uriBase)
        {
            base.BaseUriChanged(uriBase);

            // now walk over the entries and forward...
            uriBase = new AtomUri(Utilities.CalculateUri(this.Base, uriBase, null));

            foreach (AtomEntry entry in this.Entries)
            {
                entry.BaseUriChanged(uriBase);
            }
        }
Пример #5
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>helper method to encapsulate a string encoding, uses HTML encoding now</summary>
        /// <param name="writer">the xml writer to write to</param>
        /// <param name="content">the string to encode</param>
        //////////////////////////////////////////////////////////////////////
        static protected void WriteEncodedString(XmlWriter writer, AtomUri content)
        {
            if (writer == null)
            {
                throw new System.ArgumentNullException("writer", "No valid xmlWriter");
            }

            if (Utilities.IsPersistable(content))
            {
                string encoded = Utilities.EncodeString(content.ToString());
                writer.WriteString(encoded);
            }
        }
Пример #6
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>public static string CalculateUri(string base, string inheritedBase, string local)</summary>
        /// <param name="localBase">the baseUri from xml:base </param>
        /// <param name="inheritedBase">the pushed down baseUri from an outer element</param>
        /// <param name="localUri">the Uri value</param>
        /// <returns>the absolute Uri to use... </returns>
        //////////////////////////////////////////////////////////////////////
        internal static string CalculateUri(AtomUri localBase, AtomUri inheritedBase, string localUri)
        {
            try
            {
                Uri uriBase      = null;
                Uri uriSuperBase = null;
                Uri uriComplete  = null;

                if (inheritedBase != null && inheritedBase.ToString() != null)
                {
                    uriSuperBase = new Uri(inheritedBase.ToString());
                }
                if (localBase != null && localBase.ToString() != null)
                {
                    if (uriSuperBase != null)
                    {
                        uriBase = new Uri(uriSuperBase, localBase.ToString());
                    }
                    else
                    {
                        uriBase = new Uri(localBase.ToString());
                    }
                }
                else
                {
                    // if no local xml:base, take the passed down one
                    uriBase = uriSuperBase;
                }
                if (localUri != null)
                {
                    if (uriBase != null)
                    {
                        uriComplete = new Uri(uriBase, localUri.ToString());
                    }
                    else
                    {
                        uriComplete = new Uri(localUri.ToString());
                    }
                }
                else
                {
                    uriComplete = uriBase;
                }

                return(uriComplete != null ? uriComplete.AbsoluteUri : null);
            }
            catch (System.UriFormatException)
            {
                return("Unsupported URI format");
            }
        }
Пример #7
0
 /// <summary>
 /// finds a category with a given term and scheme
 /// </summary>
 /// <param name="term"></param>
 /// <param name="scheme"></param>
 /// <returns>AtomCategory or NULL</returns>
 public AtomCategory Find(string term, AtomUri scheme)
 {
     foreach (AtomCategory category in List)
     {
         if (scheme == null || scheme == category.Scheme)
         {
             if (term == category.Term)
             {
                 return(category);
             }
         }
     }
     return(null);
 }
Пример #8
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>just go down the child collections</summary>
        /// <param name="uriBase"> as currently calculated</param>
        //////////////////////////////////////////////////////////////////////
        internal override void BaseUriChanged(AtomUri uriBase)
        {
            base.BaseUriChanged(uriBase);
            // now pass it to the properties.
            uriBase = new AtomUri(Utilities.CalculateUri(this.Base, uriBase, null));

            if (this.Title != null)
            {
                this.Title.BaseUriChanged(uriBase);
            }
            if (this.Id != null)
            {
                this.Id.BaseUriChanged(uriBase);
            }
            foreach (AtomLink link in this.Links)
            {
                link.BaseUriChanged(uriBase);
            }
            foreach (AtomPerson person in this.Authors)
            {
                person.BaseUriChanged(uriBase);
            }
            foreach (AtomPerson person in this.Contributors)
            {
                person.BaseUriChanged(uriBase);
            }
            foreach (AtomCategory category in this.Categories)
            {
                category.BaseUriChanged(uriBase);
            }
            if (this.Rights != null)
            {
                this.Rights.BaseUriChanged(uriBase);
            }
            if (this.Summary != null)
            {
                this.Summary.BaseUriChanged(uriBase);
            }
            if (this.Content != null)
            {
                this.Content.BaseUriChanged(uriBase);
            }
            if (this.Source != null)
            {
                this.Source.BaseUriChanged(uriBase);
            }
        }
Пример #9
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>This starts the calculation, to push down the base
        /// URI changes.</summary>
        /// <param name="uriValue">the baseuri calculated so far</param>
        //////////////////////////////////////////////////////////////////////
        internal virtual void BaseUriChanged(AtomUri uriValue)
        {
            // if this is ever getting called explicitly (parsing), we turn on recalc
            this.fAllowRecalc   = true;
            this.uriImpliedBase = uriValue;
        }
Пример #10
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>helper method to encapsulate encoding, uses HTML encoding now</summary>
        /// <param name="writer">the xml writer to write to</param>
        /// <param name="elementName">the attribute the write</param>
        /// <param name="content">the string to encode</param>
        //////////////////////////////////////////////////////////////////////
        static protected void WriteEncodedElementString(XmlWriter writer, string elementName, AtomUri content)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (Utilities.IsPersistable(content))
            {
                string encoded = Utilities.EncodeString(content.ToString());
                writer.WriteElementString(elementName, BaseNameTable.NSAtom, encoded);
            }
        }
Пример #11
0
 /// <summary>Little helper that checks if a string is XML persistable</summary>
 public static bool IsPersistable(AtomUri uriString)
 {
     return(uriString == null ? false : Utilities.IsPersistable(uriString.ToString()));
 }
Пример #12
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Category constructor</summary>
        /// <param name="term">the term of the category</param>
        /// <param name="scheme">the scheme of the category</param>
        //////////////////////////////////////////////////////////////////////
        public AtomCategory(string term, AtomUri scheme)
        {
            this.Term   = term;
            this.Scheme = scheme;
        }
Пример #13
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Category constructor</summary>
        /// <param name="term">the term of the category</param>
        /// <param name="scheme">the scheme of the category</param>
        /// <param name="label"> the label for the category</param>
        //////////////////////////////////////////////////////////////////////
        public AtomCategory(string term, AtomUri scheme, string label)
        {
            this.Term   = term;
            this.Scheme = scheme;
            this.label  = label;
        }