diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..49a4fc7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + cokr.xit.app + app-support + 0.0.1-SNAPSHOT + app-support + app-support + jar + + + UTF-8 + 17 + + + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + + + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + true + + + false + + + + + + + + cokr.xit.base + xit-base + 23.04.01-SNAPSHOT + + + + + + install + ${basedir}/target + ${project.artifactId}-${project.version} + + + ${basedir}/src/main/resources + + + + ${basedir}/src/test/resources + ${basedir}/src/main/resources + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + UTF-8 + + + + + org.codehaus.mojo + emma-maven-plugin + 1.0-alpha-3 + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.1 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + **/*.class + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0 + + true + xml + + **/Abstract*.java + **/*Suite.java + + + **/*Test.java + + + + + org.codehaus.mojo + emma-maven-plugin + true + + + org.apache.maven.plugins + maven-source-plugin + 2.2 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + + + + + + maven-snapshot + https://nas.xit.co.kr:8888/repository/maven-snapshots/ + + + + maven-release + https://nas.xit.co.kr:8888/repository/maven-releases/ + + + + + \ No newline at end of file diff --git a/src/main/java/cokr/xit/applib/Print.java b/src/main/java/cokr/xit/applib/Print.java new file mode 100644 index 0000000..1202dc1 --- /dev/null +++ b/src/main/java/cokr/xit/applib/Print.java @@ -0,0 +1,131 @@ +package cokr.xit.applib; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import cokr.xit.foundation.UserInfo; + +public class Print { + + public Print(){ + SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + this.printRequestDt = ymdhmsFormat.format(new Date()); + } + + /** + * 출력 요청 일시 + */ + protected String printRequestDt; + + /** + * 출력 요청 유저 + */ + protected UserInfo printRequestUserInfo; + + /** + * 다중 파일 생성시 파일명 인덱스 + */ + protected int fileNameIndex = 0; + + /** + * 확장자 + */ + protected String extension; + + /** + * 서식명 + */ + protected String formatName; + + /** + * 서식한글명 + */ + protected String formatKorName; + + public String setExtension(String extension) { + return this.extension = extension; + } + + public String getFormatName() { + return this.formatName; + } + + public void setFormatName(String formatName) { + this.formatName = formatName; + } + + public String getFormatKorName() { + return this.formatKorName; + } + + public void setFormatKorName(String formatKorName) { + this.formatKorName = formatKorName; + } + + public UserInfo getPrintRequestUserInfo() { + return this.printRequestUserInfo; + } + + public void setPrintRequestUserInfo(UserInfo printRequestUserInfo) { + this.printRequestUserInfo = printRequestUserInfo; + } + + public String getPrintRequestDt() { + return this.printRequestDt; + } + + public void setPrintRequestDt(String printRequestDt) { + this.printRequestDt = printRequestDt; + } + + + public int getFileNameIndex() { + return this.fileNameIndex; + } + public int setFileNameIndex(int fileNameIndex) { + return this.fileNameIndex = fileNameIndex; + } + + + public boolean getPrivateInfoYn(PrintOption printOption) { + + boolean privateInfoYn = true; + if(printOption != null && printOption.getPrivateInfoYn() != null && printOption.getPrivateInfoYn().equals("N")) { + privateInfoYn = false; + } + return privateInfoYn; + } + + public Map getGlobalVariable(PrintOption printOption) { + + Map map = new HashMap(); + if(printOption != null && printOption.getGlobalVariable() != null && !printOption.getGlobalVariable().isEmpty()) { + map = printOption.getGlobalVariable(); + } + return map; + } + + public String pathForNewFile(){ + + SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String currentTime = ymdhmsFormat.format(new Date()); + String year = currentTime.substring(0, 4); + String month = currentTime.substring(4, 6); + String day = currentTime.substring(6, 8); + String formatFileResultRootPath = "files" + File.separator + "temp" + File.separator + "print"; + String formatFileResultFolderPath = formatFileResultRootPath + + File.separator + year + File.separator + month + File.separator + day; + File formatFileResultFolder = new File(formatFileResultFolderPath); + if(!formatFileResultFolder.exists()) { + formatFileResultFolder.mkdirs(); + } + String resultPath = formatFileResultFolderPath + File.separator + currentTime +"_"+ this.getFileNameIndex() + "."+this.extension; + + this.setFileNameIndex(this.getFileNameIndex()+1); + + return resultPath; + } +} diff --git a/src/main/java/cokr/xit/applib/PrintOption.java b/src/main/java/cokr/xit/applib/PrintOption.java new file mode 100644 index 0000000..08e8f67 --- /dev/null +++ b/src/main/java/cokr/xit/applib/PrintOption.java @@ -0,0 +1,26 @@ +package cokr.xit.applib; + +import java.util.Map; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class PrintOption { + + /** + * 개인정보 표시 여부 + */ + protected String privateInfoYn; + + /** + * 용지구분 + */ + protected String paperSeCd; + + /** + * 전역 변수 + */ + protected Map globalVariable; +} diff --git a/src/main/java/cokr/xit/applib/hwp/HwpMerge.java b/src/main/java/cokr/xit/applib/hwp/HwpMerge.java new file mode 100644 index 0000000..51d0249 --- /dev/null +++ b/src/main/java/cokr/xit/applib/hwp/HwpMerge.java @@ -0,0 +1,32 @@ +package cokr.xit.applib.hwp; +import kr.dogfoot.hwplib.object.HWPFile; +import kr.dogfoot.hwplib.object.bodytext.ParagraphListInterface; +import kr.dogfoot.hwplib.object.bodytext.paragraph.Paragraph; +import kr.dogfoot.hwplib.tool.paragraphadder.ParagraphAdder; + +public class HwpMerge { + + /**한글파일을 병합한다. + * @param attachHWPFile 기준파일 마지막 페이지에 붙일 파일, baseHWPFile 기준 파일 + * @return + */ + public static void appendToLast(HWPFile attachHWPFile, HWPFile baseHWPFile) throws Exception { + + if (attachHWPFile != null && baseHWPFile != null) { + + Paragraph[] ps = attachHWPFile.getBodyText().getSectionList().get(0).getParagraphs(); + + ParagraphListInterface baseSection = baseHWPFile.getBodyText().getLastSection(); + + ParagraphAdder paraAdder = new ParagraphAdder(baseHWPFile, baseSection); + + for(int i=0; i find = ControlFinder.find(writer.getFile(), (control, paragrpah, section) -> { + if(control.getType().equals(ControlType.Table)) { + ArrayList rl = ((ControlTable)control).getRowList(); + if(rl.size() == 1) { + ArrayList cl = rl.get(0).getCellList(); + if(cl.size() == 1) { + String fn = cl.get(0).getListHeader().getFieldName(); + if(fn != null && !fn.equals("")) { + if(fn.equals("직인")) { + return true; + } + } + } + } + } + return false; + }); + + if(find != null && !find.isEmpty()) { + ControlTable tableForOffcs = (ControlTable) find.get(0); + Cell cell = tableForOffcs.getRowList().get(0).getCellList().get(0); + return cell; + } + + return null; + } +} diff --git a/src/main/java/cokr/xit/applib/hwp/format/HWPFormat.java b/src/main/java/cokr/xit/applib/hwp/format/HWPFormat.java new file mode 100644 index 0000000..5a3f29d --- /dev/null +++ b/src/main/java/cokr/xit/applib/hwp/format/HWPFormat.java @@ -0,0 +1,112 @@ +package cokr.xit.applib.hwp.format; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import cokr.xit.applib.Print; +import cokr.xit.applib.PrintOption; +import cokr.xit.applib.hwp.HwpMerge; +import cokr.xit.base.docs.hwp.HWPWriter; +import cokr.xit.foundation.data.DataObject; +import kr.dogfoot.hwplib.object.HWPFile; +import kr.dogfoot.hwplib.reader.HWPReader; + + +public abstract class HWPFormat { + protected HWPWriter writer; + + protected Print print; + protected PrintOption printOption; + protected List data; + + protected String formatFilePath; + + protected int currentRunCount; + protected int maxRunCount; + protected List resultFilesPath; + + public HWPFormat(Print print, PrintOption printOption, List dataObjectList) { + this.resultFilesPath = new ArrayList(); + this.currentRunCount = 0; + this.data = dataObjectList; + this.printOption = printOption; + this.print = print; + this.print.setExtension("hwp"); + } + + public HWPFormat makeFile(){ + + while(currentRunCount != maxRunCount) { + HWPFile hwpFile = HWPWriter.classpath(this.formatFilePath); + this.writer = new HWPWriter(hwpFile); + runAsWriter(); + String tempPath = this.print.pathForNewFile(); + writer.write(tempPath); + resultFilesPath.add(tempPath); + + writer = null; + currentRunCount++; + } + + this.merge(); + + return this; + }; + + + protected abstract void runAsWriter(); + + + protected void merge(){ + if(resultFilesPath.size() >= 2) { + + try { + String basePath = resultFilesPath.get(0); + HWPFile baseFile = HWPReader.fromFile(basePath); + + + for(int i=2; i <= resultFilesPath.size();i++) { + String attachPath = resultFilesPath.get(i-1); + HWPFile attachFile = HWPReader.fromFile(attachPath); + HwpMerge.appendToLast(attachFile, baseFile); + } + + kr.dogfoot.hwplib.writer.HWPWriter.toFile(baseFile, basePath); + } catch (Exception e) { + throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다."); + } + + for(int i=2; i <= resultFilesPath.size();i++) { + if(!(new File(resultFilesPath.get(i-1))).delete()) { + throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다."); + } + } + } + + } + + public HashMap andDownload(){ + String resultFilePath = resultFilesPath.get(0); + HWPFile resultFile = HWPWriter.filepath(resultFilePath); + writer = new HWPWriter(resultFile); + + HashMap result = new HashMap(); + String downlaodFileName = this.print.getFormatKorName()+"_"+this.print.getPrintRequestDt()+".hwp"; + result.put("download", writer.getDownloadable().setFilename(downlaodFileName)); + result.put("downloadData", data); + result.put("dataNames", getDownloadDataNames()); + + new File(resultFilePath).delete(); + + return result; + }; + + public abstract List getDownloadDataNames(); + + public String andGetPath(){ + return resultFilesPath.get(0); + }; + +}