[ 
https://issues.apache.org/jira/browse/SHINDIG-1260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804439#action_12804439
 ] 

Jacky Wang commented on SHINDIG-1260:
-------------------------------------

After some investigation, I found this problem might be a bit more complicated 
than it looks like.

1. I'm integrating James' features sorting code into GadgetFactory.
2. Where should we put the "forcedJsLib" logic in - GadgetFactory, or 
GadgetRendering part?  I suggest we putting it in GadgetFactory, thus 
GadgetRendering could render it straightforwardly.
3. The cache's behavior looks a bit strange - I'll merge them into 
GadgetRenderer.

The following are some notes:

GadgetRenderingServlet.php -> doGet
- create GadgetFactory
- create gadget by Factory

GadgetFactory.php -> createGadget
- fetch gadget content
- parse the content

GadgetSpecParser.php -> parseModulePrefs -> parseFeatures
1) specify the "required" features
2) specify the "optional" features
3) extract content rewrite settings (if exists)
4) add external/arbitary templates (if exists)
note that the features are not expanded yet - it's just an parsing process...

GadgetFactory.php -> parseFeatures
it is the real feature parsing process.
- call resolveFeatures, which calls addFeatureToResults recursively.
Therefore, the features are expanded in this step, and the features are 
categorized as "found" and "miss". The parsing flow could still go on if the 
missed feature is optional.

GadgetRenderingServlet.php -> renderGadget
It converts the gadget features (array of names) into the real "src=" or inline 
text.
Given the deriving hierarchy GadgetRenderer -> GadgetBaseRenderer -> 
[GadgetHtmlRenderer, GadgetUrlRenderer, GadgetHrefRenderer]:
- call Gadget***Renderer -> renderGadget



> Improper JavaScript inclusion logic leads to out-of-order and duplicate 
> includes / JavaScript errors
> ----------------------------------------------------------------------------------------------------
>
>                 Key: SHINDIG-1260
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-1260
>             Project: Shindig
>          Issue Type: Bug
>          Components: PHP
>    Affects Versions: 1.1-BETA5, 1.1-BETA6, 1.1-RC1
>         Environment: RedHat Linux 5.3, Apache 2.2.3, PHP 5.2.10
>            Reporter: James McIninch
>         Attachments: shindig-1260.patch
>
>
> The logic for selecting and inserting JavaScript using the 
> GadgetFeatureRegistry and GadgetBaseRender is incorrect. The result is that 
> JavaScript for features is included out-of-order of their dependencies, 
> sometimes multiply included, and the 'gadgets' JavaScript object is not 
> defined.
> Consider the following simple gadget:
> <?xml version="1.0" encoding="UTF-8"?>
> <Module>
>       <ModulePrefs title="Hello" description="An example of a simple gadget" 
> author="James McIninch" author_email="james.mcin...@biogenidec.com" />
>       <UserPref name="firstname" display_name="Your name" datatype="string" 
> default_value="stranger" />
>       <Content type="html" preferred_height="50" preferred_width="200">
>               <![CDATA[
>                   <script type="text/javascript">
>                      var prefs = new gadgets.Prefs();
>                      var name  = prefs.getString("firstname");
>                      document.getElementById("placeholder").innerHTML = name;
>                   </script>
>                   
>                   Hello, <span id="placeholder">name goes here</span>!
>               ]]>
>       </Content>
> </Module>
> This is rendered as:
> Hello, name goes here!
> Inspecting the JavaScript error console shows that 'gadgets' is undefined. 
> However, the first instance of 'gadgets' being undefined lies in the 
> Shindig-included JavaScript. This is because auth-init.js is included before 
> config.js (both in features/src/main/javascript/features/core.*), but 
> auth-init.js contains the line (28):
> shindig.auth = new shindig.Auth();
> which, in turn calls (auth.js line 159):
> gadgets.config.register("shindig.auth", null, init);
> ... but the 'gadgets' and 'gadgets.config' objects are not yet defined at 
> that point. Despite being dependencies for the auth.js, they aren't  included 
> in the order where the dependencies precede the code that depends on them.
> Also looking at the source of the rendered gadget, the taming.js code is 
> included 5 separate times.
> Correcting the bug will entail re-thinking the logic of the feature ordering 
> to include the dependency information and order the features based on the 
> dependencies.
> All gadgets requiring the 'gadgets' object to be defined currently fail. 
> Gadgets using the legacy model still function, though there exists redundant 
> and erroneous JavaScript.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to