Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
UPDATE

JAVA
- Removed Thumbnail and Preview properties, use Path only
- client path as a URL from context reading preview config, server path
  from doc_root conf property, both should work either relative or
  absolute. TODO Bugfix in fm.js: createPreviewUrl would only need to be
  "/" + path, no call to connector

JS
- removed global object, merged

PHP, images
- merged without changes
  • Loading branch information
Georg Kallidis committed Aug 17, 2016
2 parents dfc7fdd + 7fba25f commit f803320
Show file tree
Hide file tree
Showing 26 changed files with 1,118 additions and 828 deletions.
12 changes: 12 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ Version 1.0.5
- Fixed bug: Path issue upon file selection in WYSIWYG editor
- Fixed bug: It is possible to select folders in WYSIWYG editor
- Fixed bug: Preview of media and pdf files is broken when the path contains special chars (fixed by path encoding)


Version 1.0.6
---------------------------
- removed `fileConnector` option from server-side;
- removed 'Preview' and 'Thumbnail' params from `getinfo` response;
- all preview paths (images, media, office files) are now associated to connector. Absolute paths for icons exclusively;
- all preview paths are now built at the client-side (connector independent) for better API support;
- added support of seeking for media files in PHP connector (including S3 storage plugin);
- added capability to pass custom configuration options in filemanager.php to override the default config;
- PHP connector refactored, following OOP practices;
- added icons for OpenOffice files;
20 changes: 11 additions & 9 deletions connectors/jsp/filemanager.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
* - dynamic content type setting 8/16
*/
//use new rich manager
FileManagerI fm = new RichFileManager(getServletContext(), request);
//use new rich manager - or not
boolean rich = true;
FileManagerI fm = (rich)? new RichFileManager(getServletContext(), request) : new FileManager(getServletContext(), request);
boolean strictServletCompliance = false; // default value is ISO-8859-1.
Expand Down Expand Up @@ -54,7 +57,7 @@
}
else if (mode.equals("getfolder")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
responseData = fm.getFolder();
responseData = fm.getFolder(request);
}
}
else if (mode.equals("rename")){
Expand All @@ -79,14 +82,13 @@
responseData = fm.download(request, response);
}
}
else if (mode.equals("preview")){
else if (mode.equals("getimage")){
if(fm.setGetVar("path", (strictServletCompliance)? qpm.get("path"):request.getParameter("path"))) {
fm.preview(response);
fm.preview(request, 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"))
fm.setGetVar("new", (strictServletCompliance)? qpm.get("new"):request.getParameter("new"))
) {
responseData = fm.moveItem();
}
Expand All @@ -99,7 +101,7 @@
else if(request.getMethod().equals("POST")){
mode = "upload";
responseData = fm.add();
//putTextarea = true; // this seems not required in new query upload
//putTextarea = true;
}
}
if (responseData == null){
Expand All @@ -117,7 +119,7 @@
String responseStr = responseData.toString();
if (putTextarea)
responseStr = "<textarea>" + responseStr + "</textarea>";
//fm.log("mode:" + mode + ",response:" + responseStr);
//fm.log("d:\\logs\\logfilej.txt", "mode:" + mode + ",response:" + responseStr);
pw.print(responseStr);
pw.close();
}
Expand Down
Binary file modified connectors/jsp/libraries/java/bin/com/nartex/AbstractFM.class
Binary file not shown.
Binary file modified connectors/jsp/libraries/java/bin/com/nartex/FileManagerI.class
Binary file not shown.
Binary file not shown.
147 changes: 8 additions & 139 deletions connectors/jsp/libraries/java/src/com/nartex/AbstractFM.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author gkallidis
*
*/
public abstract class AbstractFM implements FileManagerI {
public abstract class AbstractFM implements FileManagerI{

protected static Properties config = null;
protected static JSONObject language = null;
Expand All @@ -58,7 +58,7 @@ public abstract class AbstractFM implements FileManagerI {
protected SimpleDateFormat dateFormat;
protected List<FileItem> files = null;
protected boolean reload = false;
protected String previewPath = null; //static?
protected Path previewBasePath = null; //static?
protected boolean previewPathRelative = false; // needed as it is exposed either relative or absolute

public AbstractFM(ServletContext servletContext, HttpServletRequest request) throws IOException {
Expand Down Expand Up @@ -116,7 +116,11 @@ public AbstractFM(ServletContext servletContext, HttpServletRequest request) thr
log.debug("final documentRoot:"+ this.documentRoot);
}
if (reload) {
this.previewPath = null;
this.previewBasePath = null;
}
// a relative path
if (this.previewBasePath == null) {
this.previewBasePath = Paths.get(contextPath);
}

dateFormat = new SimpleDateFormat(config.getProperty("date"));
Expand All @@ -129,7 +133,6 @@ public AbstractFM(ServletContext servletContext, HttpServletRequest request) thr

}


@Override
public JSONObject error(String msg, Throwable ex) {
JSONObject errorInfo = new JSONObject();
Expand Down Expand Up @@ -201,124 +204,7 @@ protected boolean checkFlashType() {
&& contains(config.getProperty("flash"), (String)this.item.get("filetype"));
}

@Override
public JSONObject rename() {
if ((this.get.get("old")).endsWith("/")) {
this.get.put("old", (this.get.get("old")).substring(0, ((this.get.get("old")).length() - 1)));
}
boolean error = false;
JSONObject array = null;
String tmp[] = (this.get.get("old")).split("/");
String filename = tmp[tmp.length - 1];
int pos = this.get.get("old").lastIndexOf("/");
String path = (this.get.get("old")).substring(0, pos + 1);
Path fileFrom = null;
Path fileTo = null;
try {
fileFrom = this.documentRoot.resolve(path).resolve(filename);
fileTo = this.documentRoot.resolve(path).resolve( this.get.get("new"));
if (fileTo.toFile().exists()) {
if (fileTo.toFile().isDirectory()) {
this.error(sprintf(lang("DIRECTORY_ALREADY_EXISTS"), this.get.get("new")));
error = true;
} else { // fileTo.isFile
// Files.isSameFile(fileFrom, fileTo);
this.error(sprintf(lang("FILE_ALREADY_EXISTS"), this.get.get("new")));
error = true;
}
} else {
//if (fileFrom.equals(fileTo));
Files.move(fileFrom, fileTo, StandardCopyOption.REPLACE_EXISTING);
}
} catch (Exception e) {
if (fileFrom.toFile().isDirectory()) {
this.error(sprintf(lang("ERROR_RENAMING_DIRECTORY"), filename + "#" + this.get.get("new")),e);
} else {
this.error(sprintf(lang("ERROR_RENAMING_FILE"), filename + "#" + this.get.get("new")),e);
}
error = true;
}
if (!error) {
array = new JSONObject();
try {
array.put("Error", "");
array.put("Code", 0);
array.put("Old Path", this.get.get("old"));
array.put("Old Name", filename);
array.put("New Path", path + this.get.get("new"));
array.put("New Name", this.get.get("new"));
} catch (Exception e) {
this.error("JSONObject error");
}
}
return array;
}

@Override
public JSONObject delete() {
JSONObject array = null;
File file = this.documentRoot.resolve( this.get.get("path")).toFile();
//new File(this.documentRoot + this.get.get("path"));
if (file.isDirectory()) {
array = new JSONObject();
this.unlinkRecursive(this.documentRoot.resolve( this.get.get("path")).toFile(), true);
try {
array.put("Error", "");
array.put("Code", 0);
array.put("Path", this.get.get("path"));
} catch (Exception e) {
this.error("JSONObject error");
}
} else if (file.exists()) {
array = new JSONObject();
if (file.delete()) {
try {
array.put("Error", "");
array.put("Code", 0);
array.put("Path", this.get.get("path"));
} catch (Exception e) {
this.error("JSONObject error");
}
} else
this.error(sprintf(lang("ERROR_DELETING FILE"), this.get.get("path")));
return array;
} else {
this.error(lang("INVALID_DIRECTORY_OR_FILE"));
}
return array;
}


@Override
public JSONObject addFolder() {
JSONObject array = null;
String allowed[] = { "-", " " };
LinkedHashMap<String, String> strList = new LinkedHashMap<String, String>();
strList.put("fileName", this.get.get("name"));
String filename = cleanString(strList, allowed).get("fileName");
if (filename.length() == 0) // the name existed of only special
// characters
this.error(sprintf(lang("UNABLE_TO_CREATE_DIRECTORY"), this.get.get("name")));
else {
File file = this.documentRoot.resolve(this.get.get("path")).resolve(filename).toFile();
if (file.isDirectory()) {
this.error(sprintf(lang("DIRECTORY_ALREADY_EXISTS"), filename));
} else if (!file.mkdir()) {
this.error(sprintf(lang("UNABLE_TO_CREATE_DIRECTORY"), filename));
} else {
try {
array = new JSONObject();
array.put("Parent", this.get.get("path"));
array.put("Name", filename);
array.put("Error", "");
array.put("Code", 0);
} catch (Exception e) {
this.error("JSONObject error");
}
}
}
return array;
}




Expand Down Expand Up @@ -347,23 +233,6 @@ protected void readFile(HttpServletResponse resp, File file) {
}
}

@Override
public void preview(HttpServletResponse resp) {
File file =this.documentRoot.resolve(this.get.get("path")).toFile();
if (this.get.get("path") != null && file.exists()) {
resp.setHeader("Content-type", "image/" + getFileExtension(file.getName()));
resp.setHeader("Content-Transfer-Encoding", "Binary");
resp.setHeader("Content-length", "" + file.length());
resp.setHeader("Content-Disposition", "inline; filename=\"" + getFileBaseName(file.getName()) + "\"");
// handle caching
resp.setHeader("Pragma", "no-cache");
resp.setHeader("Expires", "0");
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
readFile(resp, file);
} else {
error(sprintf(lang("FILE_DOES_NOT_EXIST"), this.get.get("path")));
}
}

protected String getFileBaseName(String filename) {
String retval = filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface FileManagerI {

public abstract JSONObject getInfo() throws JSONException;

public abstract JSONObject getFolder() throws JSONException, IOException;
public abstract JSONObject getFolder(HttpServletRequest request) throws JSONException, IOException;

public abstract JSONObject rename();

Expand All @@ -45,7 +45,7 @@ public interface FileManagerI {

public abstract JSONObject download(HttpServletRequest request, HttpServletResponse resp);

public abstract void preview(HttpServletResponse resp);
public abstract void preview(HttpServletRequest request, HttpServletResponse resp);

public abstract String getConfigString(String key);

Expand Down
Loading

0 comments on commit f803320

Please sign in to comment.