Exemple #1
0
        protected virtual void WriteEmbeddedIcon(BookmarkLink link, XmlWriter xmlWriter)
        {
            const string template      = "data:{0};base64,{1}";
            var          base64Content = Convert.ToBase64String(link.IconData);

            xmlWriter.WriteAttributeString("ICON", string.Format(template, link.IconContentType, base64Content));
        }
Exemple #2
0
        private IBookmarkItem ParseItem(HTMLparser parser)
        {
            BookmarkLink item = null;
            HTMLchunk    chunk, prevChunk = parser.CurrentChunk;

            while ((chunk = parser.ParseNext()) != null)
            {
                if (chunk.IsOpenTag && chunk.Tag == "a")
                {
                    item = new BookmarkLink();
                    AssignLinkAttributes(item, chunk.oParams);
                    item.Title = GetTextOrDontMove(parser);
                }
                else if (chunk.IsOpenTag && chunk.Tag == "dd" && item != null)
                {
                    item.Description = ParseDescription(parser);
                }
                else if (chunk.IsOpenTag && chunk.Tag == "h3")
                {
                    var folder = new BookmarkFolder();
                    AssignFolderAttributes(folder, chunk.oParams);
                    folder.Title = GetTextOrDontMove(parser);
                    return(folder);
                }
                else if ((chunk.IsOpenTag && chunk.Tag == "dt") || chunk.Tag == "dl")
                {
                    parser.StepBack(prevChunk);
                    break;
                }
                prevChunk = chunk;
            }
            return(item);
        }
Exemple #3
0
        protected virtual void WriteLinkLine(BookmarkLink link, TextWriter writer, XmlWriter xmlWriter)
        {
            writer.Write("<DT>");
            xmlWriter.WriteStartElement("A");
            if (link.LastModified.HasValue)
            {
                xmlWriter.WriteAttributeString("LAST_MODIFIED", link.LastModified.Value.ToUnixTimestamp().ToString());
            }
            if (link.LastVisit.HasValue)
            {
                xmlWriter.WriteAttributeString("LAST_VISIT", link.LastVisit.Value.ToUnixTimestamp().ToString());
            }
            if (link.Added.HasValue)
            {
                xmlWriter.WriteAttributeString("ADD_DATE", link.Added.Value.ToUnixTimestamp().ToString());
            }
            if (!string.IsNullOrEmpty(link.IconUrl))
            {
                xmlWriter.WriteAttributeString("ICON_URI", link.IconUrl);
            }
            if (!string.IsNullOrEmpty(link.IconContentType) && link.IconData != null)
            {
                WriteEmbeddedIcon(link, xmlWriter);
            }
            if (!string.IsNullOrEmpty(link.FeedUrl))
            {
                xmlWriter.WriteAttributeString("FEED", "true");
                xmlWriter.WriteAttributeString("FEEDURL", link.FeedUrl);
            }
            xmlWriter.WriteAttributeString("HREF", link.Url);
            if (link.Attributes != null && link.Attributes.Any())
            {
                WriteCustomAttributes(link.Attributes, xmlWriter);
            }

            xmlWriter.WriteString(link.Title);
            xmlWriter.WriteEndElement();
            xmlWriter.Flush();
            if (!string.IsNullOrEmpty(link.Description))
            {
                writer.WriteLine();
                writer.Write("<DD>");
                xmlWriter.WriteString(link.Description);
                xmlWriter.Flush();
            }
            writer.WriteLine();
        }
Exemple #4
0
        private void AssignLinkAttributes(BookmarkLink link, IEnumerable <KeyValuePair <string, string> > attributes)
        {
            if (attributes == null)
            {
                return;
            }
            foreach (var attr in attributes)
            {
                switch (attr.Key)
                {
                case "href":
                    link.Url = attr.Value;
                    break;

                case "last_modified":
                    link.LastModified = DateTimeHelper.FromUnixTimeStamp(attr.Value);
                    break;

                case "add_date":
                    link.Added = DateTimeHelper.FromUnixTimeStamp(attr.Value);
                    break;

                case "last_visited":
                    link.LastVisit = DateTimeHelper.FromUnixTimeStamp(attr.Value);
                    break;

                case "icon":
                    string contentType;
                    link.IconData        = DecodeEmbededIcon(attr.Value, out contentType);
                    link.IconContentType = contentType;
                    break;

                case "icon_uri":
                    link.IconUrl = attr.Value;
                    break;

                case "feedurl":
                    link.FeedUrl = attr.Value;
                    break;
                }
                if (!link.Attributes.ContainsKey(attr.Key))
                {
                    link.Attributes.Add(attr.Key, attr.Value);
                }
            }
        }