Ejemplo n.º 1
0
  /**
   * Checks if the two entries represent the same publication.
   *
   * @param one BibEntry
   * @param two BibEntry
   * @return boolean
   */
  public static boolean isDuplicate(BibEntry one, BibEntry two, BibDatabaseMode bibDatabaseMode) {

    // First check if they are of the same type - a necessary condition:
    if (!one.getType().equals(two.getType())) {
      return false;
    }
    EntryType type = EntryTypes.getTypeOrDefault(one.getType(), bibDatabaseMode);

    // The check if they have the same required fields:
    java.util.List<String> var = type.getRequiredFieldsFlat();
    String[] fields = var.toArray(new String[var.size()]);
    double[] req;
    if (fields == null) {
      req = new double[] {0., 0.};
    } else {
      req = DuplicateCheck.compareFieldSet(fields, one, two);
    }

    if (Math.abs(req[0] - DuplicateCheck.duplicateThreshold) > DuplicateCheck.DOUBT_RANGE) {
      // Far from the threshold value, so we base our decision on the req. fields only
      return req[0] >= DuplicateCheck.duplicateThreshold;
    }
    // Close to the threshold value, so we take a look at the optional fields, if any:
    java.util.List<String> optionalFields = type.getOptionalFields();
    fields = optionalFields.toArray(new String[optionalFields.size()]);
    if (fields != null) {
      double[] opt = DuplicateCheck.compareFieldSet(fields, one, two);
      double totValue =
          ((DuplicateCheck.REQUIRED_WEIGHT * req[0] * req[1]) + (opt[0] * opt[1]))
              / ((req[1] * DuplicateCheck.REQUIRED_WEIGHT) + opt[1]);
      return totValue >= DuplicateCheck.duplicateThreshold;
    }
    return req[0] >= DuplicateCheck.duplicateThreshold;
  }
Ejemplo n.º 2
0
 /**
  * Will check if the current library uses any entry types from another mode. For example it will
  * warn the user if he uses entry types defined for Biblatex inside a BibTeX library.
  */
 @Override
 public List<IntegrityMessage> check(BibEntry entry) {
   if (EntryTypes.isExclusiveBibLatex(entry.getType())) {
     return Collections.singletonList(
         new IntegrityMessage(
             Localization.lang(
                 "Entry type %0 is only defined for Biblatex but not for BibTeX", entry.getType()),
             entry,
             "bibtexkey"));
   }
   return Collections.emptyList();
 }
