mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
パーサー作り直し
This commit is contained in:
parent
59ba2cdcfc
commit
6e514b216a
|
@ -1,12 +1,13 @@
|
||||||
package one.nem.lacerta.utils;
|
package one.nem.lacerta.utils;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||||
|
|
||||||
public interface XmlMetaParser {
|
public interface XmlMetaParser {
|
||||||
|
|
||||||
// ドキュメントのメタデータをXMLファイルから読み込む
|
XmlMetaModel deserialize(Document document);
|
||||||
XmlMetaModel parse(String xml);
|
|
||||||
// ドキュメントのメタデータをXMLファイルに書き込む
|
Document serialize(XmlMetaModel meta);
|
||||||
String serialize(XmlMetaModel meta);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,8 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlMetaModel parse(String xml) {
|
public XmlMetaModel deserialize(Document document) {
|
||||||
try {
|
try {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
Document document = builder.parse(new InputSource(new StringReader(xml)));
|
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Element rootElement = document.getDocumentElement();
|
||||||
|
|
||||||
XmlMetaModel meta = new XmlMetaModel();
|
XmlMetaModel meta = new XmlMetaModel();
|
||||||
|
@ -53,11 +49,10 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null; // TODO-rca: 例外
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize(XmlMetaModel meta) {
|
public Document serialize(XmlMetaModel meta) {
|
||||||
try {
|
try {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
@ -82,13 +77,12 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
||||||
|
|
||||||
document.appendChild(rootElement);
|
document.appendChild(rootElement);
|
||||||
|
|
||||||
return document.toString();
|
return document;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null; // TODO-rca: 例外
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal Methods
|
// Internal Methods
|
||||||
private Element appendElement(Document document, Element rootElement, String name, String textContent) {
|
private Element appendElement(Document document, Element rootElement, String name, String textContent) {
|
||||||
Element element = document.createElement(name);
|
Element element = document.createElement(name);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user