1
14
15 package com.liferay.portal.tools;
16
17 import com.liferay.portal.kernel.xml.Document;
18 import com.liferay.portal.kernel.xml.Element;
19 import com.liferay.portal.kernel.xml.SAXReaderUtil;
20 import com.liferay.portal.util.InitUtil;
21 import com.liferay.util.ant.Wsdl2JavaTask;
22
23 import java.io.File;
24
25 import java.util.Iterator;
26
27
32 public class PortalClientBuilder {
33
34 public static void main(String[] args) {
35 InitUtil.initWithSpring();
36
37 if (args.length == 4) {
38 new PortalClientBuilder(args[0], args[1], args[2], args[3]);
39 }
40 else {
41 throw new IllegalArgumentException();
42 }
43 }
44
45 public PortalClientBuilder(
46 String fileName, String outputDir, String mappingFile, String url) {
47
48 try {
49 Document doc = SAXReaderUtil.read(new File(fileName));
50
51 Element root = doc.getRootElement();
52
53 Iterator<Element> itr = root.elements("service").iterator();
54
55 while (itr.hasNext()) {
56 Element service = itr.next();
57
58 String name = service.attributeValue("name");
59
60 if (name.startsWith("Portal_") || name.startsWith("Portlet_")) {
61 Wsdl2JavaTask.generateJava(
62 url + "/" + name + "?wsdl", outputDir, mappingFile);
63 }
64 }
65 }
66 catch (Exception e) {
67 e.printStackTrace();
68 }
69
70 File testNamespace = new File(outputDir + "/com/liferay/portal");
71
72 if (testNamespace.exists()) {
73 throw new RuntimeException(
74 "Please update " + mappingFile + " to namespace " +
75 "com.liferay.portal to com.liferay.client.soap.portal");
76 }
77 }
78
79 }