public MessageBundle getBundle(GadgetSpec spec, Locale locale, bool ignoreCache)
        {
            if (ignoreCache)
            {
                return(getNestedBundle(spec, locale, true));
            }

            String key = spec.getUrl().ToString() + '.' + locale.ToString();

            MessageBundle cached = HttpRuntime.Cache[key] as MessageBundle;

            MessageBundle bundle;

            if (cached == null)
            {
                try
                {
                    bundle = getNestedBundle(spec, locale, ignoreCache);
                }
                catch (GadgetException)
                {
                    // Enforce negative caching.
                    bundle = cached ?? MessageBundle.EMPTY;
                }
                HttpRuntime.Cache.Insert(key, bundle, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(refresh));
            }
            else
            {
                bundle = cached;
            }

            return(bundle);
        }
Beispiel #2
0
        /**
         * Render the gadget into a string by performing the following steps:
         *
         * - Retrieve gadget specification information (GadgetSpec, MessageBundle, etc.)
         *
         * - Fetch any preloaded data needed to handle the request, as handled by Preloader.
         *
         * - Perform rewriting operations on the output content, handled by Rewriter.
         *
         * @param gadget The gadget for the rendering operation.
         * @return The rendered gadget content
         * @throws RenderingException if any issues arise that prevent rendering.
         */
        public String render(Gadget gadget)
        {
            try
            {
                View          view    = gadget.getCurrentView();
                GadgetContext context = gadget.getContext();
                GadgetSpec    spec    = gadget.getSpec();

                IPreloads preloads = preloader.preload(context, spec,
                                                       PreloaderService.PreloadPhase.HTML_RENDER);
                gadget.setPreloads(preloads);
                String content;

                if (view.getHref() == null)
                {
                    content = view.getContent();
                }
                else
                {
                    // TODO: Add current url to GadgetContext to support transitive proxying.
                    UriBuilder uri = new UriBuilder(view.getHref());
                    uri.addQueryParameter("lang", context.getLocale().getLanguage());
                    uri.addQueryParameter("country", context.getLocale().getCountry());

                    sRequest request = new sRequest(uri.toUri())
                                       .setIgnoreCache(context.getIgnoreCache())
                                       .setOAuthArguments(new OAuthArguments(view))
                                       .setAuthType(view.getAuthType())
                                       .setSecurityToken(context.getToken())
                                       .setContainer(context.getContainer())
                                       .setGadget(spec.getUrl());
                    sResponse response = DefaultHttpCache.Instance.getResponse(request);

                    if (response == null || response.isStale())
                    {
                        sRequest proxyRequest = createPipelinedProxyRequest(gadget, request);
                        response = requestPipeline.execute(proxyRequest);
                        DefaultHttpCache.Instance.addResponse(request, response);
                    }

                    if (response.isError())
                    {
                        throw new RenderingException("Unable to reach remote host. HTTP status " +
                                                     response.getHttpStatusCode());
                    }
                    content = response.responseString;
                }

                return(rewriter.rewriteGadget(gadget, content));
            }
            catch (GadgetException e)
            {
                throw new RenderingException(e.Message, e);
            }
        }
        private String GetLockedDomain(GadgetSpec gadget, String container)
        {
            String suffix;

            if (!lockedSuffixes.TryGetValue(container, out suffix))
            {
                return(null);
            }
            String hash = SHA1.Create().ComputeHash(Encoding.Default.GetBytes(gadget.getUrl().ToString())).ToString();

            return(hash + suffix);
        }
        /**
         * @param concatBase Base url of the Concat servlet. Expected to be of the
         *                   form www.host.com/concat?
         * @param relativeUrlBase to resolve relative urls
         */
        public JavascriptTagMerger(GadgetSpec spec, ContentRewriterFeature rewriterFeature,
                                   String concatBase, Uri relativeUrlBase)
        {
            // Force the mime-type to mimic browser expectation so rewriters
            // can function properly
            this.concatBase = concatBase
                              + ProxyBase.REWRITE_MIME_TYPE_PARAM
                              + "=text/javascript&"
                              + "gadget="
                              + HttpUtility.UrlEncode(spec.getUrl().ToString())
                              + "&fp="
                              + rewriterFeature.getFingerprint()
                              + '&';

            this.relativeUrlBase = relativeUrlBase;
        }
        public virtual RewriterResults rewrite(Gadget gadget, MutableContent content)
        {
            java.io.StringWriter sw   = new java.io.StringWriter();
            GadgetSpec           spec = gadget.getSpec();
            Uri  _base = spec.getUrl();
            View view  = gadget.getCurrentView();

            if (view != null && view.getHref() != null)
            {
                _base = view.getHref();
            }
            if (rewrite(spec, _base, content, "text/html", sw))
            {
                content.setContent(sw.toString());
            }
            return(null);
        }
 protected internal ILinkRewriter CreateLinkRewriter(GadgetSpec spec, ContentRewriterFeature rewriterFeature)
 {
     return(new ProxyingLinkRewriter(spec.getUrl(), rewriterFeature, ProxyUrl));
 }