From b3be0b9e21ea286c02174827f3eed9adfabf5b83 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 12:00:22 +0900 Subject: [PATCH] =?UTF-8?q?Init=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E4=BD=9C=E3=82=8A=E7=9B=B4=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/impl/DocumentProcessorImpl.java | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java b/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java index cdb274a7..7cdfd704 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java +++ b/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java @@ -55,38 +55,42 @@ public class DocumentProcessorImpl implements DocumentProcessor{ @Override public void init() { logger.debug("init", "called"); - // XMLメタデータの取得/生成 - FileManager fileManager = fileManagerFactory.create(documentDetail.getPath().getFullPath()); - if(documentDetail.getPath().getFullPath().resolve("meta.xml").toFile().exists()) { + Path path = documentDetail.getPath().getFullPath(); + logger.debug("init", "path: " + path.toString()); + + 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"); try { - xmlMetaModel = xmlMetaParser.parse(new String(Files.readAllBytes(documentDetail.getPath().getFullPath().resolve("meta.xml")))); - logger.debug("init", "parsed"); + xmlMetaModel = xmlMetaParser.parse(fileManager.loadText("meta.xml")); } catch (Exception e) { - logger.debug("init", "parse failed"); + logger.debug("init", "meta.xml parse failed"); e.printStackTrace(); } } else { logger.debug("init", "meta.xml not found"); - // Create new xmlMetaModel = new XmlMetaModel(); - xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle()); - xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); - xmlMetaModel.setDescription(""); - xmlMetaModel.setDefaultBranch("master"); + + xmlMetaModel.setTitle(documentDetail.getMeta().getTitle()); + xmlMetaModel.setAuthor(documentDetail.getAuthor()); + xmlMetaModel.setDescription(""); // FIXME-rca: + xmlMetaModel.setDefaultBranch(documentDetail.getDefaultBranch()); xmlMetaModel.setPages(new ArrayList<>()); - // Save try { - // ファイルの新規作成を行う - File file = documentDetail.getPath().getFullPath().resolve("meta.xml").toFile(); - file.createNewFile(); - - // ファイルに書き込む - Files.write(documentDetail.getPath().getFullPath().resolve("meta.xml"), xmlMetaParser.serialize(xmlMetaModel).getBytes()); - logger.debug("init", "saved"); + fileManager.createFile("meta.xml"); + fileManager.saveText(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + logger.info("init", "meta.xml created"); } catch (Exception e) { - logger.debug("init", "save failed"); + logger.debug("init", "meta.xml create failed"); e.printStackTrace(); } }