Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Connector Update, Javascript Async Handling #21

Merged
merged 10 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions connectors/jsp/auth.jsp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<%!
/**
* Check if user is authorized
*
* CHANGES
* - added Param request
*
* @return boolean true is access granted, false if no access
*/
public boolean auth() {
public boolean auth(HttpServletRequest request) {
// You can insert your own code over here to check if the user is authorized.
return true;
}
Expand Down
191 changes: 112 additions & 79 deletions connectors/jsp/filemanager.jsp
Original file line number Diff line number Diff line change
@@ -1,91 +1,124 @@
<%@ page pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ page language="java" import="java.util.*"%>
<%@ page import="com.nartex.*"%>
<%@ page import="org.json.JSONObject"%>
<%@ page import="java.io.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.fileupload.disk.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
<%@include file="auth.jsp"%>
<%
/*
* connector filemanager.jsp
* connector filemanager.jsp
*
* @license MIT License
* @author Dick Toussaint <d.tricky@gmail.com>
* @copyright Authors
*/

FileManager fm = new FileManager(getServletContext(), request);
* @license MIT License
* @author Dick Toussaint <d.tricky@gmail.com>
* @copyright Authors
*
* CHANGES:
* - check strictServletCompliance 8/16
* - dynamic content type setting 8/16
*/

//use new rich manager
FileManagerI fm = new RichFileManager(getServletContext(), request);

boolean strictServletCompliance = false; // default value is ISO-8859-1.

JSONObject responseData = null;
JSONObject responseData = null;

String mode = "";
String mode = "";
boolean putTextarea = false;
if(!auth()) {
fm.error(fm.lang("AUTHORIZATION_REQUIRED"));
}
else {
if(request.getMethod().equals("GET")) {
if(request.getParameter("mode") != null && request.getParameter("mode") != "") {
mode = request.getParameter("mode");
if (mode.equals("getinfo")){
if(fm.setGetVar("path", request.getParameter("path"))) {
responseData = fm.getInfo();
}
}
else if (mode.equals("getfolder")){
if(fm.setGetVar("path", request.getParameter("path"))) {
responseData = fm.getFolder();
}
}
else if (mode.equals("rename")){
if(fm.setGetVar("old", request.getParameter("old")) &&
fm.setGetVar("new", request.getParameter("new"))) {
responseData = fm.rename();
}
}
else if (mode.equals("delete")){
if(fm.setGetVar("path", request.getParameter("path"))) {
responseData = fm.delete();
}
}
else if (mode.equals("addfolder")){
if(fm.setGetVar("path", request.getParameter("path")) &&
fm.setGetVar("name", request.getParameter("name"))) {
responseData = fm.addFolder();
}
}
else if (mode.equals("download")){
if(fm.setGetVar("path", request.getParameter("path"))) {
fm.download(response);
}
}
else if (mode.equals("preview")){
if(fm.setGetVar("path", request.getParameter("path"))) {
fm.preview(response);
}
}
else {
fm.error(fm.lang("MODE_ERROR"));
}
if(!auth(request)) {
fm.error(fm.lang("AUTHORIZATION_REQUIRED"));
}
else {
if(request.getMethod().equals("GET")) {
if(request.getParameter("mode") != null && request.getParameter("mode") != "") {
mode = request.getParameter("mode");
// cft. http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q2
String [] queryParams = null;
Map<String,String> qpm = new HashMap<String,String>();
if (strictServletCompliance) {
queryParams = java.net.URLDecoder.decode(request.getQueryString(), "UTF-8").split("&");
for (int i = 0; i < queryParams.length; i++) {
String[] qp = queryParams[i].split("=");
if (qp.length >1) {
qpm.put(qp[0], qp[1]);
} else {
qpm.put(qp[0], "");
}
}
}
if (mode.equals("getinfo")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"): request.getParameter("path"))) {
responseData = fm.getInfo();
}
}
else if (mode.equals("getfolder")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
responseData = fm.getFolder();
}
}
else if (mode.equals("rename")){
if(fm.setGetVar("old", (strictServletCompliance)? qpm.get("old"):request.getParameter("old")) &&
fm.setGetVar("new", (strictServletCompliance)? qpm.get("new"):request.getParameter("new"))) {
responseData = fm.rename();
}
}
else if (mode.equals("delete")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
responseData = fm.delete();
}
}
else if (mode.equals("addfolder")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path")) &&
fm.setGetVar("name", (strictServletCompliance)? qpm.get("name"):request.getParameter("name"))) {
responseData = fm.addFolder();
}
}
else if (mode.equals("download")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
responseData = fm.download(request, response);
}
}
else if (mode.equals("preview")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
fm.preview(response);
}
} else if (mode.equals("move")){
if(fm.setGetVar("old", (strictServletCompliance)? qpm.get("old"):request.getParameter("old")) &&
fm.setGetVar("new", (strictServletCompliance)? qpm.get("new"):request.getParameter("new")) &&
fm.setGetVar("root", (strictServletCompliance)? qpm.get("root"):request.getParameter("root"))
) {
responseData = fm.moveItem();
}
}
else {
fm.error(fm.lang("MODE_ERROR"));
}
}
}
else if(request.getMethod().equals("POST")){
mode = "upload";
responseData = fm.add();
//putTextarea = true; // this seems not required in new query upload
}
}
if (responseData == null){
responseData = fm.getError();
}
if (responseData != null){
//request.setCharacterEncoding("UTF-8");
// only if set
if (putTextarea) {
response.setContentType("text/html; charset=UTF-8");
} else {
response.setContentType("application/json; charset=UTF-8");
}
}
else if(request.getMethod().equals("POST")){
mode = "upload";
responseData = fm.add();
putTextarea = true;
}
}
if (responseData == null){
responseData = fm.getError();
}
if (responseData != null){
PrintWriter pw = response.getWriter();
String responseStr = responseData.toString();
if (putTextarea)
responseStr = "<textarea>" + responseStr + "</textarea>";
//fm.log("c:\\logfilej.txt", "mode:" + mode + ",response:" + responseStr);
pw.print(responseStr);
pw.close();
}
%>
PrintWriter pw = response.getWriter();
String responseStr = responseData.toString();
if (putTextarea)
responseStr = "<textarea>" + responseStr + "</textarea>";
//fm.log("mode:" + mode + ",response:" + responseStr);
pw.print(responseStr);
pw.close();
}
%>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading