Search in sources :

Example 1 with Layout

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)));
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Layout(org.jabref.logic.layout.Layout) UndefinedBibtexEntry(org.jabref.logic.openoffice.UndefinedBibtexEntry) TreeMap(java.util.TreeMap) BibDatabase(org.jabref.model.database.BibDatabase) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Point(com.sun.star.awt.Point)

Example 2 with Layout

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;
}
Also used : Layout(org.jabref.logic.layout.Layout) StringReader(java.io.StringReader) LayoutHelper(org.jabref.logic.layout.LayoutHelper) IOException(java.io.IOException)

Example 3 with Layout

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));
}
Also used : Path(java.nio.file.Path) ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) Layout(org.jabref.logic.layout.Layout) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 4 with Layout

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));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Layout(org.jabref.logic.layout.Layout) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 5 with Layout

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));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Layout(org.jabref.logic.layout.Layout) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Aggregations

Layout (org.jabref.logic.layout.Layout)9 BibEntry (org.jabref.model.entry.BibEntry)7 LayoutHelper (org.jabref.logic.layout.LayoutHelper)5 IOException (java.io.IOException)4 StringReader (java.io.StringReader)4 BibDatabase (org.jabref.model.database.BibDatabase)4 Test (org.junit.Test)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Point (com.sun.star.awt.Point)1 BorderLayout (java.awt.BorderLayout)1 StringSelection (java.awt.datatransfer.StringSelection)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1