当前位置: 首页>>代码示例>>Java>>正文


Java FreeMarkerEngine类代码示例

本文整理汇总了Java中spark.template.freemarker.FreeMarkerEngine的典型用法代码示例。如果您正苦于以下问题:Java FreeMarkerEngine类的具体用法?Java FreeMarkerEngine怎么用?Java FreeMarkerEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FreeMarkerEngine类属于spark.template.freemarker包,在下文中一共展示了FreeMarkerEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public void init(ClubApplication app) {
    before("/protected/admin/*", (request, response) -> {
        if(!leadsProgram(getUser(request))) {
            response.redirect("/protected/my");
            halt();
        }
    });

    before("/protected/admin", (request, response) -> {
        response.redirect("/protected/admin/");
        halt();
    });

    get("/protected/admin/", (request, response) -> {
        MapBuilder<String, Object> model = newModel(request, "Admin");
        User user = getUser(request);
        user.asClubLeader().ifPresent(l -> l.getClub().ifPresent(c -> model.put("mygroup", c)));
        return new ModelAndView(model.build(), "admin.ftl");
    }, new FreeMarkerEngine());

    post("/protected/admin/reset", ((request, response) -> {
        app.reset();
        response.redirect("/protected/admin");
        return null;
    }));
}
 
开发者ID:AveryRegier,项目名称:club-tracker,代码行数:27,代码来源:AdminController.java

示例2: initialize

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void initialize() {

		FreeMarkerEngine fme = new FreeMarkerEngine();
		fme.setConfiguration(getConfiguration());
		before(ROUTE, (req, res) -> {
			if(WebServer.userToAuthGuilds.get(req.cookie("usession")) == null)
				halt(401, "You are not authorized to view this page. Please login through the homepage");
		});

		get(ROUTE, (req, res) -> {
			Map<String, Object> attributes = new HashMap<String, Object>();
			User user = Bot.getInstance().shards
					.getUserById(WebServer.userToAuthGuilds.get(req.cookie("usession")).getUserId());
			List<SparkGuildBean> guilds = new ArrayList<>();

			Bot.getInstance().getBots().stream()
			.forEach(j -> j.getGuilds().stream()
					.filter(g -> g.getMemberById(WebServer.userToAuthGuilds.get(req.cookie("usession")).getUserId()) != null
					&& Util.memberHasPermission(g.getMember(user), Permission.KICK))
					.forEach(g -> guilds.add(new SparkGuildBean(g.getId(), g.getName(), g.getIconUrl()))));
			guilds.stream()
			.sorted((g1, g2) -> g1.getName().compareTo(g2.getName()));
			
			attributes.put("guilds", guilds);
			attributes.put("username", WebServer.userToAuthGuilds.get(req.cookie("usession")).getUsername());
			if(user.getAvatarId() != null)
				attributes.put("userIcon", user.getAvatarUrl());
			attributes.put("botName", Bot.getInstance().getBots().get(0).getSelfUser().getName());
			return new ModelAndView(attributes, "guildlist.ftl");
		}, fme);
	}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:32,代码来源:GuildListRoute.java

示例3: initializeSparkConfiguration

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
private void initializeSparkConfiguration(String networkAddress) {
    ipAddress(networkAddress);
    port(Frontend.PORT);
    // so that all static files will be served directly by spark and we don't have to care any longer about them :)
    staticFileLocation(ASSET_DIR);

    Configuration fmConfig = new Configuration();
    fmConfig.setClassForTemplateLoading(Frontend.class, TEMPLATE_DIR);
    fmEngine = new FreeMarkerEngine(fmConfig);
}
 
开发者ID:fgreinus,项目名称:jwebpoll,代码行数:11,代码来源:Frontend.java

示例4: WhoopsHandler

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public WhoopsHandler() {
  templateEngine = new FreeMarkerEngine();
  templateConfig = new Configuration();
  templateConfig.setClassForTemplateLoading(getClass(), "/");
  templateEngine.setConfiguration(templateConfig);
  sourceLocators = ImmutableList.of(
    new FileSearchSourceLocator(new File("./src/main/java")),
    new FileSearchSourceLocator(new File("./src/test/java"))
  );
}
 
开发者ID:mschurr,项目名称:spark-whoops,代码行数:11,代码来源:WhoopsHandler.java

示例5: setupRoutes

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
private void setupRoutes(){
	get("/",(req, res) -> {
		res.redirect("refresh");
		return null;
	});
	
	get("refresh",(req, res) -> {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Programme> pros = new ArrayList<Programme>();
		Programme pro = service.getLjsw();
		// chenck new or old
		int vol = pro.getVol();
		List<Programme> prolist = service.getProgrammeByPrimaryKey(vol);
		if(prolist != null && prolist.size() == 0){
			// insert into database
			service.addProgramme(pro);
			// send email
			User user = new User();
			user.setEmail("[email protected]");
			user.setName("liubei");
			service.sendEmail(user, pro);
		}
		pros.add(pro);
		map.put("contents", pros);
		return new ModelAndView(map, "index.ftl");
	}, new FreeMarkerEngine());
	
	get("/createuser",(req,res) -> {
		
		return null;
	});
}
 
开发者ID:JavaProgrammerLB,项目名称:Sentry,代码行数:33,代码来源:WebConfig.java

示例6: template

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
@ResourceMapping("/template")
@TemplateEngine(FreeMarkerEngine.class)
public ModelAndView template(Request request, Response response) {
	Map<String, Object> attributes = new HashMap<>();
	attributes.put("message", AutoSparkTestingConstants.SUCCESS);
	return new ModelAndView(attributes, "hello.ftl");
}
 
开发者ID:stephenwilliams,项目名称:Auto-Spark,代码行数:8,代码来源:TestControllerOne.java

示例7: start

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public void start(IndexClient client, int port, Path templatePath) {
  this.client = client;

  Spark.port(port);

  staticFiles.location("/assets");

  FreeMarkerEngine freeMarkerEngine = new FreeMarkerEngine();
  if (templatePath != null && Files.exists(templatePath)) {
    log.info("Serving freemarker templates from {}", templatePath.toAbsolutePath());
    Configuration freeMarkerConfig = new Configuration();
    try {
      freeMarkerConfig.setDirectoryForTemplateLoading(templatePath.toFile());
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
    freeMarkerEngine.setConfiguration(freeMarkerConfig);
  }

  get("/", (req, res) -> new ModelAndView(null, "home.ftl"), freeMarkerEngine);

  get("/top", (req, res) -> new ModelAndView(Collections.singletonMap("top", getTop(req)),
      "top.ftl"), freeMarkerEngine);

  Gson gson = new Gson();
  get("/api/top", (req, res) -> getTop(req), gson::toJson);

  get("/page", (req, res) -> new ModelAndView(Collections.singletonMap("page", getPage(req)),
      "page.ftl"), freeMarkerEngine);
  get("/api/page", (req, res) -> getPage(req), gson::toJson);

  get("/pages", (req, res) -> new ModelAndView(Collections.singletonMap("pages", getPages(req)),
      "pages.ftl"), freeMarkerEngine);
  get("/api/pages", (req, res) -> getPages(req), gson::toJson);

  get("/links", (req, res) -> new ModelAndView(Collections.singletonMap("links", getLinks(req)),
      "links.ftl"), freeMarkerEngine);
  get("/api/links", (req, res) -> getLinks(req), gson::toJson);
}
 
开发者ID:astralway,项目名称:webindex,代码行数:40,代码来源:WebServer.java

示例8: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void main(String args[]) {

        get("/hello", (request, response) -> {
            Map<String, Object> model = new HashMap<>();
            model.put("message", "Hello Freemarker!");
            return new ModelAndView(model, "hello.ftl"); // located in src/test/resources/spark/template/freemarker
        }, new FreeMarkerEngine());

    }
 
开发者ID:perwendel,项目名称:spark-template-engines,代码行数:10,代码来源:FreeMarkerExample.java

示例9: init

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public void init(ClubApplication app) {
    String path = "/protected/provider";

    before(path, (request, response) -> {
        User user = getUser(request);
        if(user.asClubLeader().isPresent()) {

        } else {
            halt();
        }
    });

    get(path, (request, response)->{
        return new spark.ModelAndView(
                new Object(),
                "provider.ftl");
    }, new FreeMarkerEngine());

    post(path, (request, response) -> {

        String id = request.queryParams("providerId");
        String providerName = request.queryParams("providerName");
        String site = request.queryParams("site");
        String image = request.queryParams("image");
        String clientKey = request.queryParams("clientKey");
        String clientSecret = request.queryParams("clientSecret");

        new ProviderBroker(app.getConnector()).persist(new Provider(
                id, providerName, image, site, clientKey, clientSecret));

        response.redirect("/protected/my");
        return null;
    });
}
 
开发者ID:AveryRegier,项目名称:club-tracker,代码行数:35,代码来源:ProviderSetup.java

示例10: init

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public void init(ClubApplication app) {
    before("/initial-setup", (request, response) -> {
        List<Provider> providers = new ProviderBroker(app.getConnector()).find();
        if(providers.isEmpty()) {

        } else {
            halt();
        }
    });

    get("/initial-setup", (request, response)->{
        return new spark.ModelAndView(
                newModel(request, "Add Login Provider").build(),
                "provider.ftl");
    }, new FreeMarkerEngine());

    post("/initial-setup", (request, response) -> {

        String id = request.queryParams("providerId");
        String providerName = request.queryParams("providerName");
        String site = request.queryParams("site");
        String image = request.queryParams("image");
        String clientKey = request.queryParams("clientKey");
        String clientSecret = request.queryParams("clientSecret");

        new ProviderBroker(app.getConnector()).persist(new Provider(
                id, providerName, image, site, clientKey, clientSecret));

        response.redirect("/protected/setup");
        return null;
    });
}
 
开发者ID:AveryRegier,项目名称:club-tracker,代码行数:33,代码来源:InitialSetup.java

示例11: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
/**
 * Entry point for the WebCheckers web application.
 *
 * <p>
 * It wires the application components together.  This is an example
 * of <a href='https://en.wikipedia.org/wiki/Dependency_injection'>Dependency Injection</a>
 * </p>
 *
 * @param args
 *    Command line arguments; none expected.
 */
public static void main(String[] args) {
  // initialize Logging
  try {
    ClassLoader classLoader = Application.class.getClassLoader();
    final InputStream logConfig = classLoader.getResourceAsStream("log.properties");
    LogManager.getLogManager().readConfiguration(logConfig);
  } catch (Exception e) {
    e.printStackTrace();
    System.err.println("Could not initialize log manager because: " + e.getMessage());
  }

  // The application uses FreeMarker templates to generate the HTML
  // responses sent back to the client. This will be the engine processing
  // the templates and associated data.
  final TemplateEngine templateEngine = new FreeMarkerEngine();

  // Create playerLobby
  final PlayerLobby playerLobby = new PlayerLobby();

  // Create gameLobby
  final GameLobby gameLobby = new GameLobby();

  // Create gameCenter
  final GameCenter gameCenter = new GameCenter(playerLobby, gameLobby);

  // The application uses Gson to generate JSON representations of Java objects.
  // This should be used by your Ajax Routes to generate JSON for the HTTP
  // response to Ajax requests.
  final Gson gson = new Gson();

  // inject the game center and freemarker engine into web server
  final WebServer webServer = new WebServer(templateEngine, gameCenter, gson);


  // inject web server into application
  final Application app = new Application(webServer);

  // start the application up
  app.initialize();
}
 
开发者ID:ChresSSB,项目名称:Webcheckers,代码行数:52,代码来源:Application.java

示例12: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void main( String[] args ) {
    // Database migrations happen before we start
    preStart();

    Spark.port(getServerPort());

    if (1 == 1) {
        String projectDir = System.getProperty("user.dir");
        String staticDir = "/src/main/resources/public/";
        staticFiles.externalLocation(projectDir + staticDir);
    } else {
        Spark.staticFileLocation("/public");
    }


    get("/", (request, response) -> new ModelAndView(null, "index.ftl"), new FreeMarkerEngine());

    get("/login/", (EditorRoute::login), new FreeMarkerEngine());
    post("/login/", (EditorRoute::doLogin), new FreeMarkerEngine());
    get("/logout/", (EditorRoute::logout), new FreeMarkerEngine());
    get("/search/", (SearchRoute::search), new FreeMarkerEngine());

    get("/about/", (request, response) -> new ModelAndView(null, "about.ftl"), new FreeMarkerEngine());
    get("/become/", (request, response) -> new ModelAndView(null, "become.ftl"), new FreeMarkerEngine());
    get("/suggest/", (request, response) -> new ModelAndView(null, "suggest.ftl"), new FreeMarkerEngine());
    post("/suggest/", (SuggestRoute::suggest), new FreeMarkerEngine());

    // Special routes to preserve the root categories
    get("/Arts/*", (request, response) -> ContentRoute.getCategory(request, response, "Arts"), new FreeMarkerEngine());
    get("/Business/*", (request, response) -> ContentRoute.getCategory(request, response, "Business"), new FreeMarkerEngine());
    get("/Computers/*", (request, response) -> ContentRoute.getCategory(request, response, "Computers"), new FreeMarkerEngine());
    get("/Games/*", (request, response) -> ContentRoute.getCategory(request, response, "Games"), new FreeMarkerEngine());
    get("/Health/*", (request, response) -> ContentRoute.getCategory(request, response, "Health"), new FreeMarkerEngine());
    get("/Home/*", (request, response) -> ContentRoute.getCategory(request, response, "Home"), new FreeMarkerEngine());
    get("/News/*", (request, response) -> ContentRoute.getCategory(request, response, "News"), new FreeMarkerEngine());
    get("/Recreation/*", (request, response) -> ContentRoute.getCategory(request, response, "Recreation"), new FreeMarkerEngine());
    get("/Reference/*", (request, response) -> ContentRoute.getCategory(request, response, "Reference"), new FreeMarkerEngine());
    get("/Regional/*", (request, response) -> ContentRoute.getCategory(request, response, "Regional"), new FreeMarkerEngine());
    get("/Science/*", (request, response) -> ContentRoute.getCategory(request, response, "Science"), new FreeMarkerEngine());
    get("/Shopping/*", (request, response) -> ContentRoute.getCategory(request, response, "Shopping"), new FreeMarkerEngine());
    get("/Society/*", (request, response) -> ContentRoute.getCategory(request, response, "Society"), new FreeMarkerEngine());
    get("/Sports/*", (request, response) -> ContentRoute.getCategory(request, response, "Sports"), new FreeMarkerEngine());
    get("/World/*", (request, response) -> ContentRoute.getCategory(request, response, "World"), new FreeMarkerEngine());


    ////////////////////////////////////////////////////
    //              Editor Routes Below
    ////////////////////////////////////////////////////

    path("/editor", () -> {
        get("/", (EditorRoute::editorAdmin), new FreeMarkerEngine());
        get("/submissions/", (EditorRoute::editorSubmissions), new FreeMarkerEngine());
    });

    ////////////////////////////////////////////////////
    //              API Routes Below
    ////////////////////////////////////////////////////

    path("/api", () -> {
        path("/v1", () -> {
            get("/categories/", ContentRoute::getCategories, new JsonTransformer());
            get("/submission/", ContentRoute::getSubmission, new JsonTransformer());
            get("/search/", SearchRoute::searchJson, new JsonTransformer());
            get("/searchurl/", SearchRoute::searchUrlJson, new JsonTransformer());
            get("/searchdescription/", SearchRoute::searchDescriptionJson, new JsonTransformer());
        });
    });


}
 
开发者ID:boyter,项目名称:freemoz,代码行数:71,代码来源:App.java

示例13: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void main( String[] args )
{
    CommandLineOptions options = new CommandLineOptions();
    new JCommander(options, args);

    logger.finest("Options.debug = " + options.debug);
    logger.finest("Options.servicePort = " + options.servicePort);

    port(options.servicePort);

    FreeMarkerEngine freeMarkerEngine = new FreeMarkerEngine();
    Configuration freeMarkerConfiguration = new Configuration();
    freeMarkerConfiguration.setTemplateLoader(new ClassTemplateLoader(App.class, "/"));

    if (options.debug) {
        freeMarkerConfiguration.setCacheStorage(new NullCacheStorage());

        WebpackThread.run();
    }

    freeMarkerEngine.setConfiguration(freeMarkerConfiguration);

    if (options.debug) {
        String projectDir = System.getProperty("user.dir");
        String staticDir = "/src/main/frontend/public";

        staticFiles.externalLocation(projectDir + staticDir);
    } else {
        staticFileLocation("/public");
    }

    get("/", (request, response) -> {
        if (shouldReturnHtml(request)) {
            response.status(200);
            response.type("text/html");
            Map<String, Object> attributes = new HashMap<>();
            return freeMarkerEngine.render(new ModelAndView(attributes, "index.ftl"));
        } else {
            response.status(200);
            response.type("application/json");
            return dataToJson(null);
        }
    });

    get("/alive", (request, response) -> "ok");
}
 
开发者ID:viatsko,项目名称:react-redux-spark-boilerplate,代码行数:47,代码来源:App.java

示例14: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void main(String[] args) {

    port(Integer.valueOf(9000)); // sets port as 9000
    staticFileLocation("/public");

    get("/", (request, response) -> {
    	return new ModelAndView(null, "indexTeste.ftl");
    }, new FreeMarkerEngine());

	get("/index", (request, response) -> {
		return new ModelAndView(null, "index.ftl");
	}, new FreeMarkerEngine());
	
    get("/login", (request, response) -> {
        return new ModelAndView(null, "login.ftl");
    }, new FreeMarkerEngine());

	post("/menu", (request, response) -> {
	    return new ModelAndView(null, "menu.ftl");
	}, new FreeMarkerEngine());
	
	get("/menu", (request, response) -> {
	    return new ModelAndView(null, "menu.ftl");
	}, new FreeMarkerEngine());
	
	get("/buyer_home", (request, response) -> {
	    return new ModelAndView(null, "buyer_home.ftl");
	}, new FreeMarkerEngine());
	
	get("/seller_home", (request, response) -> {
	    return new ModelAndView(null, "seller_home.ftl");
	}, new FreeMarkerEngine());
	
	get("/configuration", (request, response) -> {
	    return new ModelAndView(null, "configuration.ftl");
	}, new FreeMarkerEngine());
    
//    // DEBUG
//    get("/db", (req, res) -> {
//      Connection connection = null;
//      Map<String, Object> attributes = new HashMap<>();
//      try {
//        connection = DatabaseUrl.extract().getConnection();
//
//        Statement stmt = connection.createStatement();
//        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)");
//        stmt.executeUpdate("INSERT INTO ticks VALUES (now())");
//        ResultSet rs = stmt.executeQuery("SELECT tick FROM ticks");
//
//        ArrayList<String> output = new ArrayList<String>();
//        while (rs.next()) {
//          output.add( "Read from DB: " + rs.getTimestamp("tick"));
//        }
//
//        attributes.put("results", output);
//        return new ModelAndView(attributes, "db.ftl");
//      } catch (Exception e) {
//        attributes.put("message", "There was an error: " + e);
//        return new ModelAndView(attributes, "error.ftl");
//      } finally {
//        if (connection != null) try{connection.close();} catch(SQLException e){}
//      }
//    }, new FreeMarkerEngine());
  }
 
开发者ID:filipefilardi,项目名称:FeedMe,代码行数:65,代码来源:Main.java

示例15: main

import spark.template.freemarker.FreeMarkerEngine; //导入依赖的package包/类
public static void main(String[] args) {

    port(Integer.valueOf(9000));
    staticFileLocation("/public");

    get("/hello", (req, res) -> "Hello World");

    get("/login", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Hello World!");

            return new ModelAndView(attributes, "login.ftl");
        }, new FreeMarkerEngine());


  }
 
开发者ID:filipefilardi,项目名称:FeedMe,代码行数:17,代码来源:Login.java


注:本文中的spark.template.freemarker.FreeMarkerEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。