@Override public void redirect(String nameOrUriPattern, Map<String, Object> parameters) { String uri = uriFor(nameOrUriPattern, parameters); String applicationPath = application.getRouter().getApplicationPath(); if (!applicationPath.isEmpty()) { // remove application path uri = StringUtils.removeStart(uri.substring(applicationPath.length()), "/"); } redirect(uri); }
public Request(HttpServletRequest servletRequest, Application application) { this.httpServletRequest = servletRequest; this.contentTypeEngines = application.getContentTypeEngines(); applicationPath = application.getRouter().getApplicationPath(); // fill (query&post) parameters if any initParameters(); // empty path parameters for now (see internalSetPathParameters method) pathParameters = Collections.unmodifiableMap(new HashMap<String, ParameterValue>()); // init all parameters initAllParameters(); }
private VelocityContext createVelocityContext(Map<String, Object> model) { // prepare the locale-aware i18n method String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } // prepare the locale-aware prettyTime method Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } VelocityContext context = new VelocityContext(model); context.put("pippo", new PippoHelper(messages, language, locale, router)); context.put("contextPath", router.getContextPath()); context.put("appPath", router.getApplicationPath()); return context; }
public Response(HttpServletResponse httpServletResponse, Application application) { this.httpServletResponse = httpServletResponse; this.contentTypeEngines = application.getContentTypeEngines(); this.templateEngine = application.getTemplateEngine(); this.httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString()); this.contextPath = application.getRouter().getContextPath(); this.applicationPath = StringUtils.removeEnd(application.getRouter().getApplicationPath(), "/"); this.mimeTypes = application.getMimeTypes(); this.status = 0; }
@SuppressWarnings("unchecked") public void setup(Languages languages, Messages messages, Router router) { this.languages = languages; this.messages = messages; this.router = router; // set global template variables getModel().put("contextPath", router.getContextPath()); getModel().put("appPath", router.getApplicationPath()); String language = (String) getModel().get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } this.language = language; // prepare the locale Locale locale = (Locale) getModel().get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } this.locale = locale; }
@Override public void init(Application application) { super.init(application); Router router = getRouter(); PippoSettings pippoSettings = getPippoSettings(); configuration = new JadeConfiguration(); configuration.setTemplateLoader(new ClassTemplateLoader(JadeTemplateEngine.class, getTemplatePathPrefix())); configuration.setMode(Mode.HTML); if (pippoSettings.isDev()) { configuration.setPrettyPrint(true); configuration.setCaching(false); // disable cache } // set global template variables configuration.getSharedVariables().put("contextPath", router.getContextPath()); configuration.getSharedVariables().put("appPath", router.getApplicationPath()); // allow custom initialization init(application, configuration); }
configuration.setSharedVariable("appPath", new SimpleScalar(router.getApplicationPath()));
.extension(new GlobalVariablesExtension() .set("contextPath", router.getContextPath()) .set("appPath", router.getApplicationPath())) .extension(new I18nExtension(application.getMessages())) .extension(new FormatTimeExtension())
@Override public void start() { initializeApplication(); String border = Strings.padEnd("", Constants.MIN_BORDER_LENGTH, '-'); Optional<String> applicationPackage = Optional.fromNullable(settings.getApplicationPackage()); log.info(border); log.info("Registered engines"); log.info(border); logEngines(); log.debug(border); log.debug("Initializing router"); log.debug(border); initializeRouter(applicationPackage); log.info(""); log.info(border); log.info("RESTful routes ({}) served on base path '{}'", router.getRoutes().size(), Strings.isNullOrEmpty(router.getApplicationPath()) ? "/" : router.getApplicationPath()); log.info(border); logRoutes(router); isRunning = true; }
@Override public void start() { initializeApplication(); String border = Strings.padEnd("", Constants.MIN_BORDER_LENGTH, '-'); Optional<String> applicationPackage = Optional.fromNullable(settings.getApplicationPackage()); log.info(border); log.info("Registered engines"); log.info(border); logEngines(); log.debug(border); log.debug("Initializing router"); log.debug(border); initializeRouter(applicationPackage); log.info(""); log.info(border); log.info("RESTful routes ({}) served on base path '{}'", router.getRoutes().size(), Strings.isNullOrEmpty(router.getApplicationPath()) ? "/" : router.getApplicationPath()); log.info(border); logRoutes(router); isRunning = true; }
private VelocityContext createVelocityContext(Map<String, Object> model) { // prepare the locale-aware i18n method String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } // prepare the locale-aware prettyTime method Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } VelocityContext context = new VelocityContext(model); context.put("pippo", new PippoHelper(messages, language, locale, router)); context.put("contextPath", router.getContextPath()); context.put("appPath", router.getApplicationPath()); return context; }
builder.addGlobalData("appPath", router.getApplicationPath());
@SuppressWarnings("unchecked") public void setup(Languages languages, Messages messages, Router router) { this.languages = languages; this.messages = messages; this.router = router; // set global template variables getModel().put("contextPath", router.getContextPath()); getModel().put("appPath", router.getApplicationPath()); String language = (String) getModel().get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = languages.getLanguageOrDefault(language); } this.language = language; // prepare the locale Locale locale = (Locale) getModel().get(PippoConstants.REQUEST_PARAMETER_LOCALE); if (locale == null) { locale = languages.getLocaleOrDefault(language); } this.locale = locale; }
builder.addGlobalData("appPath", router.getApplicationPath());