1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.reverendfun.tools;
24  
25  import com.liferay.portal.kernel.util.FileUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.StringUtil;
28  import com.liferay.portal.kernel.webcache.WebCacheItem;
29  import com.liferay.portal.util.InitUtil;
30  import com.liferay.portlet.reverendfun.util.ReverendFunWebCacheItem;
31  
32  import java.io.File;
33  
34  import java.util.HashSet;
35  import java.util.Set;
36  
37  /**
38   * <a href="ReverendFunBuilder.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class ReverendFunBuilder {
43  
44      public static void main(String[] args) {
45          InitUtil.initWithSpring();
46  
47          new ReverendFunBuilder();
48      }
49  
50      public ReverendFunBuilder() {
51          try {
52              File file = new File(
53                  "../portal-impl/src/com/liferay/portlet/reverendfun/" +
54                      "dependencies/dates.txt");
55  
56              String[] dates = StringUtil.split(FileUtil.read(file), "\n");
57  
58              WebCacheItem wci = new ReverendFunWebCacheItem(dates[0]);
59  
60              Set<String> moreDates = (Set<String>)wci.convert(StringPool.BLANK);
61  
62              if (moreDates.size() > 0) {
63                  StringBuilder sb = new StringBuilder();
64  
65                  Set<String> datesSet = new HashSet<String>();
66  
67                  for (String date : moreDates) {
68                      datesSet.add(date);
69  
70                      sb.append(date);
71                      sb.append("\n");
72                  }
73  
74                  for (int i = 0; i < dates.length; i++) {
75                      String date = dates[i];
76  
77                      if (!datesSet.contains(date)) {
78                          datesSet.add(date);
79  
80                          sb.append(date);
81  
82                          if ((i + 1) < dates.length) {
83                              sb.append("\n");
84                          }
85                      }
86                  }
87  
88                  FileUtil.write(file, sb.toString(), true);
89              }
90          }
91          catch (Exception e) {
92          }
93      }
94  
95  }