Пример #1
0
  public static BibtexEntry getBibtexEntry() {

    if (database == null) {

      StringReader reader =
          new StringReader(
              "@ARTICLE{HipKro03,\n"
                  + "  author = {Eric von Hippel and Georg von Krogh},\n"
                  + "  title = {Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science},\n"
                  + "  journal = {Organization Science},\n"
                  + "  year = {2003},\n"
                  + "  volume = {14},\n"
                  + "  pages = {209--223},\n"
                  + "  number = {2},\n"
                  + "  address = {Institute for Operations Research and the Management Sciences (INFORMS), Linthicum, Maryland, USA},\n"
                  + "  doi = {http://dx.doi.org/10.1287/orsc.14.2.209.14992},"
                  + "\n"
                  + "  issn = {1526-5455},"
                  + "\n"
                  + "  publisher = {INFORMS}\n"
                  + "}");

      BibtexParser parser = new BibtexParser(reader);
      ParserResult result = null;
      try {
        result = parser.parse();
      } catch (Exception e) {
        fail();
      }
      database = result.getDatabase();
      entry = database.getEntriesByKey("HipKro03")[0];
    }
    return entry;
  }
Пример #2
0
 /**
  * Parses BibtexEntries from the given string and returns the collection of all entries found.
  *
  * @param bibtexString
  * @return Returns null if an error occurred, returns an empty collection if no entries where
  *     found.
  */
 public static Collection<BibtexEntry> fromString(String bibtexString) {
   StringReader reader = new StringReader(bibtexString);
   BibtexParser parser = new BibtexParser(reader);
   try {
     return parser.parse().getDatabase().getEntries();
   } catch (Exception e) {
     return null;
   }
 }
Пример #3
0
  /**
   * Given a ticket an a list of citations, retrieve BibtexEntries from JStor
   *
   * @param ticket A valid ticket as returned by openTicket()
   * @param citations A list of citations as returned by getCitations()
   * @return A collection of BibtexEntries parsed from the bibtex returned by JStor.
   * @throws IOException Most probably related to a problem connecting to JStor.
   */
  private Collection<BibtexEntry> getBibtexEntries(String ticket, String citations)
      throws IOException {
    try {
      URL url = new URL(JSTORFetcher.URL_BIBTEX);
      URLConnection conn = url.openConnection();
      conn.setRequestProperty("Cookie", ticket + "; " + citations);
      conn.connect();

      BibtexParser parser =
          new BibtexParser(new BufferedReader(new InputStreamReader(conn.getInputStream())));
      return parser.parse().getDatabase().getEntries();
    } catch (MalformedURLException e) {
      // Propagate...
      throw new RuntimeException(e);
    }
  }
Пример #4
0
  /**
   * Import an entry from an OAI2 archive. The BibtexEntry provided has to have the field
   * OAI2_IDENTIFIER_FIELD set to the search string.
   *
   * @param key The OAI2 key to fetch from ArXiv.
   * @return The imnported BibtexEntry or null if none.
   */
  private BibtexDatabase importInspireEntries(String key, OutputPrinter frame) {
    String url = constructUrl(key);
    try {
      HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
      conn.setRequestProperty("User-Agent", "Jabref");
      InputStream inputStream = conn.getInputStream();

      INSPIREBibtexFilterReader reader =
          new INSPIREBibtexFilterReader(new InputStreamReader(inputStream));

      ParserResult pr = BibtexParser.parse(reader);

      return pr.getDatabase();
    } catch (IOException e) {
      frame.showMessage(
          Localization.lang("An Exception ocurred while accessing '%0'", url) + "\n\n" + e,
          Localization.lang(getKeyName()),
          JOptionPane.ERROR_MESSAGE);
    } catch (RuntimeException e) {
      frame.showMessage(
          Localization.lang(
                  "An Error occurred while fetching from INSPIRE source (%0):", new String[] {url})
              + "\n\n"
              + e.getMessage(),
          Localization.lang(getKeyName()),
          JOptionPane.ERROR_MESSAGE);
    }
    return null;
  }
Пример #5
0
  /* (non-Javadoc)
   * @see junit.framework.TestCase#setUp()
   */
  @Before
  public void setUp() throws Exception {
    ParserResult result =
        BibtexParser.parse(new FileReader(ImportDataTest.UNLINKED_FILES_TEST_BIB));
    database = result.getDatabase();
    entries = database.getEntries();

    entry1 = database.getEntryByKey("entry1");
    entry2 = database.getEntryByKey("entry2");
  }
Пример #6
0
  /** Test the Labelmaker and with accent grave Chars to test: "ÀÈÌÒÙ"; */
  public void testMakeLabelAndCheckLegalKeysAccentGrave() {
    BibtexEntry entry0 =
        BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Àöning}, year={2000}}");
    assertEquals(
        "Aoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Èöning}, year={2000}}");
    assertEquals(
        "Eoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ìöning}, year={2000}}");
    assertEquals(
        "Ioen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Òöning}, year={2000}}");
    assertEquals(
        "Ooen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ùöning}, year={2000}}");
    assertEquals(
        "Uoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));
  }
Пример #7
0
 /**
  * Shortcut usage to create a Parser and read the input.
  *
  * @param in - Reader to read from
  * @throws IOException
  */
 public static ParserResult parse(Reader in) throws IOException {
   BibtexParser parser = new BibtexParser(in);
   return parser.parse();
 }
Пример #8
0
  /**
   * Test for https://sourceforge.net/forum/message.php?msg_id=4498555 Test the Labelmaker and all
   * kind of accents Á á Ć ć É é Í í Ĺ ĺ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź
   */
  public void testMakeLabelAndCheckLegalKeys() {
    BibtexEntry entry0 =
        BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Köning}, year={2000}}");
    assertEquals(
        "Koen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Áöning}, year={2000}}");
    assertEquals(
        "Aoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Éöning}, year={2000}}");
    assertEquals(
        "Eoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Íöning}, year={2000}}");
    assertEquals(
        "Ioen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ĺöning}, year={2000}}");
    assertEquals(
        "Loen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ńöning}, year={2000}}");
    assertEquals(
        "Noen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Óöning}, year={2000}}");
    assertEquals(
        "Ooen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ŕöning}, year={2000}}");
    assertEquals(
        "Roen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Śöning}, year={2000}}");
    assertEquals(
        "Soen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Úöning}, year={2000}}");
    assertEquals(
        "Uoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ýöning}, year={2000}}");
    assertEquals(
        "Yoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));

    entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Źöning}, year={2000}}");
    assertEquals(
        "Zoen", net.sf.jabref.Util.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3")));
  }