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