X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fajaxplorer%2Ffile%2FAbstractFileDownloadAction.java;fp=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fajaxplorer%2Ffile%2FAbstractFileDownloadAction.java;h=0000000000000000000000000000000000000000;hb=651d33e13bfa9a7b46464be412023ee747e612e8;hp=fca3243ebecd9ede43032f13903e4be0b81fcc81;hpb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AbstractFileDownloadAction.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AbstractFileDownloadAction.java deleted file mode 100644 index fca3243eb..000000000 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AbstractFileDownloadAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.web.ajaxplorer.file; - -import java.io.File; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.argeo.slc.web.ajaxplorer.AjxpAnswer; -import org.argeo.slc.web.ajaxplorer.AjxpDriverException; - -public abstract class AbstractFileDownloadAction extends FileAction { - public AjxpAnswer execute(FileDriver driver, HttpServletRequest request) { - String fileStr = request.getParameter(getFileParameter()); - if (fileStr == null) { - throw new AjxpDriverException( - "A file to download needs to be provided."); - } - File file = new File(driver.getBasePath() + fileStr); - return new AxpBasicDownloadAnswer(file); - } - - /** Return 'file' by default. */ - protected String getFileParameter() { - return "file"; - } - - /** To be overridden. Do nothing by default. */ - protected void setHeaders(HttpServletResponse response, File file) { - // do nothing - } - - protected class AxpBasicDownloadAnswer implements AjxpAnswer { - private final File file; - - public AxpBasicDownloadAnswer(File file) { - this.file = file; - } - - public void updateResponse(HttpServletResponse response) { - InputStream in = null; - OutputStream out = null; - try { - setHeaders(response, file); - - if (log.isDebugEnabled()) - log.debug("Download file " + file); - in = FileUtils.openInputStream(file); - out = response.getOutputStream(); - - copyFile(in, out); - out.flush(); - - } catch (Exception e) { - e.printStackTrace(); - throw new AjxpDriverException("Cannot download file " + file, e); - } finally { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(out); - } - - } - - protected void copyFile(InputStream in, OutputStream out) - throws Exception { - IOUtils.copy(in, out); - } - - } -}