/** * Prefix the given path with the application path. * * @param path * @return an absolute path */ protected String prefixApplicationPath(String path) { return applicationPath + StringUtils.addStart(path, "/"); }
@Override public void ignorePaths(String... pathPrefixes) { for (String pathPrefix : pathPrefixes) { this.ignorePaths.add(StringUtils.addStart(pathPrefix, "/")); } }
@Override public void setContextPath(String contextPath) { if (StringUtils.isNullOrEmpty(contextPath) || "/".equals(contextPath.trim())) { this.contextPath = ""; } else { this.contextPath = StringUtils.addStart(contextPath, "/"); } }
private void addCookie(Cookie cookie) { checkCommitted(); if (StringUtils.isNullOrEmpty(cookie.getPath())) { cookie.setPath(StringUtils.addStart(contextPath, "/")); } getCookieMap().put(cookie.getName(), cookie); }
@Override public void setApplicationPath(String applicationPath) { if (StringUtils.isNullOrEmpty(applicationPath) || "/".equals(applicationPath.trim())) { this.applicationPath = ""; } else { this.applicationPath = StringUtils.removeEnd(StringUtils.addStart(applicationPath, "/"), "/"); } }
/** * Redirects the browser to a path relative to the Pippo application root. For * example, redirectToApplicationPath("/contacts") might redirect the browser to * http://localhost/myContext/myApp/contacts * <p>This method commits the response.</p> * * @param path */ public void redirectToApplicationPath(String path) { if ("".equals(applicationPath)) { // application path is the root redirect(path); } else { redirect(applicationPath + StringUtils.addStart(path, "/")); } }
protected List<DirEntry> getDirEntries(RouteContext routeContext, File dir, String absoluteDirUri) { List<DirEntry> list = new ArrayList<>(); for (File file : getFiles(dir)) { String fileUrl = routeContext.getRequest().getApplicationPath() + StringUtils.removeEnd(StringUtils.addStart(absoluteDirUri, "/"), "/") + StringUtils.addStart(file.getName(), "/"); list.add(new DirEntry(fileUrl, file)); } if (comparator != null) { list.sort(comparator); } if (!directory.equals(dir)) { File upDir = new File(dir, "../"); list.add(0, new DirEntry(routeContext.getRequest().getApplicationPath() + StringUtils.removeEnd(StringUtils.addStart(absoluteDirUri, "/"), "/") + StringUtils.addStart(upDir.getName(), "/"), upDir)); } return list; }
/** * Redirects the browser to a path relative to the application context. For * example, redirectToContextPath("/contacts") might redirect the browser to * http://localhost/myContext/contacts * <p>This method commits the response.</p> * * @param path */ public void redirectToContextPath(String path) { if ("".equals(contextPath)) { // context path is the root redirect(path); } else { redirect(contextPath + StringUtils.addStart(path, "/")); } }
@Override public void init(ServletConfig servletConfig) { if (System.getProperty("pippo.hideLogo") == null) { log.info(PippoUtils.getPippoLogo()); } // check for runtime mode in filter init parameter String mode = servletConfig.getInitParameter(MODE_PARAM); if (!StringUtils.isNullOrEmpty(mode)) { System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode); } if (application == null) { createApplication(servletConfig); log.debug("Created application '{}'", application); } ServletContext servletContext = servletConfig.getServletContext(); // save the servlet context object in application application.setServletContext(servletContext); // set the application as an attribute of the servlet container if (servletContext.getAttribute(WebServer.PIPPO_APPLICATION) == null) { servletContext.setAttribute(WebServer.PIPPO_APPLICATION, application); } String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/"); application.getRouter().setContextPath(contextPath); log.debug("Serving application on context path '{}'", contextPath); log.debug("Initializing Route Dispatcher"); routeDispatcher = new RouteDispatcher(application); routeDispatcher.init(); String runtimeMode = application.getRuntimeMode().toString().toUpperCase(); log.info("Pippo started ({})", runtimeMode); }
String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/"); application.getRouter().setContextPath(contextPath);
private void sendDirectoryListing(RouteContext routeContext, File dir) { String absoluteDirUri = getUrlPath() + StringUtils.addStart(directory.toPath().relativize(dir.toPath()).toString(), "/"); if (StringUtils.isNullOrEmpty(directoryTemplate)) { // Generate primitive, default directory listing String page = generateDefaultDirectoryListing(routeContext, dir, absoluteDirUri); routeContext.html().send(page); } else { // Render directory listing template int numFiles = 0; int numDirs = 0; long diskUsage = 0; List<DirEntry> dirEntries = getDirEntries(routeContext, dir, absoluteDirUri); for (DirEntry dirEntry : dirEntries) { if (dirEntry.isFile()) { numFiles++; diskUsage += dirEntry.getSize(); } else if (dirEntry.isDirectory() && !dirEntry.getName().contains("..")) { numDirs++; } } routeContext.setLocal("dirUrl", absoluteDirUri); routeContext.setLocal("dirPath", absoluteDirUri.substring(getUrlPath().length())); routeContext.setLocal("dirEntries", dirEntries); routeContext.setLocal("numDirs", numDirs); routeContext.setLocal("numFiles", numFiles); routeContext.setLocal("diskUsage", diskUsage); routeContext.render(directoryTemplate); } }
String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/"); ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName()); handler.validateMethodArgs(fullPath); String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");
String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/"); ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName()); handler.validateMethodArgs(fullPath); String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");