@Override public Messages getMessages() { return application.getMessages(); }
@Override public String getMessage(String key, String language, Object... args) { return application.getMessages().get(key, language, args); }
@Override public String getMessage(String key, Object... args) { return application.getMessages().get(key, this, args); }
@Override public void init(Application application) { this.languages = application.getLanguages(); this.messages = application.getMessages(); this.router = application.getRouter();
/** * Performs common initialization for template engines. * * Implementations must override this method to do their own template engine specific initialization. * To use the convenience of this class, implementations must invoke this class's implementation before * performing their own initialization. * * @param application reference to the Pippo {@link Application} that can be used to retrieve settings * and other settings for the initialization */ @Override public void init(Application application) { languages = application.getLanguages(); messages = application.getMessages(); router = application.getRouter(); pippoSettings = application.getPippoSettings(); fileExtension = pippoSettings.getString(PippoConstants.SETTING_TEMPLATE_EXTENSION, getDefaultFileExtension()); templatePathPrefix = pippoSettings.getString(PippoConstants.SETTING_TEMPLATE_PATH_PREFIX, TemplateEngine.DEFAULT_PATH_PREFIX); }
log.error("Unexpected error generating '{}' as '{}'", Error.class.getName(), contentType, e); routeContext.status(HttpConstants.StatusCode.INTERNAL_ERROR); routeContext.send(application.getMessages().get("pippo.statusCode500", routeContext));
/** * Prepares an Error instance for the error response. * * @param statusCode * @param routeContext * @return an Error */ protected Error prepareError(int statusCode, RouteContext routeContext) { String messageKey = "pippo.statusCode" + statusCode; Error error = new Error(); error.setStatusCode(statusCode); error.setStatusMessage(application.getMessages().get(messageKey, routeContext)); error.setRequestMethod(routeContext.getRequestMethod()); error.setRequestUri(routeContext.getRequestUri()); error.setStacktrace(routeContext.getLocal(STACKTRACE)); error.setMessage(routeContext.getLocal(MESSAGE)); return error; }
.set("contextPath", router.getContextPath()) .set("appPath", router.getApplicationPath())) .extension(new I18nExtension(application.getMessages())) .extension(new FormatTimeExtension()) .extension(new PrettyTimeExtension())
@Override public void init(Application application) { this.languages = application.getLanguages(); this.messages = application.getMessages(); this.router = application.getRouter();
builder.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING, PippoConstants.UTF8); builder.registerHelper("ng", new AngularJsHelper()); builder.registerHelper("i18n", new I18nHelper(application.getMessages())); builder.registerHelper("formatTime", new DateTimeFormatHelper()); builder.registerHelper("prettyTime", new PrettyTimeHelper());
@Override protected void setup() { String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim(); serve(basePath + "/*").with(RestServlet.class); final PippoSettings pippoSettings = getPippoSettings(getSettings()); final Application application = new Application(pippoSettings); // must set context path before starting application application.getRouter().setContextPath(getSettings().getContextPath()); // must set application path before starting application String contextPath = application.getRouter().getContextPath(); String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(basePath, "/"); application.getRouter().setApplicationPath(applicationPath); // start the application which sets up all initializers application.init(); bind(Application.class).toInstance(application); bind(Router.class).toInstance(application.getRouter()); bind(Messages.class).toInstance(application.getMessages()); bind(Languages.class).toInstance(application.getLanguages()); bind(MimeTypes.class).toInstance(application.getMimeTypes()); bind(ErrorHandler.class).toInstance(application.getErrorHandler()); bind(TemplateEngine.class).toInstance(application.getTemplateEngine()); bind(HttpCacheToolkit.class).toInstance(application.getHttpCacheToolkit()); bind(ContentTypeEngines.class).toInstance(application.getContentTypeEngines()); bind(RestService.class); }
@Override protected void setup() { String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim(); serve(basePath + "/*").with(RestServlet.class); final PippoSettings pippoSettings = getPippoSettings(getSettings()); final Application application = new Application(pippoSettings); // must set context path before starting application application.getRouter().setContextPath(getSettings().getContextPath()); // must set application path before starting application String contextPath = application.getRouter().getContextPath(); String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(basePath, "/"); application.getRouter().setApplicationPath(applicationPath); // start the application which sets up all initializers application.init(); bind(Application.class).toInstance(application); bind(Router.class).toInstance(application.getRouter()); bind(Messages.class).toInstance(application.getMessages()); bind(Languages.class).toInstance(application.getLanguages()); bind(MimeTypes.class).toInstance(application.getMimeTypes()); bind(ErrorHandler.class).toInstance(application.getErrorHandler()); bind(TemplateEngine.class).toInstance(application.getTemplateEngine()); bind(HttpCacheToolkit.class).toInstance(application.getHttpCacheToolkit()); bind(ContentTypeEngines.class).toInstance(application.getContentTypeEngines()); bind(RestService.class); }
builder.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING, PippoConstants.UTF8); builder.registerHelper("ng", new AngularJsHelper()); builder.registerHelper("i18n", new I18nHelper(application.getMessages())); builder.registerHelper("formatTime", new DateTimeFormatHelper()); builder.registerHelper("prettyTime", new PrettyTimeHelper());