|
45 | 45 | import org.w3c.dom.Element;
|
46 | 46 | import org.w3c.dom.Node;
|
47 | 47 | import org.w3c.dom.NodeList;
|
| 48 | +import org.xml.sax.InputSource; |
48 | 49 | import org.xml.sax.SAXException;
|
49 | 50 | import com.aspose.words.maven.artifacts.Metadata;
|
50 | 51 | import com.aspose.words.maven.artifacts.ObjectFactory;
|
51 | 52 |
|
| 53 | + |
52 | 54 | public class AsposeMavenProjectManager {
|
53 | 55 |
|
54 | 56 | private File projectDir = null;
|
@@ -314,27 +316,39 @@ public String readURLContents(String Url) throws IOException {
|
314 | 316 | */
|
315 | 317 | public Metadata getProductMavenDependency(String productMavenRepositoryUrl) {
|
316 | 318 | final String mavenMetaDataFileName = "maven-metadata.xml";
|
317 |
| - Metadata data = null; |
| 319 | + Metadata data = new Metadata(); |
318 | 320 |
|
319 | 321 | try {
|
320 | 322 | String productMavenInfo;
|
321 |
| - productMavenInfo = readURLContents(productMavenRepositoryUrl + mavenMetaDataFileName); |
322 |
| - JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); |
323 |
| - Unmarshaller unmarshaller; |
324 |
| - unmarshaller = jaxbContext.createUnmarshaller(); |
325 |
| - |
326 |
| - data = (Metadata) unmarshaller.unmarshal(new StreamSource(new StringReader(productMavenInfo))); |
327 |
| - |
| 323 | + productMavenInfo = readURLContents(productMavenRepositoryUrl + mavenMetaDataFileName); |
| 324 | + |
| 325 | + DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 326 | + Document doc = dBuilder.parse(new InputSource(new StringReader(productMavenInfo))); |
| 327 | + XPath xPath = XPathFactory.newInstance().newXPath(); |
| 328 | + String groupId = XPathFactory.newInstance().newXPath().compile("//metadata/groupId").evaluate(doc); |
| 329 | + String artifactId = XPathFactory.newInstance().newXPath().compile("//metadata/artifactId").evaluate(doc); |
| 330 | + String version = XPathFactory.newInstance().newXPath().compile("//metadata/version").evaluate(doc); |
| 331 | + String latest = XPathFactory.newInstance().newXPath().compile("//metadata/versioning/latest").evaluate(doc); |
| 332 | + |
| 333 | + data.setArtifactId(artifactId); |
| 334 | + data.setGroupId(groupId); |
| 335 | + data.setVersion(version); |
| 336 | + |
| 337 | + Metadata.Versioning ver = new Metadata.Versioning(); |
| 338 | + ver.setLatest(latest); |
| 339 | + data.setVersioning(ver); |
| 340 | + |
328 | 341 | String remoteArtifactFile = productMavenRepositoryUrl + data.getVersioning().getLatest() + "/"
|
329 | 342 | + data.getArtifactId() + "-" + data.getVersioning().getLatest();
|
| 343 | + |
330 | 344 |
|
331 | 345 | if (!remoteFileExists(remoteArtifactFile + ".jar")) {
|
332 | 346 | AsposeConstants.println("Not Exists");
|
333 | 347 | data.setClassifier(getResolveSupportedJDK(remoteArtifactFile));
|
334 | 348 | } else {
|
335 | 349 | AsposeConstants.println("Exists");
|
336 | 350 | }
|
337 |
| - } catch (IOException | JAXBException ex) { |
| 351 | + } catch (Exception ex) { |
338 | 352 | ex.printStackTrace();
|
339 | 353 | data = null;
|
340 | 354 | }
|
|
0 commit comments