Documentオブジェクト読み込みメソッド作成

This commit is contained in:
r-ca 2024-01-08 12:20:12 +09:00
parent 73fa8201d6
commit f000addbce
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
2 changed files with 26 additions and 0 deletions

View File

@ -37,6 +37,10 @@ public interface FileManager {
void saveDocument(Document document, String fileName); void saveDocument(Document document, String fileName);
void saveDocument(Document document, Path path); void saveDocument(Document document, Path path);
Document loadDocument(String fileName);
Document loadDocument(Path path);
boolean isExist(Path path); boolean isExist(Path path);
boolean isExist(String fileName); boolean isExist(String fileName);

View File

@ -13,6 +13,8 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
@ -243,6 +245,26 @@ public class FileManagerImpl implements FileManager {
// TODO-rca 実装する // TODO-rca 実装する
} }
@Override
public Document loadDocument(String fileName) {
try {
File file = getFile(fileName);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);
return document;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public Document loadDocument(Path path) {
// TODO-rca 実装する
return null;
}
@Override @Override
public boolean isExist(Path path) { public boolean isExist(Path path) {
logger.debug("isExist", "called"); logger.debug("isExist", "called");