/**
         * Lookup information contained in the gadget spec.
         */
        private OAuthServiceProvider lookupSpecInfo(ISecurityToken securityToken, OAuthArguments arguments,
                                                    AccessorInfoBuilder accessorBuilder, OAuthResponseParams responseParams)
        {
            GadgetSpec spec      = findSpec(securityToken, arguments, responseParams);
            OAuthSpec  oauthSpec = spec.getModulePrefs().getOAuthSpec();

            if (oauthSpec == null)
            {
                throw responseParams.oauthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION,
                                                           "Failed to retrieve OAuth URLs, spec for gadget " +
                                                           securityToken.getAppUrl() + " does not contain OAuth element.");
            }
            OAuthService service = oauthSpec.getServices()[arguments.getServiceName()];

            if (service == null)
            {
                throw responseParams.oauthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION,
                                                           "Failed to retrieve OAuth URLs, spec for gadget does not contain OAuth service " +
                                                           arguments.getServiceName() + ".  Known services: " +
                                                           String.Join(",", oauthSpec.getServices().Keys.AsEnumerable().ToArray()) + '.');
            }
            // In theory some one could specify different parameter locations for request token and
            // access token requests, but that's probably not useful.  We just use the request token
            // rules for everything.
            accessorBuilder.setParameterLocation(getStoreLocation(service.getRequestUrl().location, responseParams));
            accessorBuilder.setMethod(getStoreMethod(service.getRequestUrl().method, responseParams));
            OAuthServiceProvider provider = new OAuthServiceProvider(
                service.getRequestUrl().url.ToString(),
                service.getAuthorizationUrl().ToString(),
                service.getAccessUrl().url.ToString());

            return(provider);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
        }
Esempio 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);
        }
 private static bool GadgetWantsLockedDomain(GadgetSpec gadget)
 {
     return(gadget.getModulePrefs().getFeatures().ContainsKey("locked-domain"));
 }
        /**
         * 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);
            }
        }
Esempio n. 7
0
 /**
  * Convenience function for getting the locale spec for the current context.
  *
  * Identical to:
  * Locale locale = gadget.getContext().getLocale();
  * gadget.getSpec().getModulePrefs().getLocale(locale);
  */
 public LocaleSpec getLocale()
 {
     return(spec.getModulePrefs().getLocale(context.getLocale()));
 }
Esempio n. 8
0
        private JsonObject CallJob(GadgetContext context)
        {
            try
            {
                JsonObject gadgetJson = new JsonObject();
                Gadget     gadget     = Processor.Process(context);

                GadgetSpec  spec  = gadget.getSpec();
                ModulePrefs prefs = spec.getModulePrefs();

                // TODO: modularize response fields based on requested items.
                JsonObject views = new JsonObject();
                foreach (View view in spec.getViews().Values)
                {
                    views.Put(view.getName(), new JsonObject()
                              // .Put("content", view.getContent())
                              .Put("type", view.getType().ToString().ToLower())
                              .Put("quirks", view.getQuirks())
                              .Put("preferredHeight", view.getPreferredHeight())
                              .Put("preferredWidth", view.getPreferredWidth()));
                }

                // Features.
                List <String> feats = new List <String>();
                foreach (var entry in prefs.getFeatures())
                {
                    feats.Add(entry.Key);
                }
                string[] features = new string[feats.Count];
                feats.CopyTo(features, 0);

                // Links
                JsonObject links = new JsonObject();
                foreach (LinkSpec link in prefs.getLinks().Values)
                {
                    links.Put(link.getRel(), link.getHref());
                }

                JsonObject userPrefs = new JsonObject();

                // User pref specs
                foreach (UserPref pref in spec.getUserPrefs())
                {
                    JsonObject up = new JsonObject()
                                    .Put("displayName", pref.getDisplayName())
                                    .Put("type", pref.getDataType().ToString().ToLower())
                                    .Put("default", pref.getDefaultValue())
                                    .Put("enumValues", pref.getEnumValues())
                                    .Put("orderedEnumValues", getOrderedEnums(pref));
                    userPrefs.Put(pref.getName(), up);
                }

                // TODO: This should probably just copy all data from
                // ModulePrefs.getAttributes(), but names have to be converted to
                // camel case.
                gadgetJson.Put("iframeUrl", UrlGenerator.getIframeUrl(gadget))
                .Put("url", context.getUrl().ToString())
                .Put("moduleId", context.getModuleId())
                .Put("title", prefs.getTitle())
                .Put("titleUrl", prefs.getTitleUrl().ToString())
                .Put("views", views)
                .Put("features", features)
                .Put("userPrefs", userPrefs)
                .Put("links", links)

                // extended meta data
                .Put("directoryTitle", prefs.getDirectoryTitle())
                .Put("description", prefs.getDescription())
                .Put("thumbnail", prefs.getThumbnail().ToString())
                .Put("screenshot", prefs.getScreenshot().ToString())
                .Put("author", prefs.getAuthor())
                .Put("authorEmail", prefs.getAuthorEmail())
                .Put("authorAffiliation", prefs.getAuthorAffiliation())
                .Put("authorLocation", prefs.getAuthorLocation())
                .Put("authorPhoto", prefs.getAuthorPhoto())
                .Put("authorAboutme", prefs.getAuthorAboutme())
                .Put("authorQuote", prefs.getAuthorQuote())
                .Put("authorLink", prefs.getAuthorLink())
                .Put("categories", prefs.getCategories())
                .Put("screenshot", prefs.getScreenshot().ToString())
                .Put("height", prefs.getHeight())
                .Put("width", prefs.getWidth())
                .Put("showStats", prefs.getShowStats())
                .Put("showInDirectory", prefs.getShowInDirectory())
                .Put("singleton", prefs.getSingleton())
                .Put("scaling", prefs.getScaling())
                .Put("scrolling", prefs.getScrolling());
                return(gadgetJson);
            }
            catch (ProcessingException e)
            {
                throw new RpcException(context, e);
                //throw e;
            }
            catch (JsonException e)
            {
                // Shouldn't be possible
                throw new RpcException(context, e);
            }
        }