예제 #1
0
        public void TestAddNew()
        {
            if (Globals.prefs == null)
            {
                Globals.prefs = JabRefPreferences.getInstance();
            }

            ParserResult result;
            using (var parser = new BibtexParser(new StreamReader(@"C:\Users\Peter\Desktop\bibtest.bib")))
            {
                result = parser.Parse();
            }

            var db = result.Database;

            BibtexEntry entry = new BibtexEntry();
            entry.setType(BibtexEntryType.ARTICLE.Instance);

            db.insertEntry(entry);
            db.setCiteKeyForEntry(entry.getId(), "ABC");

            foreach (var f in entry.getRequiredFields())
            {
                string value = BibtexFields.isNumeric(f) ? "1300" : "Another Test";
                entry.setField(f, value);
            }

            db.saveDatabase(File.Open(@"C:\Users\Peter\Desktop\bibtest.bib", FileMode.Open));
        }
예제 #2
0
        public void TestCreateNew()
        {
            if (Globals.prefs == null)
            {
                Globals.prefs = JabRefPreferences.getInstance();
            }

            BibtexDatabase db = new BibtexDatabase();

            BibtexEntry entry = new BibtexEntry();
            entry.setType(BibtexEntryType.ARTICLE.Instance);

            db.insertEntry(entry);
            db.setCiteKeyForEntry(entry.getId(), "ZXY");

            foreach (var f in entry.getRequiredFields())
            {
                string value = BibtexFields.isNumeric(f) ? "1000" : "Test";
                entry.setField(f, value);
            }

            db.saveDatabase(File.Open(@"C:\Users\Peter\Desktop\bibtest.bib", FileMode.Create));
        }
예제 #3
0
        /**
         * Inserts the entry, given that its ID is not already in use.
         * use Util.createId(...) to make up a unique ID for an entry.
         */
        public bool insertEntry(BibtexEntry entry)
        {
            lock (_lock) {
            string id = entry.getId();
            if (getEntryById(id) != null)
            {
              throw new KeyCollisionException(
                    "ID is already in use, please choose another");
            }
            _entries.Add(id, entry);

            return checkForDuplicateKeyAndAdd(null, entry.getCiteKey(), false);
            }
        }
예제 #4
0
        private void AddBibTeXEntry(BibtexEntry entry)
        {
            string title = entry.getField("title");
            string subtitle = "";
            string author = entry.getField("author");
            string editor = entry.getField("editor");

            title = TrimEntry(title);
            author = TrimEntry(author);
            editor = TrimEntry(editor);

            if (author == null)
            {
                Console.WriteLine("Warning: empty author field in entry {0}", entry.getId());
                author = "";
            }

            if (editor == null)
            {
                Console.WriteLine("Warning: empty editor field in entry {0}", entry.getId());
                editor = "";
            }

            string[] authors = author.Split(new string[] { " and ", "," }, StringSplitOptions.RemoveEmptyEntries);
            string new_author = "";
            foreach (string a in authors)
            {
                if (a.Length > 0 && new_author != "")
                    new_author = new_author + ";" + TrimEntry(a);
                else if (a.Length > 0)
                    new_author = TrimEntry(a);
            }

            if (editor == "")
                editor = new_author;
            if (new_author == "")
                new_author = editor;

            string booktitle = entry.getField("booktitle");
            string edition = entry.getField("edition");
            string isbn = entry.getField("isbn");
            string journalorseriestitle = entry.getType() == BibtexEntryType.getType("ARTICLE") ? entry.getField("journal") : entry.getField("series");
            string volume = entry.getField("volume");
            string issue = entry.getField("issue");
            string pages = entry.getField("pages");
            string startpage = "";
            string endpage = "";

            if (pages != null)
            {
                string[] splittedPages = pages.Split(new string[] { "-", "--" }, StringSplitOptions.RemoveEmptyEntries);
                if (splittedPages.Length > 0)
                    startpage = splittedPages[0].Trim();
                if (splittedPages.Length > 1)
                    endpage = splittedPages[1].Trim();
            }

            string issn = entry.getField("issn");
            string publisher = entry.getField("publisher");
            string publicationdate = entry.getField("year");
            string abstract_txt = entry.getField("abstract");
            string doi = entry.getField("doi");
            string fulltexturl = entry.getField("url");
            string notes = entry.getField("notes");
            string publicationtype = "";
            string orgcode = BibTex2eCitation.Properties.Settings.Default.DefaultOrgCode.ToString();

            if (entry.getType() == BibtexEntryType.getType("ARTICLE"))
                publicationtype = "Journal Items";
            else if (entry.getType() == BibtexEntryType.getType("BOOK"))
                publicationtype = "Monographs/ Monograph Items";
            else if (entry.getType() == BibtexEntryType.getType("PHDTHESIS"))
                publicationtype = "Doctoral Thesis and Habilitation";
            else if (entry.getType() == BibtexEntryType.getType("MASTERSTHESIS"))
                publicationtype = "Master Thesis and Bachelor Thesis";
            else if (entry.getType() == BibtexEntryType.getType("INPROCEEDINGS"))
                publicationtype = "Conference Contributions";
            string language = "English";

            dataGridView1.Rows.Add(new string[] { title, new_author, publicationdate, editor, publicationtype, "", orgcode, subtitle, booktitle, edition, "", "", isbn, journalorseriestitle, volume, issue, startpage, endpage, issn, publisher, "", "", abstract_txt, doi, fulltexturl, "", "", "", notes, "", language });
        }