use of org.jabref.logic.importer.ParseException 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);
}
}
use of org.jabref.logic.importer.ParseException in project jabref by JabRef.
the class GroupsParser method importGroups.
public static GroupTreeNode importGroups(List<String> orderedData, Character keywordSeparator) throws ParseException {
try {
GroupTreeNode cursor = null;
GroupTreeNode root = null;
for (String string : orderedData) {
// This allows to read databases that have been modified by, e.g., BibDesk
string = string.trim();
if (string.isEmpty()) {
continue;
}
int spaceIndex = string.indexOf(' ');
if (spaceIndex <= 0) {
throw new ParseException("Expected \"" + string + "\" to contain whitespace");
}
int level = Integer.parseInt(string.substring(0, spaceIndex));
AbstractGroup group = GroupsParser.fromString(string.substring(spaceIndex + 1), keywordSeparator);
GroupTreeNode newNode = GroupTreeNode.fromGroup(group);
if (cursor == null) {
// create new root
cursor = newNode;
root = cursor;
} else {
// insert at desired location
while ((level <= cursor.getLevel()) && (cursor.getParent().isPresent())) {
cursor = cursor.getParent().get();
}
cursor.addChild(newNode);
cursor = newNode;
}
}
return root;
} catch (ParseException e) {
throw new ParseException(Localization.lang("Group tree could not be parsed. If you save the BibTeX library, all groups will be lost."), e);
}
}
use of org.jabref.logic.importer.ParseException 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);
}
}
use of org.jabref.logic.importer.ParseException in project jabref by JabRef.
the class MetaDataParser method getAsList.
private static List<String> getAsList(String value) throws ParseException {
StringReader valueReader = new StringReader(value);
List<String> orderedValue = new ArrayList<>();
// We must allow for ; and \ in escape sequences.
try {
Optional<String> unit;
while ((unit = getNextUnit(valueReader)).isPresent()) {
orderedValue.add(unit.get());
}
} catch (IOException ex) {
LOGGER.error("Weird error while parsing meta data.", ex);
throw new ParseException("Weird error while parsing meta data.", ex);
}
return orderedValue;
}
Aggregations