1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
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  /**
28   * <a href="PortalClientBuilder.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
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  }