-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new parseJabRefComment with unit test #12145
base: main
Are you sure you want to change the base?
Changes from 3 commits
56c1bef
b2646ae
e12e655
465d6cf
830e7e6
065a784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
@@ -58,6 +59,8 @@ | |
import com.dd.plist.BinaryPropertyListParser; | ||
import com.dd.plist.NSDictionary; | ||
import com.dd.plist.NSString; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Document; | ||
|
@@ -339,7 +342,7 @@ private void parseAndAddEntry(String type) { | |
} | ||
} | ||
|
||
private void parseJabRefComment(Map<String, String> meta) { | ||
void parseJabRefComment(Map<String, String> meta) { | ||
StringBuilder buffer; | ||
try { | ||
buffer = parseBracketedFieldContent(); | ||
|
@@ -354,6 +357,7 @@ private void parseJabRefComment(Map<String, String> meta) { | |
// We remove all line breaks in the metadata | ||
// These have been inserted to prevent too long lines when the file was saved, and are not part of the data. | ||
String comment = buffer.toString().replaceAll("[\\x0d\\x0a]", ""); | ||
|
||
if (comment.substring(0, Math.min(comment.length(), MetaData.META_FLAG.length())).equals(MetaData.META_FLAG)) { | ||
if (comment.startsWith(MetaData.META_FLAG)) { | ||
String rest = comment.substring(MetaData.META_FLAG.length()); | ||
|
@@ -386,6 +390,20 @@ private void parseJabRefComment(Map<String, String> meta) { | |
} catch (ParseException ex) { | ||
parserResult.addException(ex); | ||
} | ||
} else if (comment.substring(0, Math.min(comment.length(), MetaData.META_FLAG_010.length())).equals(MetaData.META_FLAG_010)) { | ||
parseCommentToJson(comment, meta); | ||
} | ||
} | ||
|
||
private void parseCommentToJson(String comment, Map<String, String> meta) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No - it should return the JSOn object. The following call should be rewritten: MetaData metaData = metaDataParser.parse(
meta,
importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
And then be handled accordingliny in |
||
Pattern pattern = Pattern.compile("\\{.*}", Pattern.DOTALL); | ||
Matcher matcher = pattern.matcher(comment); | ||
Comment on lines
+399
to
+400
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, just doing |
||
if (matcher.find()) { | ||
String jsonString = matcher.group(); | ||
Gson gson = new Gson(); | ||
JsonObject jsonObject = gson.fromJson(jsonString, JsonObject.class); | ||
String jsonResult = gson.toJson(jsonObject); | ||
meta.putIfAbsent(MetaData.META_FLAG_010, jsonResult); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,13 +31,12 @@ | |||||
import com.google.common.eventbus.EventBus; | ||||||
import com.tobiasdiez.easybind.optional.OptionalBinding; | ||||||
import com.tobiasdiez.easybind.optional.OptionalWrapper; | ||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
|
||||||
@AllowedToUseLogic("because it needs access to citation pattern and cleanups") | ||||||
public class MetaData { | ||||||
|
||||||
public static final String META_FLAG = "jabref-meta: "; | ||||||
public static final String META_FLAG_010 = "jabref-meta-0.1.0"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include the string
Suggested change
|
||||||
public static final String ENTRYTYPE_FLAG = "jabref-entrytype: "; | ||||||
public static final String SAVE_ORDER_CONFIG = "saveOrderConfig"; // ToDo: Rename in next major version to saveOrder, adapt testbibs | ||||||
public static final String SAVE_ACTIONS = "saveActions"; | ||||||
|
@@ -58,8 +57,6 @@ public class MetaData { | |||||
public static final char SEPARATOR_CHARACTER = ';'; | ||||||
public static final String SEPARATOR_STRING = String.valueOf(SEPARATOR_CHARACTER); | ||||||
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MetaData.class); | ||||||
|
||||||
private final EventBus eventBus = new EventBus(); | ||||||
private final Map<EntryType, String> citeKeyPatterns = new HashMap<>(); // <BibType, Pattern> | ||||||
private final Map<String, String> userFileDirectory = new HashMap<>(); // <User, FilePath> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs
@VisibileForTesting
?