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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/io/cml/CDKConvention.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: 7981 $ $Author: egonw $ $Date: 2007-02-20 18:05:37 +0100 (Tue, 20 Feb 2007) $
 
2
 *
 
3
 * Copyright (C) 2002-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
 */
 
26
package org.openscience.cdk.io.cml;
 
27
 
 
28
import java.util.StringTokenizer;
 
29
 
 
30
import org.openscience.cdk.interfaces.IChemFile;
 
31
import org.xml.sax.Attributes;
 
32
 
 
33
/**
 
34
 * This is an implementation for the CDK convention.
 
35
 *
 
36
 * @cdk.module io
 
37
 * 
 
38
 * @author egonw
 
39
 */
 
40
public class CDKConvention extends CMLCoreModule {
 
41
 
 
42
    private boolean isBond;
 
43
 
 
44
    public CDKConvention(IChemFile chemFile) {
 
45
        super(chemFile);
 
46
    }
 
47
 
 
48
    public CDKConvention(ICMLModule conv) {
 
49
        super(conv);
 
50
    }
 
51
    
 
52
    public void startDocument() {
 
53
        super.startDocument();
 
54
        isBond = false;
 
55
    }
 
56
 
 
57
    public void startElement(CMLStack xpath, String uri, String local, String raw, Attributes atts) {
 
58
        isBond = false;
 
59
        if (xpath.toString().endsWith("string/")) {
 
60
            for (int i = 0; i < atts.getLength(); i++) {
 
61
                if (atts.getQName(i).equals("buildin") &&
 
62
                    atts.getValue(i).equals("order")) {
 
63
                    isBond = true;
 
64
                }
 
65
            }
 
66
        } else {
 
67
            super.startElement(xpath, uri, local, raw, atts);
 
68
        }
 
69
    }
 
70
 
 
71
    public void characterData(CMLStack xpath, char ch[], int start, int length) {
 
72
        String s = new String(ch, start, length).trim();
 
73
        if (isBond) {
 
74
            logger.debug("CharData (bond): " + s);
 
75
            StringTokenizer st = new StringTokenizer(s);
 
76
            while (st.hasMoreElements()) {
 
77
                String border = (String)st.nextElement();
 
78
                logger.debug("new bond order: " + border);
 
79
                // assume cdk bond object has already started
 
80
//                cdo.setObjectProperty("Bond", "order", border);
 
81
                currentBond.setOrder(Double.parseDouble(border));
 
82
            }
 
83
        } else {
 
84
            super.characterData(xpath, ch, start, length);
 
85
        }
 
86
    }
 
87
}