리소스파일 복사 메서드 추가

main
이범준 9 months ago
parent 2dc2075d6c
commit ff4acb043c

@ -8,6 +8,7 @@ import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.DayOfWeek; import java.time.DayOfWeek;
@ -31,6 +32,7 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.core.io.ClassPathResource;
import cokr.xit.base.file.xls.XLSWriter; import cokr.xit.base.file.xls.XLSWriter;
import cokr.xit.base.file.xls.XLSWriter.CommentSupport; import cokr.xit.base.file.xls.XLSWriter.CommentSupport;
@ -213,6 +215,38 @@ public class CmmnUtil {
} }
/**
* .
* @param staticResourcePath
* @return
*/
public static String copyStaticResource(String staticResourcePath) {
try {
String folderPath = FilenameUtils.getFullPathNoEndSeparator(staticResourcePath);
String storageRoot = "files";
File folder = new File(storageRoot + "/" + folderPath);
if(!folder.exists()) {
folder.mkdirs();
}
ClassPathResource cps = new ClassPathResource(staticResourcePath);
String fileName = cps.getFilename();
InputStream is = cps.getInputStream();
File newFile = new File(storageRoot + "/" + folderPath + "/" + fileName);
Files.copy(is, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
return storageRoot + "/" + folderPath + "/" + fileName;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/** /**
* () . * () .

@ -472,14 +472,13 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
continue; continue;
} }
InputStream is = null; if(!imagePath.startsWith("files")) {
if(imagePath.startsWith("files")) { imagePath = CmmnUtil.copyStaticResource(imagePath);
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
} }
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
String imageKey = ""; String imageKey = "";
if(otptArtclNm.equals("rprsCrdnPhoto")) { if(otptArtclNm.equals("rprsCrdnPhoto")) {
imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil); imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
@ -488,13 +487,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) { if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) {
InputStream is0 = null; File imageFile0 = new File(imagePath);
if(imagePath.startsWith("files")) { InputStream is0 = new FileInputStream(imageFile0);
File imageFile0 = new File(imagePath);
is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath).getInputStream();
}
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic( List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1]) imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1])
@ -537,34 +531,30 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
for (int i=0; i< devideInfos.size(); i++){ for (int i=0; i< devideInfos.size(); i++){
PstnAndSize devideInfo = devideInfos.get(i); PstnAndSize devideInfo = devideInfos.get(i);
String imagePath = imagePaths.get(i);
if(ifEmpty(imagePath, ()-> "").equals("")) { if(ifEmpty(imagePaths.get(i), ()-> "").equals("")) {
continue; continue;
} }
InputStream is = null; if(!imagePaths.get(i).startsWith("files")) {
if(imagePaths.get(i).startsWith("files")) { imagePaths.set(i, CmmnUtil.copyStaticResource(imagePaths.get(i)));
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
} }
String imagePath = imagePaths.get(i);
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
pdfPrintUtil.insertImage(doc, contentStream, is, pdfPrintUtil.insertImage(doc, contentStream, is,
devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) { if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) {
InputStream is0 = null;
String imagePath0 = imagePaths.get(i); String imagePath0 = imagePaths.get(i);
if(imagePath0.startsWith("files")) {
File imageFile0 = new File(imagePath0); File imageFile0 = new File(imagePath0);
is0 = new FileInputStream(imageFile0); InputStream is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath0).getInputStream();
}
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic( List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKeys.get(i), is0, devideInfo imageKeys.get(i), is0, devideInfo
@ -670,17 +660,15 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
continue; continue;
} }
InputStream orgnFileInputStream = null; if(!orgnFilePath.startsWith("files")) {
orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath);;
}
if(orgnFilePath.startsWith("files")) { File orgnFile = new File(orgnFilePath);
File orgnFile = new File(orgnFilePath); if(!orgnFile.exists() || !orgnFile.canRead()) {
if(!orgnFile.exists() || !orgnFile.canRead()) { continue;
continue;
}
orgnFileInputStream = new FileInputStream(orgnFile);
} else {
orgnFileInputStream = new ClassPathResource(orgnFilePath).getInputStream();
} }
InputStream orgnFileInputStream = new FileInputStream(orgnFile);
String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG"; String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG";

Loading…
Cancel
Save