Ejemplo n.º 1
0
 private StyleSheet(INode parent, string type, IStyleMedia media, Uri href)
     : base(parent, XmlStyleSheetTarget, GetContent(type, media, href))
 {
     this.type = type;
     this.media = media;
     this.href = href;
 }
Ejemplo n.º 2
0
 private StyleSheet(INode parent, string type, IStyleMedia media, Uri href)
     : base(parent, XmlStyleSheetTarget, GetContent(type, media, href))
 {
     this.type  = type;
     this.media = media;
     this.href  = href;
 }
Ejemplo n.º 3
0
        private static string GetContent(string type, IStyleMedia media, Uri href)
        {
            var content = new StringBuilder();

            if (type != null)
                content.AppendFormat(" type=\"{0}\"", type);
            if (media != null)
                content.AppendFormat(" media=\"{0}\"", media);
            if (href != null)
                content.AppendFormat(" href=\"{0}\"", href);

            return content.ToString();
        }
Ejemplo n.º 4
0
        public static IStyleSheet ParseStyleSheet(INode parent, string target, string content)
        {
            if (target != XmlStyleSheetTarget)
            {
                throw new ArgumentException("target must be " + XmlStyleSheetTarget);
            }

            string      type   = null;
            IStyleMedia media  = null;
            Uri         href   = null;
            var         fields = content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var field in fields)
            {
                if (field.Contains('='))
                {
                    var tokens = field.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens != null && tokens.Length == 2 && tokens[0] != null && tokens[1] != null)
                    {
                        var name  = tokens[0].Trim();
                        var value = tokens[1].Trim().RemoveQuotes();

                        switch (name)
                        {
                        case "type":
                            type = value;
                            break;

                        case "media":
                            media = StyleMedia.Parse(value);
                            break;

                        case "href":
                            value.TryParseUri(out href);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(new StyleSheet(parent, type, media, href));
        }
Ejemplo n.º 5
0
        private static string GetContent(string type, IStyleMedia media, Uri href)
        {
            var content = new StringBuilder();

            if (type != null)
            {
                content.AppendFormat(" type=\"{0}\"", type);
            }
            if (media != null)
            {
                content.AppendFormat(" media=\"{0}\"", media);
            }
            if (href != null)
            {
                content.AppendFormat(" href=\"{0}\"", href);
            }

            return(content.ToString());
        }
Ejemplo n.º 6
0
        public static IStyleSheet ParseStyleSheet(INode parent, string target, string content)
        {
            if (target != XmlStyleSheetTarget)
                throw new ArgumentException("target must be " + XmlStyleSheetTarget);

            string type = null;
            IStyleMedia media = null;
            Uri href = null;
            var fields = content.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
            foreach (var field in fields)
            {
                if (field.Contains('='))
                {
                    var tokens = field.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens != null && tokens.Length == 2 && tokens[0] != null && tokens[1] != null)
                    {
                        var name = tokens[0].Trim();
                        var value = tokens[1].Trim().RemoveQuotes();
                        
                        switch (name)
                        {
                            case "type":
                                type = value;
                                break;
                            case "media":
                                media = StyleMedia.Parse(value);
                                break;
                            case "href":
                                value.TryParseUri(out href);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            return new StyleSheet(parent, type, media, href);
        }