From 89e2f15a29ad4b44b7401f564f6f027aea2247a4 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 16:47:42 +0900 Subject: [PATCH 01/73] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=A2=E3=82=A6=E3=83=88(=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E6=B8=9B=E3=82=89=E3=81=99=E3=81=9F=E3=82=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DebugMenuFileManagerTesterFragment.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java index f27bfe3a..12cd71c0 100644 --- a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java @@ -63,46 +63,46 @@ public class DebugMenuFileManagerTesterFragment extends Fragment { EditText editText = view.findViewById(R.id.edit_text_dir_name); String dirName = editText.getText().toString(); - FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); - fileManager.createDir(dirName); +// FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); +// fileManager.createDir(dirName); }); view.findViewById(R.id.button_save_item).setOnClickListener(v -> { - FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); - fileManager.createDir("test"); - fileManager.changeDir("test"); - Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888); - // Bitmapに描画処理を行う - Canvas canvas = new Canvas(bitmap); - // 大きな山の形状を作成 - android.graphics.Path bigMountainPath = new android.graphics.Path(); - bigMountainPath.moveTo(100, 800); // 左下の開始点 - bigMountainPath.lineTo(500, 300); // 頂点 - bigMountainPath.lineTo(900, 800); // 右下 - bigMountainPath.close(); // パスを閉じる - - // 山の描画設定 - Paint mountainPaint = new Paint(); - mountainPaint.setColor(Color.GREEN); - mountainPaint.setStyle(Paint.Style.FILL); - - // 大きな山を描画 - canvas.drawPath(bigMountainPath, mountainPaint); - - // 小さな山の形状を作成 - android.graphics.Path smallMountainPath = new android.graphics.Path(); - smallMountainPath.moveTo(400, 800); // 左下の開始点 - smallMountainPath.lineTo(650, 400); // 頂点 - smallMountainPath.lineTo(900, 800); // 右下 - smallMountainPath.close(); // パスを閉じる - - Paint smallMountainPaint = new Paint(); - smallMountainPaint.setColor(Color.parseColor("#006e54")); - smallMountainPaint.setStyle(Paint.Style.FILL); - - // 小さな山を描画 - canvas.drawPath(smallMountainPath, smallMountainPaint); - fileManager.saveBitmapAtCurrent(bitmap, "test.png"); +// FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); +// fileManager.createDir("test"); +// fileManager.changeDir("test"); +// Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888); +// // Bitmapに描画処理を行う +// Canvas canvas = new Canvas(bitmap); +// // 大きな山の形状を作成 +// android.graphics.Path bigMountainPath = new android.graphics.Path(); +// bigMountainPath.moveTo(100, 800); // 左下の開始点 +// bigMountainPath.lineTo(500, 300); // 頂点 +// bigMountainPath.lineTo(900, 800); // 右下 +// bigMountainPath.close(); // パスを閉じる +// +// // 山の描画設定 +// Paint mountainPaint = new Paint(); +// mountainPaint.setColor(Color.GREEN); +// mountainPaint.setStyle(Paint.Style.FILL); +// +// // 大きな山を描画 +// canvas.drawPath(bigMountainPath, mountainPaint); +// +// // 小さな山の形状を作成 +// android.graphics.Path smallMountainPath = new android.graphics.Path(); +// smallMountainPath.moveTo(400, 800); // 左下の開始点 +// smallMountainPath.lineTo(650, 400); // 頂点 +// smallMountainPath.lineTo(900, 800); // 右下 +// smallMountainPath.close(); // パスを閉じる +// +// Paint smallMountainPaint = new Paint(); +// smallMountainPaint.setColor(Color.parseColor("#006e54")); +// smallMountainPaint.setStyle(Paint.Style.FILL); +// +// // 小さな山を描画 +// canvas.drawPath(smallMountainPath, smallMountainPaint); +// fileManager.saveBitmapAtCurrent(bitmap, "test.png"); }); return view; From 4a66ed786dd85a70afa3ee344b8320511a0d23ab Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 16:49:11 +0900 Subject: [PATCH 02/73] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=A2=E3=82=A6=E3=83=88(=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E6=B8=9B=E3=82=89=E3=81=99=E3=81=9F=E3=82=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/impl/DocumentProcessorImpl.java | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 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 4056792f..9e59ed2b 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 @@ -50,74 +50,74 @@ public class DocumentProcessorImpl implements DocumentProcessor{ @Override public void init() { - logger.debug("init", "called"); - // Init Variables - this.documentRootPath = this.documentDetail.getPath().getFullPath(); - logger.debug("init", "documentRootPath: " + this.documentRootPath); - - this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager - logger.debug("init", "fileManager created"); - - this.fileManager.autoCreateDir(this.documentRootPath); - - // rawディレクトリInit - this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); - - // xmlファイルの読み込み - if (fileManager.isExist("meta.xml")) { - logger.debug("init", "meta.xml found"); - try { - xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); - } catch (Exception e) { - logger.debug("init", "meta.xml parse failed"); - logger.trace("init", e.getMessage()); - } - } else { - logger.debug("init", "meta.xml not found"); - xmlMetaModel = new XmlMetaModel(); - - xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle()); - xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); - xmlMetaModel.setDescription(""); // FIXME-rca: - xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch()); - xmlMetaModel.setPages(new ArrayList<>()); - - try { - this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); - logger.debug("init", "meta.xml saved"); - } catch (Exception e) { - logger.error("init", "meta.xml save failed"); - logger.trace("init", e.getMessage()); - } - } - - logger.info("init", "finished"); +// logger.debug("init", "called"); +// // Init Variables +// this.documentRootPath = this.documentDetail.getPath().getFullPath(); +// logger.debug("init", "documentRootPath: " + this.documentRootPath); +// +// this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager +// logger.debug("init", "fileManager created"); +// +// this.fileManager.autoCreateDir(this.documentRootPath); +// +// // rawディレクトリInit +// this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); +// +// // xmlファイルの読み込み +// if (fileManager.isExist("meta.xml")) { +// logger.debug("init", "meta.xml found"); +// try { +// xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); +// } catch (Exception e) { +// logger.debug("init", "meta.xml parse failed"); +// logger.trace("init", e.getMessage()); +// } +// } else { +// logger.debug("init", "meta.xml not found"); +// xmlMetaModel = new XmlMetaModel(); +// +// xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle()); +// xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); +// xmlMetaModel.setDescription(""); // FIXME-rca: +// xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch()); +// xmlMetaModel.setPages(new ArrayList<>()); +// +// try { +// this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); +// logger.debug("init", "meta.xml saved"); +// } catch (Exception e) { +// logger.error("init", "meta.xml save failed"); +// logger.trace("init", e.getMessage()); +// } +// } +// +// logger.info("init", "finished"); } @Override public void addNewPageToLast(Bitmap bitmap) { - logger.debug("addNewPageToLast", "called"); - String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - - // FileManager - if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 - logger.debug("addNewPageToLast", "currentDir is documentRootPath"); - } else { - logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); - this.fileManager.backRootDir(); - this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); - this.fileManager.changeDir(DEFAULT_SAVE_DIR); - } - logger.debug("addNewPageToLast", "DirInit finished"); - - // Save file - this.fileManager.saveBitmapAtCurrent(bitmap, filename); - - // Update meta - XmlMetaPageModel page = new XmlMetaPageModel(); - page.setIndex(xmlMetaModel.getPages().size() + 1); - page.setFilename(filename); - xmlMetaModel.addPage(page); +// logger.debug("addNewPageToLast", "called"); +// String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする +// +// // FileManager +// if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 +// logger.debug("addNewPageToLast", "currentDir is documentRootPath"); +// } else { +// logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); +// this.fileManager.backRootDir(); +// this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); +// this.fileManager.changeDir(DEFAULT_SAVE_DIR); +// } +// logger.debug("addNewPageToLast", "DirInit finished"); +// +// // Save file +// this.fileManager.saveBitmapAtCurrent(bitmap, filename); +// +// // Update meta +// XmlMetaPageModel page = new XmlMetaPageModel(); +// page.setIndex(xmlMetaModel.getPages().size() + 1); +// page.setFilename(filename); +// xmlMetaModel.addPage(page); } @Override From 3ed835ef2f203815eefef6c33b9f6b9fe97cdfa2 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:34:12 +0900 Subject: [PATCH 03/73] =?UTF-8?q?=E6=97=A2=E5=AD=98=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/FileManager.java | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 91dc217b..79ed23d8 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -12,48 +12,5 @@ import java.util.List; /** @noinspection unused*/ public interface FileManager { - Path getRootDir(); - Path getCurrentDir(); - - void changeDir(String dirName); //cd - void changeDir(Path path); //cd - void backDir(); //cd .. - void backRootDir(); //cd / - List getList(); - void createDir(String dirName); - void createDir(Path path); - void removeDir(String dirName); - void removeDir(Path path); - - File createFile(String fileName); - void removeFile(String fileName); - - File getFile(String fileName); - File getFile(Path path); - - String loadText(String fileName); - String loadText(Path path); - - void saveText(String text, String fileName); - void saveText(String text, Path path); - - void saveDocument(Document document, String fileName); - void saveDocument(Document document, Path path); - - Document loadDocument(String fileName); - Document loadDocument(Path path); - - - boolean isExist(Path path); - boolean isExist(String fileName); - - void autoCreateDir(Path path); - void autoCreateDir(String dirName); - - void autoCreateToCurrentDir(); - - void saveBitmapAtCurrent(Bitmap bitmap, String fileName); - Bitmap loadBitmap(Path path); - void removeBitmap(Path path); } From eadd65a3342c7f58359dcdcb7f5cbfddd05ddee6 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:48:06 +0900 Subject: [PATCH 04/73] WIP --- .../java/one/nem/lacerta/source/file/FileManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 79ed23d8..908b6c9c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -12,5 +12,15 @@ import java.util.List; /** @noinspection unused*/ public interface FileManager { + File getFileRef(); + boolean isExist(); + boolean isDirectory(); + boolean isFile(); + boolean isWritable(); + boolean isReadable(); + Document readXml(); + FileManager setRootDir(Path rootDir); + FileManager setPath(Path path); + FileManager setPath(String path); } From 16ac36dd4fcc5878b09dd0d2ba7faf7b186bdcbf Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:48:46 +0900 Subject: [PATCH 05/73] =?UTF-8?q?=E6=97=A2=E5=AD=98=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 307 ------------------ 1 file changed, 307 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index fe8773ca..a4e91fd7 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -28,320 +28,13 @@ import one.nem.lacerta.utils.LacertaLogger; public class FileManagerImpl implements FileManager { - // RootDir - private Path rootDir; - - // CurrentDir - private Path currentDir; - - // Internal Methods - private Path convertPath(String path) { - Path convertedPath = currentDir.resolve(path); - if (convertedPath.startsWith(rootDir)) { // 異常なパスの場合はnullを返す // TODO-rca: エラーハンドリング - return convertedPath; - } else { - return null; - } - } - // Injection private LacertaLogger logger; @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; - this.rootDir = rootDir; - this.currentDir = rootDir; } - @Override - public Path getRootDir() { - return rootDir; - } - - @Override - public Path getCurrentDir() { - return currentDir; - } - - @Override - public void changeDir(String dirName) { - this.currentDir = rootDir.resolve(dirName); - } - - @Override - public void changeDir(Path path) { - if (path.startsWith(rootDir)) { - this.currentDir = path; - } - else { - logger.debug("changeDir", "invalid path: " + path); - // TODO-rca: 例外を投げる - } - } - - @Override - public void backDir() { - this.currentDir = currentDir.getParent(); - } - - @Override - public void backRootDir() { - this.currentDir = rootDir; - } - - @Override - public List getList() { - List list = new ArrayList<>(); - try (DirectoryStream stream = Files.newDirectoryStream(currentDir)) { - for (Path entry : stream) { // TODO-rca: エラーハンドリング, 効率化 - list.add(entry); - } - } catch (IOException e) { - e.printStackTrace(); - } - return list; - } - - @Override - public void createDir(String dirName) { - //ディレクトリ作成 - logger.debug("createDir", "called"); - - Path path = currentDir.resolve(dirName); - logger.debug("createDir", "path: " + path); - try { - Files.createDirectory(path); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void createDir(Path path) { - logger.debug("createDir", "called"); - try { - Files.createDirectory(path); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void removeDir(String dirName) { - logger.debug("removeDir", "called"); - currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング - } - - @Override - public void removeDir(Path path) { - logger.debug("removeDir", "called"); - path.toFile().delete(); // TODO-rca: エラーハンドリング - } - - - @Override - public File createFile(String fileName) { - logger.debug("createFile", "called"); - return currentDir.resolve(fileName).toFile(); - } - - @Override - public void removeFile(String fileName) { - logger.debug("removeFile", "called"); - currentDir.resolve(fileName).toFile().delete(); // TODO-rca: エラーハンドリング - } - - @Override - public File getFile(String fileName) { - logger.debug("getFile", "called"); - return currentDir.resolve(fileName).toFile(); - } - - @Override - public File getFile(Path path) { - logger.debug("getFile", "called"); - return path.toFile(); - } - - @Override - public String loadText(String fileName) { // TODO-rca: 統合 - try(FileInputStream fileInputStream = new FileInputStream(currentDir.resolve(fileName).toFile())) { - byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); // TODO-rca: エラーハンドリング - return new String(bytes); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - @Override - public String loadText(Path path) { - try(FileInputStream fileInputStream = new FileInputStream(path.toFile())) { - byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); // TODO-rca: エラーハンドリング - return new String(bytes); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - @Override - public void saveText(String text, String fileName) { // TODO-rca: リファクタリング // TODO-rca: 統合 - if (isExist(fileName)) { - logger.debug("saveText", "file already exists"); - // Overwrite - try { - Files.write(currentDir.resolve(fileName), text.getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } - else { - try { - Files.createFile(currentDir.resolve(fileName)); - Files.write(currentDir.resolve(fileName), text.getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - } - - @Override - public void saveText(String text, Path path) { - if (isExist(path)) { - logger.debug("saveText", "file already exists"); - // Overwrite - try { - Files.write(path, text.getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } - else { - try { - Files.createFile(path); - Files.write(path, text.getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public void saveDocument(Document document, String fileName) { - try { - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - DOMSource source = new DOMSource(document); - File file = createFile(fileName); - StreamResult result = new StreamResult(file); - transformer.transform(source, result); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void saveDocument(Document document, Path path) { - // 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 - public boolean isExist(Path path) { - logger.debug("isExist", "called"); - return Files.exists(path); - } - - @Override - public boolean isExist(String fileName) { - logger.debug("isExist", "called"); - return Files.exists(currentDir.resolve(fileName)); - } - - @Override - public void autoCreateDir(Path path) { - logger.debug("autoCreateDir", "called"); - if (!Files.exists(path)) { - try { - Files.createDirectories(path); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public void autoCreateDir(String dirName) { - logger.debug("autoCreateDir", "called"); - if (!Files.exists(currentDir.resolve(dirName))) { - try { - Files.createDirectories(currentDir.resolve(dirName)); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public void autoCreateToCurrentDir() { - logger.debug("autoGenerateToCurrentDir", "called"); - if (isExist(currentDir)) { - logger.debug("autoGenerateToCurrentDir", "currentDir already exists"); - return; - } - else { - try { - Files.createDirectories(currentDir); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - - @Override - public void saveBitmapAtCurrent(Bitmap bitmap, String fileName) { // TODO-rca: ファイル形式を変更できるようにする? - logger.debug("saveBitmapAtCurrent", "called"); - try { - File file = currentDir.resolve(fileName).toFile(); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public Bitmap loadBitmap(Path path) { - return null; - } - - @Override - public void removeBitmap(Path path) { - - } } From cc35d8a5ea0490328b543c1af8b40c43f17a9224 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:55:24 +0900 Subject: [PATCH 06/73] Impl WIP --- .../source/file/impl/FileManagerImpl.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index a4e91fd7..0a8561dd 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -7,6 +7,7 @@ import org.w3c.dom.Document; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.DirectoryIteratorException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -28,13 +29,90 @@ import one.nem.lacerta.utils.LacertaLogger; public class FileManagerImpl implements FileManager { + // variables + private Path rootDir; + private Path path; + + // Injection private LacertaLogger logger; @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; + this.rootDir = rootDir; + } + + // Internal + private Path resolveStringPath(String path) throws IOException{ + String[] pathArray = path.split("/"); + Path resolvedPath = this.rootDir; + for (String pathPart : pathArray) { + if (pathPart.equals("..")) { + resolvedPath = resolvedPath.getParent(); + continue; + } + + try { + resolvedPath = resolvedPath.resolve(pathPart); + } catch (Exception e) { + throw new IOException("Invalid path: " + path); + return null; + } + } + logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath); + return resolvedPath; } + @Override + public File getFileRef() { + return null; + } + + @Override + public boolean isExist() { + return false; + } + + @Override + public boolean isDirectory() { + return false; + } + + @Override + public boolean isFile() { + return false; + } + + @Override + public boolean isWritable() { + return false; + } + + @Override + public boolean isReadable() { + return false; + } + + @Override + public Document readXml() { + return null; + } + + @Override + public FileManager setRootDir(Path rootDir) { + this.rootDir = rootDir; + return this; + } + + @Override + public FileManager setPath(Path path) { + return null; + } + + @Override + public FileManager setPath(String path) { + return null; + } } From c513b44e8d23bf98dabdc63551e67de88dd9ef60 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:55:37 +0900 Subject: [PATCH 07/73] Impl WIP --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 0a8561dd..bbbed15a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -57,7 +57,6 @@ public class FileManagerImpl implements FileManager { resolvedPath = resolvedPath.resolve(pathPart); } catch (Exception e) { throw new IOException("Invalid path: " + path); - return null; } } logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath); From 2233bb1a3516323d2bd7397b91d6feb3d57fea30 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:56:50 +0900 Subject: [PATCH 08/73] Impl WIP --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index bbbed15a..6df95e32 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -107,7 +107,11 @@ public class FileManagerImpl implements FileManager { @Override public FileManager setPath(Path path) { - return null; + if (path.startsWith(this.rootDir)) { + this.path = path; + } else { + // placeholder + } } @Override From 2b8766db0a6346df6e9d4d0e4b62a5849b86fe48 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 11:58:21 +0900 Subject: [PATCH 09/73] =?UTF-8?q?=E8=87=AA=E5=8B=95=E3=81=A7=E3=83=87?= =?UTF-8?q?=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=99=E3=82=8B=E3=81=8B=E3=82=92=E5=88=87=E3=82=8A?= =?UTF-8?q?=E6=9B=BF=E3=81=88=E3=82=8B=E3=83=95=E3=83=A9=E3=82=B0=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 3 +++ .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 908b6c9c..93dea306 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -20,6 +20,9 @@ public interface FileManager { boolean isReadable(); Document readXml(); + // Configure + FileManager enableAutoCreate(); + FileManager setRootDir(Path rootDir); FileManager setPath(Path path); FileManager setPath(String path); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 6df95e32..847e1758 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -32,6 +32,7 @@ public class FileManagerImpl implements FileManager { // variables private Path rootDir; private Path path; + private boolean autoCreate = false; // Injection @@ -99,6 +100,11 @@ public class FileManagerImpl implements FileManager { return null; } + @Override + public FileManager enableAutoCreate() { + return null; + } + @Override public FileManager setRootDir(Path rootDir) { this.rootDir = rootDir; From 8ebc96fa98395deb477308dfb4053cb190c17062 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:00:16 +0900 Subject: [PATCH 10/73] =?UTF-8?q?root=E3=81=AE=E5=90=88=E8=87=B4=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E3=83=95=E3=83=A9=E3=82=B0?= =?UTF-8?q?=E3=81=A7=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 1 + .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 93dea306..f1899e35 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -22,6 +22,7 @@ public interface FileManager { // Configure FileManager enableAutoCreate(); + FileManager disableRootDirCheck(); FileManager setRootDir(Path rootDir); FileManager setPath(Path path); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 847e1758..c4c07e9b 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -33,6 +33,7 @@ public class FileManagerImpl implements FileManager { private Path rootDir; private Path path; private boolean autoCreate = false; + private boolean disableRootDirCheck = false; // Injection @@ -116,7 +117,9 @@ public class FileManagerImpl implements FileManager { if (path.startsWith(this.rootDir)) { this.path = path; } else { - // placeholder + if (this.autoCreate) { + + } } } From 0d78f9fa7c46977167c65c2822471ee3b4171ebf Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:00:26 +0900 Subject: [PATCH 11/73] =?UTF-8?q?root=E3=81=AE=E5=90=88=E8=87=B4=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E3=83=95=E3=83=A9=E3=82=B0?= =?UTF-8?q?=E3=81=A7=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index c4c07e9b..dea0d455 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -106,6 +106,11 @@ public class FileManagerImpl implements FileManager { return null; } + @Override + public FileManager disableRootDirCheck() { + return null; + } + @Override public FileManager setRootDir(Path rootDir) { this.rootDir = rootDir; From 9faf5c9055e7f2e87605d40840b32a45765ac92f Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:14:43 +0900 Subject: [PATCH 12/73] =?UTF-8?q?=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/FileManager.java | 1 + .../source/file/impl/FileManagerImpl.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index f1899e35..ef6bf92a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -27,4 +27,5 @@ public interface FileManager { FileManager setRootDir(Path rootDir); FileManager setPath(Path path); FileManager setPath(String path); + FileManager resolve(String path); } diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index dea0d455..42b4184c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -65,7 +65,6 @@ public class FileManagerImpl implements FileManager { return resolvedPath; } - @Override public File getFileRef() { return null; @@ -119,17 +118,30 @@ public class FileManagerImpl implements FileManager { @Override public FileManager setPath(Path path) { - if (path.startsWith(this.rootDir)) { + if (this.disableRootDirCheck) { this.path = path; } else { - if (this.autoCreate) { - + if (path.startsWith(this.rootDir)) { + this.path = path; + } else { + throw new IllegalArgumentException("path must be in rootDir"); } } + return this; } @Override public FileManager setPath(String path) { return null; } + + @Override + public FileManager resolve(String path) { + try { + this.path = resolveStringPath(path); + } catch (IOException e) { + e.printStackTrace(); + } + } + } From fcda369a2e8769d52f1a317399864ad31a9e5609 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:15:12 +0900 Subject: [PATCH 13/73] =?UTF-8?q?resolve=E3=81=A8=E7=AB=B6=E5=90=88?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=AE=E3=81=A7String=E3=81=AEsetPath?= =?UTF-8?q?=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 1 - .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index ef6bf92a..4cff1b12 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -26,6 +26,5 @@ public interface FileManager { FileManager setRootDir(Path rootDir); FileManager setPath(Path path); - FileManager setPath(String path); FileManager resolve(String path); } diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 42b4184c..5a9885a3 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -130,11 +130,6 @@ public class FileManagerImpl implements FileManager { return this; } - @Override - public FileManager setPath(String path) { - return null; - } - @Override public FileManager resolve(String path) { try { From d5cf2f31d6462f692e595ae1f1494d346654725c Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:18:03 +0900 Subject: [PATCH 14/73] =?UTF-8?q?resolve=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 3 ++- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 4cff1b12..473cbde1 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import org.w3c.dom.Document; import java.io.File; +import java.io.IOException; import java.nio.file.Path; import java.util.List; @@ -26,5 +27,5 @@ public interface FileManager { FileManager setRootDir(Path rootDir); FileManager setPath(Path path); - FileManager resolve(String path); + FileManager resolve(String path) throws IOException; } diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 5a9885a3..ddefaf6b 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -131,12 +131,13 @@ public class FileManagerImpl implements FileManager { } @Override - public FileManager resolve(String path) { + public FileManager resolve(String path) throws IOException{ try { this.path = resolveStringPath(path); } catch (IOException e) { - e.printStackTrace(); + logger.error("resolve", e.getMessage()); + throw new IOException("Invalid path: " + path); } + return this; } - } From 9142696faccd0ec5f3bd4425e35c17983c7ca484 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:19:40 +0900 Subject: [PATCH 15/73] =?UTF-8?q?resolve=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index ddefaf6b..faf7e971 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -132,12 +132,13 @@ public class FileManagerImpl implements FileManager { @Override public FileManager resolve(String path) throws IOException{ + Path resolvedPath; try { - this.path = resolveStringPath(path); + resolvedPath = resolveStringPath(path); } catch (IOException e) { logger.error("resolve", e.getMessage()); throw new IOException("Invalid path: " + path); } - return this; + return this.setPath(resolvedPath); } } From 3efaf30b957db5858eae0c9ac3de7c8183fb7ec6 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:20:15 +0900 Subject: [PATCH 16/73] =?UTF-8?q?config=E3=81=AE=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E8=BE=BC=E3=81=BF=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index faf7e971..0b0a0f47 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -102,12 +102,14 @@ public class FileManagerImpl implements FileManager { @Override public FileManager enableAutoCreate() { - return null; + this.autoCreate = true; + return this; } @Override public FileManager disableRootDirCheck() { - return null; + this.disableRootDirCheck = true; + return this; } @Override From 37497cb1eadf9fd5e0568f8f841b2e01f910d8fb Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:22:09 +0900 Subject: [PATCH 17/73] =?UTF-8?q?config=E3=81=AE=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E8=BE=BC=E3=81=BF=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 2 +- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 473cbde1..c6aed97e 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -22,7 +22,7 @@ public interface FileManager { Document readXml(); // Configure - FileManager enableAutoCreate(); + FileManager enableAutoCreateParent(); FileManager disableRootDirCheck(); FileManager setRootDir(Path rootDir); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 0b0a0f47..5e01f3ae 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -32,7 +32,7 @@ public class FileManagerImpl implements FileManager { // variables private Path rootDir; private Path path; - private boolean autoCreate = false; + private boolean autoCreateParent = false; private boolean disableRootDirCheck = false; @@ -101,8 +101,8 @@ public class FileManagerImpl implements FileManager { } @Override - public FileManager enableAutoCreate() { - this.autoCreate = true; + public FileManager enableAutoCreateParent() { + this.autoCreateParent = true; return this; } From 3b861e3a0775afad2e44fe933142ab9eb32c7bac Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:23:37 +0900 Subject: [PATCH 18/73] =?UTF-8?q?=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=81=BF/?= =?UTF-8?q?=E6=9B=B8=E3=81=8D=E8=BE=BC=E3=81=BF=E6=A8=A9=E9=99=90=E3=81=AE?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E3=82=92=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 5e01f3ae..0f8bf98c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -86,13 +86,15 @@ public class FileManagerImpl implements FileManager { } @Override - public boolean isWritable() { - return false; + public boolean isReadable() { + File file = this.path.toFile(); + return file.canRead(); } @Override - public boolean isReadable() { - return false; + public boolean isWritable() { + File file = this.path.toFile(); + return file.canWrite(); } @Override From 5c931ece3f3a33de930312d05c78450cd73d141c Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:23:59 +0900 Subject: [PATCH 19/73] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=AD=98=E5=9C=A8=E7=A2=BA=E8=AA=8D=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 0f8bf98c..db47d158 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -72,7 +72,8 @@ public class FileManagerImpl implements FileManager { @Override public boolean isExist() { - return false; + File file = this.path.toFile(); + return file.exists(); } @Override From 9e5b2dad466bf52632013aac4c529a9618d290bd Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:24:56 +0900 Subject: [PATCH 20/73] =?UTF-8?q?=E8=AA=AD=E3=81=BF=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E3=81=AE=E7=A2=BA=E8=AA=8D=E3=81=AE=E5=89=8D=E3=81=AB=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE=E5=AD=98=E5=9C=A8=E3=82=92?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index db47d158..5d5eeb8b 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -88,14 +88,22 @@ public class FileManagerImpl implements FileManager { @Override public boolean isReadable() { - File file = this.path.toFile(); - return file.canRead(); + if (this.isExist()) { + File file = this.path.toFile(); + return file.canRead(); + } else { + return false; + } } @Override public boolean isWritable() { - File file = this.path.toFile(); - return file.canWrite(); + if (this.isExist()) { + File file = this.path.toFile(); + return file.canWrite(); + } else { + return false; + } } @Override From 0dced5d0dca0a2ab2c19db52874bcfa7d27433f6 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:25:25 +0900 Subject: [PATCH 21/73] =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA/=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=88=A4=E5=AE=9A=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/source/file/impl/FileManagerImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 5d5eeb8b..cf3192c8 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -78,12 +78,22 @@ public class FileManagerImpl implements FileManager { @Override public boolean isDirectory() { - return false; + if (this.isExist()) { + File file = this.path.toFile(); + return file.isDirectory(); + } else { + return false; + } } @Override public boolean isFile() { - return false; + if (this.isExist()) { + File file = this.path.toFile(); + return file.isFile(); + } else { + return false; + } } @Override From 91fe39d1418c84a2fddc3206fc5343d97c2a687e Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:31:31 +0900 Subject: [PATCH 22/73] =?UTF-8?q?=E8=AA=AD=E3=81=BF=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E3=81=AE=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=95=E3=82=A7=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/FileManager.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index c6aed97e..aaf78c1c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -21,6 +21,9 @@ public interface FileManager { boolean isReadable(); Document readXml(); + // Get current instance + FileManager getCurrentInstance(); + // Configure FileManager enableAutoCreateParent(); FileManager disableRootDirCheck(); @@ -28,4 +31,24 @@ public interface FileManager { FileManager setRootDir(Path rootDir); FileManager setPath(Path path); FileManager resolve(String path) throws IOException; + + // Save + // XML + FileManager saveXml(Document document, String fileName) throws IOException; + FileManager saveXml(Document document) throws IOException; + + // Bitmap + FileManager saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる + FileManager saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる + + + // Load + // XML + Document loadXml(String fileName) throws IOException; + Document loadXml() throws IOException; + + // Bitmap + Bitmap loadBitmap(String fileName) throws IOException; + Bitmap loadBitmap() throws IOException; + } From 0f8b71e739f6005ea9d5abbe7bda8d5d1ce48526 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:31:57 +0900 Subject: [PATCH 23/73] =?UTF-8?q?Impl=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index cf3192c8..27b62e2f 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -121,6 +121,11 @@ public class FileManagerImpl implements FileManager { return null; } + @Override + public FileManager getCurrentInstance() { + return null; + } + @Override public FileManager enableAutoCreateParent() { this.autoCreateParent = true; @@ -164,4 +169,44 @@ public class FileManagerImpl implements FileManager { } return this.setPath(resolvedPath); } + + @Override + public FileManager saveXml(Document document, String fileName) throws IOException { + return null; + } + + @Override + public FileManager saveXml(Document document) throws IOException { + return null; + } + + @Override + public FileManager saveBitmap(Bitmap bitmap, String fileName) throws IOException { + return null; + } + + @Override + public FileManager saveBitmap(Bitmap bitmap) throws IOException { + return null; + } + + @Override + public Document loadXml(String fileName) throws IOException { + return null; + } + + @Override + public Document loadXml() throws IOException { + return null; + } + + @Override + public Bitmap loadBitmap(String fileName) throws IOException { + return null; + } + + @Override + public Bitmap loadBitmap() throws IOException { + return null; + } } From a2eda32183d95281077da84ac3133de7f89c9575 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:32:50 +0900 Subject: [PATCH 24/73] =?UTF-8?q?getCurrentInstance=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 27b62e2f..b7d2ab08 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -123,7 +123,7 @@ public class FileManagerImpl implements FileManager { @Override public FileManager getCurrentInstance() { - return null; + return this; } @Override From e0a344bb4821a7883f347697b913cf91151cb0f3 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:34:10 +0900 Subject: [PATCH 25/73] =?UTF-8?q?Xml=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=99?= =?UTF-8?q?=E3=82=8BInternal=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b7d2ab08..34512191 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -170,6 +170,23 @@ public class FileManagerImpl implements FileManager { return this.setPath(resolvedPath); } + // Internal + private void saveXmlInternal(Document document, String fileName) throws IOException { + try { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(document); + + File file = this.path.resolve(fileName).toFile(); + StreamResult result = new StreamResult(file); + + transformer.transform(source, result); + } catch (Exception e) { + logger.error("saveXmlInternal", e.getMessage()); + throw new IOException("Failed to save xml"); + } + } + @Override public FileManager saveXml(Document document, String fileName) throws IOException { return null; From e20b3f4a35f732b2d5cdb7b9e5c18b6319b2d83a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:34:42 +0900 Subject: [PATCH 26/73] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 34512191..799a0851 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -171,14 +171,13 @@ public class FileManagerImpl implements FileManager { } // Internal - private void saveXmlInternal(Document document, String fileName) throws IOException { + private void saveXmlInternal(Document document) throws IOException { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); - File file = this.path.resolve(fileName).toFile(); - StreamResult result = new StreamResult(file); + StreamResult result = new StreamResult(this.path.toFile()); transformer.transform(source, result); } catch (Exception e) { From 301678658c575789218872f6a10fe5b4048207b2 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:36:35 +0900 Subject: [PATCH 27/73] =?UTF-8?q?Save=E7=B3=BB=E3=81=AE=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=8B=E3=82=89=E3=83=81=E3=82=A7=E3=83=BC?= =?UTF-8?q?=E3=83=B3=E3=81=A7=E3=81=8D=E3=82=8B=E5=BF=85=E8=A6=81=E3=81=AF?= =?UTF-8?q?=E3=81=AA=E3=81=95=E3=81=9D=E3=81=86=E3=81=AA=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E6=88=BB=E3=82=8A=E5=80=A4=E3=82=92void=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/FileManager.java | 8 ++++---- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index aaf78c1c..c1488183 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -34,12 +34,12 @@ public interface FileManager { // Save // XML - FileManager saveXml(Document document, String fileName) throws IOException; - FileManager saveXml(Document document) throws IOException; + void saveXml(Document document, String fileName) throws IOException; + void saveXml(Document document) throws IOException; // Bitmap - FileManager saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる - FileManager saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる + void saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる + void saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる // Load diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 799a0851..5cf0eb10 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -187,22 +187,22 @@ public class FileManagerImpl implements FileManager { } @Override - public FileManager saveXml(Document document, String fileName) throws IOException { + public void saveXml(Document document, String fileName) throws IOException { return null; } @Override - public FileManager saveXml(Document document) throws IOException { + public void saveXml(Document document) throws IOException { return null; } @Override - public FileManager saveBitmap(Bitmap bitmap, String fileName) throws IOException { + public void saveBitmap(Bitmap bitmap, String fileName) throws IOException { return null; } @Override - public FileManager saveBitmap(Bitmap bitmap) throws IOException { + public void saveBitmap(Bitmap bitmap) throws IOException { return null; } From 3a41c4e1056c7ef404023ac938eee452d8dbc4ad Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:36:55 +0900 Subject: [PATCH 28/73] =?UTF-8?q?Save=E7=B3=BB=E3=81=AE=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=8B=E3=82=89=E3=83=81=E3=82=A7=E3=83=BC?= =?UTF-8?q?=E3=83=B3=E3=81=A7=E3=81=8D=E3=82=8B=E5=BF=85=E8=A6=81=E3=81=AF?= =?UTF-8?q?=E3=81=AA=E3=81=95=E3=81=9D=E3=81=86=E3=81=AA=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E6=88=BB=E3=82=8A=E5=80=A4=E3=82=92void=E3=81=AB=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 5cf0eb10..6b4e0619 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -188,22 +188,18 @@ public class FileManagerImpl implements FileManager { @Override public void saveXml(Document document, String fileName) throws IOException { - return null; } @Override public void saveXml(Document document) throws IOException { - return null; } @Override public void saveBitmap(Bitmap bitmap, String fileName) throws IOException { - return null; } @Override public void saveBitmap(Bitmap bitmap) throws IOException { - return null; } @Override From 76f4a6c22891ba48e173d0d42f815de7903a7ec8 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:37:23 +0900 Subject: [PATCH 29/73] =?UTF-8?q?saveXml=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 6b4e0619..1c238d06 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -188,10 +188,13 @@ public class FileManagerImpl implements FileManager { @Override public void saveXml(Document document, String fileName) throws IOException { + this.resolve(fileName); + this.saveXmlInternal(document); } @Override public void saveXml(Document document) throws IOException { + this.saveXmlInternal(document); } @Override From 0736a7326a7156887cb605da6110b244f88af1b6 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:38:48 +0900 Subject: [PATCH 30/73] =?UTF-8?q?saveBitmapInternal=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 1c238d06..a5e9ca4a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -185,6 +185,15 @@ public class FileManagerImpl implements FileManager { throw new IOException("Failed to save xml"); } } + private void saveBitmapInternal(Bitmap bitmap) throws IOException { + try { + File file = this.path.toFile(); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath())); + } catch (Exception e) { + logger.error("saveBitmapInternal", e.getMessage()); + throw new IOException("Failed to save bitmap"); + } + } @Override public void saveXml(Document document, String fileName) throws IOException { From 78525d634a2a37411fc6f6076da40f2d56ddf715 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:39:05 +0900 Subject: [PATCH 31/73] =?UTF-8?q?saveBitmap=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index a5e9ca4a..b7f8e8cd 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -208,10 +208,13 @@ public class FileManagerImpl implements FileManager { @Override public void saveBitmap(Bitmap bitmap, String fileName) throws IOException { + this.resolve(fileName); + this.saveBitmapInternal(bitmap); } @Override public void saveBitmap(Bitmap bitmap) throws IOException { + this.saveBitmapInternal(bitmap); } @Override From f36dc05db19018f9c717ed029f4d9369a6d92c9b Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:39:36 +0900 Subject: [PATCH 32/73] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b7f8e8cd..aa13271d 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -187,8 +187,7 @@ public class FileManagerImpl implements FileManager { } private void saveBitmapInternal(Bitmap bitmap) throws IOException { try { - File file = this.path.toFile(); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath())); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(this.path)); } catch (Exception e) { logger.error("saveBitmapInternal", e.getMessage()); throw new IOException("Failed to save bitmap"); From 3e2a295a225d8312fc48534810fc4393adc157e0 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:40:07 +0900 Subject: [PATCH 33/73] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 2 -- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ----- 2 files changed, 7 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index c1488183..6403ef98 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -19,8 +19,6 @@ public interface FileManager { boolean isFile(); boolean isWritable(); boolean isReadable(); - Document readXml(); - // Get current instance FileManager getCurrentInstance(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index aa13271d..f3c740b6 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -116,11 +116,6 @@ public class FileManagerImpl implements FileManager { } } - @Override - public Document readXml() { - return null; - } - @Override public FileManager getCurrentInstance() { return this; From f3465bcf81d99d3d7210ea4448b375f557b5081c Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:42:03 +0900 Subject: [PATCH 34/73] =?UTF-8?q?loadXml,=20loadXmlInternal=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index f3c740b6..da908b49 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -211,14 +211,27 @@ public class FileManagerImpl implements FileManager { this.saveBitmapInternal(bitmap); } + // Internal + private Document loadXmlInternal() throws IOException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + return builder.parse(Files.newInputStream(this.path.toFile().toPath())); + } catch (Exception e) { + logger.error("loadXmlInternal", e.getMessage()); + throw new IOException("Failed to load xml"); + } + } + @Override public Document loadXml(String fileName) throws IOException { - return null; + this.resolve(fileName); + return this.loadXmlInternal(); } @Override public Document loadXml() throws IOException { - return null; + return this.loadXmlInternal(); } @Override From 8587c6a70781f3a7be276c29e6a8ea278b0a5800 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:42:16 +0900 Subject: [PATCH 35/73] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index da908b49..849d69e2 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -216,7 +216,7 @@ public class FileManagerImpl implements FileManager { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); - return builder.parse(Files.newInputStream(this.path.toFile().toPath())); + return builder.parse(Files.newInputStream(this.path)); } catch (Exception e) { logger.error("loadXmlInternal", e.getMessage()); throw new IOException("Failed to load xml"); From c28d94e41771e6394f31a5f06a086965a6547504 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:44:40 +0900 Subject: [PATCH 36/73] =?UTF-8?q?loadBitmapInternal,=20loadBitmap=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/source/file/impl/FileManagerImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 849d69e2..81e0cd76 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -1,6 +1,7 @@ package one.nem.lacerta.source.file.impl; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import org.w3c.dom.Document; @@ -222,6 +223,14 @@ public class FileManagerImpl implements FileManager { throw new IOException("Failed to load xml"); } } + private Bitmap loadBitmapInternal() throws IOException { + try { + return BitmapFactory.decodeFile(this.path.toString()); + } catch (Exception e) { + logger.error("loadBitmapInternal", e.getMessage()); + throw new IOException("Failed to load bitmap"); + } + } @Override public Document loadXml(String fileName) throws IOException { @@ -236,11 +245,12 @@ public class FileManagerImpl implements FileManager { @Override public Bitmap loadBitmap(String fileName) throws IOException { - return null; + this.resolve(fileName); + return this.loadBitmapInternal(); } @Override public Bitmap loadBitmap() throws IOException { - return null; + return this.loadBitmapInternal(); } } From 8ca642c7f4f0d50a1c5610308e02fe056108f910 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:46:20 +0900 Subject: [PATCH 37/73] =?UTF-8?q?getFileRef=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 81e0cd76..1e8c72d1 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -68,7 +68,11 @@ public class FileManagerImpl implements FileManager { @Override public File getFileRef() { - return null; + if (this.isExist()) { + return this.path.toFile(); + } else { + return null; + } } @Override From f380e7eef8d949f98916f89cf522ff08fe390edb Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:48:11 +0900 Subject: [PATCH 38/73] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAimport?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 1e8c72d1..4e40da5a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -6,14 +6,9 @@ import android.graphics.BitmapFactory; import org.w3c.dom.Document; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.nio.file.DirectoryIteratorException; -import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; From 3a270cdc9fd464d840ee4ab161bd72e7384abd2f Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:48:32 +0900 Subject: [PATCH 39/73] =?UTF-8?q?logger=E3=82=92final=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 4e40da5a..e3587114 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -33,7 +33,7 @@ public class FileManagerImpl implements FileManager { // Injection - private LacertaLogger logger; + private final LacertaLogger logger; @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { From 7cdb005ebbb22d83a068b4b61edb2eff3884320b Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:49:51 +0900 Subject: [PATCH 40/73] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB/?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 6403ef98..97fb1dae 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -30,6 +30,12 @@ public interface FileManager { FileManager setPath(Path path); FileManager resolve(String path) throws IOException; + // Create + FileManager createFile() throws IOException; + FileManager createFile(String fileName) throws IOException; + FileManager createDirectory() throws IOException; + FileManager createDirectory(String directoryName) throws IOException; + // Save // XML void saveXml(Document document, String fileName) throws IOException; From 3a9053e987f34f08dce1e9d42c0e31ae8c02ebbc Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:50:01 +0900 Subject: [PATCH 41/73] impl --- .../source/file/impl/FileManagerImpl.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index e3587114..b7c46d78 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -165,6 +165,26 @@ public class FileManagerImpl implements FileManager { return this.setPath(resolvedPath); } + @Override + public FileManager createFile() throws IOException { + return null; + } + + @Override + public FileManager createFile(String fileName) throws IOException { + return null; + } + + @Override + public FileManager createDirectory() throws IOException { + return null; + } + + @Override + public FileManager createDirectory(String directoryName) throws IOException { + return null; + } + // Internal private void saveXmlInternal(Document document) throws IOException { try { From b0c97da38271a56f216f88060b80fde4bb4d1cea Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:52:18 +0900 Subject: [PATCH 42/73] =?UTF-8?q?createFile=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/source/file/impl/FileManagerImpl.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b7c46d78..5a59a4d1 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -167,12 +167,19 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createFile() throws IOException { - return null; + try { + Files.createFile(this.path); + } catch (Exception e) { + logger.error("createFile", e.getMessage()); + throw new IOException("Failed to create file"); + } + return this; } @Override - public FileManager createFile(String fileName) throws IOException { - return null; + public FileManager createFile(String fileName) throws IOException { // pathが書き換わってしまうのは想像できない挙動かも? + this.resolve(fileName); + return this.createFile(); } @Override From a2eb04e96bc66ec43a29b7f1898d71336ff49413 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:52:39 +0900 Subject: [PATCH 43/73] =?UTF-8?q?createDirectory=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 5a59a4d1..fc0d828e 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -184,12 +184,19 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createDirectory() throws IOException { - return null; + try { + Files.createDirectory(this.path); + } catch (Exception e) { + logger.error("createDirectory", e.getMessage()); + throw new IOException("Failed to create directory"); + } + return this; } @Override public FileManager createDirectory(String directoryName) throws IOException { - return null; + this.resolve(directoryName); + return this.createDirectory(); } // Internal From 0439a998e38094e434690c5a3723085c034aaa50 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 12:53:18 +0900 Subject: [PATCH 44/73] =?UTF-8?q?createDirectory=E5=AE=9F=E8=A3=85=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index fc0d828e..af0d4a25 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -185,7 +185,11 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createDirectory() throws IOException { try { - Files.createDirectory(this.path); + if (this.autoCreateParent) { // configとして管理する必要はないかも? + Files.createDirectories(this.path); + } else { + Files.createDirectory(this.path); + } } catch (Exception e) { logger.error("createDirectory", e.getMessage()); throw new IOException("Failed to create directory"); From b3a4207762d9b97408bb80f3469644d9e7b6d42a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:42:36 +0900 Subject: [PATCH 45/73] =?UTF-8?q?=E3=82=A2=E3=83=B3=E3=82=B3=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/impl/DocumentProcessorImpl.java | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 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 9e59ed2b..4056792f 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 @@ -50,74 +50,74 @@ public class DocumentProcessorImpl implements DocumentProcessor{ @Override public void init() { -// logger.debug("init", "called"); -// // Init Variables -// this.documentRootPath = this.documentDetail.getPath().getFullPath(); -// logger.debug("init", "documentRootPath: " + this.documentRootPath); -// -// this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager -// logger.debug("init", "fileManager created"); -// -// this.fileManager.autoCreateDir(this.documentRootPath); -// -// // rawディレクトリInit -// this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); -// -// // xmlファイルの読み込み -// if (fileManager.isExist("meta.xml")) { -// logger.debug("init", "meta.xml found"); -// try { -// xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); -// } catch (Exception e) { -// logger.debug("init", "meta.xml parse failed"); -// logger.trace("init", e.getMessage()); -// } -// } else { -// logger.debug("init", "meta.xml not found"); -// xmlMetaModel = new XmlMetaModel(); -// -// xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle()); -// xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); -// xmlMetaModel.setDescription(""); // FIXME-rca: -// xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch()); -// xmlMetaModel.setPages(new ArrayList<>()); -// -// try { -// this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); -// logger.debug("init", "meta.xml saved"); -// } catch (Exception e) { -// logger.error("init", "meta.xml save failed"); -// logger.trace("init", e.getMessage()); -// } -// } -// -// logger.info("init", "finished"); + logger.debug("init", "called"); + // Init Variables + this.documentRootPath = this.documentDetail.getPath().getFullPath(); + logger.debug("init", "documentRootPath: " + this.documentRootPath); + + this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager + logger.debug("init", "fileManager created"); + + this.fileManager.autoCreateDir(this.documentRootPath); + + // rawディレクトリInit + this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); + + // xmlファイルの読み込み + if (fileManager.isExist("meta.xml")) { + logger.debug("init", "meta.xml found"); + try { + xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); + } catch (Exception e) { + logger.debug("init", "meta.xml parse failed"); + logger.trace("init", e.getMessage()); + } + } else { + logger.debug("init", "meta.xml not found"); + xmlMetaModel = new XmlMetaModel(); + + xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle()); + xmlMetaModel.setAuthor(this.documentDetail.getAuthor()); + xmlMetaModel.setDescription(""); // FIXME-rca: + xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch()); + xmlMetaModel.setPages(new ArrayList<>()); + + try { + this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + logger.debug("init", "meta.xml saved"); + } catch (Exception e) { + logger.error("init", "meta.xml save failed"); + logger.trace("init", e.getMessage()); + } + } + + logger.info("init", "finished"); } @Override public void addNewPageToLast(Bitmap bitmap) { -// logger.debug("addNewPageToLast", "called"); -// String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする -// -// // FileManager -// if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 -// logger.debug("addNewPageToLast", "currentDir is documentRootPath"); -// } else { -// logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); -// this.fileManager.backRootDir(); -// this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); -// this.fileManager.changeDir(DEFAULT_SAVE_DIR); -// } -// logger.debug("addNewPageToLast", "DirInit finished"); -// -// // Save file -// this.fileManager.saveBitmapAtCurrent(bitmap, filename); -// -// // Update meta -// XmlMetaPageModel page = new XmlMetaPageModel(); -// page.setIndex(xmlMetaModel.getPages().size() + 1); -// page.setFilename(filename); -// xmlMetaModel.addPage(page); + logger.debug("addNewPageToLast", "called"); + String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする + + // FileManager + if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 + logger.debug("addNewPageToLast", "currentDir is documentRootPath"); + } else { + logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); + this.fileManager.backRootDir(); + this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); + this.fileManager.changeDir(DEFAULT_SAVE_DIR); + } + logger.debug("addNewPageToLast", "DirInit finished"); + + // Save file + this.fileManager.saveBitmapAtCurrent(bitmap, filename); + + // Update meta + XmlMetaPageModel page = new XmlMetaPageModel(); + page.setIndex(xmlMetaModel.getPages().size() + 1); + page.setFilename(filename); + xmlMetaModel.addPage(page); } @Override From a887446d2114b2cdea2b5ffa08e6d3322c0cf467 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:44:28 +0900 Subject: [PATCH 46/73] =?UTF-8?q?isExist=E3=81=AE=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 2 +- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 97fb1dae..cad34d3b 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -14,7 +14,7 @@ import java.util.List; public interface FileManager { File getFileRef(); - boolean isExist(); + boolean isExist(String name) throws IOException; boolean isDirectory(); boolean isFile(); boolean isWritable(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index af0d4a25..21987841 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -71,9 +71,9 @@ public class FileManagerImpl implements FileManager { } @Override - public boolean isExist() { - File file = this.path.toFile(); - return file.exists(); + public boolean isExist(String name) throws IOException { + Path resolvedPath = this.resolveStringPath(name); + return Files.exists(resolvedPath); } @Override From f3ac07e633a8eba14c79b1fedaff7ae6b677b666 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:45:27 +0900 Subject: [PATCH 47/73] =?UTF-8?q?throws=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/processor/DocumentProcessor.java | 2 +- .../nem/lacerta/processor/impl/DocumentProcessorImpl.java | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java index b611e6c1..f5e55c5a 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java +++ b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java @@ -19,6 +19,6 @@ public interface DocumentProcessor { int getPageCount(); void close(); - void init(); + void init() throws Exception; // TODO-rca: 例外処理 } 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 4056792f..7df5c163 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 @@ -49,7 +49,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ } @Override - public void init() { + public void init() throws Exception{ logger.debug("init", "called"); // Init Variables this.documentRootPath = this.documentDetail.getPath().getFullPath(); @@ -58,11 +58,6 @@ public class DocumentProcessorImpl implements DocumentProcessor{ this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager logger.debug("init", "fileManager created"); - this.fileManager.autoCreateDir(this.documentRootPath); - - // rawディレクトリInit - this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); - // xmlファイルの読み込み if (fileManager.isExist("meta.xml")) { logger.debug("init", "meta.xml found"); From 1af344a6d37973aff8e25dc7699ea656de2ddf01 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:47:58 +0900 Subject: [PATCH 48/73] =?UTF-8?q?throws=E8=BF=BD=E5=8A=A0,=20=E5=AE=9F?= =?UTF-8?q?=E8=A3=85WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/processor/DocumentProcessor.java | 4 +-- .../processor/impl/DocumentProcessorImpl.java | 29 ++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java index f5e55c5a..7d4e9fcb 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java +++ b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java @@ -5,8 +5,8 @@ import android.graphics.Bitmap; public interface DocumentProcessor { // ページ操作 - void addNewPageToLast(Bitmap bitmap); - void addNewPagesToLast(Bitmap[] bitmaps); + void addNewPageToLast(Bitmap bitmap) throws Exception; + void addNewPagesToLast(Bitmap[] bitmaps) throws Exception; void addNewPageAfterIndex(Bitmap bitmap, int index); void addNewPageBeforeIndex(Bitmap bitmap, int index); void removePageAtIndex(int index); 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 7df5c163..4631b33c 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 @@ -62,7 +62,8 @@ public class DocumentProcessorImpl implements DocumentProcessor{ if (fileManager.isExist("meta.xml")) { logger.debug("init", "meta.xml found"); try { - xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); + this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml")); + logger.debug("init", "meta.xml parsed"); } catch (Exception e) { logger.debug("init", "meta.xml parse failed"); logger.trace("init", e.getMessage()); @@ -78,7 +79,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ xmlMetaModel.setPages(new ArrayList<>()); try { - this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + this.fileManager.createFile("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel)); logger.debug("init", "meta.xml saved"); } catch (Exception e) { logger.error("init", "meta.xml save failed"); @@ -90,33 +91,15 @@ public class DocumentProcessorImpl implements DocumentProcessor{ } @Override - public void addNewPageToLast(Bitmap bitmap) { + public void addNewPageToLast(Bitmap bitmap) throws Exception{ logger.debug("addNewPageToLast", "called"); String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - // FileManager - if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 - logger.debug("addNewPageToLast", "currentDir is documentRootPath"); - } else { - logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); - this.fileManager.backRootDir(); - this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); - this.fileManager.changeDir(DEFAULT_SAVE_DIR); - } - logger.debug("addNewPageToLast", "DirInit finished"); - - // Save file - this.fileManager.saveBitmapAtCurrent(bitmap, filename); - - // Update meta - XmlMetaPageModel page = new XmlMetaPageModel(); - page.setIndex(xmlMetaModel.getPages().size() + 1); - page.setFilename(filename); - xmlMetaModel.addPage(page); + this.fileManager.resolve(DEFAULT_SAVE_DIR).createDirectory(); } @Override - public void addNewPagesToLast(Bitmap[] bitmaps) { + public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{ logger.debug("addNewPagesToLast", "called"); for (Bitmap bitmap : bitmaps) { From e055f8fe9ea62c84d26f02acab76ef2c9c5667f5 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:49:46 +0900 Subject: [PATCH 49/73] =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=81=8C=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=A0=E3=81=91=E6=96=B0=E8=A6=8F=E4=BD=9C=E6=88=90=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/FileManager.java | 3 +++ .../nem/lacerta/source/file/impl/FileManagerImpl.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index cad34d3b..f996e781 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -6,6 +6,7 @@ import org.w3c.dom.Document; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.nio.file.Path; import java.util.List; @@ -35,6 +36,8 @@ public interface FileManager { FileManager createFile(String fileName) throws IOException; FileManager createDirectory() throws IOException; FileManager createDirectory(String directoryName) throws IOException; + FileManager createDirectoryIfNotExist() throws IOException; + FileManager createDirectoryIfNotExist(String directoryName) throws IOException; // Save // XML diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 21987841..71826eb2 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -203,6 +203,16 @@ public class FileManagerImpl implements FileManager { return this.createDirectory(); } + @Override + public FileManager createDirectoryIfNotExist() throws IOException { + return null; + } + + @Override + public FileManager createDirectoryIfNotExist(String directoryName) throws IOException { + return null; + } + // Internal private void saveXmlInternal(Document document) throws IOException { try { From d88c9c2030c7453670ad5f61c7d292f87a5b4981 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:50:47 +0900 Subject: [PATCH 50/73] =?UTF-8?q?isExist=E3=82=92=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E3=81=AA=E3=81=97=E3=81=A7=E3=82=82=E5=AE=9F=E8=A1=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 1 + .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index f996e781..75eba626 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -16,6 +16,7 @@ public interface FileManager { File getFileRef(); boolean isExist(String name) throws IOException; + boolean isExist() throws IOException; boolean isDirectory(); boolean isFile(); boolean isWritable(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 71826eb2..aad29ce1 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -76,6 +76,11 @@ public class FileManagerImpl implements FileManager { return Files.exists(resolvedPath); } + @Override + public boolean isExist() throws IOException { + return Files.exists(this.path); + } + @Override public boolean isDirectory() { if (this.isExist()) { From 022e7e278a2f0adfbd26f5e683db3b6584077e7a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:51:19 +0900 Subject: [PATCH 51/73] fix --- .../src/main/java/one/nem/lacerta/source/file/FileManager.java | 2 +- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 75eba626..deee58e7 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -16,7 +16,7 @@ public interface FileManager { File getFileRef(); boolean isExist(String name) throws IOException; - boolean isExist() throws IOException; + boolean isExist(); boolean isDirectory(); boolean isFile(); boolean isWritable(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index aad29ce1..01c32484 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -77,7 +77,7 @@ public class FileManagerImpl implements FileManager { } @Override - public boolean isExist() throws IOException { + public boolean isExist(){ return Files.exists(this.path); } From fbde892f4088bce7e5412e2cba3e3f3da2fcd205 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:52:00 +0900 Subject: [PATCH 52/73] =?UTF-8?q?ifNotExist=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 01c32484..b146a17a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -210,12 +210,16 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createDirectoryIfNotExist() throws IOException { - return null; + if (!this.isExist()) { + this.createDirectory(); + } + return this; } @Override public FileManager createDirectoryIfNotExist(String directoryName) throws IOException { - return null; + this.resolve(directoryName); + return this.createDirectoryIfNotExist(); } // Internal From 7951bef6e0188116ed309f06ca77eaefcf4a17af Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:02:07 +0900 Subject: [PATCH 53/73] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=87=A6=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/impl/DocumentProcessorImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 4631b33c..2b1959dd 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 @@ -95,7 +95,17 @@ public class DocumentProcessorImpl implements DocumentProcessor{ logger.debug("addNewPageToLast", "called"); String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - this.fileManager.resolve(DEFAULT_SAVE_DIR).createDirectory(); + FileManager rawFileManager = fileManager.resolve(DEFAULT_SAVE_DIR).createDirectoryIfNotExist().getCurrentInstance(); + + rawFileManager.saveBitmap(bitmap, filename); + + XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel(); + xmlMetaPageModel.setFilename(filename); + xmlMetaPageModel.setIndex(xmlMetaModel.getPages().size() + 1); + xmlMetaModel.getPages().add(xmlMetaPageModel); + + logger.info("addNewPageToLast", "finished"); + logger.info("addNewPageToLast", "filename: " + filename + ", index: " + xmlMetaPageModel.getIndex()); } @Override From e8804e8f840598b20b1a3a97b0c5dd45a591d362 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:03:29 +0900 Subject: [PATCH 54/73] =?UTF-8?q?close=E5=87=A6=E7=90=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/processor/DocumentProcessor.java | 2 +- .../processor/impl/DocumentProcessorImpl.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java index 7d4e9fcb..abca8a84 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java +++ b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java @@ -18,7 +18,7 @@ public interface DocumentProcessor { Bitmap getPageAtIndex(int index); int getPageCount(); - void close(); + void close() throws Exception; void init() throws Exception; // TODO-rca: 例外処理 } 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 2b1959dd..16213258 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 @@ -148,18 +148,16 @@ public class DocumentProcessorImpl implements DocumentProcessor{ } @Override - public void close() { + public void close() throws Exception{ logger.debug("close", "called"); - // TODO-rca: ここでxmlファイルを保存する - this.fileManager.backRootDir(); - - try { - this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); - logger.debug("close", "meta.xml saved"); - } catch (Exception e) { - logger.error("close", "meta.xml save failed"); - logger.trace("close", e.getMessage()); + if (this.fileManager.isExist("meta.xml")) { + try { + this.fileManager.createFile("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel)); + logger.debug("close", "meta.xml saved"); + } catch (Exception e) { + logger.error("close", "meta.xml save failed"); + logger.trace("close", e.getMessage()); + } } - logger.info("close", "finished"); } } From 69b60944b4ae081d58ce2c5aa0b24ea0afd38ded Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:09:05 +0900 Subject: [PATCH 55/73] =?UTF-8?q?=E6=9A=AB=E5=AE=9A)=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=83=8F=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ScannerDataManagerStubFragment.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java index 2d15b51b..ee5ef1f5 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java @@ -185,9 +185,21 @@ public class ScannerDataManagerStubFragment extends Fragment { bitmaps[i] = results.get(i).getBitmap(); } - this.documentProcessor.addNewPagesToLast(bitmaps); + try { + this.documentProcessor.addNewPagesToLast(bitmaps); + } catch (Exception e) { + Toast.makeText(getActivity(), "Error occurred while adding pages", Toast.LENGTH_LONG).show(); + Log.e("ScannerDataManagerStubFragment", "Error occurred while adding pages", e); + } - this.documentProcessor.close(); + Toast.makeText(getActivity(), "pages added", Toast.LENGTH_LONG).show(); + + try { + this.documentProcessor.close(); + } catch (Exception e) { + Toast.makeText(getActivity(), "Error occurred while closing documentProcessor", Toast.LENGTH_LONG).show(); + Log.e("ScannerDataManagerStubFragment", "Error occurred while closing documentProcessor", e); + } }); } From 730640425f23e347e5c7fd0b34e9a5342ed9c604 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:09:27 +0900 Subject: [PATCH 56/73] =?UTF-8?q?=E6=9A=AB=E5=AE=9A)=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=83=8F=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/scanner/ScannerDataManagerStubFragment.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java index ee5ef1f5..043f5cb7 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java @@ -169,7 +169,12 @@ public class ScannerDataManagerStubFragment extends Fragment { } this.documentProcessor = documentProcessorFactory.create(this.documentDetail); Toast.makeText(getActivity(), "documentProcessor created", Toast.LENGTH_LONG).show(); - this.documentProcessor.init(); + try { + this.documentProcessor.init(); + } catch (Exception e) { + Toast.makeText(getActivity(), "Error occurred while initializing documentProcessor", Toast.LENGTH_LONG).show(); + Log.e("ScannerDataManagerStubFragment", "Error occurred while initializing documentProcessor", e); + } Toast.makeText(getActivity(), "documentProcessor initialized", Toast.LENGTH_LONG).show(); }); From 360580eff2492daddcb8f3a0dfc147137a332ab6 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:20:06 +0900 Subject: [PATCH 57/73] =?UTF-8?q?=E8=87=AA=E5=8B=95=E3=81=A7=E3=83=91?= =?UTF-8?q?=E3=82=B9=E8=A7=A3=E6=B1=BA=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/processor/impl/DocumentProcessorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 16213258..079b3681 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,7 +55,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ this.documentRootPath = this.documentDetail.getPath().getFullPath(); logger.debug("init", "documentRootPath: " + this.documentRootPath); - this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager + this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager logger.debug("init", "fileManager created"); // xmlファイルの読み込み From 4cf3ff5f3cd3a2b9b4579efa282a549ce1702c4e Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:24:43 +0900 Subject: [PATCH 58/73] =?UTF-8?q?createFile=E3=81=AE=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=A7=E3=82=82=E8=A6=AA=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=82=92=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/source/file/impl/FileManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b146a17a..01f0bc07 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -173,6 +173,9 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createFile() throws IOException { try { + if (this.autoCreateParent) { + Files.createDirectories(this.path.getParent()); + } Files.createFile(this.path); } catch (Exception e) { logger.error("createFile", e.getMessage()); From 8913f8118dc9422e864812903389ed9b41d1893e Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 14:31:01 +0900 Subject: [PATCH 59/73] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=8C=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AB=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/FileManager.java | 2 ++ .../lacerta/source/file/impl/FileManagerImpl.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index deee58e7..3a088591 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -35,6 +35,8 @@ public interface FileManager { // Create FileManager createFile() throws IOException; FileManager createFile(String fileName) throws IOException; + FileManager createFileIfNotExist() throws IOException; + FileManager createFileIfNotExist(String fileName) throws IOException; FileManager createDirectory() throws IOException; FileManager createDirectory(String directoryName) throws IOException; FileManager createDirectoryIfNotExist() throws IOException; diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 01f0bc07..ed011f9c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -190,6 +190,20 @@ public class FileManagerImpl implements FileManager { return this.createFile(); } + @Override + public FileManager createFileIfNotExist() throws IOException { + if (!this.isExist()) { + this.createFile(); + } + return this; + } + + @Override + public FileManager createFileIfNotExist(String fileName) throws IOException { + this.resolve(fileName); + return this.createFileIfNotExist(); + } + @Override public FileManager createDirectory() throws IOException { try { @@ -237,6 +251,7 @@ public class FileManagerImpl implements FileManager { transformer.transform(source, result); } catch (Exception e) { logger.error("saveXmlInternal", e.getMessage()); + e.printStackTrace(); throw new IOException("Failed to save xml"); } } From 943ca1daf58dd33a994e007aa49260240e42a7e4 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:05:28 +0900 Subject: [PATCH 60/73] =?UTF-8?q?=E6=96=B0=E3=81=97=E3=81=84=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=99=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/source/file/impl/FileManagerImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index ed011f9c..b9c39de8 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -34,13 +34,21 @@ public class FileManagerImpl implements FileManager { // Injection private final LacertaLogger logger; - @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; this.rootDir = rootDir; } + // for generate new instance + public FileManagerImpl(LacertaLogger logger, Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { + this.logger = logger; + this.rootDir = rootDir; + this.path = path; + this.autoCreateParent = autoCreateParent; + this.disableRootDirCheck = disableRootDirCheck; + } + // Internal private Path resolveStringPath(String path) throws IOException{ String[] pathArray = path.split("/"); @@ -61,6 +69,11 @@ public class FileManagerImpl implements FileManager { return resolvedPath; } + private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { + logger.debug("newInstance", "Generating new instance"); + return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck); + } + @Override public File getFileRef() { if (this.isExist()) { From 30ed65079b28f58ff572a8b1cebe7528c2889cbe Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:10:19 +0900 Subject: [PATCH 61/73] WIP --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b9c39de8..013c5b47 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -153,22 +153,22 @@ public class FileManagerImpl implements FileManager { @Override public FileManager setRootDir(Path rootDir) { - this.rootDir = rootDir; - return this; + return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck); } @Override public FileManager setPath(Path path) { + Path resolvedPath; if (this.disableRootDirCheck) { - this.path = path; + resolvedPath = path; } else { if (path.startsWith(this.rootDir)) { - this.path = path; + resolvedPath = path; } else { throw new IllegalArgumentException("path must be in rootDir"); } } - return this; + return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck); } @Override From 1b676f83681f69cf322faecdf3806d82ad0ef05f Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:10:27 +0900 Subject: [PATCH 62/73] Revert "WIP" This reverts commit 30ed65079b28f58ff572a8b1cebe7528c2889cbe. --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 013c5b47..b9c39de8 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -153,22 +153,22 @@ public class FileManagerImpl implements FileManager { @Override public FileManager setRootDir(Path rootDir) { - return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck); + this.rootDir = rootDir; + return this; } @Override public FileManager setPath(Path path) { - Path resolvedPath; if (this.disableRootDirCheck) { - resolvedPath = path; + this.path = path; } else { if (path.startsWith(this.rootDir)) { - resolvedPath = path; + this.path = path; } else { throw new IllegalArgumentException("path must be in rootDir"); } } - return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck); + return this; } @Override From 27aa6a2f156586baec8cf1303b991234103a1598 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:10:27 +0900 Subject: [PATCH 63/73] =?UTF-8?q?Revert=20"=E6=96=B0=E3=81=97=E3=81=84?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=9F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 943ca1daf58dd33a994e007aa49260240e42a7e4. --- .../lacerta/source/file/impl/FileManagerImpl.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index b9c39de8..ed011f9c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -34,21 +34,13 @@ public class FileManagerImpl implements FileManager { // Injection private final LacertaLogger logger; + @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; this.rootDir = rootDir; } - // for generate new instance - public FileManagerImpl(LacertaLogger logger, Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { - this.logger = logger; - this.rootDir = rootDir; - this.path = path; - this.autoCreateParent = autoCreateParent; - this.disableRootDirCheck = disableRootDirCheck; - } - // Internal private Path resolveStringPath(String path) throws IOException{ String[] pathArray = path.split("/"); @@ -69,11 +61,6 @@ public class FileManagerImpl implements FileManager { return resolvedPath; } - private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { - logger.debug("newInstance", "Generating new instance"); - return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck); - } - @Override public File getFileRef() { if (this.isExist()) { From c05d45afdddd73f5f8ff67ec43939486aea37f01 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:11:15 +0900 Subject: [PATCH 64/73] fix --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index ed011f9c..109f9d8a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -174,7 +174,9 @@ public class FileManagerImpl implements FileManager { public FileManager createFile() throws IOException { try { if (this.autoCreateParent) { - Files.createDirectories(this.path.getParent()); + if (!this.path.getParent().toFile().exists()) { + Files.createDirectories(this.path.getParent()); + } } Files.createFile(this.path); } catch (Exception e) { From 1efac1ffb69db3229fe4cdf3da6d81b90e9a3db4 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:18:30 +0900 Subject: [PATCH 65/73] =?UTF-8?q?Revert=20"Revert=20"=E6=96=B0=E3=81=97?= =?UTF-8?q?=E3=81=84=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=9F""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 27aa6a2f156586baec8cf1303b991234103a1598. --- .../lacerta/source/file/impl/FileManagerImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 109f9d8a..207ac5f5 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -34,13 +34,21 @@ public class FileManagerImpl implements FileManager { // Injection private final LacertaLogger logger; - @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; this.rootDir = rootDir; } + // for generate new instance + public FileManagerImpl(LacertaLogger logger, Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { + this.logger = logger; + this.rootDir = rootDir; + this.path = path; + this.autoCreateParent = autoCreateParent; + this.disableRootDirCheck = disableRootDirCheck; + } + // Internal private Path resolveStringPath(String path) throws IOException{ String[] pathArray = path.split("/"); @@ -61,6 +69,11 @@ public class FileManagerImpl implements FileManager { return resolvedPath; } + private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { + logger.debug("newInstance", "Generating new instance"); + return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck); + } + @Override public File getFileRef() { if (this.isExist()) { From 65a25ad2282e34c8cd77a6af0fcb1971a77f1c99 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:18:31 +0900 Subject: [PATCH 66/73] Revert "Revert "WIP"" This reverts commit 1b676f83681f69cf322faecdf3806d82ad0ef05f. --- .../nem/lacerta/source/file/impl/FileManagerImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 207ac5f5..66b60886 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -153,22 +153,22 @@ public class FileManagerImpl implements FileManager { @Override public FileManager setRootDir(Path rootDir) { - this.rootDir = rootDir; - return this; + return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck); } @Override public FileManager setPath(Path path) { + Path resolvedPath; if (this.disableRootDirCheck) { - this.path = path; + resolvedPath = path; } else { if (path.startsWith(this.rootDir)) { - this.path = path; + resolvedPath = path; } else { throw new IllegalArgumentException("path must be in rootDir"); } } - return this; + return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck); } @Override From 01e111bdd5559c308156ba29f676a52466391e7a Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:27:42 +0900 Subject: [PATCH 67/73] =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AB=E5=BF=9C?= =?UTF-8?q?=E3=81=98=E3=81=A6=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=82=92=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 99 ++++++++++--------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 66b60886..1781457a 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -183,26 +183,31 @@ public class FileManagerImpl implements FileManager { return this.setPath(resolvedPath); } - @Override - public FileManager createFile() throws IOException { + // Internal + private void createFileInternal(Path path) throws IOException { try { if (this.autoCreateParent) { - if (!this.path.getParent().toFile().exists()) { - Files.createDirectories(this.path.getParent()); + if (!path.getParent().toFile().exists()) { + Files.createDirectories(path.getParent()); } } - Files.createFile(this.path); + Files.createFile(path); } catch (Exception e) { - logger.error("createFile", e.getMessage()); + logger.error("createFileInternal", e.getMessage()); throw new IOException("Failed to create file"); } + } + + @Override + public FileManager createFile() throws IOException { + this.createFileInternal(this.path); return this; } @Override public FileManager createFile(String fileName) throws IOException { // pathが書き換わってしまうのは想像できない挙動かも? - this.resolve(fileName); - return this.createFile(); + this.createFileInternal(this.resolveStringPath(fileName)); + return this; } @Override @@ -215,29 +220,37 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createFileIfNotExist(String fileName) throws IOException { - this.resolve(fileName); - return this.createFileIfNotExist(); + if (!this.isExist(fileName)) { + this.createFile(fileName); + } + return this; + } + + // Internal + private void createDirectoryInternal(Path path) throws IOException { + try { + if (this.autoCreateParent) { + if (!path.getParent().toFile().exists()) { + Files.createDirectories(path.getParent()); + } + } + Files.createDirectory(path); + } catch (Exception e) { + logger.error("createDirectoryInternal", e.getMessage()); + throw new IOException("Failed to create directory"); + } } @Override public FileManager createDirectory() throws IOException { - try { - if (this.autoCreateParent) { // configとして管理する必要はないかも? - Files.createDirectories(this.path); - } else { - Files.createDirectory(this.path); - } - } catch (Exception e) { - logger.error("createDirectory", e.getMessage()); - throw new IOException("Failed to create directory"); - } + this.createDirectoryInternal(this.path); return this; } @Override public FileManager createDirectory(String directoryName) throws IOException { - this.resolve(directoryName); - return this.createDirectory(); + this.createDirectoryInternal(this.resolveStringPath(directoryName)); + return this; } @Override @@ -250,18 +263,20 @@ public class FileManagerImpl implements FileManager { @Override public FileManager createDirectoryIfNotExist(String directoryName) throws IOException { - this.resolve(directoryName); - return this.createDirectoryIfNotExist(); + if (!this.isExist(directoryName)) { + this.createDirectory(directoryName); + } + return this; } // Internal - private void saveXmlInternal(Document document) throws IOException { + private void saveXmlInternal(Document document, Path path) throws IOException { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); - StreamResult result = new StreamResult(this.path.toFile()); + StreamResult result = new StreamResult(path.toFile()); transformer.transform(source, result); } catch (Exception e) { @@ -270,9 +285,9 @@ public class FileManagerImpl implements FileManager { throw new IOException("Failed to save xml"); } } - private void saveBitmapInternal(Bitmap bitmap) throws IOException { + private void saveBitmapInternal(Bitmap bitmap, Path path) throws IOException { try { - bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(this.path)); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(path)); } catch (Exception e) { logger.error("saveBitmapInternal", e.getMessage()); throw new IOException("Failed to save bitmap"); @@ -281,40 +296,38 @@ public class FileManagerImpl implements FileManager { @Override public void saveXml(Document document, String fileName) throws IOException { - this.resolve(fileName); - this.saveXmlInternal(document); + this.saveXmlInternal(document, this.resolveStringPath(fileName)); } @Override public void saveXml(Document document) throws IOException { - this.saveXmlInternal(document); + this.saveXmlInternal(document, this.path); } @Override public void saveBitmap(Bitmap bitmap, String fileName) throws IOException { - this.resolve(fileName); - this.saveBitmapInternal(bitmap); + this.saveBitmapInternal(bitmap, this.resolveStringPath(fileName)); } @Override public void saveBitmap(Bitmap bitmap) throws IOException { - this.saveBitmapInternal(bitmap); + this.saveBitmapInternal(bitmap, this.path); } // Internal - private Document loadXmlInternal() throws IOException { + private Document loadXmlInternal(Path path) throws IOException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); - return builder.parse(Files.newInputStream(this.path)); + return builder.parse(Files.newInputStream(path)); } catch (Exception e) { logger.error("loadXmlInternal", e.getMessage()); throw new IOException("Failed to load xml"); } } - private Bitmap loadBitmapInternal() throws IOException { + private Bitmap loadBitmapInternal(Path path) throws IOException { try { - return BitmapFactory.decodeFile(this.path.toString()); + return BitmapFactory.decodeFile(path.toString()); } catch (Exception e) { logger.error("loadBitmapInternal", e.getMessage()); throw new IOException("Failed to load bitmap"); @@ -323,23 +336,21 @@ public class FileManagerImpl implements FileManager { @Override public Document loadXml(String fileName) throws IOException { - this.resolve(fileName); - return this.loadXmlInternal(); + return this.loadXmlInternal(this.resolveStringPath(fileName)); } @Override public Document loadXml() throws IOException { - return this.loadXmlInternal(); + return this.loadXmlInternal(this.path); } @Override public Bitmap loadBitmap(String fileName) throws IOException { - this.resolve(fileName); - return this.loadBitmapInternal(); + return this.loadBitmapInternal(this.resolveStringPath(fileName)); } @Override public Bitmap loadBitmap() throws IOException { - return this.loadBitmapInternal(); + return this.loadBitmapInternal(this.path); } } From 36ecb3ab13d172da04f3e55a81662abc7297b88c Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:30:18 +0900 Subject: [PATCH 68/73] =?UTF-8?q?=E6=96=B0=E3=81=97=E3=81=84=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/source/file/FileManager.java | 1 + .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index 3a088591..41909906 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -23,6 +23,7 @@ public interface FileManager { boolean isReadable(); // Get current instance FileManager getCurrentInstance(); + FileManager getNewInstance(); // Configure FileManager enableAutoCreateParent(); diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 1781457a..18f6b595 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -139,6 +139,11 @@ public class FileManagerImpl implements FileManager { return this; } + @Override + public FileManager getNewInstance() { + return this.newInstance(this.rootDir, this.rootDir, this.autoCreateParent, this.disableRootDirCheck); + } + @Override public FileManager enableAutoCreateParent() { this.autoCreateParent = true; From 9065ee1e1f6aa8ea3e694c0655bd68f7ff945496 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:52:47 +0900 Subject: [PATCH 69/73] =?UTF-8?q?=E3=83=AD=E3=82=B0=E8=BF=BD=E5=8A=A0,=20?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=A0=B4=E6=89=80=E3=81=8C=E7=95=B0=E5=B8=B8?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/source/file/impl/FileManagerImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 18f6b595..6f8677db 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -52,7 +52,7 @@ public class FileManagerImpl implements FileManager { // Internal private Path resolveStringPath(String path) throws IOException{ String[] pathArray = path.split("/"); - Path resolvedPath = this.rootDir; + Path resolvedPath = this.path; for (String pathPart : pathArray) { if (pathPart.equals("..")) { resolvedPath = resolvedPath.getParent(); @@ -71,6 +71,7 @@ public class FileManagerImpl implements FileManager { private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) { logger.debug("newInstance", "Generating new instance"); + logger.debug("newInstance", "Path: " + path); return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck); } @@ -173,6 +174,7 @@ public class FileManagerImpl implements FileManager { throw new IllegalArgumentException("path must be in rootDir"); } } + logger.debug("setPath", "resolvedPath: " + resolvedPath); return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck); } @@ -292,6 +294,7 @@ public class FileManagerImpl implements FileManager { } private void saveBitmapInternal(Bitmap bitmap, Path path) throws IOException { try { + logger.debug("saveBitmapInternal", "path: " + path); bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(path)); } catch (Exception e) { logger.error("saveBitmapInternal", e.getMessage()); From 3cafa05b279b817b9797d1bd9595a9d0a9627035 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:53:20 +0900 Subject: [PATCH 70/73] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/processor/impl/DocumentProcessorImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 079b3681..bde4cb02 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 @@ -95,9 +95,9 @@ public class DocumentProcessorImpl implements DocumentProcessor{ logger.debug("addNewPageToLast", "called"); String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - FileManager rawFileManager = fileManager.resolve(DEFAULT_SAVE_DIR).createDirectoryIfNotExist().getCurrentInstance(); + FileManager imageFileManager = fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR); - rawFileManager.saveBitmap(bitmap, filename); + imageFileManager.saveBitmap(bitmap, filename); XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel(); xmlMetaPageModel.setFilename(filename); From 5fb938c263d8f16026ae2c43679aca275f78d242 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:54:14 +0900 Subject: [PATCH 71/73] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/processor/impl/DocumentProcessorImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 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 bde4cb02..8a7b8465 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 @@ -95,9 +95,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ logger.debug("addNewPageToLast", "called"); String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - FileManager imageFileManager = fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR); - - imageFileManager.saveBitmap(bitmap, filename); + this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename); XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel(); xmlMetaPageModel.setFilename(filename); From fe3d332a36b51d03e63b76f65601a84647bc058f Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 15:56:47 +0900 Subject: [PATCH 72/73] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/impl/DocumentProcessorImpl.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 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 8a7b8465..e876d44e 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 @@ -56,10 +56,13 @@ public class DocumentProcessorImpl implements DocumentProcessor{ logger.debug("init", "documentRootPath: " + this.documentRootPath); this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager + + FileManager initFileManager = this.fileManager.getNewInstance(); + logger.debug("init", "fileManager created"); // xmlファイルの読み込み - if (fileManager.isExist("meta.xml")) { + if (initFileManager.isExist("meta.xml")) { logger.debug("init", "meta.xml found"); try { this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml")); @@ -79,7 +82,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ xmlMetaModel.setPages(new ArrayList<>()); try { - this.fileManager.createFile("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel)); + initFileManager.createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); logger.debug("init", "meta.xml saved"); } catch (Exception e) { logger.error("init", "meta.xml save failed"); @@ -148,14 +151,12 @@ public class DocumentProcessorImpl implements DocumentProcessor{ @Override public void close() throws Exception{ logger.debug("close", "called"); - if (this.fileManager.isExist("meta.xml")) { - try { - this.fileManager.createFile("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel)); - logger.debug("close", "meta.xml saved"); - } catch (Exception e) { - logger.error("close", "meta.xml save failed"); - logger.trace("close", e.getMessage()); - } + try { + this.fileManager.createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + logger.debug("close", "meta.xml saved"); + } catch (Exception e) { + logger.error("close", "meta.xml save failed"); + logger.trace("close", e.getMessage()); } } } From af836ed486cc812e4739f37bda6536fdcd4a5b5b Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 16:18:02 +0900 Subject: [PATCH 73/73] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/processor/impl/DocumentProcessorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e876d44e..ad31fc6c 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 @@ -152,7 +152,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ public void close() throws Exception{ logger.debug("close", "called"); try { - this.fileManager.createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + this.fileManager.getNewInstance().createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); logger.debug("close", "meta.xml saved"); } catch (Exception e) { logger.error("close", "meta.xml save failed");