org.beangle.ems.system.web.action.StaticfileAction Maven / Gradle / Ivy
/*
* Beangle, Agile Development Scaffold and Toolkit
*
* Copyright (c) 2005-2016, Beangle Software.
*
* Beangle is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Beangle is distributed in the hope that it will be useful.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Beangle. If not, see .
*/
package org.beangle.ems.system.web.action;
import java.net.URL;
import java.util.List;
import org.beangle.commons.collection.CollectUtils;
import org.beangle.commons.lang.Strings;
import org.beangle.commons.web.io.StreamDownloader;
import org.beangle.ems.io.StaticFileLoader;
import org.beangle.struts2.action.ActionSupport;
/**
* 静态资源下载
*
* @author chaostone
*/
public class StaticfileAction extends ActionSupport {
private List loaders = CollectUtils.newArrayList();
private StreamDownloader streamDownloader;
public String index() throws Exception {
String name = get("file");
String displayName = get("display");
URL url = null;
if (Strings.isNotEmpty(name)) {
for (StaticFileLoader loader : loaders) {
url = loader.getFile(name);
if (null != url) break;
}
if (null != url) streamDownloader.download(getRequest(), getResponse(), url, displayName);
}
if (null == url) {
return "nofound";
} else {
return null;
}
}
public List getLoaders() {
return loaders;
}
public void setLoaders(List loaders) {
this.loaders = loaders;
}
public void setStreamDownloader(StreamDownloader streamDownloader) {
this.streamDownloader = streamDownloader;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy