final String expression = getUrlXpath(sdkType, version, platformType);
final XPath xPath = XPathFactory.newInstance().newXPath();
final Element artifactElement = (Element) xPath.evaluate(
expression, doc.getDocumentElement(), XPathConstants.NODE);
if(artifactElement == null) {
throw new RetrieverException("Could not find " + sdkType.toString() + " SDK with version " + version);
}
final StringBuilder stringBuilder = new StringBuilder();
if (sdkType == SdkType.FLEX) {
final String path = artifactElement.getAttribute("path");
final String file = artifactElement.getAttribute("file");
if (!path.startsWith("http://")) {
stringBuilder.append("http://archive.apache.org/dist/");
}
stringBuilder.append(path);
if(!path.endsWith("/")) {
stringBuilder.append("/");
}
stringBuilder.append(file).append(".zip");
} else {
final NodeList pathElements = artifactElement.getElementsByTagName("path");
final NodeList fileElements = artifactElement.getElementsByTagName("file");
if ((pathElements.getLength() != 1) && (fileElements.getLength() != 1)) {
throw new RetrieverException("Invalid document structure.");
}
final String path = pathElements.item(0).getTextContent();
stringBuilder.append(path);
if(!path.endsWith("/")) {
stringBuilder.append("/");
}
stringBuilder.append(fileElements.item(0).getTextContent());
}
return stringBuilder.toString();
} catch (ParserConfigurationException e) {
throw new RetrieverException("Error parsing 'sdk-installer-config-4.0.xml'", e);
} catch (SAXException e) {
throw new RetrieverException("Error parsing 'sdk-installer-config-4.0.xml'", e);
} catch (XPathExpressionException e) {
throw new RetrieverException("Error parsing 'sdk-installer-config-4.0.xml'", e);
} catch (IOException e) {
throw new RetrieverException("Error parsing 'sdk-installer-config-4.0.xml'", e);
}
}