전자정부프레임워크 기반 image뷰 컨트롤러
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package egovframework.com.cmm.web;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import egovframework.com.cmm.EgovWebUtil;
import egovframework.com.cmm.service.EgovFileMngService;
import egovframework.com.cmm.service.EgovProperties;
import egovframework.com.cmm.service.FileVO;
/**
* @Class Name : EgovImageProcessController.java
* @Description :
* @Modification Information
*
* 수정일 수정자 수정내용
* ——- ——- ——————-
* 2009. 4. 2. 이삼섭
*
* @author 공통 서비스 개발팀 이삼섭
* @since 2009. 4. 2.
* @version
* @see
*
*/
@SuppressWarnings(“serial”)
@Controller
public class EgovImageProcessController extends HttpServlet {
@Resource(name = ”EgovFileMngService”)
private EgovFileMngService fileService;
/* 첨부파일 위치 지정 /
private final String uploadDir = EgovProperties.getProperty(“Globals.fileEditorStorePath”);
private static final Logger LOG = Logger.getLogger(EgovImageProcessController.class.getName());
/**
* 첨부된 이미지에 대한 미리보기 기능을 제공한다.
*
* @param atchFileId
* @param fileSn
* @param sessionVO
* @param model
* @param response
* @throws Exception
*/
@RequestMapping(“/cmm/fms/getImage.do”)
public void getImageInf(
@RequestParam(value=”fd”, required=true) String atchFileId,
@RequestParam(value=”fn”, required=true) String fileSn,
HttpServletResponse response) throws Exception {
//@RequestParam(“atchFileId”) String atchFileId,
//@RequestParam(“fileSn”) String fileSn,
//String atchFileId = (String)commandMap.get(“atchFileId”);
//String fileSn = (String)commandMap.get(“fileSn”);
FileVO vo = new FileVO();
vo.setAtchFileId(atchFileId);
vo.setFileSn(fileSn);
FileVO fvo = fileService.selectFileInf(vo);
//String fileLoaction = fvo.getFileStreCours() + fvo.getStreFileNm();
// 2011.10.10 보안점검 후속조치
File file = null;
FileInputStream fis = null;
BufferedInputStream in = null;
ByteArrayOutputStream bStream = null;
try {
file = new File(fvo.getFileStreCours(), fvo.getStreFileNm());
fis = new FileInputStream(file);
in = new BufferedInputStream(fis);
bStream = new ByteArrayOutputStream();
int imgByte;
while ((imgByte = in.read()) != -1) {
bStream.write(imgByte);
}
String type = ””;
if (fvo.getFileExtsn() != null && !”“.equals(fvo.getFileExtsn())) {
if (“jpg”.equals(fvo.getFileExtsn().toLowerCase())) {
type = ”image/jpeg”;
} else {
type = ”image/” + fvo.getFileExtsn().toLowerCase();
}
type = ”image/” + fvo.getFileExtsn().toLowerCase();
} else {
LOG.debug(“Image fileType is null.”);
}
response.setHeader(“Content-Type”, type);
response.setHeader(“Content-Disposition”, ”filename=”+fvo.getOrignlFileNm()+”;”);
response.setContentLength(bStream.size());
bStream.writeTo(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
// 2011.10.10 보안점검 후속조치 끝
} finally {
if (bStream != null) {
try {
bStream.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
if (in != null) {
try {
in.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
if (fis != null) {
try {
fis.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
}
}
/**
* 첨부된 이미지에 대한 미리보기 기능을 제공한다. w, h에 따라서 썸내일을 만들어준다.
*
* @param atchFileId
* @param fileSn
* @param sessionVO
* @param model
* @param response
* @throws Exception
*/
@RequestMapping(“/cmm/fms/getImageP.do”)
public void getImageP(
@RequestParam(value=”fd”, required=true) String atchFileId,
@RequestParam(value=”fn”, required=true) String fileSn,
@RequestParam(value=”w”, required=true) int filewidth,
@RequestParam(value=”h”, required=true) int fileheight,
HttpServletResponse response) throws Exception {
FileVO vo = new FileVO();
vo.setAtchFileId(atchFileId);
vo.setFileSn(fileSn);
FileVO fvo = fileService.selectFileInf(vo);
FileInputStream fis = null;
BufferedInputStream in = null;
ByteArrayOutputStream bStream = null;
String type = ””;
if (fvo.getFileExtsn() != null && !”“.equals(fvo.getFileExtsn())) {
if (“jpg”.equals(fvo.getFileExtsn().toLowerCase())) {
type = ”image/jpeg”;
} else {
type = ”image/” + fvo.getFileExtsn().toLowerCase();
}
type = ”image/” + fvo.getFileExtsn().toLowerCase();
}
else
{
LOG.debug(“Image fileType is null.”);
}
try
{
System.out.println(fvo.getFileStreCours());
System.out.println(fvo.getStreFileNm());
bStream = new ByteArrayOutputStream();
File file = new File(fvo.getFileStreCours(), fvo.getStreFileNm());
System.out.println(file.isFile());
if(file == null)
{
return;
}
int width = filewidth;
BufferedImage bi = ImageIO.read(file);
//thumnailwidth
if((float)bi.getWidth() < filewidth)
{
width = (int)bi.getWidth();
}
int itype = bi.getType() == 0? BufferedImage.TYPE_INT_ARGB : bi.getType();
BufferedImage resizedImage = new BufferedImage(filewidth, fileheight, itype);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(bi, 0, 0, filewidth, fileheight, null);
g.dispose();
boolean isResult = ImageIO.write(resizedImage, ”jpg”, bStream);
//System.out.println(“type : ” + type);
response.setHeader(“Content-Type”, type);
response.setHeader(“Content-Disposition”, ”filename=”+fvo.getOrignlFileNm()+”;”);
response.setContentLength(bStream.size());
bStream.writeTo(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
finally
{
if (bStream != null) {
try {
bStream.close();
} catch (Exception ignore) {
LOG.error(“IGNORE: ” + ignore.getMessage());
}
}
if (in != null) {
try {
in.close();
} catch (Exception ignore) {
LOG.error(“IGNORE: ” + ignore.getMessage());
}
}
if (fis != null) {
try {
fis.close();
} catch (Exception ignore) {
LOG.error(“IGNORE: ” + ignore.getMessage());
}
}
}
}
/**
* 에디터의 이미지를 보여준다.
*
* @param atchFileId
* @param fileSn
* @param sessionVO
* @param model
* @param response
* @throws Exception
*/
@RequestMapping(“/icpa/cmm/fms/getEditorImage.do”)
public void getImageInf(
ModelMap model,
HttpServletResponse response,
@RequestParam(value = ”fn”, required = true) String strFile
) throws Exception {
File file = null;
FileInputStream fis = null;
BufferedInputStream in = null;
ByteArrayOutputStream bStream = null;
strFile = new String(strFile.getBytes(“8859_1”),”utf-8”);
try {
file = new File(EgovWebUtil.filePathBlackList(uploadDir + strFile));
if (!file.exists()) {
throw new FileNotFoundException(strFile);
}
fis = new FileInputStream(file);
in = new BufferedInputStream(fis);
bStream = new ByteArrayOutputStream();
int imgByte;
while ((imgByte = in.read()) != -1) {
bStream.write(imgByte);
}
String type = ””;
String fileExt = ””;
fileExt = ”jpg”;
if (fileExt != null && !”“.equals(fileExt)) {
if (“jpg”.equals(fileExt.toLowerCase())) {
type = ”image/jpeg”;
} else {
type = ”image/” + fileExt.toLowerCase();
}
type = ”image/” + fileExt.toLowerCase();
} else {
LOG.debug(“Image fileType is null.”);
}
response.setHeader(“Content-Type”, type);
response.setHeader(“Content-Disposition”, ”filename=images;”);
response.setContentLength(bStream.size());
bStream.writeTo(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
// 2011.10.10 보안점검 후속조치 끝
}
finally {
if (bStream != null) {
try {
bStream.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
if (in != null) {
try {
in.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
if (fis != null) {
try {
fis.close();
} catch (Exception ignore) {
//System.out.println(“IGNORE: ” + ignore);
LOG.debug(“IGNORE: ” + ignore.getMessage());
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package egovframework.com.cmm.service;
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @Class Name : FileVO.java
* @Description : 파일정보 처리를 위한 VO 클래스
* @Modification Information
*
* 수정일 수정자 수정내용
* ——- ——- ——————-
* 2009. 3. 25. 이삼섭
*
* @author 공통 서비스 개발팀 이삼섭
* @since 2009. 3. 25.
* @version
* @see
*
*/
@SuppressWarnings(“serial”)
public class FileVO implements Serializable {
/**
* 첨부파일 아이디
*/
public String atchFileId = ””;
/**
* 생성일자
*/
public String creatDt = ””;
/**
* 파일내용
*/
public String fileCn = ””;
/**
* 파일확장자
*/
public String fileExtsn = ””;
/**
* 파일크기
*/
public String fileMg = ””;
/**
* 파일연번
*/
public String fileSn = ””;
/**
* 파일저장경로
*/
public String fileStreCours = ””;
/**
* 원파일명
*/
public String orignlFileNm = ””;
/**
* 저장파일명
*/
public String streFileNm = ””;
/**
* atchFileId attribute를 리턴한다.
*
* @return the atchFileId
*/
public String getAtchFileId() {
return atchFileId;
}
/**
* atchFileId attribute 값을 설정한다.
*
* @param atchFileId
* the atchFileId to set
*/
public void setAtchFileId(String atchFileId) {
this.atchFileId = atchFileId;
}
/**
* creatDt attribute를 리턴한다.
*
* @return the creatDt
*/
public String getCreatDt() {
return creatDt;
}
/**
* creatDt attribute 값을 설정한다.
*
* @param creatDt
* the creatDt to set
*/
public void setCreatDt(String creatDt) {
this.creatDt = creatDt;
}
/**
* fileCn attribute를 리턴한다.
*
* @return the fileCn
*/
public String getFileCn() {
return fileCn;
}
/**
* fileCn attribute 값을 설정한다.
*
* @param fileCn
* the fileCn to set
*/
public void setFileCn(String fileCn) {
this.fileCn = fileCn;
}
/**
* fileExtsn attribute를 리턴한다.
*
* @return the fileExtsn
*/
public String getFileExtsn() {
return fileExtsn;
}
/**
* fileExtsn attribute 값을 설정한다.
*
* @param fileExtsn
* the fileExtsn to set
*/
public void setFileExtsn(String fileExtsn) {
this.fileExtsn = fileExtsn;
}
/**
* fileMg attribute를 리턴한다.
*
* @return the fileMg
*/
public String getFileMg() {
return fileMg;
}
/**
* fileMg attribute 값을 설정한다.
*
* @param fileMg
* the fileMg to set
*/
public void setFileMg(String fileMg) {
this.fileMg = fileMg;
}
/**
* fileSn attribute를 리턴한다.
*
* @return the fileSn
*/
public String getFileSn() {
return fileSn;
}
/**
* fileSn attribute 값을 설정한다.
*
* @param fileSn
* the fileSn to set
*/
public void setFileSn(String fileSn) {
this.fileSn = fileSn;
}
/**
* fileStreCours attribute를 리턴한다.
*
* @return the fileStreCours
*/
public String getFileStreCours() {
return fileStreCours;
}
/**
* fileStreCours attribute 값을 설정한다.
*
* @param fileStreCours
* the fileStreCours to set
*/
public void setFileStreCours(String fileStreCours) {
this.fileStreCours = fileStreCours;
}
/**
* orignlFileNm attribute를 리턴한다.
*
* @return the orignlFileNm
*/
public String getOrignlFileNm() {
return orignlFileNm;
}
/**
* orignlFileNm attribute 값을 설정한다.
*
* @param orignlFileNm
* the orignlFileNm to set
*/
public void setOrignlFileNm(String orignlFileNm) {
this.orignlFileNm = orignlFileNm;
}
/**
* streFileNm attribute를 리턴한다.
*
* @return the streFileNm
*/
public String getStreFileNm() {
return streFileNm;
}
/**
* streFileNm attribute 값을 설정한다.
*
* @param streFileNm
* the streFileNm to set
*/
public void setStreFileNm(String streFileNm) {
this.streFileNm = streFileNm;
}
/**
* toString 메소드를 대치한다.
*/
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
public void trace()
{
for (Field field : this.getClass().getDeclaredFields()) {
try {
field.setAccessible(true);
System.out.println(field.getName() +” = ” +field.get(this));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}