Initメソッド作り直し

This commit is contained in:
r-ca 2024-01-08 12:00:22 +09:00
parent a836410cbd
commit b3be0b9e21
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -55,38 +55,42 @@ public class DocumentProcessorImpl implements DocumentProcessor{
@Override @Override
public void init() { public void init() {
logger.debug("init", "called"); logger.debug("init", "called");
// XMLメタデータの取得/生成 Path path = documentDetail.getPath().getFullPath();
FileManager fileManager = fileManagerFactory.create(documentDetail.getPath().getFullPath()); logger.debug("init", "path: " + path.toString());
if(documentDetail.getPath().getFullPath().resolve("meta.xml").toFile().exists()) {
FileManager fileManager = fileManagerFactory.create(path); //Initialize FileManager
fileManager.changeDir(path);
fileManager.autoCreateToCurrentDir();
// rawディレクトリInit
fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
// xmlファイルの読み込み
if (fileManager.isExist("meta.xml")) {
logger.debug("init", "meta.xml found"); logger.debug("init", "meta.xml found");
try { try {
xmlMetaModel = xmlMetaParser.parse(new String(Files.readAllBytes(documentDetail.getPath().getFullPath().resolve("meta.xml")))); xmlMetaModel = xmlMetaParser.parse(fileManager.loadText("meta.xml"));
logger.debug("init", "parsed");
} catch (Exception e) { } catch (Exception e) {
logger.debug("init", "parse failed"); logger.debug("init", "meta.xml parse failed");
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
logger.debug("init", "meta.xml not found"); logger.debug("init", "meta.xml not found");
// Create new
xmlMetaModel = new XmlMetaModel(); xmlMetaModel = new XmlMetaModel();
xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle());
xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); xmlMetaModel.setTitle(documentDetail.getMeta().getTitle());
xmlMetaModel.setDescription(""); xmlMetaModel.setAuthor(documentDetail.getAuthor());
xmlMetaModel.setDefaultBranch("master"); xmlMetaModel.setDescription(""); // FIXME-rca:
xmlMetaModel.setDefaultBranch(documentDetail.getDefaultBranch());
xmlMetaModel.setPages(new ArrayList<>()); xmlMetaModel.setPages(new ArrayList<>());
// Save
try { try {
// ファイルの新規作成を行う fileManager.createFile("meta.xml");
File file = documentDetail.getPath().getFullPath().resolve("meta.xml").toFile(); fileManager.saveText(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
file.createNewFile(); logger.info("init", "meta.xml created");
// ファイルに書き込む
Files.write(documentDetail.getPath().getFullPath().resolve("meta.xml"), xmlMetaParser.serialize(xmlMetaModel).getBytes());
logger.debug("init", "saved");
} catch (Exception e) { } catch (Exception e) {
logger.debug("init", "save failed"); logger.debug("init", "meta.xml create failed");
e.printStackTrace(); e.printStackTrace();
} }
} }