ASF Bugzilla – Attachment 32260 Details for
Bug 57287
Sort files listed by DefaultServlet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 57287v3
Bug_57287v3.patch (text/plain), 6.72 KB, created by
Oleg Trokhov
on 2014-12-05 10:04:22 UTC
(
hide
)
Description:
Bug 57287v3
Filename:
MIME Type:
Creator:
Oleg Trokhov
Created:
2014-12-05 10:04:22 UTC
Size:
6.72 KB
patch
obsolete
>Index: java/org/apache/catalina/servlets/DefaultServlet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- java/org/apache/catalina/servlets/DefaultServlet.java (revision 1642802) >+++ java/org/apache/catalina/servlets/DefaultServlet.java (revision ) >@@ -33,7 +33,9 @@ > import java.io.StringWriter; > import java.security.AccessController; > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.Collection; >+import java.util.Comparator; > import java.util.Enumeration; > import java.util.Iterator; > import java.util.Locale; >@@ -259,7 +261,10 @@ > */ > protected boolean showServerInfo = true; > >- >+ /** >+ * File list sorting parameters. >+ */ >+ protected String sortingParams = null; > // --------------------------------------------------------- Public Methods > > /** >@@ -701,7 +706,7 @@ > throws IOException, ServletException { > > boolean serveContent = content; >- >+ sortingParams=request.getQueryString(); > // Identify the requested resource path > String path = getRelativePath(request); > if (debug > 0) { >@@ -1281,7 +1286,6 @@ > // rewriteUrl(contextPath) is expensive. cache result for later reuse > String rewrittenContextPath = rewriteUrl(contextPath); > String directoryWebappPath = resource.getWebappPath(); >- > for (String entry : entries) { > > if (entry.equalsIgnoreCase("WEB-INF") || >@@ -1455,7 +1459,24 @@ > sb.append("</tr>"); > > boolean shade = false; >+ Comparator cic = null; >+ if (sortingParams == null) { >+ cic = new NameAscComparator(); >+ } else { >+ cic = getComparator(sortingParams); >+ } >+ ArrayList<WebResource> resourceList = new ArrayList<WebResource>(); > for (String entry : entries) { >+ WebResource childResource = >+ resources.getResource(directoryWebappPath + entry); >+ resourceList.add(childResource); >+ } >+ WebResource[] resourceArray = resourceList.toArray(new WebResource[resourceList.size()]); >+ Arrays.sort(resourceArray, cic); >+ for (int i = 0; i < entries.length; i++) { >+ entries[i] = resourceArray[i].getName(); >+ } >+ for (String entry : entries) { > if (entry.equalsIgnoreCase("WEB-INF") || > entry.equalsIgnoreCase("META-INF")) > continue; >@@ -2229,6 +2250,104 @@ > IOException { > throw new SAXException(sm.getString("defaultServlet.blockExternalEntity2", > name, publicId, baseURI, systemId)); >+ } >+ } >+ private Comparator<WebResource> getComparator(String sortingParams) { >+ if (sortingParams.equals("s=SA")) { >+ return new SizeAscComparator(); >+ } else if (sortingParams.equals("s=SD")) { >+ return new SizeDscComparator(); >+ } else if (sortingParams.equals("s=NA")) { >+ return new NameAscComparator(); >+ } else if (sortingParams.equals("s=ND")) { >+ return new NameDscComparator(); >+ } else if (sortingParams.equals("s=MA")) { >+ return new ModifyAscComparator(); >+ } else if (sortingParams.equals("s=MD")) { >+ return new ModifyDscComparator(); >+ } else return new NameAscComparator(); >+ } >+ >+ class NameAscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory() && strB.isDirectory()) { >+ return 1; >+ } else >+ return strA.getName().compareToIgnoreCase(strB.getName()); >+ } >+ } >+ >+ class NameDscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory() && strB.isDirectory()) { >+ return 1; >+ } else >+ return strB.getName().compareToIgnoreCase(strA.getName()); >+ } >+ } >+ >+ class SizeAscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory() && strB.isDirectory()) { >+ return 1; >+ } else if (strA.getContentLength() > strB.getContentLength()) { >+ return 1; >+ } else if (strA.getContentLength() < strB.getContentLength()) { >+ return -1; >+ } else >+ return 0; >+ } >+ } >+ >+ class SizeDscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory()&& strB.isDirectory()) { >+ return 1; >+ } else if (strA.getContentLength() > strB.getContentLength()) { >+ return -1; >+ } else if (strA.getContentLength() < strB.getContentLength()) { >+ return 1; >+ } else >+ return 0; >+ } >+ } >+ >+ class ModifyAscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory() && strB.isDirectory()) { >+ return 1; >+ } else if (strA.getLastModified() > strB.getLastModified()) { >+ return 1; >+ } else if (strA.getLastModified() < strB.getLastModified()) { >+ return -1; >+ } else >+ return 0; >+ } >+ } >+ >+ class ModifyDscComparator implements Comparator<WebResource> { >+ public int compare(WebResource strA, WebResource strB) { >+ if (strA.isDirectory() && !strB.isDirectory()) { >+ return -1; >+ } else if (!strA.isDirectory() && strB.isDirectory()) { >+ return 1; >+ } else if (strA.getLastModified() > strB.getLastModified()) { >+ return -1; >+ } else if (strA.getLastModified() < strB.getLastModified()) { >+ return 1; >+ } else >+ return 0; > } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57287
:
32248
|
32249
| 32260