Refactor methods

This commit is contained in:
Brian Pellin
2009-06-27 15:44:47 -05:00
parent fc1c2199da
commit 44740c3143
2 changed files with 46 additions and 16 deletions

View File

@@ -24,6 +24,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.UUID;
@@ -56,23 +57,36 @@ public class Database {
public String mFilename;
public SearchDbHelper searchHelper;
public void LoadData(Context ctx, InputStream is, String password, String keyfile) throws InvalidCipherTextException, IOException, InvalidKeyFileException {
LoadData(ctx, is, password, keyfile, !ImporterV3.DEBUG);
}
public void LoadData(Context ctx, String filename, String password, String keyfile) throws InvalidCipherTextException, IOException, InvalidKeyFileException, FileNotFoundException {
LoadData(ctx, filename, password, keyfile, !ImporterV3.DEBUG);
}
public void LoadData(Context ctx, String filename, String password, String keyfile, boolean debug) throws InvalidCipherTextException, IOException, InvalidKeyFileException, FileNotFoundException {
FileInputStream fis;
fis = new FileInputStream(filename);
ImporterV3 Importer = new ImporterV3();
LoadData(ctx, fis, password, keyfile, debug);
mFilename = filename;
}
public void LoadData(Context ctx, InputStream is, String password, String keyfile, boolean debug) throws InvalidCipherTextException, IOException, InvalidKeyFileException {
ImporterV3 Importer = new ImporterV3(debug);
mPM = Importer.openDatabase(fis, password, keyfile);
mPM = Importer.openDatabase(is, password, keyfile);
if ( mPM != null ) {
mPM.constructTree(null);
populateGlobals(null);
}
mFilename = filename;
searchHelper = new SearchDbHelper(ctx);
searchHelper.open();
buildSearchIndex(ctx);
}
@@ -88,6 +102,10 @@ public class Database {
}
}
public PwGroup Search(String str) {
return searchHelper.search(this, str);
}
public void NewEntry(PwEntry entry) throws IOException, PwManagerOutputException {
PwGroup parent = entry.parent;

View File

@@ -29,23 +29,35 @@ import org.phoneid.keepassj2me.PwManager;
import android.content.Context;
import android.content.res.AssetManager;
import com.android.keepass.Database;
import com.android.keepass.keepasslib.InvalidKeyFileException;
public class TestData {
private static PwManager test1;
private static final String TEST1_KEYFILE = "";
private static final String TEST1_KDB = "test1.kdb";
private static final String TEST1_PASSWORD = "12345";
private static Database mDb;
public static Database GetDb1(Context ctx) throws IOException, InvalidCipherTextException, InvalidKeyFileException {
if ( mDb == null ) {
AssetManager am = ctx.getAssets();
InputStream is = am.open(TEST1_KDB, AssetManager.ACCESS_STREAMING);
mDb = new Database();
mDb.LoadData(ctx, is, TEST1_PASSWORD, TEST1_KEYFILE, ImporterV3.DEBUG);
mDb.mFilename = "/sdcard/test1.kdb";
}
return mDb;
}
public static PwManager GetTest1(Context ctx) throws InvalidCipherTextException, IOException, InvalidKeyFileException {
if ( test1 == null ) {
AssetManager am = ctx.getAssets();
InputStream is = am.open("test1.kdb", AssetManager.ACCESS_STREAMING);
ImporterV3 importer = new ImporterV3(ImporterV3.DEBUG);
test1 = importer.openDatabase(is, "12345", "");
if (test1 != null) {
test1.constructTree(null);
}
if ( mDb == null ) {
GetDb1(ctx);
}
return test1;
return mDb.mPM;
}
}