use of org.jabref.logic.layout.Layout in project jabref by JabRef.
the class OOBibBase method insertFullReferenceAtCursor.
private void insertFullReferenceAtCursor(XTextCursor cursor, Map<BibEntry, BibDatabase> entries, OOBibStyle style, String parFormat) throws UndefinedParagraphFormatException, IllegalArgumentException, UnknownPropertyException, PropertyVetoException, WrappedTargetException {
Map<BibEntry, BibDatabase> correctEntries;
// If we don't have numbered entries, we need to sort the entries before adding them:
if (style.isSortByPosition()) {
// Use the received map directly
correctEntries = entries;
} else {
// Sort map
Map<BibEntry, BibDatabase> newMap = new TreeMap<>(entryComparator);
newMap.putAll(entries);
correctEntries = newMap;
}
int number = 1;
for (Map.Entry<BibEntry, BibDatabase> entry : correctEntries.entrySet()) {
if (entry.getKey() instanceof UndefinedBibtexEntry) {
continue;
}
OOUtil.insertParagraphBreak(text, cursor);
if (style.isNumberEntries()) {
int minGroupingCount = style.getIntCitProperty(OOBibStyle.MINIMUM_GROUPING_COUNT);
OOUtil.insertTextAtCurrentLocation(text, cursor, style.getNumCitationMarker(Collections.singletonList(number++), minGroupingCount, true), Collections.emptyList());
}
Layout layout = style.getReferenceFormat(entry.getKey().getType());
layout.setPostFormatter(POSTFORMATTER);
OOUtil.insertFullReferenceAtCurrentLocation(text, cursor, layout, parFormat, entry.getKey(), entry.getValue(), uniquefiers.get(entry.getKey().getCiteKeyOptional().orElse(null)));
}
}
use of org.jabref.logic.layout.Layout in project jabref by JabRef.
the class FileUtil method createFileNameFromPattern.
/**
* Determines filename provided by an entry in a database
*
* @param database the database, where the entry is located
* @param entry the entry to which the file should be linked to
* @param fileNamePattern the filename pattern
* @param prefs the layout preferences
* @return a suggested fileName
*/
public static String createFileNameFromPattern(BibDatabase database, BibEntry entry, String fileNamePattern, LayoutFormatterPreferences prefs) {
String targetName = null;
StringReader sr = new StringReader(fileNamePattern);
Layout layout = null;
try {
layout = new LayoutHelper(sr, prefs).getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Wrong format " + e.getMessage(), e);
}
if (layout != null) {
targetName = layout.doLayout(entry, database);
}
if ((targetName == null) || targetName.isEmpty()) {
targetName = entry.getCiteKeyOptional().orElse("default");
}
//Removes illegal characters from filename
targetName = FileNameCleaner.cleanFileName(targetName);
return targetName;
}
use of org.jabref.logic.layout.Layout in project jabref by JabRef.
the class OOBibStyleTest method testLayout.
@Test
public void testLayout() throws IOException {
Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, StandardCharsets.UTF_8));
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
BibDatabase db = result.getDatabase();
Layout l = style.getReferenceFormat("default");
l.setPostFormatter(new OOPreFormatter());
BibEntry entry = db.getEntryByKey("1137631").get();
assertEquals("Boström, G.; Wäyrynen, J.; Bodén, M.; Beznosov, K. and Kruchten, P. (<b>2006</b>). <i>Extending XP practices to support security requirements engineering</i>, : 11-18.", l.doLayout(entry, db));
l = style.getReferenceFormat("incollection");
l.setPostFormatter(new OOPreFormatter());
assertEquals("Boström, G.; Wäyrynen, J.; Bodén, M.; Beznosov, K. and Kruchten, P. (<b>2006</b>). <i>Extending XP practices to support security requirements engineering</i>. In: (Ed.), <i>SESS '06: Proceedings of the 2006 international workshop on Software engineering for secure systems</i>, ACM.", l.doLayout(entry, db));
}
use of org.jabref.logic.layout.Layout in project jabref by JabRef.
the class OOBibStyleTest method testVonAuthor.
@Test
public void testVonAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
BibDatabase database = new BibDatabase();
Layout l = style.getReferenceFormat("article");
l.setPostFormatter(new OOPreFormatter());
BibEntry entry = new BibEntry();
entry.setType("article");
entry.setField("author", "Alpha von Beta");
entry.setField("title", "JabRef Manual");
entry.setField("year", "2016");
database.insertEntry(entry);
assertEquals("<b>von Beta, A.</b> (<b>2016</b>). <i>JabRef Manual</i>, .", l.doLayout(entry, database));
}
use of org.jabref.logic.layout.Layout in project jabref by JabRef.
the class OOBibStyleTest method testInstitutionAuthor.
@Test
public void testInstitutionAuthor() throws IOException {
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
BibDatabase database = new BibDatabase();
Layout l = style.getReferenceFormat("article");
l.setPostFormatter(new OOPreFormatter());
BibEntry entry = new BibEntry();
entry.setType("article");
entry.setField("author", "{JabRef Development Team}");
entry.setField("title", "JabRef Manual");
entry.setField("year", "2016");
database.insertEntry(entry);
assertEquals("<b>JabRef Development Team</b> (<b>2016</b>). <i>JabRef Manual</i>, .", l.doLayout(entry, database));
}
Aggregations