protected Map < String , String > parseNamespaces ( final String template ) { Map < String , String > namespaces = CollectionUtils . newHashMap ( ) ; Document document = XmlUtils . documentFromString ( template ) ; Element element = document . getDocumentElement ( ) ; NamedNodeMap attributes = element . getAttributes ( ) ; for ( int loop = 0 , length = attributes . getLength ( ) ; loop < length ; loop ++ ) { org . w3c . dom . Node node = attributes . item ( loop ) ; String nodeName = node . getNodeName ( ) ; int indexOf = nodeName . indexOf ( XMLNS_PREFIX ) ; if ( indexOf == - 1 ) { continue ; } namespaces . put ( nodeName . substring ( indexOf + XMLNS_PREFIX . length ( ) ) , node . getNodeValue ( ) ) ; } return namespaces ; }
Parses the given XML and determines what namespaces it already declares . These are later removed from the list of namespaces that Metawidget introduces .