25
25
import java.io.File;
26
26
import java.io.FileNotFoundException;
27
import java.io.IOException;
28
27
import java.util.List;
30
29
import javax.xml.parsers.ParserConfigurationException;
31
30
import javax.xml.parsers.SAXParserFactory;
33
import org.xml.sax.SAXException;
34
32
import org.xml.sax.XMLReader;
36
34
import au.gov.naa.digipres.xena.kernel.XenaException;
125
125
// If viewType is null, get the default view
127
if (viewType == null) {
128
viewType = viewManager.getDefaultView(xis);
127
if (currentType == null) {
128
currentType = viewManager.getDefaultView(xis);
131
131
// Set the source directory - need this to be able to link to child files stored relative to this xena file
132
viewType.setSourceDir(xenaFile.getParentFile());
132
currentType.setSourceDir(xenaFile.getParentFile());
134
134
// use our view to display the xena file...
135
135
// get our parser, and parse the thing.
139
139
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
141
// This causes problems with JdomXenaViews, as the localname is set to empty by SAXParser but
142
// the SAXHandler attempts to create an Element with the localname as it's name
141
// Not using namespaces causes problems with DOMXenaViews, as the localname is set to empty by SAXParser but
142
// the SAXHandler attempts to create an Element with the localname as its name.
143
143
// TODO: Find a solution that disables namespaces but doesn't cause any other problems!
144
144
// Don't want namespaces for viewing, as namespace problems would throw an exception...
145
145
reader.setFeature("http://xml.org/sax/features/namespaces", true);
146
146
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
148
reader.setContentHandler(viewType.getContentHandler());
148
reader.setContentHandler(currentType.getContentHandler());
150
reader.setProperty("http://xml.org/sax/properties/lexical-handler", currentType.getLexicalHandler());
149
152
reader.parse(xis);
151
viewType.closeContentHandler();
152
viewType.initListenersAndSubViews();
154
} catch (IOException iox) {
155
throw new XenaException(iox);
156
} catch (SAXException sx) {
157
throw new XenaException(sx);
154
currentType.closeContentHandler();
155
currentType.initListenersAndSubViews();
158
157
} catch (ParserConfigurationException pce) {
159
158
throw new XenaException(pce);
159
} catch (Exception ex) {
160
throw new XenaException("Could not parse file. Please check that it a valid Xena file.", ex);