You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by John Hjelmstad <fa...@google.com> on 2011/01/11 01:37:33 UTC

Re: custom GadgetRewriter question

Hey Nik:

Interesting use case, and find. For my part I wouldn't be opposed to seeing
this put in our list of "default" rewriters. This conveniently bypasses the
Module override issue, though of course doesn't solve it.

Do you plan to add this to the flash JS APIs as well?

--j

On Mon, Dec 27, 2010 at 3:12 AM, NikNik <n_...@infostoria.com.ua>wrote:

> hi
>
> yes. This is a good solution for my problem.
> But it's in a Shindig 3.0.0 Snapshot. But I have 2.0.0 release :(
>
> For now I have done this:
>
> public class GaSGadgetRewritersProvider
>    extends GadgetRewritersProvider
> {
>    private List<GadgetRewriter> rewriters;
>
>    @Inject
>    public GaSGadgetRewritersProvider(
>        @com.google.inject.name.Named("shindig.rewriters.gadget")
> List<GadgetRewriter> baseRewriters)
>    {
>        super(Collections.<GadgetRewriter>emptyList());
>        List<GadgetRewriter> rewriters = new
> LinkedList<GadgetRewriter>(baseRewriters);
>        rewriters.add(new GaSFlashEmbedRewriter());
>        this.rewriters = Collections.unmodifiableList(rewriters);
>    }
>
>    @Override
>    public List<GadgetRewriter> getRewriters(GadgetContext context)
>    {
>        return this.rewriters;
>    }
> }
>
> But I don't like it :(
>
> Maybe I should describe whole situation:
>
> Rewriters code:
>
> public class GaSFlashEmbedRewriter
>    implements GadgetRewriter
> {
>    @Override
>    public void rewrite(Gadget gadget, MutableContent mutableContent)
>        throws RewritingException
>    {
>        Document document = mutableContent.getDocument();
>
>        NodeList embeds = document.getElementsByTagName("embed");
>        for (int i = 0; i < embeds.getLength(); i++)
>        {
>            Element embed = (Element) embeds.item(i);
>            embed.setAttribute("wmode", "transparent");
>        }
>
>        NodeList objects = document.getElementsByTagName("object");
>        for (int i = 0; i < objects.getLength(); i++)
>        {
>            Element object = (Element) objects.item(i);
>            NodeList params = object.getChildNodes();
>            boolean modeChanged = false;
>            for (int j = 0; j < params.getLength(); j++)
>            {
>                if (params.item(j) instanceof Element)
>                {
>                    Element param = (Element) params.item(j);
>                    if (("param".equals(param.getNodeName().toLowerCase()))
> && ("wmode".equals(param.getAttribute(
>                        "name").toLowerCase())))
>                    {
>                        param.setAttribute("value", "transparent");
>                        modeChanged = true;
>                    }
>                }
>            }
>            if (!modeChanged)
>            {
>                Element newParam = document.createElement("param");
>                newParam.setAttribute("name", "wmode");
>                newParam.setAttribute("value", "transparent");
>                object.appendChild(newParam);
>            }
>        }
>    }
> }
>
> Problem discussion:
>
> http://jamestombs.co.uk/2008-10-09/html-display-html-content-over-a-flash-object/835
>
> What I'm trying to do is that, if gadget contains flash objects, HTML
> elements on the containers site can be placed above it.
>
> I don't like my injection point. Any thoughts ?
>
> thanks
>
>
> On 12/27/2010 07:50 AM, Kai Feng Zhang wrote:
>
>> I happened to reported a jira for custom rewriters. See here:
>>
>>  https://issues.apache.org/jira/browse/SHINDIG-1456
>>
>> Does it help?
>>
>> On Wednesday, December 22, 2010, NikNik<n_...@infostoria.com.ua>
>>  wrote:
>>
>>> hi
>>>
>>> I want to add 1 custom rewriter.
>>> It doesn't matter in which part of rewriters chain.
>>>
>>> If I'll extend RewriteModule I'll be forced to rewrite DefaultGuiceModule
>>> (because RewriteModule installing from there). This solution may lead
>>> me to future synchronization troubles with new versions of shindig.
>>>
>>> RewriteModule.provideGadgetRewriters -- is annotation injection:
>>>
>>>   @Provides
>>>   @Singleton
>>>   @Named("shindig.rewriters.gadget")
>>>   protected List<GadgetRewriter>  provideGadgetRewriters(
>>>       PipelineDataGadgetRewriter pipelineRewriter,
>>>       TemplateRewriter templateRewriter,
>>>       AbsolutePathReferenceRewriter absolutePathRewriter,
>>>       StyleTagExtractorContentRewriter styleTagExtractorRewriter,
>>>       StyleAdjacencyContentRewriter styleAdjacencyRewriter,
>>>       ProxyingContentRewriter proxyingRewriter,
>>>       CajaContentRewriter cajaRewriter,
>>>       SanitizingGadgetRewriter sanitizedRewriter,
>>>       RenderingGadgetRewriter renderingRewriter,
>>>       OpenSocialI18NGadgetRewriter i18nRewriter) {
>>>     return ImmutableList.of(pipelineRewriter, templateRewriter,
>>>         absolutePathRewriter, styleTagExtractorRewriter,
>>> styleAdjacencyRewriter, proxyingRewriter,
>>>         cajaRewriter, sanitizedRewriter, renderingRewriter,
>>> i18nRewriter);
>>>   }
>>>
>>> What if I'll create my own module. Which will directly inject
>>> List<GadgetRewriter>
>>>      to override annotation injection.
>>>
>>> But I don't know how to inject collections directly. This construction
>>> doesn't work:
>>>
>>>         this.binder()
>>>             .bind(List.class)
>>>             .annotatedWith(Names.named("shindig.rewriters.gadget"))
>>>             .toInstance(new ArrayList<GadgetRewriter>());
>>>
>>> And I don't know where can I get other injected rewriters to create final
>>> rewriters List in my module...
>>>
>>> Does this make sense ?
>>>
>>> thanks
>>>
>>> On 12/21/2010 11:06 PM, John Hjelmstad wrote:
>>>
>>> IMO depends on how much customization you want to do. If you want to add
>>> a
>>> rewriter to the beginning or end of the rewriter chain you might just be
>>> able to extend RewriteModule. We @Google have enough customization that
>>> we
>>> basically just created our own RewriteModule and in it supply our own
>>> bindings in the order we require. We don't get as much code reuse this
>>> way
>>> (ie. we don't use Shindig's RewriteModule) but we get more flexibility.
>>>
>>> Cheers,
>>> John
>>>
>>> On Tue, Dec 21, 2010 at 12:59 PM, NikNik<n_nikolaenko@infostoria.com.ua
>>> >wrote:
>>>
>>>
>>> hi
>>>
>>> I have a small question because I'm newbie in Guice.
>>>
>>> Where is the best place to inject my additional GadgetRewriter
>>> implementation ?
>>> I mean which module I should replace or where add provider/module or ...
>>> if I don't want to harm whole architecture ?
>>>
>>> Should I replace/extend DefaultGuiceModule and RewriteModule?
>>> Or better way to provide new module for GadgetRewritersProvider injection
>>> ?
>>>
>>> I just want to keep the shindig clear like it is :)
>>>
>>> thanks
>>>
>>>
>>>
>>>
>>>
>