Search in sources :

Example 11 with ExplicitGroup

use of org.jabref.model.groups.ExplicitGroup 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 12 with ExplicitGroup

use of org.jabref.model.groups.ExplicitGroup 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)

Example 13 with ExplicitGroup

use of org.jabref.model.groups.ExplicitGroup in project jabref by JabRef.

the class GroupSerializerTest method serializeSingleExplicitGroup.

@Test
public void serializeSingleExplicitGroup() {
    ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, ',');
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 StaticGroup:myExplicitGroup;0;1;;;;"), serialization);
}
Also used : ExplicitGroup(org.jabref.model.groups.ExplicitGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Example 14 with ExplicitGroup

use of org.jabref.model.groups.ExplicitGroup in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeGroupsAndEncoding.

@Test
public void writeGroupsAndEncoding() throws Exception {
    SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);
    GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup(""));
    groupRoot.addChild(GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, ',')));
    metaData.setGroups(groupRoot);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences);
    // @formatter:off
    assertEquals("% Encoding: US-ASCII" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: grouping:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE + "1 StaticGroup:test\\;2\\;1\\;\\;\\;\\;;" + OS.NEWLINE + "}" + OS.NEWLINE, session.getStringValue());
// @formatter:on
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Example 15 with ExplicitGroup

use of org.jabref.model.groups.ExplicitGroup in project jabref by JabRef.

the class GroupSerializerTest method serializeSingleExplicitGroupWithIconAndDescription.

@Test
public void serializeSingleExplicitGroupWithIconAndDescription() {
    ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, ',');
    group.setIconCode("test icon");
    group.setExpanded(true);
    group.setColor(Color.ALICEBLUE);
    group.setDescription("test description");
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 StaticGroup:myExplicitGroup;0;1;0xf0f8ffff;test icon;test description;"), serialization);
}
Also used : ExplicitGroup(org.jabref.model.groups.ExplicitGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Aggregations

ExplicitGroup (org.jabref.model.groups.ExplicitGroup)15 Test (org.junit.Test)9 AbstractGroup (org.jabref.model.groups.AbstractGroup)4 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)4 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)4 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)3 ArrayList (java.util.ArrayList)2 ParseException (org.jabref.logic.importer.ParseException)2 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)2 BibEntry (org.jabref.model.entry.BibEntry)2 NamedCompound (org.jabref.gui.undo.NamedCompound)1 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)1 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibDatabase (org.jabref.model.database.BibDatabase)1 BibtexString (org.jabref.model.entry.BibtexString)1 KeywordGroup (org.jabref.model.groups.KeywordGroup)1 SearchGroup (org.jabref.model.groups.SearchGroup)1 ContentSelector (org.jabref.model.metadata.ContentSelector)1 MetaData (org.jabref.model.metadata.MetaData)1