| | |
| | | import java.text.ParseException;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.google.inject.Inject;
|
| | | import com.google.inject.Singleton;
|
| | |
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.http.HttpServlet;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.IStoredSettings;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.dagger.DaggerServlet;
|
| | | import com.gitblit.manager.IFilestoreManager;
|
| | | import com.gitblit.manager.IRepositoryManager;
|
| | | import com.gitblit.utils.CompressionUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.MarkdownUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | import dagger.ObjectGraph;
|
| | |
|
| | | /**
|
| | | * Streams out a zip file from the specified repository for any tree path at any
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class DownloadZipServlet extends DaggerServlet {
|
| | | @Singleton
|
| | | public class DownloadZipServlet extends HttpServlet {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | | private IStoredSettings settings;
|
| | |
|
| | | private IRepositoryManager repositoryManager;
|
| | | |
| | | private IFilestoreManager filestoreManager;
|
| | |
|
| | | public static enum Format {
|
| | | zip(".zip"), tar(".tar"), gz(".tar.gz"), xz(".tar.xz"), bzip2(".tar.bzip2");
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void inject(ObjectGraph dagger) {
|
| | | this.settings = dagger.get(IStoredSettings.class);
|
| | | this.repositoryManager = dagger.get(IRepositoryManager.class);
|
| | | @Inject
|
| | | public DownloadZipServlet(IStoredSettings settings, IRepositoryManager repositoryManager, IFilestoreManager filestoreManager) {
|
| | | this.settings = settings;
|
| | | this.repositoryManager = repositoryManager;
|
| | | this.filestoreManager = filestoreManager;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | response.setHeader("Pragma", "no-cache");
|
| | | response.setDateHeader("Expires", 0);
|
| | |
|
| | | |
| | | try {
|
| | | switch (format) {
|
| | | case zip:
|
| | | CompressionUtils.zip(r, basePath, objectId, response.getOutputStream());
|
| | | CompressionUtils.zip(r, filestoreManager, basePath, objectId, response.getOutputStream());
|
| | | break;
|
| | | case tar:
|
| | | CompressionUtils.tar(r, basePath, objectId, response.getOutputStream());
|
| | | CompressionUtils.tar(r, filestoreManager, basePath, objectId, response.getOutputStream());
|
| | | break;
|
| | | case gz:
|
| | | CompressionUtils.gz(r, basePath, objectId, response.getOutputStream());
|
| | | CompressionUtils.gz(r, filestoreManager, basePath, objectId, response.getOutputStream());
|
| | | break;
|
| | | case xz:
|
| | | CompressionUtils.xz(r, basePath, objectId, response.getOutputStream());
|
| | | CompressionUtils.xz(r, filestoreManager, basePath, objectId, response.getOutputStream());
|
| | | break;
|
| | | case bzip2:
|
| | | CompressionUtils.bzip2(r, basePath, objectId, response.getOutputStream());
|
| | | CompressionUtils.bzip2(r, filestoreManager, basePath, objectId, response.getOutputStream());
|
| | | break;
|
| | | }
|
| | |
|