class OpenStackParser {

    public String[] parseAuthorizationResponse (String response) {
        List result;
        HashMap<String, String> urls = new HashMap<String, String>();
        String[] openStackServices = {"nova", "cinder", "neutron"};
        String[] ret = new String[6];
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document xmldoc;
        String url;
        
        log.info("[OpenStackParser] Parsing authorization response...");
        try {
            /**** Get the token ****/
            xmldoc = builder.build(new StringReader(response));
            XPath xpath = XPath.newInstance("//ns:token/@id");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            ret[0] = ((Attribute)xpath.selectSingleNode(xmldoc)).getValue();
            
            /**** Get Open Stack Services' URLs ****/
            for (String service : openStackServices) { 
                xpath = XPath.newInstance("//ns:service[@name=\"" + service + 
                        "\"]/ns:endpoint/@publicURL");
                xpath.addNamespace("ns", KEYSTONENAMESPACE);
                result = xpath.selectNodes(xmldoc);
                
                for (Object obj : result) {
                	Attribute attribute = (Attribute)obj;
                    url = attribute.getValue();
                    
                    if (url != null &&
                            !url.contains("/v3") &&
                            !url.contains("/v1")) {
                        urls.put(service, url);
                    }
                }
            }
            
            xmldoc = builder.build(new StringReader(response));
            xpath  = XPath.newInstance("//ns:user/@username");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            ret[1] = ((Attribute)xpath.selectSingleNode(xmldoc)).getValue();
            
            xmldoc = builder.build(new StringReader(response));
            xpath  = XPath.newInstance("//ns:user/@id");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            ret[2] = ((Attribute)xpath.selectSingleNode(xmldoc)).getValue();
            
            ret[3] = urls.get("nova");
            ret[4] = urls.get("cinder");
            ret[5] = urls.get("neutron");
            
        } catch (JDOMException e) {
            log.error(e.getMessage());
        } catch (IOException e) {
        	log.error(e.getMessage());
        }
        log.debug("[OpenStackParser] Authorization response parsed...");
        
        return ret;
    }

}