public void readCatalog ( Catalog catalog , InputStream is ) throws IOException , CatalogException { DocumentBuilderFactory factory = null ; DocumentBuilder builder = null ; factory = DocumentBuilderFactory . newInstance ( ) ; factory . setNamespaceAware ( false ) ; factory . setValidating ( false ) ; try { builder = factory . newDocumentBuilder ( ) ; } catch ( ParserConfigurationException pce ) { throw new CatalogException ( CatalogException . UNPARSEABLE ) ; } Document doc = null ; try { doc = builder . parse ( is ) ; } catch ( SAXException se ) { throw new CatalogException ( CatalogException . UNKNOWN_FORMAT ) ; } Element root = doc . getDocumentElement ( ) ; String namespaceURI = Namespaces . getNamespaceURI ( root ) ; String localName = Namespaces . getLocalName ( root ) ; String domParserClass = getCatalogParser ( namespaceURI , localName ) ; if ( domParserClass == null ) { if ( namespaceURI == null ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "No Catalog parser for " + localName ) ; } else { catalog . getCatalogManager ( ) . debug . message ( 1 , "No Catalog parser for " + "{" + namespaceURI + "}" + localName ) ; } return ; } DOMCatalogParser domParser = null ; try { domParser = ( DOMCatalogParser ) Class . forName ( domParserClass ) . newInstance ( ) ; } catch ( ClassNotFoundException cnfe ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Cannot load XML Catalog Parser class" , domParserClass ) ; throw new CatalogException ( CatalogException . UNPARSEABLE ) ; } catch ( InstantiationException ie ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Cannot instantiate XML Catalog Parser class" , domParserClass ) ; throw new CatalogException ( CatalogException . UNPARSEABLE ) ; } catch ( IllegalAccessException iae ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Cannot access XML Catalog Parser class" , domParserClass ) ; throw new CatalogException ( CatalogException . UNPARSEABLE ) ; } catch ( ClassCastException cce ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Cannot cast XML Catalog Parser class" , domParserClass ) ; throw new CatalogException ( CatalogException . UNPARSEABLE ) ; } Node node = root . getFirstChild ( ) ; while ( node != null ) { domParser . parseCatalogEntry ( catalog , node ) ; node = node . getNextSibling ( ) ; } }
Read a catalog from an input stream .