mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3205923eb5 | ||
|
|
441479d9b9 | ||
|
|
099d900ffd | ||
|
|
080e86d05d | ||
|
|
6d6f4790a0 | ||
|
|
1a31d63786 | ||
|
|
ce834a7cfd | ||
|
|
f7b8006fa4 | ||
|
|
5bb2f0d387 | ||
|
|
e54cc07e9d |
No files matched your search
+7
-3
@@ -180,10 +180,14 @@ public class ScannerDataManagerStubFragment extends Fragment {
|
||||
Toast.makeText(getActivity(), "documentProcessor is null", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
for (CapturedData capturedData : this.results) {
|
||||
this.documentProcessor.addNewPageToLast(capturedData.getBitmap());
|
||||
Bitmap[] bitmaps = new Bitmap[results.size()];
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
bitmaps[i] = results.get(i).getBitmap();
|
||||
}
|
||||
|
||||
this.documentProcessor.addNewPagesToLast(bitmaps);
|
||||
|
||||
this.documentProcessor.close();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||
import one.nem.lacerta.processor.DocumentProcessor;
|
||||
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
@@ -25,9 +26,12 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
|
||||
// Magic Numbers
|
||||
private static final String DEFAULT_SAVE_DIR = "raw";
|
||||
|
||||
// Variables
|
||||
private final DocumentDetail documentDetail;
|
||||
private XmlMetaModel xmlMetaModel;
|
||||
private Path documentRootPath;
|
||||
private FileManager fileManager;
|
||||
|
||||
// Injection
|
||||
private final FileManagerFactory fileManagerFactory;
|
||||
@@ -48,22 +52,22 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
public void init() {
|
||||
logger.debug("init", "called");
|
||||
// Init Variables
|
||||
this.documentRootPath = documentDetail.getPath().getFullPath();
|
||||
this.documentRootPath = this.documentDetail.getPath().getFullPath();
|
||||
logger.debug("init", "documentRootPath: " + this.documentRootPath);
|
||||
|
||||
FileManager fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager
|
||||
this.fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager
|
||||
logger.debug("init", "fileManager created");
|
||||
|
||||
fileManager.autoCreateDir(this.documentRootPath);
|
||||
this.fileManager.autoCreateDir(this.documentRootPath);
|
||||
|
||||
// rawディレクトリInit
|
||||
fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
||||
this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
||||
|
||||
// xmlファイルの読み込み
|
||||
if (fileManager.isExist("meta.xml")) {
|
||||
logger.debug("init", "meta.xml found");
|
||||
try {
|
||||
xmlMetaModel = xmlMetaParser.deserialize(fileManager.loadDocument("meta.xml"));
|
||||
xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml"));
|
||||
} catch (Exception e) {
|
||||
logger.debug("init", "meta.xml parse failed");
|
||||
logger.trace("init", e.getMessage());
|
||||
@@ -72,14 +76,14 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
logger.debug("init", "meta.xml not found");
|
||||
xmlMetaModel = new XmlMetaModel();
|
||||
|
||||
xmlMetaModel.setTitle(documentDetail.getMeta().getTitle());
|
||||
xmlMetaModel.setAuthor(documentDetail.getAuthor());
|
||||
xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle());
|
||||
xmlMetaModel.setAuthor(this.documentDetail.getAuthor());
|
||||
xmlMetaModel.setDescription(""); // FIXME-rca:
|
||||
xmlMetaModel.setDefaultBranch(documentDetail.getDefaultBranch());
|
||||
xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch());
|
||||
xmlMetaModel.setPages(new ArrayList<>());
|
||||
|
||||
try {
|
||||
fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||
this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||
logger.debug("init", "meta.xml saved");
|
||||
} catch (Exception e) {
|
||||
logger.error("init", "meta.xml save failed");
|
||||
@@ -93,26 +97,36 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
@Override
|
||||
public void addNewPageToLast(Bitmap bitmap) {
|
||||
logger.debug("addNewPageToLast", "called");
|
||||
String fileName = String.format(UUID.randomUUID().toString() + ".png"); // TODO-rca: 対応表をもたせる
|
||||
logger.debug("addNewPageToLast", "fileName: " + fileName);
|
||||
FileManager fileManager = fileManagerFactory.create(this.documentRootPath);
|
||||
if(fileManager.getList().contains(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) {
|
||||
logger.debug("addNewPageToLast", "raw dir found");
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
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", "raw dir not found");
|
||||
fileManager.createDir(DEFAULT_SAVE_DIR);
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
logger.debug("addNewPageToLast", "currentDir is not documentRootPath");
|
||||
this.fileManager.backRootDir();
|
||||
this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
||||
this.fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
}
|
||||
fileManager.saveBitmapAtCurrent(bitmap, fileName);
|
||||
logger.debug("addNewPageToLast", "DirInit finished");
|
||||
|
||||
// Save file
|
||||
this.fileManager.saveBitmapAtCurrent(bitmap, filename);
|
||||
|
||||
// Update meta
|
||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||
page.setIndex(xmlMetaModel.getPages().size() + 1);
|
||||
page.setFilename(filename);
|
||||
xmlMetaModel.addPage(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
||||
logger.debug("addNewPagesToLast(List)", "called");
|
||||
for(Bitmap bitmap : bitmaps) {
|
||||
logger.debug("addNewPagesToLast", "called");
|
||||
|
||||
for (Bitmap bitmap : bitmaps) {
|
||||
addNewPageToLast(bitmap);
|
||||
} // TODO-rca: 保存処理をまとめて行う?
|
||||
} // TODO-rca: 効率悪いので改善する
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,6 +161,17 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
logger.debug("close", "called");
|
||||
// TODO-rca: ここでxmlファイルを保存する
|
||||
this.fileManager.backRootDir();
|
||||
|
||||
try {
|
||||
this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||
logger.debug("close", "meta.xml saved");
|
||||
} catch (Exception e) {
|
||||
logger.error("close", "meta.xml save failed");
|
||||
logger.trace("close", e.getMessage());
|
||||
}
|
||||
logger.info("close", "finished");
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
public interface FileManager {
|
||||
|
||||
Path getRootDir();
|
||||
Path getCurrentDir();
|
||||
|
||||
void changeDir(String dirName); //cd
|
||||
void changeDir(Path path); //cd
|
||||
void backDir(); //cd ..
|
||||
|
||||
@@ -59,6 +59,11 @@ public class FileManagerImpl implements FileManager {
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getCurrentDir() {
|
||||
return currentDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeDir(String dirName) {
|
||||
this.currentDir = rootDir.resolve(dirName);
|
||||
|
||||
Reference in new issue
Block a user