共通モジュールとかとか
Revisión | 196f90d449e6872b738ef6efdf0de44dcfbb39f2 (tree) |
---|---|
Tiempo | 2018-01-05 10:56:00 |
Autor | shupeluter@hotmail.com <shupeluter@hotm...> |
Commiter | shupeluter@hotmail.com |
整理
@@ -1,129 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package org.stux.common.util.excel; | |
7 | - | |
8 | -import java.io.File; | |
9 | -import java.io.IOException; | |
10 | -import java.util.HashMap; | |
11 | -import java.util.Map; | |
12 | - | |
13 | -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | |
14 | -import org.apache.poi.ss.formula.Formula; | |
15 | -import org.apache.poi.ss.usermodel.Cell; | |
16 | -import org.apache.poi.ss.usermodel.FormulaEvaluator; | |
17 | -import org.apache.poi.ss.usermodel.Row; | |
18 | -import org.apache.poi.ss.usermodel.Sheet; | |
19 | -import org.apache.poi.ss.usermodel.Workbook; | |
20 | -import org.apache.poi.ss.usermodel.WorkbookFactory; | |
21 | -import org.stux.common.Exception.StuxBasicException; | |
22 | - | |
23 | -/** | |
24 | - * | |
25 | - * @author YoshihiroSaitoh | |
26 | - */ | |
27 | -public abstract class BaseExcelParser { | |
28 | - | |
29 | - public final String KEY_PROP_PATH = "path.prop"; | |
30 | - | |
31 | - private Map<Integer, Sheet> sheetMap = new HashMap(); | |
32 | - protected String fileName; | |
33 | - protected String filePath; | |
34 | - protected String propFilepath; | |
35 | - | |
36 | - public void parse(File file) throws StuxBasicException { | |
37 | - fileName = file.getName(); | |
38 | - filePath = file.getPath(); | |
39 | - try { | |
40 | - Workbook wb = WorkbookFactory.create(file); | |
41 | - int numberOfSheet = wb.getNumberOfSheets(); | |
42 | - | |
43 | - for (int i = 0; i < numberOfSheet; i++) { | |
44 | - sheetMap.put(i, wb.getSheetAt(i)); | |
45 | - } | |
46 | - | |
47 | - parse(sheetMap); | |
48 | - wb.close(); | |
49 | - | |
50 | - } catch (IOException ex) { | |
51 | - throw new StuxBasicException(ex, "ワークブック読み取り中に例外が発生しました。"); | |
52 | - } catch (InvalidFormatException ex) { | |
53 | - throw new StuxBasicException(ex, "ファイルのフォーマットが正しくありません。"); | |
54 | - } finally { | |
55 | - //TODO wbはここで閉じたいだけ。 | |
56 | - } | |
57 | - | |
58 | - } | |
59 | - | |
60 | - protected String getStringValue(Sheet sheet, IndexInfo tempInfo) { | |
61 | - Row targetRow = sheet.getRow(tempInfo.getRow()); | |
62 | - if (targetRow == null) { | |
63 | - return ""; | |
64 | - } | |
65 | - Cell targetCell = targetRow.getCell(tempInfo.getCol()); | |
66 | - if (targetCell == null) { | |
67 | - return ""; | |
68 | - } | |
69 | - | |
70 | - switch (targetCell.getCellType()) { | |
71 | - case Cell.CELL_TYPE_NUMERIC: | |
72 | - return Integer.toString((int) targetCell.getNumericCellValue()); | |
73 | - case Cell.CELL_TYPE_STRING: | |
74 | - return targetCell.getStringCellValue().replaceAll("\n", ""); | |
75 | - case Cell.CELL_TYPE_FORMULA: | |
76 | - return targetCell.getCellFormula(); | |
77 | - | |
78 | - } | |
79 | - return ""; | |
80 | - } | |
81 | - | |
82 | - protected String getStringValue(Sheet sheet, int row, IndexInfo tempInfo) { | |
83 | - Row tmprow = sheet.getRow(row); | |
84 | - if (tmprow == null) { | |
85 | - return ""; | |
86 | - } | |
87 | - Cell targetCell = tmprow.getCell(tempInfo.getCol()); | |
88 | - if (targetCell == null) { | |
89 | - return ""; | |
90 | - } | |
91 | - switch (targetCell.getCellType()) { | |
92 | - case Cell.CELL_TYPE_NUMERIC: | |
93 | - //return targetCell.getDateCellValue().toString(); | |
94 | - return Integer.toString((int) targetCell.getNumericCellValue()); | |
95 | - //return Double.toString(targetCell.getNumericCellValue()); | |
96 | - case Cell.CELL_TYPE_STRING: | |
97 | - return targetCell.getStringCellValue().replaceAll("\n", " "); | |
98 | - case Cell.CELL_TYPE_FORMULA: | |
99 | - return targetCell.getCellFormula(); | |
100 | - default: | |
101 | - return targetCell.getStringCellValue(); | |
102 | - } | |
103 | - | |
104 | - } | |
105 | - | |
106 | - protected String getFormulaValue(Sheet sheet, IndexInfo tempInfo) { | |
107 | - String res = ""; | |
108 | - Cell targetCell = sheet.getRow(tempInfo.getRow()).getCell(tempInfo.getCol()); | |
109 | - if (targetCell.getCellType() == Cell.CELL_TYPE_FORMULA) { | |
110 | - | |
111 | - FormulaEvaluator evaluator = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator(); | |
112 | - targetCell = evaluator.evaluateInCell(targetCell); | |
113 | - } | |
114 | - switch (targetCell.getCellType()) { | |
115 | - case Cell.CELL_TYPE_NUMERIC: | |
116 | - return Integer.toString((int) targetCell.getNumericCellValue()); | |
117 | - //return Double.toString(targetCell.getNumericCellValue()); | |
118 | - case Cell.CELL_TYPE_STRING: | |
119 | - return targetCell.getStringCellValue().replaceAll("\n", " "); | |
120 | - case Cell.CELL_TYPE_FORMULA: | |
121 | - return targetCell.getCellFormula(); | |
122 | - } | |
123 | - | |
124 | - return res; | |
125 | - } | |
126 | - | |
127 | - public abstract void parse(Map<Integer, Sheet> sheets) throws StuxBasicException; | |
128 | - | |
129 | -} |
@@ -1,14 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package org.stux.common.util.excel; | |
7 | - | |
8 | -/** | |
9 | - * | |
10 | - * @author 0000011141935 | |
11 | - */ | |
12 | -public abstract class BasicResultWriter { | |
13 | - public abstract void write(IParseResult target); | |
14 | -} |
@@ -1,14 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package org.stux.common.util.excel; | |
7 | - | |
8 | -/** | |
9 | - * | |
10 | - * @author 0000011141935 | |
11 | - */ | |
12 | -public interface IParseResult { | |
13 | - | |
14 | -} |
@@ -1,61 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package org.stux.common.util.excel; | |
7 | - | |
8 | -import org.stux.common.Exception.StuxBasicException; | |
9 | -import org.stux.worktool.reviewinfocounter.EnumCellType; | |
10 | - | |
11 | -/** | |
12 | - * | |
13 | - * @author YoshihiroSaitoh | |
14 | - */ | |
15 | -public class IndexInfo { | |
16 | - | |
17 | - private final int INDEX_ROWNO=0; | |
18 | - private final int INDEX_COLNO=1; | |
19 | - private final int INDEX_CELLTYPE=2; | |
20 | - private final String STR_DATE_TYPE="DATE"; | |
21 | - private final String STR_NUM_TYPE="NUMBER"; | |
22 | - private final String STR_FORMULA_TYPE ="FORMULA"; | |
23 | - | |
24 | - private final String demiliter = ","; | |
25 | - private final int colSize = 3; | |
26 | - private int row; | |
27 | - private int col; | |
28 | - private EnumCellType type; | |
29 | - | |
30 | - | |
31 | - public IndexInfo(String arg) throws StuxBasicException{ | |
32 | - String[] factors = arg.split(demiliter); | |
33 | - | |
34 | - if(factors.length != colSize) throw new StuxBasicException("設定値が<ROW_NO>,<COL_NO>,<CEL_TYPE>のフォーマットになっていません。"); | |
35 | - String strCelType= factors[INDEX_CELLTYPE]; | |
36 | - this.row = Integer.parseInt(factors[INDEX_ROWNO]); | |
37 | - this.col = Integer.parseInt(factors[INDEX_COLNO]); | |
38 | - | |
39 | - //セルの書式に応じて、TYPEを設定 | |
40 | - if(STR_DATE_TYPE.equals(strCelType.toUpperCase())) this.type = EnumCellType.DATE; | |
41 | - else if(STR_NUM_TYPE.equals(strCelType.toUpperCase())) this.type = EnumCellType.NUMBER; | |
42 | - else if(STR_FORMULA_TYPE.equals(strCelType.toUpperCase()))this.type = EnumCellType.FORMULA; | |
43 | - else this.type = EnumCellType.STRING; | |
44 | - | |
45 | - } | |
46 | - | |
47 | - public EnumCellType getType() { | |
48 | - return type; | |
49 | - } | |
50 | - | |
51 | - public int getRow() { | |
52 | - return row; | |
53 | - } | |
54 | - | |
55 | - public int getCol() { | |
56 | - return col; | |
57 | - } | |
58 | - | |
59 | - | |
60 | - | |
61 | -} |
@@ -9,7 +9,7 @@ import java.io.File; | ||
9 | 9 | import java.io.FileFilter; |
10 | 10 | import java.util.ArrayList; |
11 | 11 | import java.util.List; |
12 | -import org.stux.common.Exception.StuxBasicException; | |
12 | +import org.stux.common.exception.StuxBasicException; | |
13 | 13 | |
14 | 14 | /** |
15 | 15 | * 指定したディレクトリ配下の全フォルダ/全ファイルを取得するツール |
@@ -1,17 +0,0 @@ | ||
1 | -/* | |
2 | - * To change this license header, choose License Headers in Project Properties. | |
3 | - * To change this template file, choose Tools | Templates | |
4 | - * and open the template in the editor. | |
5 | - */ | |
6 | -package org.stux.common.util.file; | |
7 | - | |
8 | -import org.stux.worktool.testspecanalizer.model.TestSpecFactor; | |
9 | - | |
10 | - | |
11 | -/** | |
12 | - * | |
13 | - * @author YoshihiroSaitoh | |
14 | - */ | |
15 | -public interface ResultWriter { | |
16 | - public void write(TestSpecFactor factor); | |
17 | -} |