Ejemplo n.º 1
0
  public static void writeModules(String filename) {
    Data data = makeHDF();

    int i = 0;
    for (PackageInfo pkg : chooseModulePackages()) {

      data.setValue("reference", "1");
      data.setValue("reference.apilevels", sinceTagger.hasVersions() ? "1" : "0");
      data.setValue("docs.packages." + i + ".name", pkg.name());
      makeModuleListHDF(data, "docs.packages." + i + ".modules", pkg.modules());

      for (int j = 0; j < pkg.modules().length; j++) {
        Data classData = makeHDF();
        ClassInfo mod = pkg.modules()[j];
        writeModule(mod, classData);
      }

      i++;
    }

    setPageTitle(data, "Module Index");

    TagInfo.makeHDF(data, "root.descr", Converter.convertTags(root.inlineTags(), null));

    ClearPage.write(data, "modules.cs", filename);

    Proofread.writePackages(filename, Converter.convertTags(root.inlineTags(), null));
  }
Ejemplo n.º 2
0
  @Test
  public void testCustomConvert() {

    JSilver jSilver =
        new JSilver(
            new ClassLoaderResourceLoader(MvcModule.class.getClassLoader(), "org/example/views"));

    Data data = jSilver.createData();

    // prepare data
    List<Book> books = new LinkedList<Book>();
    books.add(new Book("Programming Scala", "Wampler & Payne"));
    books.add(new Book("Modern C++ Design", "Andrei Alexandrescu"));

    // convert
    ModelService service =
        ModelService.createTestService(
            new ModelObjectConverter<Book>(Book.class) {

              @Override
              public void convertObject(Book obj, Data data, ModelService convService) {
                data.setValue("name", obj.name);
                data.setValue("author", obj.author);
              }
            });

    service.convert("books", books, data);

    // check result
    System.out.println(data.toString());
  }
Ejemplo n.º 3
0
  @Test
  public void testComplexConvert() {

    JSilver jSilver =
        new JSilver(
            new ClassLoaderResourceLoader(MvcModule.class.getClassLoader(), "org/example/views"));

    Data data = jSilver.createData();

    // prepare data
    List<Map<String, String>> x = new LinkedList<Map<String, String>>();

    Map<String, String> m = new HashMap<String, String>();
    m.put("name", "Home");
    m.put("URL", "/");
    x.add(m);

    m = new HashMap<String, String>();
    m.put("name", "Preferences");
    m.put("URL", "/pref");
    x.add(m);

    m = new HashMap<String, String>();
    m.put("name", "Help");
    m.put("URL", "/help");
    x.add(m);

    // convert
    ModelService service = ModelService.createTestService();
    service.convert("menu", x, data);

    // check result
    System.out.println(data.toString());
  }
Ejemplo n.º 4
0
 public void makeLink(Data data, String base) {
   if (checkLevel()) {
     data.setValue(base + ".link", htmlPage());
   }
   data.setValue(base + ".name", name());
   data.setValue(base + ".since.key", SinceTagger.keyForName(getSince()));
   data.setValue(base + ".since.name", getSince());
 }
Ejemplo n.º 5
0
 @Override
 public void makeHDF(Data data, String base) {
   data.setValue(base + ".name", name());
   data.setValue(base + ".kind", kind());
   if (mIncluded != null) {
     data.setValue(base + ".text", mIncluded);
   } else {
     data.setValue(base + ".text", "INCLUDE_ERROR");
   }
 }
Ejemplo n.º 6
0
 public void makeClassLinkListHDF(Data data, String base) {
   makeLink(data, base);
   ClassInfo.makeLinkListHDF(data, base + ".annotations", getAnnotations());
   ClassInfo.makeLinkListHDF(data, base + ".interfaces", getInterfaces());
   ClassInfo.makeLinkListHDF(data, base + ".classes", ordinaryClasses());
   ClassInfo.makeLinkListHDF(data, base + ".enums", enums());
   ClassInfo.makeLinkListHDF(data, base + ".exceptions", exceptions());
   ClassInfo.makeLinkListHDF(data, base + ".errors", errors());
   data.setValue(base + ".since.key", SinceTagger.keyForName(getSince()));
   data.setValue(base + ".since.name", getSince());
 }
