/** * Produces a new, substituted ModulePrefs */ private ModulePrefs(ModulePrefs prefs, Substitutions substituter) { _base = prefs._base; categories = prefs.getCategories(); features = prefs.getFeatures(); locales = prefs.getLocales(); oauth = prefs.oauth; List <Preload> preloads = new List <Preload>(); if (prefs.preloads != null) { foreach (Preload preload in prefs.preloads) { preloads.Add(preload.substitute(substituter)); } } this.preloads = preloads; List <Icon> icons = new List <Icon>(prefs.icons.Count); foreach (Icon icon in prefs.icons) { icons.Add(icon.substitute(substituter)); } this.icons = icons; Dictionary <String, LinkSpec> links = new Dictionary <String, LinkSpec>(prefs.links.Count); foreach (LinkSpec link in prefs.links.Values) { LinkSpec sub = link.substitute(substituter); links.Add(sub.getRel(), sub); } this.links = links; Dictionary <String, String> attributes = new Dictionary <String, String>(prefs.attributes.Count); foreach (var attr in prefs.attributes) { String substituted = substituter.substituteString(null, attr.Value); attributes.Add(attr.Key, substituted); } this.attributes = attributes; }
/** * Produces a new, substituted ModulePrefs */ private ModulePrefs(ModulePrefs prefs, Substitutions substituter) { _base = prefs._base; categories = prefs.getCategories(); features = prefs.getFeatures(); locales = prefs.getLocales(); oauth = prefs.oauth; List<Preload> preloads = new List<Preload>(); if (prefs.preloads != null) { foreach (Preload preload in prefs.preloads) { preloads.Add(preload.substitute(substituter)); } } this.preloads = preloads; List<Icon> icons = new List<Icon>(prefs.icons.Count); foreach (Icon icon in prefs.icons) { icons.Add(icon.substitute(substituter)); } this.icons = icons; Dictionary<String, LinkSpec> links = new Dictionary<String, LinkSpec>(prefs.links.Count); foreach (LinkSpec link in prefs.links.Values) { LinkSpec sub = link.substitute(substituter); links.Add(sub.getRel(), sub); } this.links = links; Dictionary<String, String> attributes = new Dictionary<String, String>(prefs.attributes.Count); foreach (var attr in prefs.attributes) { String substituted = substituter.substituteString(null, attr.Value); attributes.Add(attr.Key, substituted); } this.attributes = attributes; }
/** * Creates a new Module from the given xml input. * * @param url * @param xml * @throws SpecParserException */ public GadgetSpec(Uri url, String xml) { XmlElement doc; try { doc = XmlUtil.Parse(xml); } catch (XmlException e) { throw new SpecParserException("Malformed XML in file " + url.ToString(), e); } this.url = url; // This might not be good enough; should we take message bundle changes // into account? this.checksum = HashUtil.checksum(xml); XmlNodeList children = doc.ChildNodes; ModulePrefs modulePrefs = null; List<UserPref> userPrefs = new List<UserPref>(); Dictionary<String, List<XmlElement>> views = new Dictionary<String, List<XmlElement>>(); for (int i = 0, j = children.Count; i < j; ++i) { XmlNode child = children[i]; if (!(child is XmlElement)) { continue; } XmlElement element = (XmlElement)child; switch (element.Name) { case "ModulePrefs": if (modulePrefs == null) { modulePrefs = new ModulePrefs(element, url); } else { throw new SpecParserException("Only 1 ModulePrefs is allowed."); } break; case "UserPref": UserPref pref = new UserPref(element); userPrefs.Add(pref); break; case "Content": String viewNames = XmlUtil.getAttribute(element, "view", "default"); foreach (String _view in viewNames.Split(',')) { String view = _view.Trim(); List<XmlElement> viewElements; if (!views.TryGetValue(view, out viewElements)) { viewElements = new List<XmlElement>(); views.Add(view, viewElements); } viewElements.Add(element); } break; } } if (modulePrefs == null) { throw new SpecParserException("At least 1 ModulePrefs is required."); } this.modulePrefs = modulePrefs; if (views.Count == 0) { throw new SpecParserException("At least 1 Content is required."); } Dictionary<String, View> tmpViews = new Dictionary<String, View>(); foreach (var view in views) { View v = new View(view.Key, view.Value, url); tmpViews.Add(v.getName(), v); } this.views = tmpViews; if (userPrefs.Count != 0) { this.userPrefs = userPrefs; } else { this.userPrefs = new List<UserPref>(); } }
/** * Creates a new Module from the given xml input. * * @param url * @param xml * @throws SpecParserException */ public GadgetSpec(Uri url, String xml) { XmlElement doc; try { doc = XmlUtil.Parse(xml); } catch (XmlException e) { throw new SpecParserException("Malformed XML in file " + url.ToString(), e); } this.url = url; // This might not be good enough; should we take message bundle changes // into account? this.checksum = HashUtil.checksum(xml); XmlNodeList children = doc.ChildNodes; ModulePrefs modulePrefs = null; List <UserPref> userPrefs = new List <UserPref>(); Dictionary <String, List <XmlElement> > views = new Dictionary <String, List <XmlElement> >(); for (int i = 0, j = children.Count; i < j; ++i) { XmlNode child = children[i]; if (!(child is XmlElement)) { continue; } XmlElement element = (XmlElement)child; switch (element.Name) { case "ModulePrefs": if (modulePrefs == null) { modulePrefs = new ModulePrefs(element, url); } else { throw new SpecParserException("Only 1 ModulePrefs is allowed."); } break; case "UserPref": UserPref pref = new UserPref(element); userPrefs.Add(pref); break; case "Content": String viewNames = XmlUtil.getAttribute(element, "view", "default"); foreach (String _view in viewNames.Split(',')) { String view = _view.Trim(); List <XmlElement> viewElements; if (!views.TryGetValue(view, out viewElements)) { viewElements = new List <XmlElement>(); views.Add(view, viewElements); } viewElements.Add(element); } break; } } if (modulePrefs == null) { throw new SpecParserException("At least 1 ModulePrefs is required."); } this.modulePrefs = modulePrefs; if (views.Count == 0) { throw new SpecParserException("At least 1 Content is required."); } Dictionary <String, View> tmpViews = new Dictionary <String, View>(); foreach (var view in views) { View v = new View(view.Key, view.Value, url); tmpViews.Add(v.getName(), v); } this.views = tmpViews; if (userPrefs.Count != 0) { this.userPrefs = userPrefs; } else { this.userPrefs = new List <UserPref>(); } }