示例#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
        /**
         * Take the given BibtexEntry and resolve any string references.
         *
         * @param entry
         *            A BibtexEntry in which all strings of the form #xxx# will be
         *            resolved against the hash map of string references stored in
         *            the databasee.
         *
         * @param inPlace
         *            If inPlace is true then the given BibtexEntry will be
         *            modified, if false then a copy is made using close made before
         *            resolving the strings.
         *
         * @return a BibtexEntry with all string references resolved. It is
         *         dependent on the value of inPlace whether a copy is made or the
         *         given BibtexEntries is modified.
         */
        public BibtexEntry resolveForStrings(BibtexEntry entry, bool inPlace)
        {
            if (!inPlace){
            entry = (BibtexEntry)entry.clone();
            }

            foreach (object field in entry.getAllFields()){
            entry.setField(field.ToString(), this.resolveForStrings(entry.getField(field.ToString()).ToString()));
            }

            return entry;
        }