protected boolean acceptsGZipEncoding(HttpServletRequest httpServletRequest) { String acceptEncoding = httpServletRequest.getHeader("accept-encoding"); return !StringUtils.isNullOrEmpty(acceptEncoding) && ( acceptEncoding.contains("gzip") || acceptEncoding.contains("*") ); }
public List<String> toList(List<String> defaultValue) { if (isNull() || (values.length == 1 && StringUtils.isNullOrEmpty(values[0]))) { return defaultValue; } if (values.length == 1) { String tmp = values[0]; tmp = StringUtils.removeStart(tmp, "["); tmp = StringUtils.removeEnd(tmp, "]"); return StringUtils.getList(tmp, "(,|\\|)"); } return Arrays.asList(values); }
@Override public void setContextPath(String contextPath) { if (StringUtils.isNullOrEmpty(contextPath) || "/".equals(contextPath.trim())) { this.contextPath = ""; } else { this.contextPath = StringUtils.addStart(contextPath, "/"); } }
@Override public void setApplicationPath(String applicationPath) { if (StringUtils.isNullOrEmpty(applicationPath) || "/".equals(applicationPath.trim())) { this.applicationPath = ""; } else { this.applicationPath = StringUtils.removeEnd(StringUtils.addStart(applicationPath, "/"), "/"); } }
public static Collection<String> getSuffixes(Method method) { Set<String> suffixes = new LinkedHashSet<>(); for (String produces : getProduces(method)) { int i = produces.lastIndexOf('/') + 1; String type = StringUtils.removeStart(produces.substring(i).toLowerCase(), "x-"); suffixes.add(type); } return suffixes; }
if (methodPaths.length == 0) { String fullPath = StringUtils.addStart(controllerPath, "/"); String path = Stream.of(StringUtils.removeEnd(controllerPath, "/"), StringUtils.removeStart(methodPath, "/")) .filter(Objects::nonNull) .collect(Collectors.joining("/")); String fullPath = StringUtils.addStart(path, "/");
private PebbleTemplate getTemplate(String templateName, String localePart) throws PebbleException { PebbleTemplate template = null; try { if (StringUtils.isNullOrEmpty(localePart)) { template = engine.getTemplate(templateName); } else { String localizedName = StringUtils.removeEnd(templateName, "." + getFileExtension()) + "_" + localePart; template = engine.getTemplate(localizedName); } } catch (LoaderException e) { log.debug(e.getMessage()); } return template; }
if (!StringUtils.isNullOrEmpty(mode)) { System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode); String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/"); application.getRouter().setContextPath(contextPath); initFilterPath(filterConfig); String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(filterPath, "/"); application.getRouter().setApplicationPath(applicationPath);
paths.add(StringUtils.removeEnd(parentPath, "/") + "/" + StringUtils.removeStart(path, "/"));
if (StringUtils.isNullOrEmpty(pathPrefix)) { pathPrefix = TemplateEngine.DEFAULT_PATH_PREFIX; properties.setProperty("myloader.resource.loader.prefix", StringUtils.addEnd(pathPrefix, "/")); properties.setProperty("myloader.resource.loader.cache", String.valueOf(!pippoSettings.isDev()));
String undertowPropName = StringUtils.removeStart(propertyName, prefix); String typeName = getTypeName(undertowPropName); if (StringUtils.isNullOrEmpty(typeName)) return;
@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); }
public PippoRuntimeException(Throwable cause, String message, Object... args) { super(StringUtils.format(message, args), cause); }
private String getLocalizedTemplateName(String templateName, String localePart) { return StringUtils.removeEnd(templateName, "." + getFileExtension()) + "_" + localePart; }
@Override public void handle(RouteContext routeContext) { // get request path Request request = routeContext.getRequest(); String path = request.getPath(); // add or remove trailing slash if (path.length() > 1) { if (addSlash) { path = StringUtils.addEnd(path, "/"); } else { path = StringUtils.removeEnd(path, "/"); } } if (!path.equals(request.getPath())) { // redirect routeContext.redirect(path); } else { // continue with the next handler routeContext.next(); } }
/** * Prefix the given path with the application path. * * @param path * @return an absolute path */ protected String prefixApplicationPath(String path) { return applicationPath + StringUtils.addStart(path, "/"); }
/** * Sets the engine for it's specified content type. An suffix for the engine is also registered based on the * specific type; extension types are supported and the leading "x-" is trimmed out. * * @param engine */ public void setContentTypeEngine(ContentTypeEngine engine) { String contentType = engine.getContentType(); String suffix = StringUtils.removeStart(contentType.substring(contentType.lastIndexOf('/') + 1), "x-"); engines.put(engine.getContentType(), engine); suffixes.put(suffix.toLowerCase(), engine); log.debug("'{}' content engine is '{}'", engine.getContentType(), engine.getClass().getName()); }
String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/"); ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName()); handler.validateMethodArgs(fullPath); String path = Joiner.on("/").skipNulls().join(StringUtils.removeEnd(controllerPath, "/"), StringUtils.removeStart(methodPath, "/")); String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");
@Override public void renderResource(String templateName, Map<String, Object> model, Writer writer) { String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG); if (StringUtils.isNullOrEmpty(language)) { language = getLanguageOrDefault(language); templateName = StringUtils.removeEnd(templateName, "." + getFileExtension());