Package net.sf.jabref.export.layout

Examples of net.sf.jabref.export.layout.Layout


  public String layout(String layoutFile, String entry) throws Exception {

    BibtexEntry be = bibtexString2BibtexEntry(entry);
    StringReader sr = new StringReader(layoutFile.replaceAll("__NEWLINE__", "\n"));
    Layout layout = new LayoutHelper(sr).getLayoutFromText(Globals.FORMATTER_PACKAGE);
    StringBuffer sb = new StringBuffer();
    sb.append(layout.doLayout(be, null));

    return sb.toString();
  }
View Full Code Here


    if (ss == null)
        ss = getSaveSession(encoding, outFile);
       
    VerifyingWriter ps = ss.getWriter();

        Layout beginLayout = null;
    Reader reader = null;

        // Check if this export filter has bundled name formatters:
        HashMap<String,String> customNameFormatters = readFormatterFile(lfFileName);
        // Set a global field, so all layouts have access to the custom name formatters:
        Globals.prefs.customExportNameFormatters = customNameFormatters;

        ArrayList<String> missingFormatters = new ArrayList<String>(1);

        // Print header
        try {
      reader = getReader(lfFileName + ".begin.layout");
      LayoutHelper layoutHelper = new LayoutHelper(reader);
      beginLayout = layoutHelper
        .getLayoutFromText(Globals.FORMATTER_PACKAGE);
            reader.close();
    } catch (IOException ex) {
      // If an exception was cast, export filter doesn't have a begin
      // file.
    }
    // Write the header
    if (beginLayout != null) {
      ps.write(beginLayout.doLayout(database, encoding));
            missingFormatters.addAll(beginLayout.getMissingFormatters());
    }

    /*
     * Write database entries; entries will be sorted as they appear on the
     * screen, or sorted by author, depending on Preferences. We also supply
     * the Set entries - if we are to export only certain entries, it will
     * be non-null, and be used to choose entries. Otherwise, it will be
     * null, and be ignored.
     */
    List<BibtexEntry> sorted = FileActions.getSortedEntries(database,
      entryIds, false);

    // Load default layout
    reader = getReader(lfFileName + ".layout");

    LayoutHelper layoutHelper = new LayoutHelper(reader);
    Layout defLayout = layoutHelper
      .getLayoutFromText(Globals.FORMATTER_PACKAGE);
    reader.close();
        if (defLayout != null) {
            missingFormatters.addAll(defLayout.getMissingFormatters());
            System.out.println(defLayout.getMissingFormatters());
        }
    HashMap<String, Layout> layouts = new HashMap<String, Layout>();
    Layout layout;

        ExportFormats.entryNumber = 0;
    for (BibtexEntry entry : sorted) {
            ExportFormats.entryNumber++; // Increment entry counter.
      // Get the layout
      String type = entry.getType().getName().toLowerCase();
      if (layouts.containsKey(type))
        layout = layouts.get(type);
      else {
        try {
          // We try to get a type-specific layout for this entry.
          reader = getReader(lfFileName + "." + type + ".layout");
          layoutHelper = new LayoutHelper(reader);
          layout = layoutHelper
            .getLayoutFromText(Globals.FORMATTER_PACKAGE);
          layouts.put(type, layout);
          reader.close();
                    if (layout != null)
                        missingFormatters.addAll(layout.getMissingFormatters());

        } catch (IOException ex) {
          // The exception indicates that no type-specific layout
          // exists, so we
          // go with the default one.
          layout = defLayout;
        }
      }

      // Write the entry
      ps.write(layout.doLayout(entry, database));
    }

    // Print footer

    // changed section - begin (arudert)
    Layout endLayout = null;
    try {
      reader = getReader(lfFileName + ".end.layout");
      layoutHelper = new LayoutHelper(reader);
      endLayout = layoutHelper
        .getLayoutFromText(Globals.FORMATTER_PACKAGE);
      reader.close();
    } catch (IOException ex) {
      // If an exception was thrown, export filter doesn't have an end
      // file.
    }

    // Write footer
    if (endLayout != null) {
      ps.write(endLayout.doLayout(database, encoding));
            missingFormatters.addAll(endLayout.getMissingFormatters());
    }

        // Clear custom name formatters:
        Globals.prefs.customExportNameFormatters = null;

View Full Code Here

TOP

Related Classes of net.sf.jabref.export.layout.Layout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.