From 6e514b216a80c274445487f8265d0eb90136d2af Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 12:14:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=82=B5=E3=83=BC=E4=BD=9C?= =?UTF-8?q?=E3=82=8A=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/utils/XmlMetaParser.java | 9 +++++---- .../lacerta/utils/impl/XmlMetaParserImpl.java | 16 +++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/utils/src/main/java/one/nem/lacerta/utils/XmlMetaParser.java b/utils/src/main/java/one/nem/lacerta/utils/XmlMetaParser.java index 255b5f22..9aeac296 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/XmlMetaParser.java +++ b/utils/src/main/java/one/nem/lacerta/utils/XmlMetaParser.java @@ -1,12 +1,13 @@ package one.nem.lacerta.utils; +import org.w3c.dom.Document; + import one.nem.lacerta.model.document.internal.XmlMetaModel; public interface XmlMetaParser { - // ドキュメントのメタデータをXMLファイルから読み込む - XmlMetaModel parse(String xml); - // ドキュメントのメタデータをXMLファイルに書き込む - String serialize(XmlMetaModel meta); + XmlMetaModel deserialize(Document document); + + Document serialize(XmlMetaModel meta); } diff --git a/utils/src/main/java/one/nem/lacerta/utils/impl/XmlMetaParserImpl.java b/utils/src/main/java/one/nem/lacerta/utils/impl/XmlMetaParserImpl.java index 890d2ca0..674f358c 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/impl/XmlMetaParserImpl.java +++ b/utils/src/main/java/one/nem/lacerta/utils/impl/XmlMetaParserImpl.java @@ -23,12 +23,8 @@ public class XmlMetaParserImpl implements XmlMetaParser{ } @Override - public XmlMetaModel parse(String xml) { + public XmlMetaModel deserialize(Document document) { try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse(new InputSource(new StringReader(xml))); - Element rootElement = document.getDocumentElement(); XmlMetaModel meta = new XmlMetaModel(); @@ -53,11 +49,10 @@ public class XmlMetaParserImpl implements XmlMetaParser{ } catch (Exception e) { e.printStackTrace(); } - return null; // TODO-rca: 例外 + return null; } - @Override - public String serialize(XmlMetaModel meta) { + public Document serialize(XmlMetaModel meta) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); @@ -82,13 +77,12 @@ public class XmlMetaParserImpl implements XmlMetaParser{ document.appendChild(rootElement); - return document.toString(); + return document; } catch (Exception e) { e.printStackTrace(); } - return null; // TODO-rca: 例外 + return null; } - // Internal Methods private Element appendElement(Document document, Element rootElement, String name, String textContent) { Element element = document.createElement(name);