Esempio n. 1
0
  private static List<String> buildScriptList(PageAlias pageAlias, ScriptConfig scriptConfig) {

    List<String> resultList = new ArrayList<String>();
    if (scriptConfig != null) {
      List<Script> scriptList = scriptConfig.getScriptListInPage(pageAlias.toString());

      if (scriptList != null) {
        for (Script script : scriptList) {
          if (script.getName().equals("environmentVariable")) {
            script.setScript(buildEnvironmentVariable());
          }
          resultList.add(buildScriptItem(script));
        }
      }
    }

    return resultList;
  }
Esempio n. 2
0
  private static String buildScriptItem(Script script) {
    String externalTagFormat = "%1$s<script type=\"text/javascript\" src=\"%2$s\"></script>%3$s";
    String inlineTagFormat = "%1$s<script type=\"text/javascript\">%2$s</script>%3$s";

    String tagFormat;
    String jsContent;
    String jsTagHeader = "";
    String jsTagFooter = "";
    String version =
        (script.getLimitBrowserVersion() > 0)
            ? String.valueOf(script.getLimitBrowserVersion())
            : "";

    if (script.getResourceType() == ResourceType.External) {
      tagFormat = externalTagFormat;
      if (script.isDevelop()) {
        jsContent = UrlHelper.buildDevJs(script.getScript());
      } else {
        jsContent = UrlHelper.buildJs(script.getScript());
      }
    } else {
      tagFormat = inlineTagFormat;
      jsContent = script.getScript();
    }

    switch (script.getLimitBrowserType()) {
      case IEOnly:
        jsTagHeader = "<!--[if IE" + version + "]>";
        jsTagFooter = "<![endif]-->";
        break;
      case NonIEOnly:
        jsTagHeader = "<![if IE" + version + "]>";
        jsTagFooter = "<![endif]>";
        break;
      default:
        break;
    }

    return String.format(tagFormat, jsTagHeader, jsContent, jsTagFooter);
  }