Skip to content

Commit 7283e58

Browse files
committed
- Refactored classes to use the javaxt-server library (vs javax.servlet)
git-svn-id: svn://192.168.0.80/JavaXT/javaxt-portal@271 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 496c63d commit 7283e58

File tree

11 files changed

+843
-663
lines changed

11 files changed

+843
-663
lines changed

src/javaxt/portal/Content.java

Lines changed: 143 additions & 231 deletions
Large diffs are not rendered by default.

src/javaxt/portal/Documentation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package javaxt.portal;
22
import java.util.zip.*;
3+
import javaxt.http.servlet.*;
34

45
//******************************************************************************
56
//** Documentation Class
@@ -11,7 +12,7 @@
1112

1213
public class Documentation {
1314

14-
private javax.servlet.http.HttpServletRequest request;
15+
private HttpServletRequest request;
1516
private String jar;
1617
private com.jeldoclet.Parser parser;
1718

@@ -46,7 +47,7 @@ public class Documentation {
4647
* @param dir Path to the jar directory
4748
* @param request HttpServletRequest
4849
*/
49-
public Documentation(String jar, javaxt.io.Directory dir, javax.servlet.http.HttpServletRequest request) {
50+
public Documentation(String jar, javaxt.io.Directory dir, HttpServletRequest request) {
5051

5152
if (jar.toLowerCase().endsWith(".jar") || jar.toLowerCase().endsWith(".zip")){
5253
jar = jar.substring(0, jar.lastIndexOf("."));
@@ -78,7 +79,7 @@ public String getIndex(String title) throws Exception {
7879
}
7980
if (showIndex){
8081

81-
String path = new javaxt.utils.URL(request.getRequestURL().toString()).getPath();
82+
String path = request.getURL().getPath();
8283

8384
if (title==null) str.append("<h1>JavaDocs</h1>");
8485
else str.append("<h1>" + title + "</h1>");
@@ -359,7 +360,7 @@ public static String mergeTrees(java.util.List<String> trees){
359360
*/
360361
private com.jeldoclet.Parser getJELParser(javaxt.io.File javadoc){
361362

362-
javax.servlet.ServletContext application = request.getSession().getServletContext();
363+
ServletContext application = request.getSession().getServletContext();
363364
com.jeldoclet.Parser parser = (com.jeldoclet.Parser) application.getAttribute(jar);
364365
java.util.Date lastUpdate = (java.util.Date) application.getAttribute(jar + "-timestamp");
365366
if (parser==null || lastUpdate==null || javadoc.getDate().after(lastUpdate)){

src/javaxt/portal/Download.java

Lines changed: 0 additions & 205 deletions
This file was deleted.

src/javaxt/portal/File.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package javaxt.portal;
2+
import javaxt.http.servlet.HttpServletRequest;
3+
import javaxt.http.servlet.HttpServletResponse;
4+
import javaxt.http.servlet.ServletException;
5+
6+
//******************************************************************************
7+
//** File Class
8+
//******************************************************************************
9+
/**
10+
* Used to represent a file found on the web server.
11+
*
12+
******************************************************************************/
13+
14+
public class File {
15+
16+
private javaxt.io.File file;
17+
18+
//**************************************************************************
19+
//** Constructor
20+
//**************************************************************************
21+
22+
public File(HttpServletRequest request, javaxt.io.Directory share, String Path)
23+
throws ServletException {
24+
25+
26+
//Get requested file from the querystring
27+
String filename = null;
28+
java.util.Enumeration<String> it = request.getParameterNames();
29+
while (it.hasMoreElements()){
30+
String key = it.nextElement();
31+
if (key.equalsIgnoreCase("img") || key.equalsIgnoreCase("image") ||
32+
key.equalsIgnoreCase("file") || key.equalsIgnoreCase("filename")){
33+
filename = request.getParameter(key);
34+
if (filename!=null){
35+
break;
36+
}
37+
}
38+
}
39+
if (filename==null) filename = request.getQueryString();
40+
41+
//If no file found in the querystring, use the path from the url
42+
if (filename==null){
43+
String path = request.getURL().getPath();
44+
path = path.substring(path.indexOf(Path)).substring(Path.length());
45+
if (!path.endsWith("/")) filename = path;
46+
}
47+
48+
49+
//Remove any leading path separators
50+
if (filename!=null){
51+
if (filename.startsWith("/")||filename.startsWith("\\")){
52+
filename = filename.substring(1);
53+
}
54+
}
55+
56+
57+
58+
//Validate the filename/path
59+
if (filename==null || filename.equals("") || filename.contains("..") ||
60+
filename.toLowerCase().contains("keystore")){
61+
throw new ServletException(400);
62+
}
63+
else{
64+
//Make sure none of the directories/files in the path are "hidden"
65+
for (String path : filename.replace("\\", "/").split("/")){
66+
if (path.trim().startsWith(".")){
67+
throw new ServletException(400);
68+
}
69+
}
70+
}
71+
72+
73+
74+
file = new javaxt.io.File(share.toString() + filename);
75+
if (!file.exists()) file = new javaxt.io.File(share.toString() + "downloads/" + filename);
76+
77+
//System.out.println("Download: " + file);
78+
79+
if (!file.exists()){
80+
throw new ServletException();
81+
}
82+
83+
}
84+
85+
86+
public javaxt.io.File getFile(){
87+
return file;
88+
}
89+
90+
//**************************************************************************
91+
//** sendFile
92+
//**************************************************************************
93+
/** Used to send a static file to the client.
94+
*/
95+
public void send(HttpServletResponse response) throws java.io.IOException {
96+
String contentType = file.getContentType();
97+
if (file.getExtension().equalsIgnoreCase("xml")) contentType = "text/xml";
98+
response.write(file.toFile(), contentType, true);
99+
}
100+
101+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy