root / sqs-reader / src / main / java / net / sqs2 / omr / swing / session / MarkReaderSessionResultBrowserController.java @ 1846
View | Annotate | Download (4 KB)
| 1 | package net.sqs2.omr.swing.session;
|
|---|---|
| 2 | |
| 3 | import java.io.File;
|
| 4 | import java.net.MalformedURLException;
|
| 5 | import java.net.URL;
|
| 6 | import java.util.ArrayList;
|
| 7 | import java.util.List;
|
| 8 | |
| 9 | import net.sqs2.browser.Browser;
|
| 10 | import net.sqs2.omr.AppConstants;
|
| 11 | import net.sqs2.omr.app.service.OpenResultBrowserAppService;
|
| 12 | import net.sqs2.omr.master.FormArea;
|
| 13 | import net.sqs2.omr.master.FormMaster;
|
| 14 | import net.sqs2.omr.master.PageMaster;
|
| 15 | import net.sqs2.omr.session.service.MarkReaderSession;
|
| 16 | import net.sqs2.util.FileUtil;
|
| 17 | |
| 18 | import org.mortbay.util.URIUtil;
|
| 19 | |
| 20 | public class MarkReaderSessionResultBrowserController { |
| 21 | |
| 22 | MarkReaderSession markReaderSession; |
| 23 | MarkReaderSessionResultBrowserPanel resultPanel; |
| 24 | File textAreaIndexFile = null;
|
| 25 | |
| 26 | public MarkReaderSessionResultBrowserController(MarkReaderSession markReaderSession, MarkReaderSessionResultBrowserPanel resultPanel) {
|
| 27 | this.markReaderSession = markReaderSession;
|
| 28 | this.resultPanel = resultPanel;
|
| 29 | } |
| 30 | |
| 31 | public void init() { |
| 32 | List<Integer> textAreaColumnIndexList = getTextAreaColumnIndexList(); |
| 33 | int numTextAreaColumn = textAreaColumnIndexList.size();
|
| 34 | if (numTextAreaColumn == 0) { |
| 35 | this.resultPanel.textareaButton.setEnabled(false); |
| 36 | } else if (1 == numTextAreaColumn) { |
| 37 | this.textAreaIndexFile = new File(getTextAreaIndexPath(textAreaColumnIndexList.get(0))); |
| 38 | } else {
|
| 39 | this.textAreaIndexFile = new File(getTextAreaIndexPath(null)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private String getTextAreaIndexPath(Integer columnIndex) {
|
| 44 | String resultDir = this.markReaderSession.getSourceDirectoryRootFile().getAbsolutePath()
|
| 45 | + File.separatorChar + AppConstants.RESULT_DIRNAME; |
| 46 | String textareatDir = resultDir + File.separatorChar + "TEXTAREA";
|
| 47 | if (columnIndex == null) { |
| 48 | return textareatDir + File.separatorChar + "index.html"; |
| 49 | } else {
|
| 50 | return textareatDir + File.separatorChar + columnIndex.toString() + File.separatorChar
|
| 51 | + "index.html";
|
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private void showBySuffix(String suffix) { |
| 56 | try {
|
| 57 | List<File> files = FileUtil.find(this.markReaderSession.getSourceDirectoryRootFile()
|
| 58 | .getAbsolutePath() |
| 59 | + File.separatorChar + AppConstants.RESULT_DIRNAME, suffix); |
| 60 | if (0 < files.size()) { |
| 61 | File file = files.get(0);
|
| 62 | |
| 63 | URL url = convertFileToURL(file); |
| 64 | Browser.showDocument(file, url); |
| 65 | } |
| 66 | } catch (Exception ex) {
|
| 67 | ex.printStackTrace(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | private URL convertFileToURL(File file) throws MalformedURLException { |
| 72 | URL url = null;
|
| 73 | if (File.separatorChar == '\\') { |
| 74 | url = new URL("file:///" |
| 75 | + URIUtil.encodeString(null, file.getAbsolutePath().replace("\\", "/"), "MS932")); |
| 76 | } else {
|
| 77 | url = file.toURI().toURL(); |
| 78 | } |
| 79 | return url;
|
| 80 | } |
| 81 | |
| 82 | private void showIndex(File file) { |
| 83 | try {
|
| 84 | if (file.exists()) {
|
| 85 | URL url = convertFileToURL(file); |
| 86 | Browser.showDocument(file, url); |
| 87 | } |
| 88 | } catch (MalformedURLException ex) {
|
| 89 | ex.printStackTrace(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public void openResultBrowser(){ |
| 94 | openResultBrowser(markReaderSession.getSessionID()); |
| 95 | } |
| 96 | |
| 97 | private void openResultBrowser(long sessionID) { |
| 98 | new OpenResultBrowserAppService(sessionID).call();
|
| 99 | } |
| 100 | |
| 101 | public void showExcel() { |
| 102 | showBySuffix(".xls");
|
| 103 | } |
| 104 | |
| 105 | public void showCSV() { |
| 106 | showBySuffix("tsv.txt");
|
| 107 | } |
| 108 | |
| 109 | private List<Integer> getTextAreaColumnIndexList() {
|
| 110 | List<Integer> textAreaColumnIndexList = new ArrayList<Integer>();
|
| 111 | List<PageMaster> pageMasterList = this.markReaderSession.getSessionSource()
|
| 112 | .getContentIndexer().getPageMasterList(); |
| 113 | if (1 == pageMasterList.size()) { |
| 114 | FormMaster master = (FormMaster) pageMasterList.get(0);
|
| 115 | for (FormArea formArea : master.getFormAreaList()) {
|
| 116 | if (formArea.isTextArea()) {
|
| 117 | textAreaColumnIndexList.add(formArea.getQuestionIndex()); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return textAreaColumnIndexList;
|
| 122 | } |
| 123 | |
| 124 | public void showTextarea() { |
| 125 | showIndex(this.textAreaIndexFile);
|
| 126 | } |
| 127 | |
| 128 | public void showChart() { |
| 129 | String resultDir = this.markReaderSession.getSourceDirectoryRootFile().getAbsolutePath()
|
| 130 | + File.separatorChar + AppConstants.RESULT_DIRNAME; |
| 131 | String chartDir = resultDir + File.separatorChar + "CHART";
|
| 132 | File file = new File(chartDir + File.separatorChar + "index.html"); |
| 133 | showIndex(file); |
| 134 | } |
| 135 | |
| 136 | } |

SourceEditor2.0(2010/08/18)
