Search in sources :

Example 1 with SearchParametersV4

use of com.keepassdroid.database.SearchParametersV4 in project KeePassDX by Kunzisoft.

the class SprEngineV4 method findRefTarget.

public TargetResult findRefTarget(String fullRef, SprContextV4 ctx) {
    if (fullRef == null) {
        return null;
    }
    fullRef = fullRef.toUpperCase(Locale.ENGLISH);
    if (!fullRef.startsWith(STR_REF_START) || !fullRef.endsWith(STR_REF_END)) {
        return null;
    }
    String ref = fullRef.substring(STR_REF_START.length(), fullRef.length() - STR_REF_START.length() - STR_REF_END.length());
    if (ref.length() <= 4) {
        return null;
    }
    if (ref.charAt(1) != '@') {
        return null;
    }
    if (ref.charAt(3) != ':') {
        return null;
    }
    char scan = Character.MIN_VALUE;
    char wanted = Character.MIN_VALUE;
    scan = Character.toUpperCase(ref.charAt(2));
    wanted = Character.toUpperCase(ref.charAt(0));
    SearchParametersV4 sp = new SearchParametersV4();
    sp.setupNone();
    sp.searchString = ref.substring(4);
    if (scan == 'T') {
        sp.searchInTitles = true;
    } else if (scan == 'U') {
        sp.searchInUserNames = true;
    } else if (scan == 'A') {
        sp.searchInUrls = true;
    } else if (scan == 'P') {
        sp.searchInPasswords = true;
    } else if (scan == 'N') {
        sp.searchInNotes = true;
    } else if (scan == 'I') {
        sp.searchInUUIDs = true;
    } else if (scan == 'O') {
        sp.searchInOther = true;
    } else {
        return null;
    }
    List<PwEntry> list = new ArrayList<PwEntry>();
    ctx.db.rootGroup.searchEntries(sp, list);
    if (list.size() > 0) {
        return new TargetResult((PwEntryV4) list.get(0), wanted);
    }
    return null;
}
Also used : SearchParametersV4(com.keepassdroid.database.SearchParametersV4) PwEntry(com.keepassdroid.database.PwEntry) ArrayList(java.util.ArrayList)

Aggregations

PwEntry (com.keepassdroid.database.PwEntry)1 SearchParametersV4 (com.keepassdroid.database.SearchParametersV4)1 ArrayList (java.util.ArrayList)1