List of usage examples for javax.servlet ServletContext getContextPath
public String getContextPath();
From source file:eu.trentorise.smartcampus.permissionprovider.oauth.ExtRedirectResolver.java
public static String testTokenPath(ServletContext ctx) { return ctx.getContextPath() + URL_TEST; }
From source file:org.impalaframework.web.utils.ServletContextUtils.java
public static String getContextPathWithoutSlash(ServletContext servletContext) { String contextPath;/*from w w w. j a v a 2s. co m*/ try { contextPath = servletContext.getContextPath(); if (contextPath.startsWith("/")) { contextPath = contextPath.substring(1); } return contextPath; } catch (NoSuchMethodError e) { logger.warn(NoSuchMethodError.class.getName() + " called when attempting to call ServletContext.getContextPath(). Check that you have packaged your application with a Servlet API jar for version 2.5 or later"); return null; } }
From source file:org.tangram.view.Utils.java
public static String getUriPrefix(ServletContext context) { String contextPath = context.getContextPath(); contextPath = (contextPath.length() == 1) ? "" : contextPath; return contextPath; }
From source file:com.dcs.controller.filter.SecurityServlet.java
private static String getContextPath_2_5(ServletContext context) { String contextPath = context.getContextPath(); if (contextPath == null || contextPath.length() == 0) { contextPath = "/"; }// w ww .ja v a 2 s .c o m return contextPath; }
From source file:com.bedatadriven.renjin.appengine.AppEngineContextFactory.java
private static File contextRoot(ServletContext context) { return new File(context.getRealPath(context.getContextPath())); }
From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java
/** * Returns a VFSFile for the given path and context. * /*from ww w . j a va 2s.com*/ * @param context * @param relPath The folder path. * @return VFSFile from the relPath and context. */ private static VFSFile getRootFile(ServletContext context, String relPath) { String rootKey = context.getContextPath() + relPath; if (mappedServlets.containsKey(rootKey)) return mappedServlets.get(rootKey).getRoot(); ServletVFS vfs = new ServletVFS(context, relPath); mappedServlets.put(rootKey, vfs); return vfs.getRoot(); }
From source file:com.seajas.search.utilities.tags.URLTag.java
/** * Rewrite a URL.//ww w . ja v a2s . c om * * @param context * @param request * @param url * @param fullUrl * @return String */ public static String rewriteURL(final ServletContext context, final HttpServletRequest request, final String url, final Boolean fullUrl) { String rewrittenURL = url; String contextName = context.getContextPath(); if (contextName == null) contextName = System.getProperty(SYSTEM_DEFAULT_CONTEXT); if (contextName.startsWith("/")) contextName = contextName.substring(1); if (Boolean.getBoolean(SYSTEM_REWRITTEN_URLS)) { if (rewrittenURL.startsWith(contextName)) rewrittenURL = rewrittenURL.substring(contextName.length()); if (rewrittenURL.startsWith("/" + contextName)) rewrittenURL = rewrittenURL.substring(contextName.length() + 1); // Make sure the index link redirects to '/' if (rewrittenURL.equals("/index.html")) rewrittenURL = "/"; } else if (!rewrittenURL.startsWith("/" + contextName)) rewrittenURL = "/" + contextName + rewrittenURL; if (fullUrl) { String forwardedFor = request.getHeader("X-Forwarded-Host"); rewrittenURL = request.getScheme() + "://" + (StringUtils.isEmpty(forwardedFor) ? request.getServerName() + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") : forwardedFor) + (rewrittenURL.startsWith("/") ? rewrittenURL : "/" + rewrittenURL); } return rewrittenURL; }
From source file:eu.openanalytics.rpooli.RPooliServer.java
public static RPooliServer create(final ServletContext servletContext, final RPooliContext context) { checkNotNull(servletContext, "servletContext can't be null"); checkNotNull(context, "context can't be null"); final String serverId = removeStart(servletContext.getContextPath(), "/"); return new RPooliServer(serverId, context); }
From source file:com.thejustdo.util.Utils.java
/** * Given some data it creates a new file inside the servlet context. * * @param location Where to create the file. * @param ctx Gives us the real paths to be used. * @param content What to write./*from w w w . j av a 2 s .c o m*/ * @param filename What name will have the new file. * @return The created file. * @throws IOException If any errors. */ public static File createNewFileInsideContext(String location, ServletContext ctx, String content, String filename) throws IOException { String real = ctx.getContextPath(); String path = real + location + filename; log.info(String.format("File to save: %s", path)); File f = new File(path); // 1. Creating the writers. FileWriter fw = new FileWriter(f); BufferedWriter writer = new BufferedWriter(fw); // 2. Writing contents. writer.write(content); // 3. Closing stream. writer.flush(); writer.close(); fw.close(); return f; }
From source file:com.thejustdo.util.Utils.java
/** * Reads the content of a file and returns it in a big string object. * * @param location Name and location to the plain file. * @param ctx Context to use.//from w w w .j a v a 2 s.c o m * @return */ public static String getPlainTextFileFromContext(String location, ServletContext ctx) { log.log(Level.INFO, "Loading contents of file: {0} and context: {1}.", new Object[] { location, ctx.getContextPath() }); try { InputStream is = ctx.getResourceAsStream(location); StringBuilder answer = new StringBuilder(); InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr); // while there are more lines. String line; while (reader.ready()) { line = reader.readLine(); answer.append(line).append("\n"); } // closing resources. reader.close(); return answer.toString(); } catch (IOException ex) { log.log(Level.SEVERE, null, ex); return null; } }