Exemple #1
0
 protected void printStartElement(QName element, XMLAttributes attrs) throws XNIException {
   if (element.rawname.equalsIgnoreCase("script") && attrs != null) {
     String value = attrs.getValue("type");
     if (value != null && value.equalsIgnoreCase(SCRIPT_TYPE)) {
       String src = attrs.getValue("src");
       if (src != null && src.equals(scriptURL)) {
         attrs.setValue(attrs.getIndex("src"), zazlPath);
         String dojoDataConfigStr = attrs.getValue(attrs.getIndex("data-dojo-config"));
         configScriptTag =
             configScriptTag.replace("__DOJOCONFIG__", "{" + dojoDataConfigStr + "}");
         attrs.removeAttributeAt(attrs.getIndex("data-dojo-config"));
         Matcher m = packagesRegex.matcher(dojoDataConfigStr);
         if (m.find()) {
           String packagesString = m.group(0);
           if (packagesString != null) {
             StringBuffer sb = new StringBuffer();
             try {
               Map<String, Object> packages =
                   (Map<String, Object>)
                       JSONParser.parse(new StringReader('{' + packagesString + '}'));
               List<Map<String, Object>> packageList =
                   (List<Map<String, Object>>) packages.get("packages");
               for (Map<String, Object> pkg : packageList) {
                 String name = (String) pkg.get("name");
                 if (name.equals("zazl")) {
                   continue;
                 }
                 String location = (String) pkg.get("location");
                 location = normalize(dojoLoaderPath + location);
                 sb.append("		'");
                 sb.append(name);
                 sb.append("' : '");
                 sb.append(location);
                 sb.append("',\n");
               }
               sb.deleteCharAt(sb.length() - 1);
               sb.deleteCharAt(sb.length() - 1);
               configScriptTag = configScriptTag.replace("__PATHS__", sb.toString());
             } catch (IOException e) {
               e.printStackTrace();
             }
           }
         }
       }
       super.printStartElement(element, attrs);
     } else {
       super.printStartElement(element, attrs);
     }
   } else {
     super.printStartElement(element, attrs);
   }
 }
Exemple #2
0
 protected void printEndElement(QName element) throws XNIException {
   super.printEndElement(element);
   if (element.rawname.equalsIgnoreCase("script")) {
     if (scriptURL != null && scriptURL.indexOf("/dojo/dojo.js") != -1) {
       fPrinter.println();
       fPrinter.println(configScriptTag);
       scriptURL = null;
     }
   }
 }