Java Code Examples for org.apache.catalina.WebResource#isDirectory()
The following examples show how to use
org.apache.catalina.WebResource#isDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebdavServlet.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Process a PUT request for the specified resource. * * @param req The servlet request we are processing * @param resp The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet-specified error occurs */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (isLocked(req)) { resp.sendError(WebdavStatus.SC_LOCKED); return; } String path = getRelativePath(req); WebResource resource = resources.getResource(path); if (resource.isDirectory()) { sendNotAllowed(req, resp); return; } super.doPut(req, resp); // Removing any lock-null resource which would be present lockNullResources.remove(path); }
Example 2
Source File: WebappClassLoaderBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Start the class loader. * * @exception LifecycleException if a lifecycle error occurs */ @Override public void start() throws LifecycleException { state = LifecycleState.STARTING_PREP; WebResource[] classesResources = resources.getResources("/WEB-INF/classes"); for (WebResource classes : classesResources) { if (classes.isDirectory() && classes.canRead()) { localRepositories.add(classes.getURL()); } } WebResource[] jars = resources.listResources("/WEB-INF/lib"); for (WebResource jar : jars) { if (jar.getName().endsWith(".jar") && jar.isFile() && jar.canRead()) { localRepositories.add(jar.getURL()); jarModificationTimes.put( jar.getName(), Long.valueOf(jar.getLastModified())); } } state = LifecycleState.STARTED; }
Example 3
Source File: ResolverImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public boolean resolveResource(int type, String name) { WebResourceRoot resources = request.getContext().getResources(); WebResource resource = resources.getResource(name); if (!resource.exists()) { return false; } else { switch (type) { case 0: return resource.isDirectory(); case 1: return resource.isFile(); case 2: return resource.isFile() && resource.getContentLength() > 0; default: return false; } } }
Example 4
Source File: WebdavServlet.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Propfind helper method. * * @param req The servlet request * @param generatedXML XML response to the Propfind request * @param path Path of the current resource * @param type Propfind type * @param propertiesVector If the propfind type is find properties by * name, then this Vector contains those properties */ private void parseProperties(HttpServletRequest req, XMLWriter generatedXML, String path, int type, Vector<String> propertiesVector) { // Exclude any resource in the /WEB-INF and /META-INF subdirectories if (isSpecialPath(path)) return; WebResource resource = resources.getResource(path); if (!resource.exists()) { // File is in directory listing but doesn't appear to exist // Broken symlink or odd permission settings? return; } String href = req.getContextPath() + req.getServletPath(); if ((href.endsWith("/")) && (path.startsWith("/"))) href += path.substring(1); else href += path; if (resource.isDirectory() && (!href.endsWith("/"))) href += "/"; String rewrittenUrl = rewriteUrl(href); generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector, resource.isFile(), false, resource.getCreation(), resource.getLastModified(), resource.getContentLength(), getServletContext().getMimeType(resource.getName()), resource.getETag()); }
Example 5
Source File: WebdavServlet.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Determines the methods normally allowed for the resource. * * @param req The Servlet request * * @return The allowed HTTP methods */ @Override protected String determineMethodsAllowed(HttpServletRequest req) { WebResource resource = resources.getResource(getRelativePath(req)); // These methods are always allowed. They may return a 404 (not a 405) // if the resource does not exist. StringBuilder methodsAllowed = new StringBuilder( "OPTIONS, GET, POST, HEAD"); if (!readOnly) { methodsAllowed.append(", DELETE"); if (!resource.isDirectory()) { methodsAllowed.append(", PUT"); } } // Trace - assume disabled unless we can prove otherwise if (req instanceof RequestFacade && ((RequestFacade) req).getAllowTrace()) { methodsAllowed.append(", TRACE"); } methodsAllowed.append(", LOCK, UNLOCK, PROPPATCH, COPY, MOVE"); if (listings) { methodsAllowed.append(", PROPFIND"); } if (!resource.exists()) { methodsAllowed.append(", MKCOL"); } return methodsAllowed.toString(); }
Example 6
Source File: DefaultServlet.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public int compare(WebResource r1, WebResource r2) { if(r1.isDirectory()) { if(r2.isDirectory()) { return base.compare(r1, r2); } else { return -1; // r1, directory, first } } else if(r2.isDirectory()) { return 1; // r2, directory, first } else { return base.compare(r1, r2); } }
Example 7
Source File: WebdavServlet.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Delete a resource. * * @param path Path of the resource which is to be deleted * @param req Servlet request * @param resp Servlet response * @param setStatus Should the response status be set on successful * completion * @return <code>true</code> if the delete is successful * @throws IOException If an IO error occurs */ private boolean deleteResource(String path, HttpServletRequest req, HttpServletResponse resp, boolean setStatus) throws IOException { String ifHeader = req.getHeader("If"); if (ifHeader == null) ifHeader = ""; String lockTokenHeader = req.getHeader("Lock-Token"); if (lockTokenHeader == null) lockTokenHeader = ""; if (isLocked(path, ifHeader + lockTokenHeader)) { resp.sendError(WebdavStatus.SC_LOCKED); return false; } WebResource resource = resources.getResource(path); if (!resource.exists()) { resp.sendError(WebdavStatus.SC_NOT_FOUND); return false; } if (!resource.isDirectory()) { if (!resource.delete()) { resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR); return false; } } else { Hashtable<String,Integer> errorList = new Hashtable<>(); deleteCollection(req, path, errorList); if (!resource.delete()) { errorList.put(path, Integer.valueOf (WebdavStatus.SC_INTERNAL_SERVER_ERROR)); } if (!errorList.isEmpty()) { sendReport(req, resp, errorList); return false; } } if (setStatus) { resp.setStatus(WebdavStatus.SC_NO_CONTENT); } return true; }
Example 8
Source File: WebdavServlet.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Deletes a collection. * @param req The Servlet request * @param path Path to the collection to be deleted * @param errorList Contains the list of the errors which occurred */ private void deleteCollection(HttpServletRequest req, String path, Hashtable<String,Integer> errorList) { if (debug > 1) log("Delete:" + path); // Prevent deletion of special subdirectories if (isSpecialPath(path)) { errorList.put(path, Integer.valueOf(WebdavStatus.SC_FORBIDDEN)); return; } String ifHeader = req.getHeader("If"); if (ifHeader == null) ifHeader = ""; String lockTokenHeader = req.getHeader("Lock-Token"); if (lockTokenHeader == null) lockTokenHeader = ""; String[] entries = resources.list(path); for (String entry : entries) { String childName = path; if (!childName.equals("/")) childName += "/"; childName += entry; if (isLocked(childName, ifHeader + lockTokenHeader)) { errorList.put(childName, Integer.valueOf(WebdavStatus.SC_LOCKED)); } else { WebResource childResource = resources.getResource(childName); if (childResource.isDirectory()) { deleteCollection(req, childName, errorList); } if (!childResource.delete()) { if (!childResource.isDirectory()) { // If it's not a collection, then it's an unknown // error errorList.put(childName, Integer.valueOf( WebdavStatus.SC_INTERNAL_SERVER_ERROR)); } } } } }