Ejemplo n.º 7
0
  public void makeHDF(Data data, String base, Map<String, TypeInfo> typeMapping) {
    data.setValue(base + ".kind", kind());
    data.setValue(base + ".name", name());
    data.setValue(base + ".href", htmlPage());
    data.setValue(base + ".anchor", anchor());

    if (mReturnType != null) {
      returnType()
          .getTypeWithArguments(typeMapping)
          .makeHDF(data, base + ".returnType", false, typeVariables());
      data.setValue(base + ".abstract", mIsAbstract ? "abstract" : "");
    }

    data.setValue(base + ".synchronized", mIsSynchronized ? "synchronized" : "");
    data.setValue(base + ".final", isFinal() ? "final" : "");
    data.setValue(base + ".static", isStatic() ? "static" : "");

    TagInfo.makeHDF(data, base + ".shortDescr", firstSentenceTags());
    TagInfo.makeHDF(data, base + ".descr", inlineTags());
    TagInfo.makeHDF(data, base + ".deprecated", deprecatedTags());
    TagInfo.makeHDF(data, base + ".seeAlso", seeTags());
    data.setValue(base + ".since", getSince());
    if (isDeprecated()) {
      data.setValue(base + ".deprecatedsince", getDeprecatedSince());
    }
    ParamTagInfo.makeHDF(data, base + ".paramTags", paramTags());
    AttrTagInfo.makeReferenceHDF(data, base + ".attrRefs", comment().attrTags());
    ThrowsTagInfo.makeHDF(data, base + ".throws", throwsTags());
    ParameterInfo.makeHDF(
        data,
        base + ".params",
        mParameters.toArray(new ParameterInfo[mParameters.size()]),
        isVarArgs(),
        typeVariables(),
        typeMapping);
    if (isProtected()) {
      data.setValue(base + ".scope", "protected");
    } else if (isPublic()) {
      data.setValue(base + ".scope", "public");
    }
    TagInfo.makeHDF(data, base + ".returns", returnTags());

    if (mTypeParameters != null) {
      TypeInfo.makeHDF(data, base + ".generic.typeArguments", mTypeParameters, false);
    }

    AnnotationInstanceInfo.makeLinkListHDF(
        data,
        base + ".showAnnotations",
        showAnnotations().toArray(new AnnotationInstanceInfo[showAnnotations().size()]));

    setFederatedReferences(data, base);
  }
Ejemplo n.º 8
0
  public static void writeLists() {
    Data data = makeHDF();

    ClassInfo[] classes = Converter.rootClasses();

    SortedMap<String, Object> sorted = new TreeMap<String, Object>();
    for (ClassInfo cl : classes) {
      if (cl.isHidden()) {
        continue;
      }
      sorted.put(cl.qualifiedName(), cl);
      PackageInfo pkg = cl.containingPackage();
      String name;
      if (pkg == null) {
        name = "";
      } else {
        name = pkg.name();
      }
      sorted.put(name, pkg);
      for (MethodInfo method : cl.methods()) {
        if (method.isProcessor() || method.isSource() || method.isTransformer()) {
          sorted.put(method.elementName(), method);
        }
      }
    }

    int i = 0;
    for (String s : sorted.keySet()) {
      data.setValue("docs.pages." + i + ".id", "" + i);
      data.setValue("docs.pages." + i + ".label", s);

      Object o = sorted.get(s);
      if (o instanceof PackageInfo) {
        PackageInfo pkg = (PackageInfo) o;
        data.setValue("docs.pages." + i + ".link", "java/" + pkg.htmlPage());
        data.setValue("docs.pages." + i + ".type", "package");
      } else if (o instanceof ClassInfo) {
        ClassInfo cl = (ClassInfo) o;
        data.setValue("docs.pages." + i + ".link", "java/" + cl.htmlPage());
        data.setValue("docs.pages." + i + ".type", "class");
      } else if (o instanceof MethodInfo) {
        MethodInfo mi = (MethodInfo) o;
        data.setValue("docs.pages." + i + ".id", "" + i);
        data.setValue("docs.pages." + i + ".link", "mule/" + mi.relativeModulePath());
        data.setValue("docs.pages." + i + ".type", "method");
      }
      i++;
    }

    ClearPage.write(data, "lists.cs", javadocDir + "lists.js");
  }
Ejemplo n.º 9
0
 public static void setPageTitle(Data data, String title) {
   String s = title;
   if (Doclava.title.length() > 0) {
     s += " - " + Doclava.title;
   }
   data.setValue("page.title", s);
 }
