create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / importt / RocksimLoader.java
1 /*
2  * RocksimLoader.java
3  */
4 package net.sf.openrocket.file.rocksim.importt;
5
6 import java.io.IOException;
7 import java.io.InputStream;
8
9 import net.sf.openrocket.document.OpenRocketDocument;
10 import net.sf.openrocket.file.AbstractRocketLoader;
11 import net.sf.openrocket.file.MotorFinder;
12 import net.sf.openrocket.file.RocketLoadException;
13 import net.sf.openrocket.file.simplesax.SimpleSAX;
14
15 import org.xml.sax.InputSource;
16 import org.xml.sax.SAXException;
17
18 /**
19  * This class is the main entry point for Rocksim design file imported to OpenRocket.  Currently only Rocksim v9
20  * file formats are supported, although it is possible that v8 formats will work for most components.
21  * 
22  * In the cases of v9 components that exist in Rocksim but have no corollary in OpenRocket a message is added to
23  * a warning set and presented to the user.  In effect, this loading is a 'best-effort' mapping and is not meant to
24  * be an exact representation of any possible Rocksim design in an OpenRocket format.
25  * 
26  * Rocksim simulations are not imported.
27  * 
28  * Wish List:
29  *       Material interface (or at least make them abstract in RocketComponent)
30  *          setMaterial
31  *          getMaterial
32  */
33 public class RocksimLoader extends AbstractRocketLoader {
34         /**
35          * This method is called by the default implementations of {@link #load(java.io.File)}
36          * and {@link #load(java.io.InputStream)} to load the rocket.
37          *
38          * @throws net.sf.openrocket.file.RocketLoadException
39          *          if an error occurs during loading.
40          */
41         @Override
42         protected OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws IOException, RocketLoadException {
43                 
44                 InputSource xmlSource = new InputSource(source);
45                 
46                 RocksimHandler handler = new RocksimHandler();
47                 
48                 try {
49                         SimpleSAX.readXML(xmlSource, handler, warnings);
50                 } catch (SAXException e) {
51                         throw new RocketLoadException("Malformed XML in input.", e);
52                 }
53                 
54                 final OpenRocketDocument document = handler.getDocument();
55                 document.setFile(null);
56                 document.clearUndo();
57                 return document;
58         }
59 }