Example #1
0
  /** Inserts a Bibtex String at the given index. */
  public synchronized void addString(BibtexString string) throws KeyCollisionException {
    if (hasStringLabel(string.getName())) {
      throw new KeyCollisionException("A string with this label already exists,");
    }

    if (_strings.containsKey(string.getId()))
      throw new KeyCollisionException("Duplicate BibtexString id.");

    _strings.put(string.getId(), string);
  }
Example #2
0
  /**
   * If the label represents a string contained in this database, returns that string's content.
   * Resolves references to other strings, taking care not to follow a circular reference pattern.
   * If the string is undefined, returns null.
   */
  private String resolveString(String label, HashSet<String> usedIds) {
    for (BibtexString string : _strings.values()) {

      // Util.pr(label+" : "+string.getName());
      if (string.getName().toLowerCase().equals(label.toLowerCase())) {

        // First check if this string label has been resolved
        // earlier in this recursion. If so, we have a
        // circular reference, and have to stop to avoid
        // infinite recursion.
        if (usedIds.contains(string.getId())) {
          Util.pr("Stopped due to circular reference in strings: " + label);
          return label;
        }
        // If not, log this string's ID now.
        usedIds.add(string.getId());

        // Ok, we found the string. Now we must make sure we
        // resolve any references to other strings in this one.
        String res = string.getContent();
        res = resolveContent(res, usedIds);

        // Finished with recursing this branch, so we remove our
        // ID again:
        usedIds.remove(string.getId());

        return res;
      }
    }

    // If we get to this point, the string has obviously not been defined locally.
    // Check if one of the standard BibTeX month strings has been used:
    Object o;
    if ((o = Globals.MONTH_STRINGS.get(label.toLowerCase())) != null) {
      return (String) o;
    }

    return null;
  }
Example #3
0
 /** Returns true if a string with the given label already exists. */
 public synchronized boolean hasStringLabel(String label) {
   for (BibtexString value : _strings.values()) {
     if (value.getName().equals(label)) return true;
   }
   return false;
 }