static String getCanonicalURL(String legalurl) { if(legalurl == null) return null; int index = legalurl.indexOf('?'); if(index >= 0) legalurl = legalurl.substring(0, index); // remove any trailing extension //index = legalurl.lastIndexOf('.'); //if(index >= 0) legalurl = legalurl.substring(0,index); return HTTPUtil.canonicalpath(legalurl); }
/** * Convert path to use '/' consistently and * to remove any trailing '/' * * @param path convert this path * @return canonicalized version */ static public String canonicalpath(String path) { if(path == null) return null; StringBuilder b = new StringBuilder(path); canonicalpath(b); return b.toString(); }
/** * Convert path to remove any leading '/' or drive letter assumes canonical. * * @param path convert this path * @return relatived version */ static public String relpath(String path) { if(path == null) return null; StringBuilder b = new StringBuilder(path); canonicalpath(b); if(b.length() > 0) { if(b.charAt(0) == '/') b.deleteCharAt(0); if(hasDriveLetter(b)) b.delete(0, 2); } return b.toString(); }
/** * Convert path to add a leading '/'; assumes canonical. * * @param path convert this path * @return absolute version */ static public String abspath(String path) { if(path == null) return "/"; StringBuilder b = new StringBuilder(path); canonicalpath(b); if(b.charAt(0) == '/') b.deleteCharAt(0); if(b.charAt(0) != '/' || !hasDriveLetter(b)) b.insert(0, '/'); return b.toString(); }
prefix = HTTPUtil.canonicalpath(prefix); suffix = HTTPUtil.canonicalpath(suffix); StringBuilder result = new StringBuilder(); result.append(prefix);
String cxtpath = HTTPUtil.canonicalpath(myHttpRequest.getContextPath()); if (cxtpath != null && cxtpath.length() == 0) cxtpath = null; if (cxtpath == null) cxtpath = "/"; // we are running as webapps/ROOT String servletpath = HTTPUtil.canonicalpath(myHttpRequest.getServletPath()); if (servletpath != null && servletpath.length() == 0) servletpath = null; this.dataSetName = HTTPUtil.canonicalpath(myHttpRequest.getPathInfo()); if (this.dataSetName != null && this.dataSetName.length() == 0) this.dataSetName = null;
protected TestCase(String filename, boolean overwrite, String target) { super(null); this.filename = HTTPUtil.canonicalpath(filename); this.status = ""; this.overwrite = overwrite; this.target = HTTPUtil.canonicalpath(HTTPUtil.nullify(target)); try { this.file = HTTPUtil.readbinaryfile(new File(filename)); } catch (IOException ioe) { throw new IllegalArgumentException(ioe); } }
protected TestCase(String cmd, String url, String target, String... params) { super(url); this.target = HTTPUtil.canonicalpath(target); this.cmd = Command.parse(cmd); this.params.put("request", this.cmd.name().toLowerCase()); if(this.url != null) this.params.put("url", this.url); if(this.target != null) this.params.put("target", this.target); for(int i = 0; i < params.length; i++) { String[] pieces = params[i].trim().split("[=]"); if(pieces.length == 1) this.params.put(pieces[0].trim().toLowerCase(), ""); else this.params.put(pieces[0].trim().toLowerCase(), pieces[1].trim()); } }
/** * @param realpath path to this servlet's dir in webapps (typically nding in WEB-INF) * @param which parameter name to check: typically a relative path * @param dfalt for parameter * @return The absolute path froom the which directory(ending in '/'). */ private String getCachedString(String realpath, String which, String dfalt) { String dir = getInitParameter(which); if(dir == null) dir = dfalt; if(HTTPUtil.isAbsolutePath(dir)) dir = HTTPUtil.canonicalpath(dir); else dir = HTTPUtil.relpath(dir); dir = HTTPUtil.canonjoin(realpath,dir); if (!dir.endsWith("/")) dir += "/"; return (dir); }
buf.append("/"); buf.append(targetpath); String abstarget = HTTPUtil.canonicalpath(buf.toString()); File targetfile = new File(abstarget); Assert.assertTrue("***Fail: Upload file not created: " + abstarget, targetfile.exists());