| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
package com.buckosoft.PicMan.web; |
| 9 | |
|
| 10 | |
import java.io.File; |
| 11 | |
import java.io.IOException; |
| 12 | |
import java.io.OutputStream; |
| 13 | |
import java.io.UnsupportedEncodingException; |
| 14 | |
import java.util.List; |
| 15 | |
|
| 16 | |
import javax.servlet.http.HttpServletRequest; |
| 17 | |
import javax.servlet.http.HttpServletResponse; |
| 18 | |
|
| 19 | |
import org.apache.commons.logging.Log; |
| 20 | |
import org.apache.commons.logging.LogFactory; |
| 21 | |
import org.dom4j.Document; |
| 22 | |
import org.dom4j.io.OutputFormat; |
| 23 | |
import org.dom4j.io.XMLWriter; |
| 24 | |
import org.springframework.web.servlet.ModelAndView; |
| 25 | |
import org.springframework.web.servlet.mvc.Controller; |
| 26 | |
|
| 27 | |
import com.buckosoft.BSAccount.web.BSAccountPageController; |
| 28 | |
import com.buckosoft.BSAccount.web.BSAccountUserWebSession; |
| 29 | |
import com.buckosoft.PicMan.business.PicManFacade; |
| 30 | |
import com.buckosoft.PicMan.dom.FilesInDirCountDom; |
| 31 | |
import com.buckosoft.PicMan.dom.ImportPicsDom; |
| 32 | |
import com.buckosoft.PicMan.dom.MosaicManDom; |
| 33 | |
import com.buckosoft.PicMan.domain.User; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public class ImportPicsAjaxController extends BSAccountPageController implements Controller { |
| 41 | 0 | private static boolean DEBUG = true; |
| 42 | |
private final static boolean DEBUGLOTS = true; |
| 43 | 0 | protected final Log log = LogFactory.getLog(getClass()); |
| 44 | |
|
| 45 | |
private PicManFacade pmf; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public void setPicMan(PicManFacade pmf) { this.pmf = pmf; } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public void setDEBUG(boolean debugFlag) { |
| 55 | 0 | DEBUG = debugFlag; |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public ModelAndView handleRequest(HttpServletRequest request, |
| 64 | |
HttpServletResponse response) { |
| 65 | |
String v; |
| 66 | |
String s; |
| 67 | |
if (DEBUGLOTS) |
| 68 | 0 | log.info("XML Import Pics Request"); |
| 69 | |
|
| 70 | 0 | response.setContentType("text/xml"); |
| 71 | 0 | response.addHeader("Cache-Control", "max-age=0"); |
| 72 | 0 | response.addHeader("Cache-Control", "no-cache"); |
| 73 | 0 | response.addHeader("expires", "0"); |
| 74 | 0 | response.addHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT"); |
| 75 | 0 | response.addHeader("Pragma", "no-cache"); |
| 76 | |
|
| 77 | 0 | User user = null; |
| 78 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 79 | 0 | if (userWebSession != null) |
| 80 | 0 | user = (User)userWebSession.getUser(); |
| 81 | 0 | Document dom = null; |
| 82 | 0 | String getPics = request.getParameter("getPics"); |
| 83 | 0 | if (getPics != null) { |
| 84 | 0 | if (DEBUG) |
| 85 | 0 | log.info("Determine Pics"); |
| 86 | 0 | List<File> list = pmf.getPicImporter().getPicNamesToImport(); |
| 87 | 0 | dom = ImportPicsDom.createDocument(list); |
| 88 | |
} |
| 89 | 0 | v = request.getParameter("getFilesInDirCount"); |
| 90 | 0 | if (v != null) { |
| 91 | 0 | v = request.getParameter("rid"); |
| 92 | 0 | int rid = Integer.parseInt(v); |
| 93 | 0 | v = request.getParameter("dir"); |
| 94 | 0 | dom = FilesInDirCountDom.createDocument(pmf, rid, v); |
| 95 | |
} |
| 96 | 0 | v = request.getParameter("ajaxImportOnePic"); |
| 97 | 0 | if (v != null) { |
| 98 | 0 | v = request.getParameter("rid"); |
| 99 | 0 | int rid = Integer.parseInt(v); |
| 100 | 0 | String odir = request.getParameter("odir"); |
| 101 | 0 | String iname = request.getParameter("iname"); |
| 102 | 0 | String oname = request.getParameter("oname"); |
| 103 | 0 | if (DEBUG) |
| 104 | 0 | log.info("importOnePic rid=" + rid + " odir=" + odir + " iname=" + iname + " oname=" + oname); |
| 105 | 0 | dom = pmf.getPicImporter().importPic(rid, odir, iname, oname); |
| 106 | |
} |
| 107 | 0 | v = request.getParameter("analyzeOnePic"); |
| 108 | 0 | if (v != null) { |
| 109 | 0 | v = request.getParameter("fname"); |
| 110 | 0 | s = request.getParameter("customDate"); |
| 111 | 0 | dom = pmf.getPicImporter().analyzePic(v, s); |
| 112 | |
} |
| 113 | |
try { |
| 114 | 0 | if (dom == null) |
| 115 | 0 | dom = MosaicManDom.createDocument(pmf, user); |
| 116 | 0 | OutputStream stream = response.getOutputStream(); |
| 117 | 0 | OutputFormat outformat = OutputFormat.createPrettyPrint(); |
| 118 | 0 | outformat.setEncoding("ISO-8859-1"); |
| 119 | 0 | XMLWriter writer = new XMLWriter(stream, outformat); |
| 120 | 0 | writer.write(dom); |
| 121 | 0 | writer.flush(); |
| 122 | 0 | } catch (UnsupportedEncodingException e) { |
| 123 | 0 | log.info(e); |
| 124 | 0 | pmf.addError(e); |
| 125 | 0 | } catch (IOException e) { |
| 126 | 0 | log.info(e); |
| 127 | 0 | pmf.addError(e); |
| 128 | 0 | } |
| 129 | 0 | return null; |
| 130 | |
} |
| 131 | |
|
| 132 | |
} |