Ejemplo n.º 10
0
  public static void writeMarkdowns() {
    MarkdownProcessor markdown = new MarkdownProcessor();
    for (String[] m : mMarkdown) {
      try {
        String mdContent = FileUtils.readFileToString(new File(m[1]));
        String htmlContent = markdown.markdown(mdContent);
        String outFile = FilenameUtils.getName(m[1]).replaceAll(".md", ".html").toLowerCase();
        Data data = makeHDF();

        data.setValue("content", htmlContent);
        data.setValue("section", m[0]);
        ClearPage.write(data, "markdown.cs", outFile);
      } catch (IOException e) {
        System.err.println("Cannot read " + m[1] + " file: " + e.getMessage());
      }
    }
  }
Ejemplo n.º 11
0
 public static void writeSource(ClassInfo cl, Data data) {
   try {
     cl.makeHDF(data);
     data.setValue("class.source", SampleTagInfo.escapeHtml(cl.getSource()));
     setPageTitle(data, cl.name());
     ClearPage.write(data, "source.cs", Doclava.javadocDir + cl.relativePath("-source"));
   } catch (IOException e) {
     Errors.error(Errors.IO_ERROR, null, "Could not find source file for " + cl.name());
   }
 }
Ejemplo n.º 12
0
  @Test
  public void testCollectionConvert() {
    // prepare data
    JSilver jSilver =
        new JSilver(
            new ClassLoaderResourceLoader(MvcModule.class.getClassLoader(), "org/example/views"));

    Data data = jSilver.createData();

    List<Integer> x = new LinkedList<Integer>();
    x.add(10);
    x.add(20);
    x.add(30);

    // convert
    ModelService service = ModelService.createTestService();
    service.convert("root", x, data);

    // check result
    System.out.println(data.toString());
  }
Ejemplo n.º 13
0
  @Test
  public void testMapConvert() {
    JSilver jSilver =
        new JSilver(
            new ClassLoaderResourceLoader(MvcModule.class.getClassLoader(), "org/example/views"));

    Data data = jSilver.createData();

    // prepare data
    Map<String, Boolean> x = new HashMap<String, Boolean>();
    x.put("val1", true);
    x.put("val2", false);
    x.put("val3", false);
    x.put("val4", true);

    // convert
    ModelService service = ModelService.createTestService();
    service.convert("root", x, data);

    // check result
    System.out.println(data.toString());
  }
Ejemplo n.º 14
0
  public static void writePackage(PackageInfo pkg) {
    // these this and the description are in the same directory,
    // so it's okay
    Data data = makePackageHDF();

    String name = pkg.name();

    data.setValue("package.name", name);
    data.setValue("package.since.key", SinceTagger.keyForName(pkg.getSince()));
    data.setValue("package.since.name", pkg.getSince());
    data.setValue("package.descr", "...description...");
    pkg.setFederatedReferences(data, "package");

    makeClassListHDF(data, "package.annotations", ClassInfo.sortByName(pkg.getAnnotations()));
    makeClassListHDF(data, "package.interfaces", ClassInfo.sortByName(pkg.getInterfaces()));
    makeClassListHDF(data, "package.classes", ClassInfo.sortByName(pkg.ordinaryClasses()));
    makeClassListHDF(data, "package.modules", ClassInfo.sortByName(pkg.modules()));
    makeClassListHDF(data, "package.enums", ClassInfo.sortByName(pkg.enums()));
    makeClassListHDF(data, "package.exceptions", ClassInfo.sortByName(pkg.exceptions()));
    makeClassListHDF(data, "package.errors", ClassInfo.sortByName(pkg.errors()));

    TagInfo[] shortDescrTags = pkg.firstSentenceTags();
    TagInfo[] longDescrTags = pkg.inlineTags();
    TagInfo.makeHDF(data, "package.shortDescr", shortDescrTags);
    TagInfo.makeHDF(data, "package.descr", longDescrTags);
    data.setValue(
        "package.hasLongDescr", TagInfo.tagsEqual(shortDescrTags, longDescrTags) ? "0" : "1");

    String filename = Doclava.javadocDir + pkg.relativePath();
    setPageTitle(data, name);
    ClearPage.write(data, "package.cs", filename);

    filename = javadocDir + pkg.fullDescriptionFile();
    setPageTitle(data, name + " Details");
    ClearPage.write(data, "package-descr.cs", filename);

    Proofread.writePackage(filename, pkg.inlineTags());
  }
