Search in sources :

Example 11 with ParseException

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);
    }
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) ParseException(org.jabref.logic.importer.ParseException) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 12 with ParseException

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);
    }
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ParseException(org.jabref.logic.importer.ParseException)

Example 13 with ParseException

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);
    }
}
Also used : QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) ParseException(org.jabref.logic.importer.ParseException) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 14 with ParseException

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;
}
Also used : StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParseException(org.jabref.logic.importer.ParseException)

Aggregations

ParseException (org.jabref.logic.importer.ParseException)14 IOException (java.io.IOException)8 BibEntry (org.jabref.model.entry.BibEntry)6 URL (java.net.URL)4 FetcherException (org.jabref.logic.importer.FetcherException)4 URLDownload (org.jabref.logic.net.URLDownload)4 MalformedURLException (java.net.MalformedURLException)3 BufferedReader (java.io.BufferedReader)2 URISyntaxException (java.net.URISyntaxException)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)2 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)2 DOI (org.jabref.model.entry.identifier.DOI)2 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 Dimension (java.awt.Dimension)1