示例#1
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());
  }
示例#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());
  }
示例#3
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());
  }
示例#4
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());
  }
示例#5
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;
  }