mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
100
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89a3a179bd | ||
|
|
ff905d9280 | ||
|
|
4b0ea02f16 | ||
|
|
ca37a97e2f | ||
|
|
217f096a38 | ||
|
|
0c59c85b28 | ||
|
|
e3a5dee36c | ||
|
|
1805cd7d73 | ||
|
|
513a91b41e | ||
|
|
3f2534b1eb | ||
|
|
af836ed486 | ||
|
|
fe3d332a36 | ||
|
|
5fb938c263 | ||
|
|
3cafa05b27 | ||
|
|
9065ee1e1f | ||
|
|
36ecb3ab13 | ||
|
|
01e111bdd5 | ||
|
|
65a25ad228 | ||
|
|
1efac1ffb6 | ||
|
|
c05d45afdd | ||
|
|
27aa6a2f15 | ||
|
|
1b676f8368 | ||
|
|
30ed65079b | ||
|
|
943ca1daf5 | ||
|
|
8913f8118d | ||
|
|
4cf3ff5f3c | ||
|
|
360580eff2 | ||
|
|
730640425f | ||
|
|
69b60944b4 | ||
|
|
e8804e8f84 | ||
|
|
7951bef6e0 | ||
|
|
fbde892f40 | ||
|
|
022e7e278a | ||
|
|
d88c9c2030 | ||
|
|
e055f8fe9e | ||
|
|
1af344a6d3 | ||
|
|
f3ac07e633 | ||
|
|
a887446d21 | ||
|
|
b3a4207762 | ||
|
|
0439a998e3 | ||
|
|
a2eb04e96b | ||
|
|
b0c97da382 | ||
|
|
3a9053e987 | ||
|
|
7cdb005ebb | ||
|
|
3a270cdc9f | ||
|
|
f380e7eef8 | ||
|
|
8ca642c7f4 | ||
|
|
c28d94e417 | ||
|
|
8587c6a707 | ||
|
|
f3465bcf81 | ||
|
|
3e2a295a22 | ||
|
|
f36dc05db1 | ||
|
|
78525d634a | ||
|
|
0736a7326a | ||
|
|
76f4a6c228 | ||
|
|
3a41c4e105 | ||
|
|
301678658c | ||
|
|
e20b3f4a35 | ||
|
|
e0a344bb48 | ||
|
|
a2eda32183 | ||
|
|
0f8b71e739 | ||
|
|
91fe39d141 | ||
|
|
0dced5d0dc | ||
|
|
9e5b2dad46 | ||
|
|
5c931ece3f | ||
|
|
3b861e3a07 | ||
|
|
37497cb1ea | ||
|
|
3efaf30b95 | ||
|
|
9142696fac | ||
|
|
d5cf2f31d6 | ||
|
|
fcda369a2e | ||
|
|
9faf5c9055 | ||
|
|
0d78f9fa7c | ||
|
|
8ebc96fa98 | ||
|
|
2b8766db0a | ||
|
|
2233bb1a35 | ||
|
|
c513b44e8d | ||
|
|
cc35d8a5ea | ||
|
|
16ac36dd4f | ||
|
|
eadd65a334 | ||
|
|
3ed835ef2f | ||
|
|
4a66ed786d | ||
|
|
89e2f15a29 | ||
|
|
717b8e9637 | ||
|
|
3e24896bd1 | ||
|
|
94943184c4 | ||
|
|
30f2dc39ae | ||
|
|
4621025e62 | ||
|
|
164527d41a | ||
|
|
d770ac76aa | ||
|
|
642f306ad6 | ||
|
|
930b48af2f | ||
|
|
54f2076eda | ||
|
|
c31a590ce3 | ||
|
|
2402936a19 | ||
|
|
ba87fb283e | ||
|
|
c35c4e829e | ||
|
|
017748b4a6 | ||
|
|
c2ee49d274 | ||
|
|
dd98602309 |
No files matched your search
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: 不具合用テンプレート
|
||||
about: 不具合用テンプレート
|
||||
title: "[BUG]: "
|
||||
labels: バグ
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
# 概要
|
||||
<!-- Issueの概要 -->
|
||||
|
||||
# 詳細
|
||||
<!-- バグの詳細 -->
|
||||
|
||||
# 影響箇所
|
||||
<!-- 予想される影響箇所(省略可) -->
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: 改善用テンプレート
|
||||
about: 改善用テンプレート
|
||||
title: "[IMPROVE]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
# 概要
|
||||
<!-- Issueの概要 -->
|
||||
|
||||
# 詳細
|
||||
<!-- 改善内容の詳細 -->
|
||||
|
||||
# 影響箇所
|
||||
<!-- 予想される影響箇所(省略可) -->
|
||||
@@ -1,10 +1,20 @@
|
||||
---
|
||||
name: 新機能用テンプレート
|
||||
about: 新規開発Issue用テンプレート
|
||||
about: 新規能用テンプレート
|
||||
title: ''
|
||||
labels: ''
|
||||
labels: 新機能
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
WIP
|
||||
# 概要
|
||||
<!-- Issueの概要 -->
|
||||
|
||||
# 詳細
|
||||
<!-- 機能の詳細 -->
|
||||
|
||||
# 関連Issue
|
||||
<!-- 関連するIssueがあれば -->
|
||||
|
||||
# 影響箇所
|
||||
<!-- 予想される影響箇所(省略可) -->
|
||||
@@ -0,0 +1,18 @@
|
||||
# 概要
|
||||
<!-- PRの概要 -->
|
||||
|
||||
# 関連Issue
|
||||
- #000 <!-- 関連するIssueを指定(なければ省略可) -->
|
||||
|
||||
# 詳細
|
||||
<!-- 詳細 -->
|
||||
|
||||
# 影響箇所
|
||||
<!-- 予想される影響箇所 -->
|
||||
|
||||
# チェック
|
||||
<!-- 参考用, 全てにチェックがついている必要があるわけではありません -->
|
||||
- [ ] 機能として完成している
|
||||
- [ ] WIP(Work in progress: 作業中)
|
||||
- [ ] 正常にビルド/起動ができる
|
||||
- [ ] 既存の機能を壊していない
|
||||
Generated
-17
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="ZY227DCBHN" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-12-21T04:53:14.729902700Z" />
|
||||
</component>
|
||||
</project>
|
||||
+20
-3
@@ -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();
|
||||
});
|
||||
|
||||
@@ -185,9 +190,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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+37
-37
@@ -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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'com.google.dagger.hilt.android'
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -46,5 +47,9 @@ dependencies {
|
||||
|
||||
implementation project(':shared:ui')
|
||||
|
||||
implementation project(':model')
|
||||
|
||||
implementation project(':data')
|
||||
|
||||
|
||||
}
|
||||
@@ -10,12 +10,18 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import one.nem.lacerta.model.document.DocumentMeta;
|
||||
|
||||
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
||||
|
||||
private List<String> documentList;
|
||||
private List<DocumentMeta> documentMetas;
|
||||
|
||||
public DocumentAdapter(List<String> documentList) {
|
||||
this.documentList = documentList;
|
||||
public DocumentAdapter(List<DocumentMeta> documentMetas) {
|
||||
// nullの場合に例外を発生させる
|
||||
if (documentMetas == null) {
|
||||
throw new IllegalArgumentException("DocumentMetas list cannot be null or empty");
|
||||
}
|
||||
this.documentMetas = documentMetas;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -27,12 +33,15 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
|
||||
holder.title.setText(documentList.get(position));
|
||||
DocumentMeta documentMeta = documentMetas.get(position);
|
||||
if (documentMeta != null) {
|
||||
holder.title.setText(documentMeta.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return documentList.size();
|
||||
return documentMetas.size();
|
||||
}
|
||||
|
||||
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
||||
@@ -40,7 +49,7 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
||||
|
||||
DocumentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.debug_menu_item_title);
|
||||
title = itemView.findViewById(R.id.debug_menu_item_title); // 適切な id に変更する
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -8,6 +8,9 @@ import android.widget.TextView;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
// LibraryArchiveFragment.java
|
||||
|
||||
//画面変移用のコード
|
||||
//Fragmentへのデータの受け渡し機能
|
||||
public class LibraryArchiveFragment extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
//Fragmentにデータを受け渡す機能
|
||||
public class LibraryDocFragment extends Fragment {
|
||||
|
||||
private TextView textView; // フィールドとして TextView を定義
|
||||
|
||||
+18
-5
@@ -13,17 +13,29 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.lacerta.data.Document;
|
||||
import one.nem.lacerta.model.document.DocumentMeta;
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link LibraryTopFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
public class LibraryTopFragment extends Fragment {
|
||||
|
||||
@Inject
|
||||
Document document;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
@@ -76,13 +88,14 @@ public class LibraryTopFragment extends Fragment {
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||
documentRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
List<String> documentList = new ArrayList<>();
|
||||
documentList.add("Document A");
|
||||
documentList.add("Document B");
|
||||
documentList.add("Document C");
|
||||
//データを取得
|
||||
|
||||
List<DocumentMeta> metas = document.getAllDocumentMetas(100);
|
||||
|
||||
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
|
||||
|
||||
// Create and set the adapter
|
||||
DocumentAdapter adapter = new DocumentAdapter(documentList);
|
||||
DocumentAdapter adapter = new DocumentAdapter(metas);
|
||||
documentRecyclerView.setAdapter(adapter);
|
||||
|
||||
// Use a LinearLayoutManager to specify the layout
|
||||
|
||||
@@ -70,35 +70,4 @@ public class XmlMetaModel {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
|
||||
public void addPage(XmlMetaPageModel page) {
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
||||
public void addPageAfterIndex(int index, XmlMetaPageModel page) {
|
||||
this.pages.add(index, page);
|
||||
|
||||
//Update index
|
||||
this.updateIndex();
|
||||
}
|
||||
|
||||
public void removePage(XmlMetaPageModel page) {
|
||||
this.pages.remove(page);
|
||||
}
|
||||
|
||||
public void removePageAtIndex(int index) {
|
||||
this.pages.remove(index);
|
||||
|
||||
//Update index
|
||||
this.updateIndex();
|
||||
}
|
||||
|
||||
// Internal Methods
|
||||
private void updateIndex() { // TODO-rca: 効率悪そう
|
||||
for (int i = 0; i < this.pages.size(); i++) {
|
||||
this.pages.get(i).setIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package one.nem.lacerta.model.document.internal;
|
||||
|
||||
public class XmlMetaPageModel {
|
||||
|
||||
int index;
|
||||
String filename;
|
||||
|
||||
// Constructor
|
||||
@@ -10,27 +9,18 @@ public class XmlMetaPageModel {
|
||||
public XmlMetaPageModel() {
|
||||
}
|
||||
|
||||
public XmlMetaPageModel(int index, String filename) {
|
||||
this.index = index;
|
||||
public XmlMetaPageModel(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
// Getter
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Setter
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import android.graphics.Bitmap;
|
||||
public interface DocumentProcessor {
|
||||
|
||||
// ページ操作
|
||||
void addNewPageToLast(Bitmap bitmap);
|
||||
void addNewPagesToLast(Bitmap[] bitmaps);
|
||||
void addNewPageAfterIndex(Bitmap bitmap, int index);
|
||||
void addNewPageBeforeIndex(Bitmap bitmap, int index);
|
||||
void removePageAtIndex(int index);
|
||||
void addNewPageToLast(Bitmap bitmap) throws Exception;
|
||||
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
|
||||
void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception;
|
||||
void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception;
|
||||
void removePageAtIndex(int index) throws Exception;
|
||||
|
||||
// 更新
|
||||
void updatePageAtIndex(Bitmap bitmap, int index);
|
||||
@@ -18,7 +18,7 @@ public interface DocumentProcessor {
|
||||
Bitmap getPageAtIndex(int index);
|
||||
int getPageCount();
|
||||
|
||||
void close();
|
||||
void init();
|
||||
void close() throws Exception;
|
||||
void init() throws Exception; // TODO-rca: 例外処理
|
||||
|
||||
}
|
||||
@@ -49,25 +49,24 @@ 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();
|
||||
logger.debug("init", "documentRootPath: " + this.documentRootPath);
|
||||
|
||||
this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager
|
||||
this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager
|
||||
|
||||
FileManager initFileManager = this.fileManager.getNewInstance();
|
||||
|
||||
logger.debug("init", "fileManager created");
|
||||
|
||||
this.fileManager.autoCreateDir(this.documentRootPath);
|
||||
|
||||
// rawディレクトリInit
|
||||
this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
||||
|
||||
// xmlファイルの読み込み
|
||||
if (fileManager.isExist("meta.xml")) {
|
||||
if (initFileManager.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());
|
||||
@@ -83,7 +82,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
xmlMetaModel.setPages(new ArrayList<>());
|
||||
|
||||
try {
|
||||
this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||
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");
|
||||
@@ -95,33 +94,22 @@ 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");
|
||||
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||
|
||||
// Save file
|
||||
this.fileManager.saveBitmapAtCurrent(bitmap, filename);
|
||||
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||
xmlMetaPageModel.setFilename(filename);
|
||||
xmlMetaModel.getPages().add(xmlMetaPageModel);
|
||||
|
||||
// Update meta
|
||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||
page.setIndex(xmlMetaModel.getPages().size() + 1);
|
||||
page.setFilename(filename);
|
||||
xmlMetaModel.addPage(page);
|
||||
logger.info("addNewPageToLast", "finished");
|
||||
logger.info("addNewPageToLast", "filename: " + filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
|
||||
logger.debug("addNewPagesToLast", "called");
|
||||
|
||||
for (Bitmap bitmap : bitmaps) {
|
||||
@@ -130,13 +118,27 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPageAfterIndex(Bitmap bitmap, int index) {
|
||||
public void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception {
|
||||
logger.debug("addNewPageAfterIndex", "called");
|
||||
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||
|
||||
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||
|
||||
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||
xmlMetaPageModel.setFilename(filename);
|
||||
xmlMetaModel.getPages().add(index, xmlMetaPageModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPageBeforeIndex(Bitmap bitmap, int index) {
|
||||
public void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception {
|
||||
logger.debug("addNewPageBeforeIndex", "called");
|
||||
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||
|
||||
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||
|
||||
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||
xmlMetaPageModel.setFilename(filename);
|
||||
xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,18 +162,14 @@ 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");
|
||||
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");
|
||||
logger.trace("close", e.getMessage());
|
||||
}
|
||||
logger.info("close", "finished");
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.graphics.Bitmap;
|
||||
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;
|
||||
|
||||
@@ -12,48 +14,52 @@ import java.util.List;
|
||||
/** @noinspection unused*/
|
||||
public interface FileManager {
|
||||
|
||||
Path getRootDir();
|
||||
Path getCurrentDir();
|
||||
File getFileRef();
|
||||
boolean isExist(String name) throws IOException;
|
||||
boolean isExist();
|
||||
boolean isDirectory();
|
||||
boolean isFile();
|
||||
boolean isWritable();
|
||||
boolean isReadable();
|
||||
// Get current instance
|
||||
FileManager getCurrentInstance();
|
||||
FileManager getNewInstance();
|
||||
|
||||
void changeDir(String dirName); //cd
|
||||
void changeDir(Path path); //cd
|
||||
void backDir(); //cd ..
|
||||
void backRootDir(); //cd /
|
||||
List<Path> getList();
|
||||
void createDir(String dirName);
|
||||
void createDir(Path path);
|
||||
void removeDir(String dirName);
|
||||
void removeDir(Path path);
|
||||
// Configure
|
||||
FileManager enableAutoCreateParent();
|
||||
FileManager disableRootDirCheck();
|
||||
|
||||
File createFile(String fileName);
|
||||
void removeFile(String fileName);
|
||||
FileManager setRootDir(Path rootDir);
|
||||
FileManager setPath(Path path);
|
||||
FileManager resolve(String path) throws IOException;
|
||||
|
||||
File getFile(String fileName);
|
||||
File getFile(Path path);
|
||||
// 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;
|
||||
FileManager createDirectoryIfNotExist(String directoryName) throws IOException;
|
||||
|
||||
String loadText(String fileName);
|
||||
String loadText(Path path);
|
||||
// Save
|
||||
// XML
|
||||
void saveXml(Document document, String fileName) throws IOException;
|
||||
void saveXml(Document document) throws IOException;
|
||||
|
||||
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);
|
||||
// Bitmap
|
||||
void saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる
|
||||
void saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる
|
||||
|
||||
|
||||
boolean isExist(Path path);
|
||||
boolean isExist(String fileName);
|
||||
// Load
|
||||
// XML
|
||||
Document loadXml(String fileName) throws IOException;
|
||||
Document loadXml() throws IOException;
|
||||
|
||||
void autoCreateDir(Path path);
|
||||
void autoCreateDir(String dirName);
|
||||
|
||||
void autoCreateToCurrentDir();
|
||||
|
||||
void saveBitmapAtCurrent(Bitmap bitmap, String fileName);
|
||||
Bitmap loadBitmap(Path path);
|
||||
void removeBitmap(Path path);
|
||||
// Bitmap
|
||||
Bitmap loadBitmap(String fileName) throws IOException;
|
||||
Bitmap loadBitmap() throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
package one.nem.lacerta.source.file.impl;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
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.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;
|
||||
@@ -28,320 +25,340 @@ import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
public class FileManagerImpl implements FileManager {
|
||||
|
||||
// RootDir
|
||||
// variables
|
||||
private Path rootDir;
|
||||
private Path path;
|
||||
private boolean autoCreateParent = false;
|
||||
private boolean disableRootDirCheck = false;
|
||||
|
||||
// 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;
|
||||
// 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("/");
|
||||
Path resolvedPath = this.path;
|
||||
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);
|
||||
}
|
||||
}
|
||||
logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath);
|
||||
return resolvedPath;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFileRef() {
|
||||
if (this.isExist()) {
|
||||
return this.path.toFile();
|
||||
} 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 boolean isExist(String name) throws IOException {
|
||||
Path resolvedPath = this.resolveStringPath(name);
|
||||
return Files.exists(resolvedPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getRootDir() {
|
||||
return rootDir;
|
||||
public boolean isExist(){
|
||||
return Files.exists(this.path);
|
||||
}
|
||||
|
||||
@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: 例外を投げる
|
||||
public boolean isDirectory() {
|
||||
if (this.isExist()) {
|
||||
File file = this.path.toFile();
|
||||
return file.isDirectory();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backDir() {
|
||||
this.currentDir = currentDir.getParent();
|
||||
public boolean isFile() {
|
||||
if (this.isExist()) {
|
||||
File file = this.path.toFile();
|
||||
return file.isFile();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backRootDir() {
|
||||
this.currentDir = rootDir;
|
||||
public boolean isReadable() {
|
||||
if (this.isExist()) {
|
||||
File file = this.path.toFile();
|
||||
return file.canRead();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Path> getList() {
|
||||
List<Path> list = new ArrayList<>();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentDir)) {
|
||||
for (Path entry : stream) { // TODO-rca: エラーハンドリング, 効率化
|
||||
list.add(entry);
|
||||
public boolean isWritable() {
|
||||
if (this.isExist()) {
|
||||
File file = this.path.toFile();
|
||||
return file.canWrite();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager getCurrentInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager getNewInstance() {
|
||||
return this.newInstance(this.rootDir, this.rootDir, this.autoCreateParent, this.disableRootDirCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager enableAutoCreateParent() {
|
||||
this.autoCreateParent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager disableRootDirCheck() {
|
||||
this.disableRootDirCheck = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager setRootDir(Path rootDir) {
|
||||
return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager setPath(Path path) {
|
||||
Path resolvedPath;
|
||||
if (this.disableRootDirCheck) {
|
||||
resolvedPath = path;
|
||||
} else {
|
||||
if (path.startsWith(this.rootDir)) {
|
||||
resolvedPath = path;
|
||||
} else {
|
||||
throw new IllegalArgumentException("path must be in rootDir");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
logger.debug("setPath", "resolvedPath: " + resolvedPath);
|
||||
return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDir(String dirName) {
|
||||
//ディレクトリ作成
|
||||
logger.debug("createDir", "called");
|
||||
|
||||
Path path = currentDir.resolve(dirName);
|
||||
logger.debug("createDir", "path: " + path);
|
||||
public FileManager resolve(String path) throws IOException{
|
||||
Path resolvedPath;
|
||||
try {
|
||||
Files.createDirectory(path);
|
||||
resolvedPath = resolveStringPath(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("resolve", e.getMessage());
|
||||
throw new IOException("Invalid path: " + path);
|
||||
}
|
||||
return this.setPath(resolvedPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDir(Path path) {
|
||||
logger.debug("createDir", "called");
|
||||
// Internal
|
||||
private void createFileInternal(Path path) throws IOException {
|
||||
try {
|
||||
if (this.autoCreateParent) {
|
||||
if (!path.getParent().toFile().exists()) {
|
||||
Files.createDirectories(path.getParent());
|
||||
}
|
||||
}
|
||||
Files.createFile(path);
|
||||
} catch (Exception e) {
|
||||
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.createFileInternal(this.resolveStringPath(fileName));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager createFileIfNotExist() throws IOException {
|
||||
if (!this.isExist()) {
|
||||
this.createFile();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileManager createFileIfNotExist(String fileName) throws IOException {
|
||||
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 (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error("createDirectoryInternal", e.getMessage());
|
||||
throw new IOException("Failed to create directory");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDir(String dirName) {
|
||||
logger.debug("removeDir", "called");
|
||||
currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング
|
||||
public FileManager createDirectory() throws IOException {
|
||||
this.createDirectoryInternal(this.path);
|
||||
return this;
|
||||
}
|
||||
|
||||
@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();
|
||||
public FileManager createDirectory(String directoryName) throws IOException {
|
||||
this.createDirectoryInternal(this.resolveStringPath(directoryName));
|
||||
return this;
|
||||
}
|
||||
|
||||
@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;
|
||||
public FileManager createDirectoryIfNotExist() throws IOException {
|
||||
if (!this.isExist()) {
|
||||
this.createDirectory();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@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;
|
||||
public FileManager createDirectoryIfNotExist(String directoryName) throws IOException {
|
||||
if (!this.isExist(directoryName)) {
|
||||
this.createDirectory(directoryName);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@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) {
|
||||
// Internal
|
||||
private void saveXmlInternal(Document document, Path path) throws IOException {
|
||||
try {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource source = new DOMSource(document);
|
||||
File file = createFile(fileName);
|
||||
StreamResult result = new StreamResult(file);
|
||||
|
||||
StreamResult result = new StreamResult(path.toFile());
|
||||
|
||||
transformer.transform(source, result);
|
||||
} catch (Exception e) {
|
||||
logger.error("saveXmlInternal", e.getMessage());
|
||||
e.printStackTrace();
|
||||
throw new IOException("Failed to save xml");
|
||||
}
|
||||
}
|
||||
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());
|
||||
throw new IOException("Failed to save bitmap");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDocument(Document document, Path path) {
|
||||
// TODO-rca 実装する
|
||||
public void saveXml(Document document, String fileName) throws IOException {
|
||||
this.saveXmlInternal(document, this.resolveStringPath(fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document loadDocument(String fileName) {
|
||||
public void saveXml(Document document) throws IOException {
|
||||
this.saveXmlInternal(document, this.path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBitmap(Bitmap bitmap, String fileName) throws IOException {
|
||||
this.saveBitmapInternal(bitmap, this.resolveStringPath(fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBitmap(Bitmap bitmap) throws IOException {
|
||||
this.saveBitmapInternal(bitmap, this.path);
|
||||
}
|
||||
|
||||
// Internal
|
||||
private Document loadXmlInternal(Path path) throws IOException {
|
||||
try {
|
||||
File file = getFile(fileName);
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(file);
|
||||
return document;
|
||||
return builder.parse(Files.newInputStream(path));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
logger.error("loadXmlInternal", e.getMessage());
|
||||
throw new IOException("Failed to load xml");
|
||||
}
|
||||
}
|
||||
|
||||
@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");
|
||||
private Bitmap loadBitmapInternal(Path path) throws IOException {
|
||||
try {
|
||||
File file = currentDir.resolve(fileName).toFile();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return BitmapFactory.decodeFile(path.toString());
|
||||
} catch (Exception e) {
|
||||
logger.error("loadBitmapInternal", e.getMessage());
|
||||
throw new IOException("Failed to load bitmap");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap loadBitmap(Path path) {
|
||||
return null;
|
||||
public Document loadXml(String fileName) throws IOException {
|
||||
return this.loadXmlInternal(this.resolveStringPath(fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBitmap(Path path) {
|
||||
|
||||
public Document loadXml() throws IOException {
|
||||
return this.loadXmlInternal(this.path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap loadBitmap(String fileName) throws IOException {
|
||||
return this.loadBitmapInternal(this.resolveStringPath(fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap loadBitmap() throws IOException {
|
||||
return this.loadBitmapInternal(this.path);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,6 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
||||
for(int i = 0; i < rootElement.getElementsByTagName("pages").getLength(); i++) {
|
||||
Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i);
|
||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||
page.setIndex(Integer.parseInt(pageElement.getElementsByTagName("index").item(0).getTextContent()));
|
||||
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
|
||||
pages.add(page);
|
||||
}
|
||||
@@ -73,7 +72,6 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
||||
Element pagesElement = document.createElement("pages");
|
||||
for(XmlMetaPageModel page : meta.getPages()) {
|
||||
Element pageElement = document.createElement("page");
|
||||
appendElement(document, pageElement, "index", String.valueOf(page.getIndex()));
|
||||
appendElement(document, pageElement, "filename", page.getFilename());
|
||||
pagesElement.appendChild(pageElement);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user