in flex-maven-tools/flex-sdk-converter/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java [339:405]
protected String getBinaryUrl(SdkType sdkType, String version, PlatformType platformType)
throws RetrieverException {
try {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final URL configUrl = new URL(getFlexInstallerConfigUrl());
URLConnection connection;
ProxySettings proxySettings = ProxySettings.getProxySettings();
if(proxySettings != null) {
SocketAddress socketAddress = new InetSocketAddress(proxySettings.getHost(), proxySettings.getPort());
Proxy proxy = new Proxy(Proxy.Type.valueOf(proxySettings.getProtocol().toUpperCase()), socketAddress);
connection = configUrl.openConnection(proxy);
LOG.info("Using proxy: " + proxySettings.getHost());
} else {
connection = configUrl.openConnection();
}
final Document doc = builder.parse(connection.getInputStream());
//Evaluate XPath against Document itself
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) || (sdkType == SdkType.SWFOBJECT)) {
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);
if(sdkType == SdkType.FLEX) {
stringBuilder.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);
}
}