~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to src/au/gov/naa/digipres/xena/core/NormalisedObjectViewFactory.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import java.io.File;
26
26
import java.io.FileNotFoundException;
27
 
import java.io.IOException;
28
27
import java.util.List;
29
28
 
30
29
import javax.xml.parsers.ParserConfigurationException;
31
30
import javax.xml.parsers.SAXParserFactory;
32
31
 
33
 
import org.xml.sax.SAXException;
34
32
import org.xml.sax.XMLReader;
35
33
 
36
34
import au.gov.naa.digipres.xena.kernel.XenaException;
112
110
                // check out our file here...
113
111
                // make sure it is the appropriate type etc.
114
112
 
 
113
                XenaView currentType = viewType;
 
114
 
115
115
                XenaInputSource xis = null;
116
116
                // create the xis
117
117
                try {
124
124
 
125
125
                // If viewType is null, get the default view
126
126
 
127
 
                if (viewType == null) {
128
 
                        viewType = viewManager.getDefaultView(xis);
 
127
                if (currentType == null) {
 
128
                        currentType = viewManager.getDefaultView(xis);
129
129
                }
130
130
 
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());
133
133
 
134
134
                // use our view to display the xena file...
135
135
                // get our parser, and parse the thing.
138
138
                try {
139
139
                        XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
140
140
 
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);
147
147
 
148
 
                        reader.setContentHandler(viewType.getContentHandler());
 
148
                        reader.setContentHandler(currentType.getContentHandler());
 
149
 
 
150
                        reader.setProperty("http://xml.org/sax/properties/lexical-handler", currentType.getLexicalHandler());
 
151
 
149
152
                        reader.parse(xis);
150
153
                        xis.close();
151
 
                        viewType.closeContentHandler();
152
 
                        viewType.initListenersAndSubViews();
153
 
                        viewType.parse();
154
 
                } catch (IOException iox) {
155
 
                        throw new XenaException(iox);
156
 
                } catch (SAXException sx) {
157
 
                        throw new XenaException(sx);
 
154
                        currentType.closeContentHandler();
 
155
                        currentType.initListenersAndSubViews();
 
156
                        currentType.parse();
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);
160
161
                }
161
 
                return viewType;
 
162
                return currentType;
162
163
        }
163
164
 
164
165
        /**