Package freemarker.template

Examples of freemarker.template.Template


        context.setRenderer(renderer);
        renderer.setTemplateName(templateName);

        final Map<String, Object> dataModel = renderer.getDataModel();

        final Template template = Templates.getTemplate((String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), templateName);

        if (null == template) {
            try {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
View Full Code Here


    public String getTopBarHTML(final HttpServletRequest request, final HttpServletResponse response)
        throws ServiceException {
        Stopwatchs.start("Gens Top Bar HTML");

        try {
            final Template topBarTemplate = ConsoleRenderer.TEMPLATE_CFG.getTemplate("top-bar.ftl");
            final StringWriter stringWriter = new StringWriter();

            final Map<String, Object> topBarModel = new HashMap<String, Object>();

            userMgmtService.tryLogInWithCookie(request, response);
            final JSONObject currentUser = userQueryService.getCurrentUser(request);

            Keys.fillServer(topBarModel);
            topBarModel.put(Common.IS_LOGGED_IN, false);

            topBarModel.put(Common.IS_MOBILE_REQUEST, Requests.mobileRequest(request));
            topBarModel.put("mobileLabel", langPropsService.get("mobileLabel"));

            topBarModel.put("onlineVisitor1Label", langPropsService.get("onlineVisitor1Label"));
            topBarModel.put(Common.ONLINE_VISITOR_CNT, statisticQueryService.getOnlineVisitorCount());

            if (null == currentUser) {
                topBarModel.put(Common.LOGIN_URL, userService.createLoginURL(Common.ADMIN_INDEX_URI));
                topBarModel.put("loginLabel", langPropsService.get("loginLabel"));
                topBarModel.put("registerLabel", langPropsService.get("registerLabel"));

                topBarTemplate.process(topBarModel, stringWriter);

                return stringWriter.toString();
            }

            topBarModel.put(Common.IS_LOGGED_IN, true);
            topBarModel.put(Common.LOGOUT_URL, userService.createLogoutURL("/"));
            topBarModel.put(Common.IS_ADMIN, Role.ADMIN_ROLE.equals(currentUser.getString(User.USER_ROLE)));
            topBarModel.put(Common.IS_VISITOR, Role.VISITOR_ROLE.equals(currentUser.getString(User.USER_ROLE)));

            topBarModel.put("adminLabel", langPropsService.get("adminLabel"));
            topBarModel.put("logoutLabel", langPropsService.get("logoutLabel"));

            final String userName = currentUser.getString(User.USER_NAME);

            topBarModel.put(User.USER_NAME, userName);

            topBarTemplate.process(topBarModel, stringWriter);

            return stringWriter.toString();
        } catch (final JSONException e) {
            LOGGER.log(Level.ERROR, "Gens top bar HTML failed", e);
            throw new ServiceException(e);
View Full Code Here

            final int pageCount = (int) Math.ceil((double) publishedArticleCnt / (double) pageSize);

            final Query query = new Query().setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(pageCount).setFilter(
                new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, PUBLISHED));

            final Template template = Templates.getTemplate((String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), "index.ftl");

            boolean isArticles1 = false;

            if (null == template) {
                LOGGER.debug("The skin dose not contain [index.ftl] template");
View Full Code Here

        throws ServiceException {
        Stopwatchs.start("Fill Side");
        try {
            LOGGER.debug("Filling side....");

            Template template = Templates.getTemplate((String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), "side.ftl");

            if (null == template) {
                LOGGER.debug("The skin dose not contain [side.ftl] template");

                template = Templates.getTemplate((String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), "index.ftl");
View Full Code Here

            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");

            try {
                final Template template = ConsoleRenderer.TEMPLATE_CFG.getTemplate("kill-browser.ftl");

                final PrintWriter writer = response.getWriter();

                final StringWriter stringWriter = new StringWriter();

                template.setOutputEncoding("UTF-8");
                template.process(getDataModel(), stringWriter);

                final String pageContent = stringWriter.toString();

                writer.write(pageContent);
                writer.flush();
View Full Code Here

   
    try
    {
      /* template call */
      ftlPath  = appendExt(path);
      Template template = cfg.getTemplate(ftlPath);
     
      /* write */
      Writer out = response.getWriter();
     
      /* freemaker call */
      template.process(model.getAll(), out);
    }
    catch (IOException e)
    {
      log.severe(ftlPath+" 해당 파일을 찾을 수 없습니다.");
    }
View Full Code Here

    */
   public Template getTemplate(String templateLocation)
   {
      try
      {
         Template templateFile = freemarkerConfig.getTemplate(templateLocation);
         return templateFile;
      }
      catch (IOException ioEx)
      {
         throw new RuntimeException(ioEx);
View Full Code Here

   public String processTemplate(Map<Object, Object> map, String templateLocation)
   {
      Writer output = new StringWriter();
      try
      {
         Template templateFile = freemarkerConfig.getTemplate(templateLocation);
         templateFile.process(map, output);
         output.flush();
      }
      catch (IOException ioEx)
      {
         throw new RuntimeException(ioEx);
View Full Code Here

    config.setClassForTemplateLoading(getClass(), "");
    config.setObjectWrapper(new DefaultObjectWrapper());

    try {
      // load template
      Template template = config.getTemplate("tag.ftl");
      String rootDir = (new File(getOption("outTemplatesDir"))).getAbsolutePath();
      File rootFile = new File(rootDir);
      rootFile.mkdirs();
      for (Tag tag : tags.values()) {
        if (tag.isInclude()) {
          // model
          HashMap<String, Tag> root = new HashMap<String, Tag>();
          root.put("tag", tag);

          // save file
          BufferedWriter writer = new BufferedWriter(new FileWriter(new File(rootDir, tag.getName() + ".html")));
          try {
            template.process(root, writer);
          } finally {
            writer.close();
          }
        }
      }
View Full Code Here

        if (debug) {
            log("Requested template: " + path);
        }

        Template template = null;
        try {
            template = config.getTemplate(
                    path,
                    deduceLocale(path, request, response));
        } catch (FileNotFoundException e) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        Object attrContentType = template.getCustomAttribute("content_type");
        if(attrContentType != null) {
            response.setContentType(attrContentType.toString());
        }
        else {
            if (noCharsetInContentType) {
                response.setContentType(
                        contentType + "; charset=" + template.getEncoding());
            } else {
                response.setContentType(contentType);
            }
        }

        // Set cache policy
        setBrowserCachingPolicy(response);

        ServletContext servletContext = getServletContext();
        try {
            TemplateModel model = createModel(wrapper, servletContext, request, response);

            // Give subclasses a chance to hook into preprocessing
            if (preTemplateProcess(request, response, template, model)) {
                try {
                    // Process the template
                    template.process(model, response.getWriter());
                } finally {
                    // Give subclasses a chance to hook into postprocessing
                    postTemplateProcess(request, response, template, model);
                }
            }
View Full Code Here

TOP

Related Classes of freemarker.template.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.