feat: xml parser

main
Jonguk. Lim 2 years ago
parent 6d398fa381
commit a5a93d6ec2

@ -0,0 +1,99 @@
package kr.xit.framework.biz.cmm.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import egovframework.rte.fdl.idgnr.impl.Base64;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
//@Setter
@ToString
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="apndfilinfo")
public class AppendFileInfo {
/**
* 1
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path1_v")
@Setter
private String petiFilePath1V;
@XmlElement(name = "apndfilcont1")
private String apndfilcont1;
/**
* 2
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path2_v")
@Setter
private String petiFilePath2V;
@XmlElement(name = "apndfilcont2")
private String apndfilcont2;
/**
* 3
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path3_v")
@Setter
private String petiFilePath3V;
@XmlElement(name = "apndfilcont3")
private String apndfilcont3;
/**
* 4
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path4_v")
@Setter
private String petiFilePath4V;
@XmlElement(name = "apndfilcont4")
private String apndfilcont4;
/**
* 5
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path5_v")
@Setter
private String petiFilePath5V;
@XmlElement(name = "apndfilcont5")
private String apndfilcont5;
@XmlElement(name = "apndfilcount")
private String apndfilcount;
public void setApndfilcont1(String apndfilcont1) {
this.apndfilcont1 = Base64.encode(apndfilcont1.getBytes());
}
public void setApndfilcont2(String apndfilcont2) {
this.apndfilcont2 = Base64.encode(apndfilcont2.getBytes());
}
public void setApndfilcont3(String apndfilcont3) {
this.apndfilcont3 = Base64.encode(apndfilcont3.getBytes());
}
public void setApndfilcont4(String apndfilcont4) {
this.apndfilcont4 = Base64.encode(apndfilcont4.getBytes());
}
public void setApndfilcont5(String apndfilcont5) {
this.apndfilcont5 = Base64.encode(apndfilcont5.getBytes());
}
}

@ -0,0 +1,33 @@
package kr.xit.framework.biz.cmm.model;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.ValidationEventLocator;
import lombok.extern.slf4j.Slf4j;
/**
* JAXB API
* ValidationEvent.WARNING( 0),
* ValidationEvent.ERROR( 1),
* ValidationEvent.FATAL_ERROR( 2)
*/
@Slf4j
public class CustomEventHandler implements ValidationEventHandler {
public boolean handleEvent(ValidationEvent event) {
if (event.getSeverity() == ValidationEvent.FATAL_ERROR
|| event.getSeverity() == ValidationEvent.ERROR) {
ValidationEventLocator locator = event.getLocator();
String message = event.getMessage();
log.error("Severity: " + event.getSeverity());
log.error("Line Number: " + locator.getLineNumber());
log.error("Column Number: " + locator.getColumnNumber());
log.error("Event Message: " + message);
//log.error("{}", event);
log.error("{}", locator);
}
// 이벤트 에러 발생시 중단 : true - 계속 진행
return false;
}
}

@ -1,11 +1,27 @@
package kr.xit.framework.biz.cmm.model; package kr.xit.framework.biz.cmm.model;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader; import java.io.StringReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.json.JSONObject;
import org.json.XML;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -15,6 +31,11 @@ import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.traversal.NodeIterator; import org.w3c.dom.traversal.NodeIterator;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import com.sun.xml.internal.ws.developer.JAXBContextFactory;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
public class NatlNewspaper { public class NatlNewspaper {
private NatlNewspaperXmlDto natlNewspaperXmlDto; private NatlNewspaperXmlDto natlNewspaperXmlDto;
@ -23,7 +44,7 @@ public class NatlNewspaper {
public static void main(String[] args) { public static void main(String[] args) {
// String fileFullPath = "file:///D:/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959023e60d9$EPOUGA$1140100_2022091609485096255243399.xml"; // String fileFullPath = "file:///Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959023e60d9$EPOUGA$1140100_2022091609485096255243399.xml";
// try { // try {
// Document doc = XMLFilePath2Doc(fileFullPath); // Document doc = XMLFilePath2Doc(fileFullPath);
// getNodeList(doc, "dmndinfo"); // getNodeList(doc, "dmndinfo");
@ -36,18 +57,82 @@ public class NatlNewspaper {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// String fpath = "D:/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959023e60d9$EPOUGA$1140100_2022091609485096255243399.xml"; String fpath = "/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959023e60d9$EPOUGA$1140100_2022091609485096255243399.xml";
// // String jsonStr = null;
// try(BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get(fpath)), // try(BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get(fpath)),
// StandardCharsets.UTF_8) , 1024*1024*2)) { // StandardCharsets.UTF_8) , 1024*1024*2)) {
// JSONObject json = XML.toJSONObject(reader); // //JSONObject json = XML.toJSONObject(reader);
// String jsonStr = json.toString(4); // jsonStr = XML.toString(reader);
// System.out.println(jsonStr); // System.out.println(jsonStr);
// }catch(IOException fe){ // }catch(IOException fe){
// //
// } // }
//
// JAXBContext context = null;
// try {
// context = JAXBContext.newInstance(NatlNewspaperXmlDto.class);
// Unmarshaller unmarshaller = context.createUnmarshaller();
// NatlNewspaperXmlDto unmarshal = (NatlNewspaperXmlDto)unmarshaller.unmarshal(new StringReader(jsonStr));
// System.out.println(unmarshal);
// } catch (JAXBException e) {
// throw new RuntimeException(e);
// }
try {
Person person = new Person("jaxb", "jaxb@hello.com");
// JAXBContext 생성 & marshaller 생성
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
// 보기 좋게 출력해주는 옵션
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// 표준 출력으로 결과를 보여준다.
marshaller.marshal(person, System.out);
//JAXBContext context = JAXBContextFactory.createContext(new Class[]{Person.class}, someProperties);
List<String> list = Arrays.asList(
"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959023e60d9$EPOUGA$1140100_2022091609485096255243399.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959269e166c$EPOUGA$1140100_2022091609490868474847710.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/2022091609590430a45c$EPOUGA$1140100_2022091609483801480139449.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/2022091609590685e4d0$EPOUGA$1140100_2022091609483205285052976.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/2022091609591011a94b$EPOUGA$1140100_2022091609484378849086728.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/20220916095908123eab$EPOUGA$1140100_2022091609484239715980892.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/202209160959384350e0$EPOUGA$1140100_2022091609485968983152594.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/20220916095854881357$EPOUGA$1140100_2022091609485673727045043.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/2022091609585009058a$EPOUGA$1140100_2022091609484095150560203.xml"
,"/Users/minuk/project_data/fims/01. 연계/01. 국민신문고/rcv/2022091609585264580e$EPOUGA$1140100_2022091609485381568241998.xml"
);
list.forEach((path) -> {
try{
// JAXBContext 생성 & marshaller 생성
FileInputStream fileInputStream = new FileInputStream(path);
JAXBContext jaxbContext = JAXBContext.newInstance(NatlNewspaperXmlDto.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new CustomEventHandler());
// When
NatlNewspaperXmlDto xmlListTag = (NatlNewspaperXmlDto)unmarshaller.unmarshal(fileInputStream);
System.out.println(xmlListTag.toString());
// 표준 출력으로 결과를 보여준다.
//unmarshaller.unmarshal(xmlListTag);
//AppendFileInfo fileInfo = (AppendFileInfo)unmarshaller.unmarshal(fileInputStream);
//System.out.println(fileInfo.toString());
fileInputStream.close();
}catch(Exception e){
}
});
}catch(Exception e){
}
// try { // try {
// Document doc = XMLFilePath2Doc(fileFullPath); // Document doc = XMLFilePath2Doc(fileFullPath);
// getTraversalNodeList(doc); // getTraversalNodeList(doc);
@ -173,5 +258,15 @@ public class NatlNewspaper {
} }
} }
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement
private static class Person {
@XmlElement
private String name;
@XmlElement
private String email;
// 생성자, getter, setter 생략
}
} }

@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
/** /**
* <pre> * <pre>
@ -25,6 +26,7 @@ import lombok.Setter;
*/ */
@Getter @Getter
@Setter @Setter
@ToString
@XmlRootElement(name = "dmndinfo") @XmlRootElement(name = "dmndinfo")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class NatlNewspaperXmlDto { public class NatlNewspaperXmlDto {
@ -229,6 +231,11 @@ public class NatlNewspaperXmlDto {
*/ */
/** /**
* *
* date * date
@ -360,6 +367,11 @@ public class NatlNewspaperXmlDto {
private String tgtorgcd; private String tgtorgcd;
@XmlElement(name = "peti_path_gubun_c")
private String petiPathGubunC;
@XmlElement(name = "apndfilinfo")
private AppendFileInfo appendFileInfo;

@ -0,0 +1,577 @@
package kr.xit.framework.biz.cmm.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* <pre>
* interface
* XmlRootElement
* JAXBContext
* XmlAccessorType
* FIELD - (static transient ) XML
* NONE - XML .
* PROPERTY - getter/setter XML .
* PUBLIC_MEMBER - public getter/setter XML .
*
* comment / /
* / /
* </pre>
*/
@Getter
@Setter
@ToString
@XmlRootElement(name = "dmndinfo")
@XmlAccessorType(XmlAccessType.FIELD)
public class NatlNewspaperXmlDto2 {
/**
* :
* PK : number(30) - YYYYMMDDHH24MISSFF+random(9)
*/
@XmlElement(name = "interface_seq_n")
private String interfaceSeqN;
/**
* :
* char(88)
* EC010008
*/
@XmlElement(name = "sys_gubun_c")
private String sysGubunC;
/**
* :
* varchar2(7)
* 1140100 / /
* ex) - 641000
*/
@XmlElement(name = "anc_code_v")
private String ancCodeV;
/**
* :
* char(3)
* 140:(-) / 180: / 140: (-)
*/
@XmlElement(name = "peti_gubun_c")
private String petiGubunC;
/**
* :
* varchar2(7)
* ()
*/
@XmlElement(name = "peti_anc_code_v")
private String petiAncCodeV;
/**
* :
* varchar2(16)
* ( ), null .
* ( )
*/
@XmlElement(name = "peti_no_c")
private String petiNoC;
/**
* :
* varchar2(16)
* ( ), null .
* ( )"
*/
@XmlElement(name = "civil_no_c")
private String civilNoC;
/**
* : /
* varchar2(128)
*/
@XmlElement(name = "peter_name_v")
private String peterNameV;
/**
* : /
* varchar2(7)
*/
@XmlElement(name = "zip_code_c")
private String zipCodeC;
/**
* : /
* varchar2(400)
*/
@XmlElement(name = "address_v")
private String addressV;
/**
*
* varchar2(64)
*/
@XmlElement(name = "email_v")
private String emailV;
/**
*
* varchar2(20)
*/
@XmlElement(name = "cel_no_v")
private String celNoV;
/**
*
* varchar2(20)
*/
@XmlElement(name = "tel_no_v")
private String telNoV;
/**
* : /
* varchar2(500)
*/
@XmlElement(name = "peti_title_v")
private String petiTitleV;
/**
* : /
* clob
*/
@XmlElement(name = "peti_reason_l")
private String petiReasonL;
/**
* : /
* char(1)
* Y = , N = (default N)
* Y ()
* N
*/
@XmlElement(name = "open_yn_c")
private String openYnC;
/**
* : /
* date : YYYYMMDDHH24MISS
*/
@XmlElement(name = "peti_reg_d")
private String petiRegD;
/**
* :
* char(1)
* Y = , N = (default)
*/
@XmlElement(name = "peti_reason_attach_yn_c")
private String petiReasonAttachYnC;
/**
* :
* number(10)
*/
@XmlElement(name = "peti_file_size_n")
private String petiFileSizeN;
@XmlElement(name = "apndfilinfo")
private AppendFileInfo appendFileInfo;
//-------------------------------------------------------------
// /**
// * 민원 신청 첨부파일명1
// * varchar2(2000)
// */
// @XmlElement(name = "peti_file_path1_v")
// private String petiFilePath1V;
//
// /**
// * 민원 신청 첨부파일명2
// * varchar2(2000)
// */
// @XmlElement(name = "peti_file_path2_v")
// private String petiFilePath2V;
//
// /**
// * 민원 신청 첨부파일명3
// * varchar2(2000)
// */
// @XmlElement(name = "peti_file_path3_v")
// private String petiFilePath3V;
//
// /**
// * 민원 신청 첨부파일명4
// * varchar2(2000)
// */
// @XmlElement(name = "peti_file_path4_v")
// private String petiFilePath4V;
//
// /**
// * 민원 신청 첨부파일명5
// * varchar2(2000)
// */
// @XmlElement(name = "peti_file_path5_v")
// private String petiFilePath5V;
//-----------------------------------------------------------------------------
/*
@Getter
@Setter
@XmlRootElement(name="petiFilePaths")
private static class PetiFilePaths{
private List<PetiFilePath> petiFilePath;
@Getter
@Setter
@XmlRootElement(name="petiFilePath")
public static class PetiFilePath {
private String petiFilePath;
}
}
*/
/**
*
* date
*/
@XmlElement(name = "anc_reg_d")
private String ancRegD;
/**
*
* varchar2(4000)
*/
@XmlElement(name = "more_again_v")
private String moreAgainV;
//------------------------------------------------------------------------------
/**
* 1
* char(8)
*/
@XmlElement(name = "satisfy_c")
private String satisfyC;
/**
* 2
* char(8)
*/
@XmlElement(name = "satisfy2_c")
private String satisfy2C;
/**
* 3
* char(8)
*/
@XmlElement(name = "satisfy3_c")
private String satisfy3C;
//------------------------------------------------------------------------------
/**
*
* date
*/
@XmlElement(name = "satisfy_reg_d")
private String satisfyRegD;
/**
* :
* date
* sysdate(YYYYMMDDHH24MISS)
*/
@XmlElement(name = "reg_d")
private String regD;
/**
* :
* char(1)
* 1: / 2: / 1:
*/
@XmlElement(name = "send_yn_c")
private String sendYnC;
/**
*
* date : YYYYMMDDHH24MISS
*/
@XmlElement(name = "send_d")
private String sendD;
/**
* :
* date
* interface DB->XML sysdate(YYYYMMDDHH24MISS)
*/
@XmlElement(name = "apply_d")
private String applyD;
/**
* :
* char(1)
* :Y OR N (default:N , DB Y )
*/
@XmlElement(name = "apply_gubun_c")
private String applyGubunC;
//------------------------------------------------------------------------------------
/**
* 1:
* varchar2(400)
* 0 / / 0
*/
@XmlElement(name = "pcd_gubun_v")
private String pcdGubunV;
/**
* 2:
* varchar2(400)
*/
@XmlElement(name = "pcd_gubun2_v")
private String pcdGubun2V;
/**
* 3:
* varchar2(400)
*/
@XmlElement(name = "pcd_gubun3_v")
private String pcdGubun3V;
//-------------------------------------------------------------------------------------
/**
* xml :
* varchar2(10)
*/
@XmlElement(name = "ifid")
private String ifid;
/**
* :
* varchar2(7)
*
*/
@XmlElement(name = "srcorgcd")
private String srcorgcd;
/**
* :
* varchar2(7)
* insert 1140100
*/
@XmlElement(name = "tgtorgcd")
private String tgtorgcd;
//----------------------------------------------------------------------------------------------------
// 결과(응답) 처리
//----------------------------------------------------------------------------------------------------
/**
* :
* varchar2(512)
*
*/
@XmlElement(name = "civil_gist_v")
private String civilGistV;
/**
* :
* clob
*
*/
@XmlElement(name = "civil_abstract_l")
private String civilAbstractL;
/**
* :
* varchar2(7)
*/
@XmlElement(name = "pcd_dept_v")
private String pcdDeptV;
/**
* :
* varchar2(50)
*/
@XmlElement(name = "pcd_dept_nm_v")
private String pcdDeptNmV;
/**
* :
* varchar2(50)
*/
@XmlElement(name = "duty_id_v")
private String dutyIdV;
/**
* :
* varchar2(64)
*/
@XmlElement(name = "pcd_email_v")
private String pcdEmailV;
/**
* :
* varchar2(20)
*/
@XmlElement(name = "pcd_tel_v")
private String pcdTelV;
/**
* :
* clob
*/
@XmlElement(name = "pcd_rst_cont_l")
private String pcdRstContL;
/**
* :
* varchar2(14) : YYYYMMDDHH24MISS
*/
@XmlElement(name = "do_reg_d")
private String doRegD;
/**
* :
* char(1)
* Y = , N = (default)
*/
@XmlElement(name = "pcd_rst_cont_attach_yn_c")
private String pcdRstContAttachYnC;
/**
*
* number(10)
*/
@XmlElement(name = "pcd_file_size_n")
private String pcdFileSizeN;
//------------------------------------------------------------------------
/**
* 1
* varchar2(2000)
*/
@XmlElement(name = "pcd_file_path1_v")
private String pcdFilePath1V;
/**
* 2
* varchar2(2000)
*/
@XmlElement(name = "pcd_file_path2_v")
private String pcdFilePath2V;
/**
* 3
* varchar2(2000)
*/
@XmlElement(name = "pcd_file_path3_v")
private String pcdFilePath3V;
/**
* 4
* varchar2(2000)
*/
@XmlElement(name = "pcd_file_path4_v")
private String pcdFilePath4V;
/**
* 5
* varchar2(2000)
*/
@XmlElement(name = "pcd_file_path5_v")
private String pcdFilePath5V;
//----------------------------------------------------------------------
/**
* :
* varchar2(7)
* ex) 6410000
*/
@XmlElement(name = "pcd_anc_code_v")
private String pcdAncCodeV;
/**
*
* number(5)
*/
@XmlElement(name = "peti_proc_dur_n")
private String petiProcDurN;
/**
*
* date
*/
@XmlElement(name = "peti_end_d")
private String petiEndD;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
private static class AppendFileInfo {
/**
* 1
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path1_v")
private String petiFilePath1V;
@XmlElement(name = "apndfilcont1")
private String apndfilcont1;
/**
* 2
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path2_v")
private String petiFilePath2V;
@XmlElement(name = "apndfilcont2")
private String apndfilcont2;
/**
* 3
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path3_v")
private String petiFilePath3V;
@XmlElement(name = "apndfilcont3")
private String apndfilcont3;
/**
* 4
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path4_v")
private String petiFilePath4V;
@XmlElement(name = "apndfilcont4")
private String apndfilcont4;
/**
* 5
* varchar2(2000)
*/
@XmlElement(name = "peti_file_path5_v")
private String petiFilePath5V;
@XmlElement(name = "apndfilcont5")
private String apndfilcont5;
}
}
Loading…
Cancel
Save