Search in sources :

Example 1 with QuotedStringTokenizer

use of org.jabref.logic.util.strings.QuotedStringTokenizer in project jabref by JabRef.

the class GroupsParser method automaticPersonsGroupFromString.

private static AbstractGroup automaticPersonsGroupFromString(String string) {
    if (!string.startsWith(MetadataSerializationConfiguration.AUTOMATIC_PERSONS_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + string + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(string.substring(MetadataSerializationConfiguration.AUTOMATIC_PERSONS_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
    String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    AutomaticPersonsGroup newGroup = new AutomaticPersonsGroup(name, context, field);
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType) AutomaticPersonsGroup(org.jabref.model.groups.AutomaticPersonsGroup)

Example 2 with QuotedStringTokenizer

use of org.jabref.logic.util.strings.QuotedStringTokenizer in project jabref by JabRef.

the class GroupsParser method legacyExplicitGroupFromString.

private static ExplicitGroup legacyExplicitGroupFromString(String input, Character keywordSeparator) throws ParseException {
    if (!input.startsWith(MetadataSerializationConfiguration.LEGACY_EXPLICIT_GROUP_ID)) {
        throw new IllegalArgumentException("ExplicitGroup cannot be created from \"" + input + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(input.substring(MetadataSerializationConfiguration.LEGACY_EXPLICIT_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = tok.nextToken();
    try {
        int context = Integer.parseInt(tok.nextToken());
        ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumberOrDefault(context), keywordSeparator);
        GroupsParser.addLegacyEntryKeys(tok, newGroup);
        return newGroup;
    } catch (NumberFormatException exception) {
        throw new ParseException("Could not parse context in " + input);
    }
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) ParseException(org.jabref.logic.importer.ParseException) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 3 with QuotedStringTokenizer

use of org.jabref.logic.util.strings.QuotedStringTokenizer in project jabref by JabRef.

the class GroupsParser method searchGroupFromString.

/**
     * Parses s and recreates the SearchGroup from it.
     *
     * @param s The String representation obtained from
     *          SearchGroup.toString(), or null if incompatible
     */
private static AbstractGroup searchGroupFromString(String s) {
    if (!s.startsWith(MetadataSerializationConfiguration.SEARCH_GROUP_ID)) {
        throw new IllegalArgumentException("SearchGroup cannot be created from \"" + s + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.SEARCH_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = tok.nextToken();
    int context = Integer.parseInt(tok.nextToken());
    String expression = tok.nextToken();
    boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
    boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
    // fields; these are ignored now, all fields are always searched
    return new SearchGroup(StringUtil.unquote(name, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR), GroupHierarchyType.getByNumberOrDefault(context), StringUtil.unquote(expression, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR), caseSensitive, regExp);
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) SearchGroup(org.jabref.model.groups.SearchGroup)

Example 4 with QuotedStringTokenizer

use of org.jabref.logic.util.strings.QuotedStringTokenizer in project jabref by JabRef.

the class GroupsParser method keywordGroupFromString.

/**
     * Parses s and recreates the KeywordGroup from it.
     *
     * @param s The String representation obtained from
     *          KeywordGroup.toString()
     */
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) throws ParseException {
    if (!s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.KEYWORD_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
    String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String expression = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
    boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
    KeywordGroup newGroup;
    if (regExp) {
        newGroup = new RegexKeywordGroup(name, context, field, expression, caseSensitive);
    } else {
        newGroup = new WordKeywordGroup(name, context, field, expression, caseSensitive, keywordSeparator, false);
    }
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup)

Example 5 with QuotedStringTokenizer

use of org.jabref.logic.util.strings.QuotedStringTokenizer in project jabref by JabRef.

the class GroupsParser method explicitGroupFromString.

private static ExplicitGroup explicitGroupFromString(String input, Character keywordSeparator) throws ParseException {
    if (!input.startsWith(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID)) {
        throw new IllegalArgumentException("ExplicitGroup cannot be created from \"" + input + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(input.substring(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = tok.nextToken();
    try {
        int context = Integer.parseInt(tok.nextToken());
        ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumberOrDefault(context), keywordSeparator);
        addGroupDetails(tok, newGroup);
        return newGroup;
    } catch (NumberFormatException exception) {
        throw new ParseException("Could not parse context in " + input);
    }
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) ParseException(org.jabref.logic.importer.ParseException) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Aggregations

QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)6 GroupHierarchyType (org.jabref.model.groups.GroupHierarchyType)3 ParseException (org.jabref.logic.importer.ParseException)2 AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)2 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)2 AutomaticPersonsGroup (org.jabref.model.groups.AutomaticPersonsGroup)1 KeywordGroup (org.jabref.model.groups.KeywordGroup)1 RegexKeywordGroup (org.jabref.model.groups.RegexKeywordGroup)1 SearchGroup (org.jabref.model.groups.SearchGroup)1 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)1