JsLibraray.java has a bug
-------------------------

                 Key: SHINDIG-1102
                 URL: https://issues.apache.org/jira/browse/SHINDIG-1102
             Project: Shindig
          Issue Type: Bug
          Components: Java
    Affects Versions: 1.0
            Reporter: Vinu Neelambaran
            Priority: Critical
             Fix For: 1.0


I downloaded the latest shindig. I tried to create a sample feature called 
sample-0.1 which has two files namely feature.xml and sample.js.
I when I tried to use that feature in a gadget, I found that the javascript for 
that feature is not getting injected into the gadget.

I found the that the bug is in JsLibrary.java. It has a create() method which 
is responsible for getting the javasript library from the 
required resource/location. If the feature does not have a *.opt.js file, then 
the javascript content returned was null. This was because one if statement
was missing in the method. Please find below the modified create() method. 


 public static JsLibrary create(Type type, String content, String feature,
      HttpFetcher fetcher) throws GadgetException {
    String optimizedContent = null;
    String debugContent;
    switch (type) {
      case FILE:
      case RESOURCE:
        StringBuffer opt = new StringBuffer();
        StringBuffer dbg = new StringBuffer();
        loadOptimizedAndDebugData(content, type, opt, dbg);
        optimizedContent = opt.toString();
        debugContent = dbg.toString();
        
          /*
         * the foolowing conditional statements are to be added to check wheter 
optimizedContent =null
         */
        
        if(optimizedContent == null) {
                optimizedContent = debugContent;
        }
        else if(optimizedContent.equalsIgnoreCase("null")) { // this is because 
null was returned as a String
                optimizedContent = debugContent;
        }
        else if(optimizedContent.length() == 0) {
                optimizedContent = debugContent;
        }
        



        break;
      case URL:
        if (fetcher == null) {
          debugContent = optimizedContent = content;
        } else {
          type = Type.FILE;
          debugContent = optimizedContent = loadDataFromUrl(content, fetcher);
        }
        break;
      default:
        debugContent = content;
        optimizedContent = content;
        break;
    }
        return new JsLibrary(feature, type, optimizedContent, debugContent);
  }


-- 
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