Ejemplo n.º 3
0
  /**
   * Generates a Citation based on the given entry, style, and output format WARNING: the citation
   * is generated with JavaScript which may take some time, better call it in outside the main
   * Thread
   */
  protected static String generateCitation(
      BibEntry entry, String style, CitationStyleOutputFormat outputFormat) {
    try {
      String citeKey = entry.getCiteKeyOptional().orElse("");
      BibTeXEntry bibTeXEntry = new BibTeXEntry(new Key(entry.getType()), new Key(citeKey));
      for (Map.Entry<String, String> field : entry.getFieldMap().entrySet()) {
        String value = UNICODE_TO_LATEX_FORMATTER.format(field.getValue());
        bibTeXEntry.addField(new Key(field.getKey()), new DigitStringValue(value));
      }

      CSLItemData cslItemData = BIBTEX_CONVERTER.toItemData(bibTeXEntry);
      Bibliography bibliography =
          CSL.makeAdhocBibliography(style, outputFormat.getFormat(), cslItemData);
      return bibliography.getEntries()[0];

    } catch (IOException | ArrayIndexOutOfBoundsException e) {
      LOGGER.error("Could not generate BibEntry citation", e);
      return Localization.lang("Cannot generate preview based on selected citation style.");
    } catch (TokenMgrException e) {
      LOGGER.error("Bad character inside BibEntry", e);
      // sadly one cannot easily retrieve the bad char from the TokenMgrError
      return new StringBuilder()
          .append(Localization.lang("Cannot generate preview based on selected citation style."))
          .append(outputFormat == CitationStyleOutputFormat.HTML ? "<br>" : "\n")
          .append(Localization.lang("Bad character inside entry"))
          .append(outputFormat == CitationStyleOutputFormat.HTML ? "<br>" : "\n")
          .append(e.getLocalizedMessage())
          .toString();
    }
  }
  public Document getDOMrepresentation() {
    Document result = null;
    try {
      DocumentBuilder dbuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      result = dbuild.newDocument();
      Element collection = result.createElement("office:document-content");
      // collection.setAttribute("xmlns", "http://openoffice.org/2000/office");
      collection.setAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
      collection.setAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
      collection.setAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
      collection.setAttribute("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
      collection.setAttribute("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
      collection.setAttribute("office:version", "1.0");
      collection.setAttribute(
          "xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
      collection.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
      Element el = result.createElement("office:scripts");
      collection.appendChild(el);

      el = result.createElement("office:automatic-styles");
      Element el2 = result.createElement("style:style");
      el2.setAttribute("style:name", "ro1");
      el2.setAttribute("style:family", "table-row");
      Element el3 = result.createElement("style.table-row-properties");
      el3.setAttribute("style:row-height", "0.1681inch");
      el3.setAttribute("fo:break-before", "auto");
      el3.setAttribute("style:use-optimal-row-height", "true");
      el2.appendChild(el3);
      el.appendChild(el2);
      el2 = result.createElement("style:style");
      el2.setAttribute("style:name", "ta1");
      el2.setAttribute("style:family", "table");
      el2.setAttribute("style:master-page-name", "Default");
      el3 = result.createElement("style:properties");
      el3.setAttribute("table:display", "true");
      el2.appendChild(el3);
      el.appendChild(el2);
      collection.appendChild(el);

      Element body = result.createElement("office:body");
      Element spreadsheet = result.createElement("office:spreadsheet");
      Element table = result.createElement("table:table");
      table.setAttribute("table:name", "biblio");
      table.setAttribute("table.style-name", "ta1");

      Element row = result.createElement("table:table-row");
      row.setAttribute("table.style-name", "ro1");
      addTableCell(result, row, "Identifier");
      addTableCell(result, row, "Type");
      addTableCell(result, row, "Address");
      addTableCell(result, row, "Assignee");
      addTableCell(result, row, "Annote");
      addTableCell(result, row, "Author");
      addTableCell(result, row, "Booktitle");
      addTableCell(result, row, "Chapter");
      addTableCell(result, row, "Day");
      addTableCell(result, row, "Dayfiled");
      addTableCell(result, row, "Edition");
      addTableCell(result, row, "Editor");
      addTableCell(result, row, "Howpublish");
      addTableCell(result, row, "Institution");
      addTableCell(result, row, "Journal");
      addTableCell(result, row, "Language");
      addTableCell(result, row, "Month");
      addTableCell(result, row, "Monthfiled");
      addTableCell(result, row, "Nationality");
      addTableCell(result, row, "Note");
      addTableCell(result, row, "Number");
      addTableCell(result, row, "Organization");
      addTableCell(result, row, "Pages");
      addTableCell(result, row, "Publisher");
      addTableCell(result, row, "Revision");
      addTableCell(result, row, "School");
      addTableCell(result, row, "Series");
      addTableCell(result, row, "Title");
      addTableCell(result, row, "RepType");
      addTableCell(result, row, "Volume");
      addTableCell(result, row, "Year");
      addTableCell(result, row, "Yearfiled");
      addTableCell(result, row, "URL");
      addTableCell(result, row, "Custom1");
      addTableCell(result, row, "Custom2");
      addTableCell(result, row, "Custom3");
      addTableCell(result, row, "Custom4");
      addTableCell(result, row, "Custom5");
      addTableCell(result, row, "ISBN");
      table.appendChild(row);

      for (BibEntry e : entries) {
        row = result.createElement("table:table-row");
        addTableCell(result, row, getField(e, BibEntry.KEY_FIELD));
        addTableCell(result, row, new GetOpenOfficeType().format(e.getType()));
        addTableCell(result, row, getField(e, FieldName.ADDRESS));
        addTableCell(result, row, getField(e, FieldName.ASSIGNEE));
        addTableCell(result, row, getField(e, FieldName.ANNOTE));
        addTableCell(
            result, row, getField(e, FieldName.AUTHOR)); // new AuthorLastFirst().format(getField(e,
        // FieldName.AUTHOR_FIELD)));
        addTableCell(result, row, getField(e, FieldName.BOOKTITLE));
        addTableCell(result, row, getField(e, FieldName.CHAPTER));
        addTableCell(result, row, getField(e, FieldName.DAY));
        addTableCell(result, row, getField(e, FieldName.DAYFILED));
        addTableCell(result, row, getField(e, FieldName.EDITION));
        addTableCell(
            result, row, getField(e, FieldName.EDITOR)); // new AuthorLastFirst().format(getField(e,
        // FieldName.EDITOR_FIELD)));
        addTableCell(result, row, getField(e, FieldName.HOWPUBLISHED));
        addTableCell(result, row, getField(e, FieldName.INSTITUTION));
        addTableCell(result, row, getField(e, FieldName.JOURNAL));
        addTableCell(result, row, getField(e, FieldName.LANGUAGE));
        addTableCell(result, row, getField(e, FieldName.MONTH));
        addTableCell(result, row, getField(e, FieldName.MONTHFILED));
        addTableCell(result, row, getField(e, FieldName.NATIONALITY));
        addTableCell(result, row, getField(e, FieldName.NOTE));
        addTableCell(result, row, getField(e, FieldName.NUMBER));
        addTableCell(result, row, getField(e, FieldName.ORGANIZATION));
        addTableCell(result, row, getField(e, FieldName.PAGES));
        addTableCell(result, row, getField(e, FieldName.PUBLISHER));
        addTableCell(result, row, getField(e, FieldName.REVISION));
        addTableCell(result, row, getField(e, FieldName.SCHOOL));
        addTableCell(result, row, getField(e, FieldName.SERIES));
        addTableCell(
            result,
            row,
            new RemoveWhitespace()
                .format(new RemoveBrackets().format(getField(e, FieldName.TITLE))));
        addTableCell(result, row, getField(e, "reporttype"));
        addTableCell(result, row, getField(e, FieldName.VOLUME));
        addTableCell(result, row, getField(e, FieldName.YEAR));
        addTableCell(result, row, getField(e, FieldName.YEARFILED));
        addTableCell(result, row, getField(e, FieldName.URL));
        addTableCell(result, row, "");
        addTableCell(result, row, "");
        addTableCell(result, row, "");
        addTableCell(result, row, "");
        addTableCell(result, row, "");
        addTableCell(result, row, getField(e, FieldName.ISBN));
        table.appendChild(row);
      }

      spreadsheet.appendChild(table);
      body.appendChild(spreadsheet);
      collection.appendChild(body);

      result.appendChild(collection);
    } catch (Exception e) {
      LOGGER.warn("Exception caught...", e);
    }
    return result;
  }