// Path: src/main/java/com/neva/felix/webconsole/plugins/search/core/SearchPaths.java
// public class SearchPaths {
// 
// 	public static final String APP_NAME = "search";
// 
// 	private static final String APP_ROOT_PROP = "felix.webconsole.manager.root";
// 
// 	private static final String APP_ROOT_DEFAULT = "/system/console";
// 
// 	private final BundleContext context;
// 
// 	public SearchPaths(BundleContext context) {
// 		this.context = context;
// 	}
// 
// 	public static SearchPaths from(BundleContext context) {
// 		return new SearchPaths(context);
// 	}
// 
// 	public String appRoot() {
// 		return StringUtils.defaultIfEmpty(context.getProperty(APP_ROOT_PROP), APP_ROOT_DEFAULT);
// 	}
// 
// 	public String appAlias(String alias) {
// 		return appRoot() + "/" + alias;
// 	}
// 
// 	public String pluginRoot() {
// 		return appRoot() + "/" + APP_NAME;
// 	}
// 
// 	public String pluginAlias(String alias) {
// 		return pluginRoot() + "/" + alias;
// 	}
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/io/FileDownloader.java
// public final class FileDownloader {
// 
// 	private final HttpServletResponse response;
// 
// 	private final MemoryStream fileContent;
// 
// 	private final String fileName;
// 
// 	public FileDownloader(HttpServletResponse response, InputStream input, String fileName) {
// 		this.response = response;
// 		this.fileContent = new MemoryStream(input);
// 		this.fileName = fileName;
// 	}
// 
// 	public void download() throws IOException {
// 		setResponseHeaders();
// 		writeResponseOutput();
// 	}
// 
// 	private void setResponseHeaders() throws IOException {
// 		response.setContentLength(fileContent.getLength());
// 		response.setContentType("application/force-download");
// 		response.setHeader("Content-Transfer-Encoding", "binary");
// 		response.setHeader("Content-Disposition",
// 				String.format("attachment; filename=\"%s\"", fileName.trim()));
// 		response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// 		response.setHeader("Pragma", "no-cache");
// 	}
// 
// 	private void writeResponseOutput() throws IOException {
// 		fileContent.writeOutput(response.getOutputStream());
// 	}
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/JsonUtils.java
// public enum MessageType {
//     SUCCESS,
//     ERROR
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/JsonUtils.java
// public static void writeMessage(HttpServletResponse response, MessageType type, String text)
//         throws IOException {
//     writeMessage(response, type, text, Collections.<String, Object>emptyMap());
// }


import com.neva.felix.webconsole.plugins.search.core.SearchPaths;
import com.neva.felix.webconsole.plugins.search.utils.io.FileDownloader;
import org.apache.commons.lang3.StringUtils;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;
import static com.neva.felix.webconsole.plugins.search.utils.JsonUtils.MessageType;
import static com.neva.felix.webconsole.plugins.search.utils.JsonUtils.writeMessage;
package com.neva.felix.webconsole.plugins.search.rest;




public class FileDownloadServlet extends RestServlet {

    public static final String ALIAS_NAME = "file-download";

    private static final Logger LOG = LoggerFactory.getLogger(FileDownloadServlet.class);

    public FileDownloadServlet(BundleContext bundleContext) {
        super(bundleContext);
    }

    public static String url(BundleContext context, String path, String fileName) {
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/core/SearchPaths.java
// public class SearchPaths {
// 
// 	public static final String APP_NAME = "search";
// 
// 	private static final String APP_ROOT_PROP = "felix.webconsole.manager.root";
// 
// 	private static final String APP_ROOT_DEFAULT = "/system/console";
// 
// 	private final BundleContext context;
// 
// 	public SearchPaths(BundleContext context) {
// 		this.context = context;
// 	}
// 
// 	public static SearchPaths from(BundleContext context) {
// 		return new SearchPaths(context);
// 	}
// 
// 	public String appRoot() {
// 		return StringUtils.defaultIfEmpty(context.getProperty(APP_ROOT_PROP), APP_ROOT_DEFAULT);
// 	}
// 
// 	public String appAlias(String alias) {
// 		return appRoot() + "/" + alias;
// 	}
// 
// 	public String pluginRoot() {
// 		return appRoot() + "/" + APP_NAME;
// 	}
// 
// 	public String pluginAlias(String alias) {
// 		return pluginRoot() + "/" + alias;
// 	}
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/io/FileDownloader.java
// public final class FileDownloader {
// 
// 	private final HttpServletResponse response;
// 
// 	private final MemoryStream fileContent;
// 
// 	private final String fileName;
// 
// 	public FileDownloader(HttpServletResponse response, InputStream input, String fileName) {
// 		this.response = response;
// 		this.fileContent = new MemoryStream(input);
// 		this.fileName = fileName;
// 	}
// 
// 	public void download() throws IOException {
// 		setResponseHeaders();
// 		writeResponseOutput();
// 	}
// 
// 	private void setResponseHeaders() throws IOException {
// 		response.setContentLength(fileContent.getLength());
// 		response.setContentType("application/force-download");
// 		response.setHeader("Content-Transfer-Encoding", "binary");
// 		response.setHeader("Content-Disposition",
// 				String.format("attachment; filename=\"%s\"", fileName.trim()));
// 		response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// 		response.setHeader("Pragma", "no-cache");
// 	}
// 
// 	private void writeResponseOutput() throws IOException {
// 		fileContent.writeOutput(response.getOutputStream());
// 	}
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/JsonUtils.java
// public enum MessageType {
//     SUCCESS,
//     ERROR
// }
// 
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/JsonUtils.java
// public static void writeMessage(HttpServletResponse response, MessageType type, String text)
//         throws IOException {
//     writeMessage(response, type, text, Collections.<String, Object>emptyMap());
// }


// Path: src/main/java/com/neva/felix/webconsole/plugins/search/rest/FileDownloadServlet.java
import com.neva.felix.webconsole.plugins.search.core.SearchPaths;
import com.neva.felix.webconsole.plugins.search.utils.io.FileDownloader;
import org.apache.commons.lang3.StringUtils;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;
import static com.neva.felix.webconsole.plugins.search.utils.JsonUtils.MessageType;
import static com.neva.felix.webconsole.plugins.search.utils.JsonUtils.writeMessage;

package com.neva.felix.webconsole.plugins.search.rest;




public class FileDownloadServlet extends RestServlet {

    public static final String ALIAS_NAME = "file-download";

    private static final Logger LOG = LoggerFactory.getLogger(FileDownloadServlet.class);

    public FileDownloadServlet(BundleContext bundleContext) {
        super(bundleContext);
    }

    public static String url(BundleContext context, String path, String fileName) {
        return String.format("%s?%s=%s&%s=%s", SearchPaths.from(context).pluginAlias(ALIAS_NAME),