1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }