Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fixUrlLink
Browse files Browse the repository at this point in the history
* upstream/main:
  Add some JavaDoc to Fetchers
  Support two argument form of \abx@aux@cite macro in DefaultAuxParser (#8549)
  • Loading branch information
Siedlerchr committed Mar 7, 2022
2 parents bda2458 + 3c247ff commit bc1495a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where "Copy DOI url" in the right-click menu of the Entry List would just copy the DOI and not the DOI url. [#8389](https://github.com/JabRef/jabref/issues/8389)
- We fixed an issue where opening the console from the drop-down menu would cause an exception. [#8466](https://github.com/JabRef/jabref/issues/8466)
- We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448)
- We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class DefaultAuxParser implements AuxParser {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAuxParser.class);

private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)\\{(.+)\\}");
private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)(\\{\\d+\\})?\\{(?<citationkey>.+)\\}");
private static final Pattern INPUT_PATTERN = Pattern.compile("\\\\@input\\{(.+)\\}");

private final BibDatabase masterDatabase;
Expand Down Expand Up @@ -108,7 +108,7 @@ private void matchCitation(AuxParserResult result, String line) {
Matcher citeMatch = CITE_PATTERN.matcher(line);

while (citeMatch.find()) {
String keyString = citeMatch.group(2);
String keyString = citeMatch.group("citationkey");
String[] keys = keyString.split(",");

for (String key : keys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Searches web resources for bibliographic information based on a {@link BibEntry}.
* Useful to complete an existing entry with fetched information.
* Useful to <emph>complete</emph> an existing entry with fetched information.
* May return multiple search hits.
*/
public interface EntryBasedFetcher extends WebFetcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Searches web resources for bibliographic information based on an identifier.
* Examples are ISBN numbers and DOIs.
*/
public interface IdBasedFetcher extends WebFetcher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
/**
* Searches web resources for bibliographic information based on a free-text query.
* May return multiple search hits.
* <p>
* This interface is used for web resources which directly return BibTeX data ({@link BibEntry})
* </p>
*/
public interface SearchBasedFetcher extends WebFetcher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;

/**
* Provides a convenient interface for search-based fetcher, which follow the usual three-step procedure:
* Provides a convenient interface for search-based fetcher, which follows the usual three-step procedure:
* <ol>
* <li>Open a URL based on the search query</li>
* <li>Parse the response to get a list of {@link BibEntry}</li>
* <li>Post-process fetched entries</li>
* </ol>
* <p>
* This interface is used for web resources which do NOT provide BibTeX data (@link {@link BibEntry)}.
* JabRef's infrastructure to convert arbitrary input data to BibTeX is {@link Parser}.
* </p>
* <p>
* This interface inherits {@link SearchBasedFetcher}, because the methods <code>performSearch</code> have to be provided by both.
* As non-BibTeX web fetcher one could do "magic" stuff without this helper interface and directly use {@link WebFetcher}, but this is more work.
* </p>
* <p>
* Note that this interface "should" be an abstract class.
* However, Java does not support multi inheritance with classes (but with interfaces).
* We need multi inheritance, because a fetcher might implement multiple query types (such as id fetching {@link IdBasedFetcher)}, complete entry {@link EntryBasedFetcher}, and search-based fetcher (this class).
* </p>
*/
public interface SearchBasedParserFetcher extends SearchBasedFetcher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public List<String> parseDoiSearchPage(InputStream stream) throws ParseException
Elements doiHrefs = doc.select("div.issue-item__content-right > h5 > span > a");

for (Element elem : doiHrefs) {
String fullSegement = elem.attr("href");
String doi = fullSegement.substring(fullSegement.indexOf("10"));
String fullSegment = elem.attr("href");
String doi = fullSegment.substring(fullSegment.indexOf("10"));
doiList.add(doi);
}
} catch (IOException ex) {
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/jabref/logic/auxparser/AuxParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ void testNormal() throws URISyntaxException, IOException {
}
}

@Test
void testTwoArgMacro() throws URISyntaxException, IOException {
// Result should be identical to that of testNormal

InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Path.of(AuxParserTest.class.getResource("papertwoargmacro.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
assertEquals(0, auxResult.getUnresolvedKeysCount());
BibDatabase newDB = auxResult.getGeneratedBibDatabase();
List<BibEntry> newEntries = newDB.getEntries();
assertEquals(2, newEntries.size());
assertTrue(newEntries.get(0).hasChanged());
assertTrue(newEntries.get(1).hasChanged());
assertEquals(2, auxResult.getResolvedKeysCount());
assertEquals(2, auxResult.getFoundKeysInAux());
assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(),
auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
assertEquals(0, auxResult.getCrossRefEntriesCount());
}
}

@Test
void testNotAllFound() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\relax
\abx@aux@cite{0}{Darwin1888}
\abx@aux@cite{0}{Einstein1920}
\bibstyle{plain}
\bibdata{origin}
\bibcite{Darwin1888}{1}
\bibcite{Einstein1920}{2}
\@writefile{toc}{\contentsline {section}{\numberline {1}}{1}}

0 comments on commit bc1495a

Please sign in to comment.