private void initNamespaces ( ) { Map < Integer , String > namespaceMap = new HashMap < Integer , String > ( ) ; try { int b = read ( ) ; this . keywords . reset ( ) ; StringBuilder buffer = null ; while ( b != - 1 ) { // System.out.print((char)b); if ( buffer != null ) { buffer . append ( ( char ) b ) ; } if ( this . keywords . check ( ( char ) b ) ) { switch ( this . keywords . getValue ( ) ) { case KEY_START_NAMESPACES : buffer = new StringBuilder ( WikipediaXMLKeys . KEY_START_NAMESPACES . getKeyword ( ) ) ; break ; case KEY_END_NAMESPACES : DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setIgnoringElementContentWhitespace ( true ) ; Document namespaces = factory . newDocumentBuilder ( ) . parse ( new InputSource ( new StringReader ( buffer . toString ( ) ) ) ) ; NodeList nsList = namespaces . getChildNodes ( ) . item ( 0 ) . getChildNodes ( ) ; for ( int i = 0 ; i < nsList . getLength ( ) ; i ++ ) { Node curNamespace = nsList . item ( i ) ; //get the prefix for the current namespace String prefix = curNamespace . getTextContent ( ) . trim ( ) ; if ( ! prefix . isEmpty ( ) ) { NamedNodeMap nsAttributes = curNamespace . getAttributes ( ) ; String namespace = nsAttributes . getNamedItem ( "key" ) . getTextContent ( ) ; namespaceMap . put ( Integer . parseInt ( namespace ) , prefix ) ; } } buffer = null ; articleFilter . initializeNamespaces ( namespaceMap ) ; return ; //init done } this . keywords . reset ( ) ; } b = read ( ) ; } } catch ( IOException e ) { System . err . println ( "Error reading namespaces from xml dump." ) ; } catch ( ParserConfigurationException e ) { System . err . println ( "Error parsing namespace data." ) ; } catch ( SAXException e ) { System . err . println ( "Error parsing namespace data." ) ; } }
Reads the namespaces from the siteinfo section and processes them in order to initialize the ArticleFilter