예제 #1
0
 /// <summary>
 /// used to copy the unknown childnodes for later saving
 /// </summary>
 /// <param name="node">the node to process</param>
 /// <param name="parser">the feed parser to pass down if need be</param>
 public override void ProcessChildNodes(XmlNode node, AtomFeedParser parser)
 {
     if (node != null && node.HasChildNodes)
     {
         XmlNode childNode = node.FirstChild;
         while (childNode != null)
         {
             bool fProcessed = false;
             if (childNode is XmlElement)
             {
                 foreach (IExtensionElementFactory f in this.ExtensionFactories)
                 {
                     if (String.Compare(childNode.NamespaceURI, f.XmlNameSpace) == 0)
                     {
                         if (String.Compare(childNode.LocalName, f.XmlName) == 0)
                         {
                             //Tracing.TraceMsg("Added extension to SimpleContainer for: " + f.XmlName);
                             ExtensionElements.Add(f.CreateInstance(childNode, parser));
                             fProcessed = true;
                             break;
                         }
                     }
                 }
             }
             if (fProcessed == false)
             {
                 this.ChildNodes.Add(childNode);
             }
             childNode = childNode.NextSibling;
         }
     }
 }
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Adds element from the gm: namespace</summary>
        ///////////////////////////////////////////////////////////////////////
        internal bool AddFromMetaNamespace(XmlNode node)
        {
            if (String.Compare(node.NamespaceURI,
                               GBaseNameTable.NSGBaseMeta, true) == 0)
            {
                switch (node.LocalName)
                {
                case "item_type":
                    ExtensionElements.Add(MetadataItemType.Parse(node));
                    break;

                case "attributes":
                    ExtensionElements.Add(ItemTypeAttributes.Parse(node));
                    break;

                case "attribute":
                    ExtensionElements.Add(AttributeHistogram.Parse(node));
                    break;

                case "stats":
                    ExtensionElements.Add(Stats.Parse(node));
                    break;

                default:
                    return(false);
                }
                return(true);
            }
            return(false);
        }
예제 #3
0
        /// <summary>
        /// finds our position element, if we don't have one
        /// creates a new one depending on the fCreate parameter
        /// </summary>
        /// <param name="create">creates the subelements on true</param>
        /// <returns>GeoKmlPosition</returns>
        protected GeoKmlPosition GetPosition(bool create)
        {
            GeoKmlPoint point = FindExtension(
                GeoNametable.GeoKmlPointElement,
                GeoNametable.NSGeoKml) as GeoKmlPoint;

            GeoKmlPosition position = null;

            if (point == null && create)
            {
                point = new GeoKmlPoint();
                ExtensionElements.Add(point);
            }

            if (point != null)
            {
                position = point.FindExtension(
                    GeoNametable.GeoKmlPositionElement,
                    GeoNametable.NSGeoKml) as GeoKmlPosition;

                if (position == null && create)
                {
                    position = new GeoKmlPosition("0 0");
                    point.ExtensionElements.Add(position);
                }
            }

            return(position);
        }
        /// <summary>takes the updated entry returned and sets the properties to this object</summary>
        /// <param name="updatedEntry"> </param>
        protected void CopyEntry(AtomEntry updatedEntry)
        {
            Tracing.Assert(updatedEntry != null, "updatedEntry should not be null");
            if (updatedEntry == null)
            {
                throw new ArgumentNullException("updatedEntry");
            }

            _title           = updatedEntry.Title;
            _authors         = updatedEntry.Authors;
            _id              = updatedEntry.Id;
            _links           = updatedEntry.Links;
            _lastUpdateDate  = updatedEntry.Updated;
            _publicationDate = updatedEntry.Published;
            _authors         = updatedEntry.Authors;
            _rights          = updatedEntry.Rights;
            _categories      = updatedEntry.Categories;
            _summary         = updatedEntry.Summary;
            _content         = updatedEntry.Content;
            _source          = updatedEntry.Source;

            ExtensionElements.Clear();

            foreach (IExtensionElementFactory extension in updatedEntry.ExtensionElements)
            {
                ExtensionElements.Add(extension);
            }
        }
        /// <summary>
        /// we have one string based setter
        /// usage is: entry.setExtensionValue("tagname", "ns", "value") to set the element
        /// this will create the extension if it's not there
        /// note, you can ofcourse, just get an existing one and work with that
        /// object:
        /// </summary>
        /// <param name="extension">the name of the extension to look for</param>
        /// <param name="ns">the namespace of the extension to look for</param>
        /// <param name="newValue">the new value for this extension element</param>
        /// <returns>SimpleElement, either a brand new one, or the one
        /// returned by the service</returns>
        public SimpleElement SetExtensionValue(string extension, string ns, string newValue)
        {
            if (extension == null)
            {
                throw new System.ArgumentNullException("extension");
            }

            SimpleElement ele = FindExtension(extension, ns) as SimpleElement;

            if (ele == null)
            {
                ele = CreateExtension(extension, ns) as SimpleElement;
                if (ele == null)
                {
                    throw new System.ArgumentException("The namespace or tagname was invalid");
                }

                ExtensionElements.Add(ele);
            }

            ele.Value = newValue;
            return(ele);
        }
        /// <summary>
        /// Parses the inner state of the element
        /// </summary>
        /// <param name="e">The extension element that should be added to this entry</param>
        /// <param name="parser">The AtomFeedParser that called this</param>
        public virtual void Parse(ExtensionElementEventArgs e, AtomFeedParser parser)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            Tracing.TraceMsg("Entering Parse on AbstractEntry");
            XmlNode node = e.ExtensionElement;

            if (ExtensionFactories != null && ExtensionFactories.Count > 0)
            {
                Tracing.TraceMsg("Entring default Parsing for AbstractEntry");

                IExtensionElementFactory f = FindExtensionFactory(
                    node.LocalName,
                    node.NamespaceURI);
                if (f != null)
                {
                    ExtensionElements.Add(f.CreateInstance(node, parser));
                    e.DiscardEntry = true;
                }
            }
        }