forked from neil/plugin-external-background
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
package com.fr.plugin.external.web; |
|
|
|
import com.fr.plugin.external.ImageManager; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.stable.fun.RequestInterceptor; |
|
import com.fr.stable.fun.Service; |
|
import com.fr.stable.web.ServletContext; |
|
import com.fr.stable.web.ServletContextAdapter; |
|
import com.fr.web.core.WebActionsDispatcher; |
|
import com.fr.web.utils.WebUtils; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
import java.util.HashMap; |
|
import java.util.concurrent.ExecutorService; |
|
import java.util.concurrent.Executors; |
|
|
|
public class ImageViewService implements Service{ |
|
|
|
static { |
|
ServletContext.addServletContextListener(new ServletContextAdapter() { |
|
@Override |
|
public void onServletStop() { |
|
ImageManager.getInstance().release(); |
|
} |
|
}); |
|
} |
|
|
|
public ImageViewService() { |
|
ExecutorService executorService = Executors.newSingleThreadExecutor(); |
|
executorService.execute(new Runnable() { |
|
@Override |
|
public void run() { |
|
// 预初始化 |
|
ImageManager.getInstance(); |
|
} |
|
}); |
|
} |
|
|
|
private RequestInterceptor[] actions = { |
|
new ShowImageAction(), |
|
new GetAllImageInfoAction(), |
|
new DownloadImageAction(), |
|
new DeleteImageAction(), |
|
new UpdateImageAction() |
|
}; |
|
|
|
@Override |
|
public String actionOP() { |
|
return "im"; |
|
} |
|
|
|
@Override |
|
public void process(HttpServletRequest req, HttpServletResponse res, String op, String sessionID) throws Exception { |
|
// if (isAdmin(req)) { |
|
// WebUtils.printAsString(res, "Please log on as an admin, and then try again."); |
|
// return; |
|
// } |
|
|
|
String cmd = WebUtils.getHTTPRequestParameter(req, "cmd"); |
|
if (StringUtils.isEmpty(cmd)) { |
|
String errorTemplate = "/com/fr/plugin/external/web/ui/im/manager.html"; |
|
WebUtils.writeOutTemplate(errorTemplate, res, new HashMap()); |
|
} else { |
|
WebActionsDispatcher.dealForActionCMD(req, res, sessionID, actions); |
|
} |
|
} |
|
|
|
}
|
|
|