Java Code Examples for org.apache.commons.lang3.StringUtils.stripStart()

The following are Jave code examples for showing how to use stripStart() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gitplex-mit   File: GitFilter.java   View Source Code Vote up 6 votes
@Sessional
protected ProjectFacade getProject(HttpServletRequest request, HttpServletResponse response, String projectInfo) 
		throws IOException {
	projectInfo = StringUtils.stripStart(StringUtils.stripEnd(projectInfo, "/"), "/");

	if (StringUtils.isBlank(projectInfo) || !projectInfo.startsWith("projects/")) {
		String url = request.getRequestURL().toString();
		String urlRoot = url.substring(0, url.length()-getPathInfo(request).length());
		throw new GitException(String.format("Expecting url of format %sprojects/<project name>", urlRoot));
	} 
	
	String projectName = StringUtils.substringAfter(projectInfo, "/");
	
	if (projectName.endsWith(".git"))
		projectName = projectName.substring(0, projectName.length()-".git".length());
	
	Project project = projectManager.find(projectName);
	if (project == null) {
		throw new GitException(String.format("Unable to find project %s", projectName));
	}
	
	return project.getFacade();
}
 
Example 2
Project: gitplex-mit   File: GitFilter.java   View Source Code Vote up 6 votes
protected void processRefs(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String pathInfo = request.getRequestURI().substring(request.getContextPath().length());
	pathInfo = StringUtils.stripStart(pathInfo, "/");

	String projectInfo = pathInfo.substring(0, pathInfo.length() - INFO_REFS.length());
	ProjectFacade project = getProject(request, response, projectInfo);
	String service = request.getParameter("service");
	
	File gitDir = storageManager.getProjectGitDir(project.getId());

	if (service.contains("upload")) {
		if (!SecurityUtils.canRead(project)) 
			throw new UnauthorizedException("You do not have permission to pull from this project.");
		writeInitial(response, service);
		new AdvertiseUploadRefsCommand(gitDir).output(response.getOutputStream()).call();
	} else {
		if (!SecurityUtils.canWrite(project)) {
			throw new UnauthorizedException("You do not have permission to push to this project.");
		}
		writeInitial(response, service);
		new AdvertiseReceiveRefsCommand(gitDir).output(response.getOutputStream()).call();
	}
}
 
Example 3
Project: gitplex-mit   File: AssetServlet.java   View Source Code Vote up 5 votes
@Override
public final Resource getResource(String pathInContext) {
	ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
	ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
	
	for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
		if (mapping.getServletName().equals(getServletName())) {
			for (String pathSpec: mapping.getPathSpecs()) {
				String relativePath = null;
				if (pathSpec.endsWith("/*")) {
					pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
					if (pathInContext.startsWith(pathSpec + "/")) 
						relativePath = pathInContext.substring(pathSpec.length());
				} else if (pathSpec.startsWith("*.")) {
					pathSpec = StringUtils.stripStart(pathSpec, "*");
					if (pathInContext.endsWith(pathSpec))
						relativePath = pathInContext;
				} else if (pathSpec.equals(pathInContext)) {
					relativePath = pathInContext;
				}
				if (relativePath != null) {
					relativePath = StringUtils.stripStart(relativePath, "/");
					Resource resource = Resource.newResource(loadResource(relativePath));
					if (resource != null && resource.exists())
						return resource;
				}
			}
		}
	}
	
	return null;
}
 
Example 4
Project: gitplex-mit   File: GitFilter.java   View Source Code Vote up 4 votes
private String getPathInfo(HttpServletRequest request) {
	String pathInfo = request.getRequestURI().substring(request.getContextPath().length());
	return StringUtils.stripStart(pathInfo, "/");
}
 
Example 5
Project: satisfy   File: SatisfyAnnotatedStepDescription.java   View Source Code Vote up 4 votes
private String unqualified(String methodName) {
    return StringUtils.stripStart(methodName, "[0123456789] ");
}
 
Example 6
Project: history-api-navigation   File: HistoryApiNavigationStateManager.java   View Source Code Vote up 4 votes
private static String sanitizePath(final String path){
    // prevent double slashes, because that causes errors in pushState()
    return SEPARATOR + StringUtils.stripStart(path, SEPARATOR);
}