~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/net/sf/cdk/tools/bibtex/BibTeXMLFile.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Revision: 6707 $ $Author: egonw $ $Date: 2006-07-30 16:38:18 -0400 (Sun, 30 Jul 2006) $
 
2
 * 
 
3
 * Copyright (C) 2007  Egon Willighagen <egonw@users.sf.net>
 
4
 * 
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public License
 
9
 * as published by the Free Software Foundation; either version 2.1
 
10
 * of the License, or (at your option) any later version.
 
11
 * All we ask is that proper credit is given for our work, which includes
 
12
 * - but is not limited to - adding the above copyright notice to the beginning
 
13
 * of your source code files, and to any copyright notice that you may distribute
 
14
 * with programs based on this work.
 
15
 * 
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
24
 */
 
25
package net.sf.cdk.tools.bibtex;
 
26
 
 
27
import java.util.ArrayList;
 
28
import java.util.Iterator;
 
29
import java.util.List;
 
30
 
 
31
import nu.xom.Node;
 
32
import nu.xom.Nodes;
 
33
import nu.xom.XPathContext;
 
34
 
 
35
/**
 
36
 * Wrapper for a BibTeXML file.
 
37
 * 
 
38
 * @author egonw
 
39
 */
 
40
public class BibTeXMLFile {
 
41
 
 
42
        public final static String BIBTEXML_NAMESPACE = "http://bibtexml.sf.net/";
 
43
        
 
44
        private Node root;
 
45
        private XPathContext context;
 
46
        
 
47
        public BibTeXMLFile(Node root) {
 
48
                this.root = root;
 
49
                context = new XPathContext("bibtex", BIBTEXML_NAMESPACE);
 
50
                context.addNamespace("b", BIBTEXML_NAMESPACE);          
 
51
        }
 
52
        
 
53
        /**
 
54
         * Returns an Iterator&lt;BibTeXMLEntry>.
 
55
         */
 
56
        public Iterator getEntries() {
 
57
                List entries = new ArrayList();
 
58
                Nodes results = root.query("//b:entry", context);
 
59
                for (int i=0; i<results.size(); i++) {
 
60
                        entries.add(new BibTeXMLEntry(results.get(i)));
 
61
                }
 
62
                return entries.iterator();
 
63
        }
 
64
        
 
65
        public BibTeXMLEntry getEntry(String id) {
 
66
                Nodes results = root.query("//b:entry[./@id='" + id+ "']", context);
 
67
                if (results.size() > 0) {
 
68
                        return new BibTeXMLEntry(results.get(0));
 
69
                }
 
70
                return null;
 
71
        }
 
72
        
 
73
}