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

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.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
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.ss.usermodel.Font;
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.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;
}
InputStream is = null;
if(imagePath.startsWith("files")) {
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
if(!imagePath.startsWith("files")) {
imagePath = CmmnUtil.copyStaticResource(imagePath);
}
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
String imageKey = "";
if(otptArtclNm.equals("rprsCrdnPhoto")) {
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("")) {
InputStream is0 = null;
if(imagePath.startsWith("files")) {
File imageFile0 = new File(imagePath);
is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath).getInputStream();
}
File imageFile0 = new File(imagePath);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
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++){
PstnAndSize devideInfo = devideInfos.get(i);
String imagePath = imagePaths.get(i);
if(ifEmpty(imagePath, ()-> "").equals("")) {
if(ifEmpty(imagePaths.get(i), ()-> "").equals("")) {
continue;
}
InputStream is = null;
if(imagePaths.get(i).startsWith("files")) {
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
if(!imagePaths.get(i).startsWith("files")) {
imagePaths.set(i, CmmnUtil.copyStaticResource(imagePaths.get(i)));
}
String imagePath = imagePaths.get(i);
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
pdfPrintUtil.insertImage(doc, contentStream, is,
devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) {
InputStream is0 = null;
String imagePath0 = imagePaths.get(i);
if(imagePath0.startsWith("files")) {
File imageFile0 = new File(imagePath0);
is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath0).getInputStream();
}
File imageFile0 = new File(imagePath0);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKeys.get(i), is0, devideInfo
@ -670,17 +660,15 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
continue;
}
InputStream orgnFileInputStream = null;
if(!orgnFilePath.startsWith("files")) {
orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath);;
}
if(orgnFilePath.startsWith("files")) {
File orgnFile = new File(orgnFilePath);
if(!orgnFile.exists() || !orgnFile.canRead()) {
continue;
}
orgnFileInputStream = new FileInputStream(orgnFile);
} else {
orgnFileInputStream = new ClassPathResource(orgnFilePath).getInputStream();
File orgnFile = new File(orgnFilePath);
if(!orgnFile.exists() || !orgnFile.canRead()) {
continue;
}
InputStream orgnFileInputStream = new FileInputStream(orgnFile);
String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG";

Loading…
Cancel
Save