Ejemplo n.º 15
0
  public static void writePackages(String filename) {
    Data data = makePackageHDF();

    int i = 0;
    for (PackageInfo pkg : choosePackages()) {
      writePackage(pkg);

      data.setValue("docs.packages." + i + ".name", pkg.name());
      data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
      TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr", pkg.firstSentenceTags());

      i++;
    }

    setPageTitle(data, "Package Index");

    TagInfo.makeHDF(data, "root.descr", Converter.convertTags(root.inlineTags(), null));

    ClearPage.write(data, "packages.cs", filename);
    ClearPage.write(data, "package-list.cs", javadocDir + "package-list");

    Proofread.writePackages(filename, Converter.convertTags(root.inlineTags(), null));
  }
Ejemplo n.º 16
0
  private static boolean readTemplateSettings() {
    Data data = makeHDF();

    // The .html extension is hard-coded in several .cs files,
    // and so you cannot currently set it as a property.
    htmlExtension = ".html";
    // htmlExtension = data.getValue("template.extension", ".html");
    int i = 0;
    while (true) {
      String k = data.getValue("template.escape." + i + ".key", "");
      String v = data.getValue("template.escape." + i + ".value", "");
      if ("".equals(k)) {
        break;
      }
      if (k.length() != 1) {
        System.err.println("template.escape." + i + ".key must have a length of 1: " + k);
        return false;
      }
      escapeChars.put(k.charAt(0), v);
      i++;
    }
    return true;
  }
Ejemplo n.º 17
0
  public static void writePage(String docfile, String relative, String outfile) {
    Data hdf = Doclava.makeHDF();

    /*
     * System.out.println("docfile='" + docfile + "' relative='" + relative + "'" + "' outfile='" +
     * outfile + "'");
     */

    String filedata = readFile(docfile);

    // The document is properties up until the line "@jd:body".
    // Any blank lines are ignored.
    int start = -1;
    int lineno = 1;
    Matcher lines = LINE.matcher(filedata);
    String line = null;
    while (lines.find()) {
      line = lines.group(1);
      if (line.length() > 0) {
        if (line.equals("@jd:body")) {
          start = lines.end();
          break;
        }
        Matcher prop = PROP.matcher(line);
        if (prop.matches()) {
          String key = prop.group(1);
          String value = prop.group(2);
          hdf.setValue(key, value);
        } else {
          break;
        }
      }
      lineno++;
    }
    if (start < 0) {
      System.err.println(docfile + ":" + lineno + ": error parsing docfile");
      if (line != null) {
        System.err.println(docfile + ":" + lineno + ":" + line);
      }
      System.exit(1);
    }

    // if they asked to only be for a certain template, maybe skip it
    String fromTemplate = hdf.getValue("template.which", "");
    String fromPage = hdf.getValue("page.onlyfortemplate", "");
    if (!"".equals(fromPage) && !fromTemplate.equals(fromPage)) {
      return;
    }

    // and the actual text after that
    String commentText = filedata.substring(start);

    Comment comment = new Comment(commentText, null, new SourcePositionInfo(docfile, lineno, 1));
    TagInfo[] tags = comment.tags();

    TagInfo.makeHDF(hdf, "root.descr", tags);

    hdf.setValue("commentText", commentText);

    // write the page using the appropriate root template, based on the
    // whichdoc value supplied by build
    String fromWhichmodule = hdf.getValue("android.whichmodule", "");
    if (fromWhichmodule.equals("online-pdk")) {
      // leaving this in just for temporary compatibility with pdk doc
      hdf.setValue("online-pdk", "true");
      // add any conditional login for root template here (such as
      // for custom left nav based on tab etc.
      ClearPage.write(hdf, "docpage.cs", outfile);
    } else {
      String filename = outfile;
      // Check whether this is a localized page and remove the intl/*/ path from filename
      if (filename.indexOf("intl/") == 0) {
        filename = filename.substring(filename.indexOf("/", 5) + 1); // After intl/ to get 2nd /
      }
      if (filename.indexOf("design/") == 0) {
        hdf.setValue("design", "true");
      } else if (filename.indexOf("develop/") == 0) {
        hdf.setValue("develop", "true");
      } else if (filename.indexOf("guide/") == 0) {
        hdf.setValue("guide", "true");
      } else if (filename.indexOf("training/") == 0) {
        hdf.setValue("training", "true");
      } else if (filename.indexOf("more/") == 0) {
        hdf.setValue("more", "true");
      } else if (filename.indexOf("google/") == 0) {
        hdf.setValue("google", "true");
      } else if (filename.indexOf("distribute/") == 0) {
        hdf.setValue("distribute", "true");
      } else if (filename.indexOf("about/") == 0) {
        hdf.setValue("about", "true");
      } else if ((filename.indexOf("tools/") == 0) || (filename.indexOf("sdk/") == 0)) {
        hdf.setValue("tools", "true");
      }

      if ((filename.indexOf("tools/sdk/preview/index.html") == 0)
          || (filename.indexOf("sdk/index.html") == 0)
          || (filename.indexOf("tools/sdk/ndk/index.html") == 0)) {
        ClearPage.write(hdf, "sdkpage.cs", outfile);
      } else {
        ClearPage.write(hdf, "docpage.cs", outfile);
      }
    }
  } // writePage
