예제 #1
0
        /// <summary>
        /// Process a single gadget. Creates a gadget from a retrieved GadgetSpec and context object,
        /// automatically performing variable substitution on the spec for use elsewhere.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Gadget Process(GadgetContext context)
        {
            Uri url = context.getUrl();

            if (url == null)
            {
                throw new ProcessingException("Missing or malformed url parameter");
            }

            if (!url.Scheme.ToLower().Equals("http") && !url.Scheme.ToLower().Equals("https"))
            {
                throw new ProcessingException("Unsupported scheme (must be http or https).");
            }

            if (blacklist.isBlacklisted(context.getUrl()))
            {
                throw new ProcessingException("The requested gadget is unavailable");
            }

            try
            {
                GadgetSpec spec = gadgetSpecFactory.getGadgetSpec(context);
                spec = substituter.substitute(context, spec);

                return(new Gadget()
                       .setContext(context)
                       .setSpec(spec)
                       .setCurrentView(GetView(context, spec)));
            }
            catch (GadgetException e)
            {
                throw new ProcessingException(e.Message, e);
            }
        }
예제 #2
0
        public virtual RewriterResults rewrite(sRequest request, sResponse original, MutableContent content)
        {
            ByteArrayOutputStream baos   = new ByteArrayOutputStream((content.getContent().Length * 110) / 100);
            OutputStreamWriter    output = new OutputStreamWriter(baos);
            String mimeType = original.getHeader("Content-Type");

            if (request.RewriteMimeType != null)
            {
                mimeType = request.RewriteMimeType;
            }
            GadgetSpec spec = null;

            if (request.Gadget != null)
            {
                spec = _specFactory.getGadgetSpec(request.Gadget.toJavaUri(), false);
            }
            if (rewrite(spec, request.getUri(),
                        content,
                        mimeType,
                        output))
            {
                content.setContent(Encoding.Default.GetString(baos.toByteArray()));
                return(RewriterResults.cacheableIndefinitely());
            }

            return(null);
        }
예제 #3
0
 private GadgetSpec findSpec(ISecurityToken securityToken, OAuthArguments arguments, OAuthResponseParams responseParams)
 {
     try
     {
         return(specFactory.getGadgetSpec(new Uri(securityToken.getAppUrl()),
                                          arguments.getBypassSpecCache()));
     }
     catch (UriFormatException e)
     {
         throw responseParams.oauthRequestException(OAuthError.UNKNOWN_PROBLEM,
                                                    "Could not fetch gadget spec, gadget URI invalid.", e);
     }
     catch (GadgetException e)
     {
         throw responseParams.oauthRequestException(OAuthError.UNKNOWN_PROBLEM,
                                                    "Could not fetch gadget spec", e);
     }
 }
        public ContentRewriterFeature get(sRequest request)
        {
            Uri        gadgetUri = request.Gadget;
            GadgetSpec spec;

            if (gadgetUri != null)
            {
                URI gadgetJavaUri = gadgetUri.toJavaUri();
                try
                {
                    spec = specFactory.getGadgetSpec(gadgetJavaUri, false);
                    if (spec != null)
                    {
                        return(get(spec));
                    }
                }
                catch (GadgetException)
                {
                    return(defaultFeature);
                }
            }
            return(defaultFeature);
        }