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.portlet.reverendfun.tools;
16  
17  import com.liferay.portal.kernel.util.FileUtil;
18  import com.liferay.portal.kernel.util.StringBundler;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.util.StringUtil;
21  import com.liferay.portal.kernel.webcache.WebCacheItem;
22  import com.liferay.portal.util.InitUtil;
23  import com.liferay.portlet.reverendfun.util.ReverendFunWebCacheItem;
24  
25  import java.io.File;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  /**
31   * <a href="ReverendFunBuilder.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class ReverendFunBuilder {
36  
37      public static void main(String[] args) {
38          InitUtil.initWithSpring();
39  
40          new ReverendFunBuilder();
41      }
42  
43      public ReverendFunBuilder() {
44          try {
45              File file = new File(
46                  "../portal-impl/src/com/liferay/portlet/reverendfun/" +
47                      "dependencies/dates.txt");
48  
49              String[] dates = StringUtil.split(FileUtil.read(file), "\n");
50  
51              WebCacheItem wci = new ReverendFunWebCacheItem(dates[0]);
52  
53              Set<String> moreDates = (Set<String>)wci.convert(StringPool.BLANK);
54  
55              if (moreDates.size() > 0) {
56                  StringBundler sb = new StringBundler();
57  
58                  Set<String> datesSet = new HashSet<String>();
59  
60                  for (String date : moreDates) {
61                      datesSet.add(date);
62  
63                      sb.append(date);
64                      sb.append("\n");
65                  }
66  
67                  for (int i = 0; i < dates.length; i++) {
68                      String date = dates[i];
69  
70                      if (!datesSet.contains(date)) {
71                          datesSet.add(date);
72  
73                          sb.append(date);
74  
75                          if ((i + 1) < dates.length) {
76                              sb.append("\n");
77                          }
78                      }
79                  }
80  
81                  FileUtil.write(file, sb.toString(), true);
82              }
83          }
84          catch (Exception e) {
85          }
86      }
87  
88  }