| | 162 | |
|---|
| | 163 | /** |
|---|
| | 164 | * Parse an input stream. |
|---|
| | 165 | * |
|---|
| | 166 | * @param stream input stream to parse |
|---|
| | 167 | * @throws XJConfException |
|---|
| | 168 | * @throws IOException |
|---|
| | 169 | */ |
|---|
| | 170 | public void parse(InputStream stream) throws XJConfException, IOException { |
|---|
| | 171 | this.initParserFactory(); |
|---|
| | 172 | |
|---|
| | 173 | SAXParser saxParser; |
|---|
| | 174 | try { |
|---|
| | 175 | saxParser = this.parserFactory.newSAXParser(); |
|---|
| | 176 | saxParser.parse(stream, this); |
|---|
| | 177 | } catch (XJConfException e) { |
|---|
| | 178 | throw e; |
|---|
| | 179 | } catch (ParserConfigurationException e) { |
|---|
| | 180 | throw new InternalError("Could not configure the parser correctly."); |
|---|
| | 181 | } catch (SAXException e) { |
|---|
| | 182 | throw new XJConfException(e.getMessage()); |
|---|
| | 183 | } |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | /** |
|---|
| | 187 | * initialize the parser factory |
|---|
| | 188 | * |
|---|
| | 189 | */ |
|---|
| | 190 | private void initParserFactory() { |
|---|
| | 191 | if (null == this.parserFactory) { |
|---|
| | 192 | this.parserFactory = SAXParserFactory.newInstance(); |
|---|
| | 193 | this.parserFactory.setNamespaceAware(true); |
|---|
| | 194 | } |
|---|
| | 195 | } |
|---|