Ejemplo n.º 1
0
 public override List<preloadProcessor> createPreloadTasks(GadgetContext context,
                                                                         GadgetSpec gadget, PreloaderService.PreloadPhase phase) 
 {
     List<preloadProcessor> preloads = new List<preloadProcessor>();
     if (phase == PreloaderService.PreloadPhase.HTML_RENDER) 
     {
         foreach(Preload preload in gadget.getModulePrefs().getPreloads()) 
         {
             HashSet<String> preloadViews = preload.getViews();
             if (preloadViews.Count == 0 || preloadViews.Contains(context.getView())) 
             {
                 PreloadTask task = new PreloadTask(context, preload, preload.getHref().ToString());
                 preloads.Add(new preloadProcessor(task.call));
             }
         }
     }
     return preloads;
 }
Ejemplo n.º 2
0
 public MessageBundle getBundle(GadgetSpec spec, Locale locale, bool ignoreCache)
 {
     MessageBundle parent = getParentBundle(spec, locale, ignoreCache);
     MessageBundle child = null;
     LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale);
     if (localeSpec == null)
     {
         return parent ?? MessageBundle.EMPTY;
     }
     Uri messages = localeSpec.getMessages();
     if (messages == null || messages.ToString().Length == 0)
     {
         child = localeSpec.getMessageBundle();
     }
     else
     {
         child = fetchBundle(localeSpec, ignoreCache);
     }
     return new MessageBundle(parent, child);
 }
Ejemplo n.º 3
0
 private static bool GadgetWantsLockedDomain(GadgetSpec gadget)
 {
     return gadget.getModulePrefs().getFeatures().ContainsKey("locked-domain");
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get all features needed to satisfy this rendering request.
        /// </summary>
        /// <param name="spec"></param>
        /// <param name="forced">Forced libraries; added in addition to those found in the spec. Defaults to "core"</param>
        /// <returns></returns>
        private ICollection<GadgetFeature> GetFeatures(GadgetSpec spec, ICollection<String> forced)
        {
            Dictionary<String, Feature> features = spec.getModulePrefs().getFeatures();
            HashKey<String> libs = new HashKey<string>();
            foreach (var item in features.Keys)
            {
                libs.Add(item);
            }
            if (forced.Count != 0) 
            {
                foreach (var item in forced)
                {
                    libs.Add(item);
                }
            }

            HashSet<String> unsupported = new HashSet<String>();
            ICollection<GadgetFeature> feats = featureRegistry.GetFeatures(libs, unsupported);
            foreach (var item in forced)
            {
                unsupported.Remove(item);
            }

            if (unsupported.Count != 0)
            {
                // Remove non-required libs
                unsupported.RemoveWhere(x => !features[x].getRequired());

                // Throw error with full list of unsupported libraries
                if (unsupported.Count != 0) 
                {
                    throw new UnsupportedFeatureException(String.Join(",", unsupported.ToArray()));
                }
            }
            return feats;
        }
Ejemplo n.º 5
0
        /**
         * Constructor which takes a gadget spec and the default container settings
         *
         * @param spec
         * @param defaultInclude As a regex
         * @param defaultExclude As a regex
         * @param defaultExpires Either "HTTP" or a ttl in seconds
         * @param defaultTags    Set of default tags that can be rewritten
         */
        public ContentRewriterFeature(GadgetSpec spec, String defaultInclude,
                                      String defaultExclude,
                                      String defaultExpires,
                                      HashSet<String> defaultTags)
        {
            Feature f = null;
            if (spec != null)
            {
                spec.getModulePrefs().getFeatures().TryGetValue("content-rewrite", out f);
            }
            String includeRegex = normalizeParam(defaultInclude, null);
            String excludeRegex = normalizeParam(defaultExclude, null);

            this.includeTags = new HashSet<String>(defaultTags);

            List<String> expiresOptions = new List<string>(3);
            if (f != null)
            {
                if (f.getParams().ContainsKey(INCLUDE_URLS))
                {
                    includeRegex = normalizeParam(f.getParams()[INCLUDE_URLS], includeRegex);
                }

                // Note use of default for exclude as null here to allow clearing value in the
                // presence of a container default.
                if (f.getParams().ContainsKey(EXCLUDE_URLS))
                {
                    excludeRegex = normalizeParam(f.getParams()[EXCLUDE_URLS], null);
                }
                String includeTagList;
                if (f.getParams().TryGetValue(INCLUDE_TAGS, out includeTagList))
                {
                    HashSet<String> tags = new HashSet<String>();
                    foreach (String tag in includeTagList.Split(','))
                    {
                        if (tag != null)
                        {
                            tags.Add(tag.Trim().ToLower());
                        }
                    }
                    includeTags = tags;
                }

                if (f.getParams().ContainsKey(EXPIRES))
                {
                    expiresOptions.Add(normalizeParam(f.getParams()[EXPIRES], null));
                }
            }

            expiresOptions.Add(defaultExpires);
            expiresOptions.Add(EXPIRES_DEFAULT);

            foreach (String expiryOption in expiresOptions)
            {
                try
                {
                    expires = int.Parse(expiryOption);
                    break;
                }
                catch
                {
                    // Not an integer
                    if (EXPIRES_DEFAULT.ToLower().Equals(expiryOption))
                    {
                        break;
                    }
                }
            }

            if (".*".Equals(includeRegex) && excludeRegex == null)
            {
                includeAll = true;
            }

            if (".*".Equals(excludeRegex) || includeRegex == null)
            {
                includeNone = true;
            }

            if (includeRegex != null)
            {
                include = new Regex(includeRegex);
            }
            if (excludeRegex != null)
            {
                exclude = new Regex(excludeRegex);
            }
        }