Ejemplo n.º 18
0
  public static Data makePackageHDF() {
    Data data = makeHDF();
    ClassInfo[] classes = Converter.rootClasses();

    SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>();
    for (ClassInfo cl : classes) {
      PackageInfo pkg = cl.containingPackage();
      String name;
      if (pkg == null) {
        name = "";
      } else {
        name = pkg.name();
      }
      sorted.put(name, pkg);
    }

    int i = 0;
    for (String s : sorted.keySet()) {
      PackageInfo pkg = sorted.get(s);

      if (pkg.isHidden()) {
        continue;
      }
      Boolean allHidden = true;
      int pass = 0;
      ClassInfo[] classesToCheck = null;
      while (pass < 5) {
        switch (pass) {
          case 0:
            classesToCheck = pkg.ordinaryClasses();
            break;
          case 1:
            classesToCheck = pkg.enums();
            break;
          case 2:
            classesToCheck = pkg.errors();
            break;
          case 3:
            classesToCheck = pkg.exceptions();
            break;
          case 4:
            classesToCheck = pkg.getInterfaces();
            break;
          default:
            System.err.println("Error reading package: " + pkg.name());
            break;
        }
        for (ClassInfo cl : classesToCheck) {
          if (!cl.isHidden()) {
            allHidden = false;
            break;
          }
        }
        if (!allHidden) {
          break;
        }
        pass++;
      }
      if (allHidden) {
        continue;
      }

      data.setValue("reference", "1");
      data.setValue("reference.apilevels", sinceTagger.hasVersions() ? "1" : "0");
      data.setValue("docs.packages." + i + ".name", s);
      data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
      data.setValue("docs.packages." + i + ".since.key", SinceTagger.keyForName(pkg.getSince()));
      data.setValue("docs.packages." + i + ".since.name", pkg.getSince());
      TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr", pkg.firstSentenceTags());
      i++;
    }

    sinceTagger.writeVersionNames(data);
    return data;
  }
Ejemplo n.º 19
0
  public static Data makeHDF() {
    Data data = jSilver.createData();

    for (String[] p : mHDFData) {
      data.setValue(p[0], p[1]);
    }

    data.setValue("tabs.0.id", "guide");
    data.setValue("tabs.0.title", "Install Guide");
    data.setValue("tabs.0.link", guideDir + "install.html");

    int i = 0;
    for (String[] p : mMarkdown) {
      i++;
      data.setValue("tabs." + i + ".id", p[0]);
      data.setValue("tabs." + i + ".title", p[2]);
      String outFile = FilenameUtils.getName(p[1]).replaceAll(".md", ".html").toLowerCase();
      data.setValue("tabs." + i + ".link", outFile);
    }

    i++;
    data.setValue("tabs." + i + ".id", "java");
    data.setValue("tabs." + i + ".title", "Java API Reference");
    data.setValue("tabs." + i + ".link", javadocDir + "packages.html");

    boolean hasModules = false;
    ClassInfo[] classes = Converter.rootClasses();
    for (ClassInfo cl : classes) {
      if (cl.isModule()) {
        hasModules = true;
      }
    }

    if (hasModules) {
      i++;
      data.setValue("tabs." + i + ".id", "mule");
      data.setValue("tabs." + i + ".title", "Mule API Reference");
      data.setValue("tabs." + i + ".link", muleXmlDir + "modules.html");
    }

    return data;
  }