mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
90
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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: 新機能用テンプレート
|
name: 新機能用テンプレート
|
||||||
about: 新規開発Issue用テンプレート
|
about: 新規能用テンプレート
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: 新機能
|
||||||
assignees: ''
|
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);
|
this.documentProcessor = documentProcessorFactory.create(this.documentDetail);
|
||||||
Toast.makeText(getActivity(), "documentProcessor created", Toast.LENGTH_LONG).show();
|
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();
|
Toast.makeText(getActivity(), "documentProcessor initialized", Toast.LENGTH_LONG).show();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -185,9 +190,21 @@ public class ScannerDataManagerStubFragment extends Fragment {
|
|||||||
bitmaps[i] = results.get(i).getBitmap();
|
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);
|
EditText editText = view.findViewById(R.id.edit_text_dir_name);
|
||||||
String dirName = editText.getText().toString();
|
String dirName = editText.getText().toString();
|
||||||
|
|
||||||
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
// FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
||||||
fileManager.createDir(dirName);
|
// fileManager.createDir(dirName);
|
||||||
});
|
});
|
||||||
|
|
||||||
view.findViewById(R.id.button_save_item).setOnClickListener(v -> {
|
view.findViewById(R.id.button_save_item).setOnClickListener(v -> {
|
||||||
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
// FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
||||||
fileManager.createDir("test");
|
// fileManager.createDir("test");
|
||||||
fileManager.changeDir("test");
|
// fileManager.changeDir("test");
|
||||||
Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
|
// Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
|
||||||
// Bitmapに描画処理を行う
|
// // Bitmapに描画処理を行う
|
||||||
Canvas canvas = new Canvas(bitmap);
|
// Canvas canvas = new Canvas(bitmap);
|
||||||
// 大きな山の形状を作成
|
// // 大きな山の形状を作成
|
||||||
android.graphics.Path bigMountainPath = new android.graphics.Path();
|
// android.graphics.Path bigMountainPath = new android.graphics.Path();
|
||||||
bigMountainPath.moveTo(100, 800); // 左下の開始点
|
// bigMountainPath.moveTo(100, 800); // 左下の開始点
|
||||||
bigMountainPath.lineTo(500, 300); // 頂点
|
// bigMountainPath.lineTo(500, 300); // 頂点
|
||||||
bigMountainPath.lineTo(900, 800); // 右下
|
// bigMountainPath.lineTo(900, 800); // 右下
|
||||||
bigMountainPath.close(); // パスを閉じる
|
// bigMountainPath.close(); // パスを閉じる
|
||||||
|
//
|
||||||
// 山の描画設定
|
// // 山の描画設定
|
||||||
Paint mountainPaint = new Paint();
|
// Paint mountainPaint = new Paint();
|
||||||
mountainPaint.setColor(Color.GREEN);
|
// mountainPaint.setColor(Color.GREEN);
|
||||||
mountainPaint.setStyle(Paint.Style.FILL);
|
// mountainPaint.setStyle(Paint.Style.FILL);
|
||||||
|
//
|
||||||
// 大きな山を描画
|
// // 大きな山を描画
|
||||||
canvas.drawPath(bigMountainPath, mountainPaint);
|
// canvas.drawPath(bigMountainPath, mountainPaint);
|
||||||
|
//
|
||||||
// 小さな山の形状を作成
|
// // 小さな山の形状を作成
|
||||||
android.graphics.Path smallMountainPath = new android.graphics.Path();
|
// android.graphics.Path smallMountainPath = new android.graphics.Path();
|
||||||
smallMountainPath.moveTo(400, 800); // 左下の開始点
|
// smallMountainPath.moveTo(400, 800); // 左下の開始点
|
||||||
smallMountainPath.lineTo(650, 400); // 頂点
|
// smallMountainPath.lineTo(650, 400); // 頂点
|
||||||
smallMountainPath.lineTo(900, 800); // 右下
|
// smallMountainPath.lineTo(900, 800); // 右下
|
||||||
smallMountainPath.close(); // パスを閉じる
|
// smallMountainPath.close(); // パスを閉じる
|
||||||
|
//
|
||||||
Paint smallMountainPaint = new Paint();
|
// Paint smallMountainPaint = new Paint();
|
||||||
smallMountainPaint.setColor(Color.parseColor("#006e54"));
|
// smallMountainPaint.setColor(Color.parseColor("#006e54"));
|
||||||
smallMountainPaint.setStyle(Paint.Style.FILL);
|
// smallMountainPaint.setStyle(Paint.Style.FILL);
|
||||||
|
//
|
||||||
// 小さな山を描画
|
// // 小さな山を描画
|
||||||
canvas.drawPath(smallMountainPath, smallMountainPaint);
|
// canvas.drawPath(smallMountainPath, smallMountainPaint);
|
||||||
fileManager.saveBitmapAtCurrent(bitmap, "test.png");
|
// fileManager.saveBitmapAtCurrent(bitmap, "test.png");
|
||||||
});
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'com.android.library'
|
id 'com.android.library'
|
||||||
|
id 'com.google.dagger.hilt.android'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -46,5 +47,9 @@ dependencies {
|
|||||||
|
|
||||||
implementation project(':shared:ui')
|
implementation project(':shared:ui')
|
||||||
|
|
||||||
|
implementation project(':model')
|
||||||
|
|
||||||
|
implementation project(':data')
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,18 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
|
|
||||||
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
||||||
|
|
||||||
private List<String> documentList;
|
private List<DocumentMeta> documentMetas;
|
||||||
|
|
||||||
public DocumentAdapter(List<String> documentList) {
|
public DocumentAdapter(List<DocumentMeta> documentMetas) {
|
||||||
this.documentList = documentList;
|
// nullの場合に例外を発生させる
|
||||||
|
if (documentMetas == null) {
|
||||||
|
throw new IllegalArgumentException("DocumentMetas list cannot be null or empty");
|
||||||
|
}
|
||||||
|
this.documentMetas = documentMetas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -27,12 +33,15 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
|
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
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return documentList.size();
|
return documentMetas.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -40,7 +49,7 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
|||||||
|
|
||||||
DocumentViewHolder(View itemView) {
|
DocumentViewHolder(View itemView) {
|
||||||
super(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;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
// LibraryArchiveFragment.java
|
// LibraryArchiveFragment.java
|
||||||
|
|
||||||
|
//画面変移用のコード
|
||||||
|
//Fragmentへのデータの受け渡し機能
|
||||||
public class LibraryArchiveFragment extends AppCompatActivity {
|
public class LibraryArchiveFragment extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
//Fragmentにデータを受け渡す機能
|
||||||
public class LibraryDocFragment extends Fragment {
|
public class LibraryDocFragment extends Fragment {
|
||||||
|
|
||||||
private TextView textView; // フィールドとして TextView を定義
|
private TextView textView; // フィールドとして TextView を定義
|
||||||
|
|||||||
+18
-5
@@ -13,17 +13,29 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.
|
* A simple {@link Fragment} subclass.
|
||||||
* Use the {@link LibraryTopFragment#newInstance} factory method to
|
* Use the {@link LibraryTopFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
|
@AndroidEntryPoint
|
||||||
public class LibraryTopFragment extends Fragment {
|
public class LibraryTopFragment extends Fragment {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Document document;
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
@@ -76,13 +88,14 @@ public class LibraryTopFragment extends Fragment {
|
|||||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||||
documentRecyclerView.setLayoutManager(layoutManager);
|
documentRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
List<String> documentList = new ArrayList<>();
|
//データを取得
|
||||||
documentList.add("Document A");
|
|
||||||
documentList.add("Document B");
|
List<DocumentMeta> metas = document.getAllDocumentMetas(100);
|
||||||
documentList.add("Document C");
|
|
||||||
|
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
// Create and set the adapter
|
// Create and set the adapter
|
||||||
DocumentAdapter adapter = new DocumentAdapter(documentList);
|
DocumentAdapter adapter = new DocumentAdapter(metas);
|
||||||
documentRecyclerView.setAdapter(adapter);
|
documentRecyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
// Use a LinearLayoutManager to specify the layout
|
// Use a LinearLayoutManager to specify the layout
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import android.graphics.Bitmap;
|
|||||||
public interface DocumentProcessor {
|
public interface DocumentProcessor {
|
||||||
|
|
||||||
// ページ操作
|
// ページ操作
|
||||||
void addNewPageToLast(Bitmap bitmap);
|
void addNewPageToLast(Bitmap bitmap) throws Exception;
|
||||||
void addNewPagesToLast(Bitmap[] bitmaps);
|
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
|
||||||
void addNewPageAfterIndex(Bitmap bitmap, int index);
|
void addNewPageAfterIndex(Bitmap bitmap, int index);
|
||||||
void addNewPageBeforeIndex(Bitmap bitmap, int index);
|
void addNewPageBeforeIndex(Bitmap bitmap, int index);
|
||||||
void removePageAtIndex(int index);
|
void removePageAtIndex(int index);
|
||||||
@@ -18,7 +18,7 @@ public interface DocumentProcessor {
|
|||||||
Bitmap getPageAtIndex(int index);
|
Bitmap getPageAtIndex(int index);
|
||||||
int getPageCount();
|
int getPageCount();
|
||||||
|
|
||||||
void close();
|
void close() throws Exception;
|
||||||
void init();
|
void init() throws Exception; // TODO-rca: 例外処理
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -49,25 +49,24 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() throws Exception{
|
||||||
logger.debug("init", "called");
|
logger.debug("init", "called");
|
||||||
// Init Variables
|
// Init Variables
|
||||||
this.documentRootPath = this.documentDetail.getPath().getFullPath();
|
this.documentRootPath = this.documentDetail.getPath().getFullPath();
|
||||||
logger.debug("init", "documentRootPath: " + this.documentRootPath);
|
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");
|
logger.debug("init", "fileManager created");
|
||||||
|
|
||||||
this.fileManager.autoCreateDir(this.documentRootPath);
|
|
||||||
|
|
||||||
// rawディレクトリInit
|
|
||||||
this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
|
||||||
|
|
||||||
// xmlファイルの読み込み
|
// xmlファイルの読み込み
|
||||||
if (fileManager.isExist("meta.xml")) {
|
if (initFileManager.isExist("meta.xml")) {
|
||||||
logger.debug("init", "meta.xml found");
|
logger.debug("init", "meta.xml found");
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
logger.debug("init", "meta.xml parse failed");
|
logger.debug("init", "meta.xml parse failed");
|
||||||
logger.trace("init", e.getMessage());
|
logger.trace("init", e.getMessage());
|
||||||
@@ -83,7 +82,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||||||
xmlMetaModel.setPages(new ArrayList<>());
|
xmlMetaModel.setPages(new ArrayList<>());
|
||||||
|
|
||||||
try {
|
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");
|
logger.debug("init", "meta.xml saved");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("init", "meta.xml save failed");
|
logger.error("init", "meta.xml save failed");
|
||||||
@@ -95,33 +94,23 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNewPageToLast(Bitmap bitmap) {
|
public void addNewPageToLast(Bitmap bitmap) throws Exception{
|
||||||
logger.debug("addNewPageToLast", "called");
|
logger.debug("addNewPageToLast", "called");
|
||||||
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||||
|
|
||||||
// FileManager
|
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||||
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
|
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||||
this.fileManager.saveBitmapAtCurrent(bitmap, filename);
|
xmlMetaPageModel.setFilename(filename);
|
||||||
|
xmlMetaPageModel.setIndex(xmlMetaModel.getPages().size() + 1);
|
||||||
|
xmlMetaModel.getPages().add(xmlMetaPageModel);
|
||||||
|
|
||||||
// Update meta
|
logger.info("addNewPageToLast", "finished");
|
||||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
logger.info("addNewPageToLast", "filename: " + filename + ", index: " + xmlMetaPageModel.getIndex());
|
||||||
page.setIndex(xmlMetaModel.getPages().size() + 1);
|
|
||||||
page.setFilename(filename);
|
|
||||||
xmlMetaModel.addPage(page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
|
||||||
logger.debug("addNewPagesToLast", "called");
|
logger.debug("addNewPagesToLast", "called");
|
||||||
|
|
||||||
for (Bitmap bitmap : bitmaps) {
|
for (Bitmap bitmap : bitmaps) {
|
||||||
@@ -160,18 +149,14 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() throws Exception{
|
||||||
logger.debug("close", "called");
|
logger.debug("close", "called");
|
||||||
// TODO-rca: ここでxmlファイルを保存する
|
|
||||||
this.fileManager.backRootDir();
|
|
||||||
|
|
||||||
try {
|
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");
|
logger.debug("close", "meta.xml saved");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("close", "meta.xml save failed");
|
logger.error("close", "meta.xml save failed");
|
||||||
logger.trace("close", e.getMessage());
|
logger.trace("close", e.getMessage());
|
||||||
}
|
}
|
||||||
logger.info("close", "finished");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import android.graphics.Bitmap;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,48 +14,52 @@ import java.util.List;
|
|||||||
/** @noinspection unused*/
|
/** @noinspection unused*/
|
||||||
public interface FileManager {
|
public interface FileManager {
|
||||||
|
|
||||||
Path getRootDir();
|
File getFileRef();
|
||||||
Path getCurrentDir();
|
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
|
// Configure
|
||||||
void changeDir(Path path); //cd
|
FileManager enableAutoCreateParent();
|
||||||
void backDir(); //cd ..
|
FileManager disableRootDirCheck();
|
||||||
void backRootDir(); //cd /
|
|
||||||
List<Path> getList();
|
|
||||||
void createDir(String dirName);
|
|
||||||
void createDir(Path path);
|
|
||||||
void removeDir(String dirName);
|
|
||||||
void removeDir(Path path);
|
|
||||||
|
|
||||||
File createFile(String fileName);
|
FileManager setRootDir(Path rootDir);
|
||||||
void removeFile(String fileName);
|
FileManager setPath(Path path);
|
||||||
|
FileManager resolve(String path) throws IOException;
|
||||||
|
|
||||||
File getFile(String fileName);
|
// Create
|
||||||
File getFile(Path path);
|
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);
|
// Save
|
||||||
String loadText(Path path);
|
// XML
|
||||||
|
void saveXml(Document document, String fileName) throws IOException;
|
||||||
|
void saveXml(Document document) throws IOException;
|
||||||
|
|
||||||
void saveText(String text, String fileName);
|
// Bitmap
|
||||||
void saveText(String text, Path path);
|
void saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる
|
||||||
|
void saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる
|
||||||
void saveDocument(Document document, String fileName);
|
|
||||||
void saveDocument(Document document, Path path);
|
|
||||||
|
|
||||||
Document loadDocument(String fileName);
|
|
||||||
Document loadDocument(Path path);
|
|
||||||
|
|
||||||
|
|
||||||
boolean isExist(Path path);
|
// Load
|
||||||
boolean isExist(String fileName);
|
// XML
|
||||||
|
Document loadXml(String fileName) throws IOException;
|
||||||
|
Document loadXml() throws IOException;
|
||||||
|
|
||||||
void autoCreateDir(Path path);
|
// Bitmap
|
||||||
void autoCreateDir(String dirName);
|
Bitmap loadBitmap(String fileName) throws IOException;
|
||||||
|
Bitmap loadBitmap() throws IOException;
|
||||||
void autoCreateToCurrentDir();
|
|
||||||
|
|
||||||
void saveBitmapAtCurrent(Bitmap bitmap, String fileName);
|
|
||||||
Bitmap loadBitmap(Path path);
|
|
||||||
void removeBitmap(Path path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
package one.nem.lacerta.source.file.impl;
|
package one.nem.lacerta.source.file.impl;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@@ -28,320 +25,340 @@ import one.nem.lacerta.utils.LacertaLogger;
|
|||||||
|
|
||||||
public class FileManagerImpl implements FileManager {
|
public class FileManagerImpl implements FileManager {
|
||||||
|
|
||||||
// RootDir
|
// variables
|
||||||
private Path rootDir;
|
private Path rootDir;
|
||||||
|
private Path path;
|
||||||
|
private boolean autoCreateParent = false;
|
||||||
|
private boolean disableRootDirCheck = false;
|
||||||
|
|
||||||
// CurrentDir
|
|
||||||
private Path currentDir;
|
|
||||||
|
|
||||||
// Internal Methods
|
// Injection
|
||||||
private Path convertPath(String path) {
|
private final LacertaLogger logger;
|
||||||
Path convertedPath = currentDir.resolve(path);
|
@AssistedInject
|
||||||
if (convertedPath.startsWith(rootDir)) { // 異常なパスの場合はnullを返す // TODO-rca: エラーハンドリング
|
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
||||||
return convertedPath;
|
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Injection
|
@Override
|
||||||
private LacertaLogger logger;
|
public boolean isExist(String name) throws IOException {
|
||||||
|
Path resolvedPath = this.resolveStringPath(name);
|
||||||
@AssistedInject
|
return Files.exists(resolvedPath);
|
||||||
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
|
||||||
this.logger = logger;
|
|
||||||
this.rootDir = rootDir;
|
|
||||||
this.currentDir = rootDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getRootDir() {
|
public boolean isExist(){
|
||||||
return rootDir;
|
return Files.exists(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getCurrentDir() {
|
public boolean isDirectory() {
|
||||||
return currentDir;
|
if (this.isExist()) {
|
||||||
}
|
File file = this.path.toFile();
|
||||||
|
return file.isDirectory();
|
||||||
@Override
|
} else {
|
||||||
public void changeDir(String dirName) {
|
return false;
|
||||||
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
|
@Override
|
||||||
public void backDir() {
|
public boolean isFile() {
|
||||||
this.currentDir = currentDir.getParent();
|
if (this.isExist()) {
|
||||||
|
File file = this.path.toFile();
|
||||||
|
return file.isFile();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void backRootDir() {
|
public boolean isReadable() {
|
||||||
this.currentDir = rootDir;
|
if (this.isExist()) {
|
||||||
|
File file = this.path.toFile();
|
||||||
|
return file.canRead();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Path> getList() {
|
public boolean isWritable() {
|
||||||
List<Path> list = new ArrayList<>();
|
if (this.isExist()) {
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentDir)) {
|
File file = this.path.toFile();
|
||||||
for (Path entry : stream) { // TODO-rca: エラーハンドリング, 効率化
|
return file.canWrite();
|
||||||
list.add(entry);
|
} 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
|
@Override
|
||||||
public void createDir(String dirName) {
|
public FileManager resolve(String path) throws IOException{
|
||||||
//ディレクトリ作成
|
Path resolvedPath;
|
||||||
logger.debug("createDir", "called");
|
|
||||||
|
|
||||||
Path path = currentDir.resolve(dirName);
|
|
||||||
logger.debug("createDir", "path: " + path);
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(path);
|
resolvedPath = resolveStringPath(path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("resolve", e.getMessage());
|
||||||
|
throw new IOException("Invalid path: " + path);
|
||||||
}
|
}
|
||||||
|
return this.setPath(resolvedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Internal
|
||||||
public void createDir(Path path) {
|
private void createFileInternal(Path path) throws IOException {
|
||||||
logger.debug("createDir", "called");
|
|
||||||
try {
|
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);
|
Files.createDirectory(path);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("createDirectoryInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to create directory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeDir(String dirName) {
|
public FileManager createDirectory() throws IOException {
|
||||||
logger.debug("removeDir", "called");
|
this.createDirectoryInternal(this.path);
|
||||||
currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeDir(Path path) {
|
public FileManager createDirectory(String directoryName) throws IOException {
|
||||||
logger.debug("removeDir", "called");
|
this.createDirectoryInternal(this.resolveStringPath(directoryName));
|
||||||
path.toFile().delete(); // TODO-rca: エラーハンドリング
|
return this;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File createFile(String fileName) {
|
|
||||||
logger.debug("createFile", "called");
|
|
||||||
return currentDir.resolve(fileName).toFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFile(String fileName) {
|
public FileManager createDirectoryIfNotExist() throws IOException {
|
||||||
logger.debug("removeFile", "called");
|
if (!this.isExist()) {
|
||||||
currentDir.resolve(fileName).toFile().delete(); // TODO-rca: エラーハンドリング
|
this.createDirectory();
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String loadText(Path path) {
|
public FileManager createDirectoryIfNotExist(String directoryName) throws IOException {
|
||||||
try(FileInputStream fileInputStream = new FileInputStream(path.toFile())) {
|
if (!this.isExist(directoryName)) {
|
||||||
byte[] bytes = new byte[fileInputStream.available()];
|
this.createDirectory(directoryName);
|
||||||
fileInputStream.read(bytes); // TODO-rca: エラーハンドリング
|
|
||||||
return new String(bytes);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Internal
|
||||||
public void saveText(String text, String fileName) { // TODO-rca: リファクタリング // TODO-rca: 統合
|
private void saveXmlInternal(Document document, Path path) throws IOException {
|
||||||
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 {
|
try {
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
DOMSource source = new DOMSource(document);
|
DOMSource source = new DOMSource(document);
|
||||||
File file = createFile(fileName);
|
|
||||||
StreamResult result = new StreamResult(file);
|
StreamResult result = new StreamResult(path.toFile());
|
||||||
|
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
logger.error("saveXmlInternal", e.getMessage());
|
||||||
e.printStackTrace();
|
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
|
@Override
|
||||||
public void saveDocument(Document document, Path path) {
|
public void saveXml(Document document, String fileName) throws IOException {
|
||||||
// TODO-rca 実装する
|
this.saveXmlInternal(document, this.resolveStringPath(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
try {
|
||||||
File file = getFile(fileName);
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
Document document = builder.parse(file);
|
return builder.parse(Files.newInputStream(path));
|
||||||
return document;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("loadXmlInternal", e.getMessage());
|
||||||
return null;
|
throw new IOException("Failed to load xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private Bitmap loadBitmapInternal(Path path) throws IOException {
|
||||||
@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 {
|
try {
|
||||||
File file = currentDir.resolve(fileName).toFile();
|
return BitmapFactory.decodeFile(path.toString());
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath()));
|
} catch (Exception e) {
|
||||||
} catch (IOException e) {
|
logger.error("loadBitmapInternal", e.getMessage());
|
||||||
e.printStackTrace();
|
throw new IOException("Failed to load bitmap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap loadBitmap(Path path) {
|
public Document loadXml(String fileName) throws IOException {
|
||||||
return null;
|
return this.loadXmlInternal(this.resolveStringPath(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user