001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.reverendfun.tools;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portal.kernel.webcache.WebCacheItem;
026: import com.liferay.portal.util.InitUtil;
027: import com.liferay.portlet.reverendfun.util.ReverendFunWebCacheItem;
028: import com.liferay.util.FileUtil;
029:
030: import java.io.File;
031:
032: import java.util.HashSet;
033: import java.util.Iterator;
034: import java.util.Set;
035:
036: /**
037: * <a href="ReverendFunBuilder.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class ReverendFunBuilder {
043:
044: static {
045: InitUtil.init();
046: }
047:
048: public static void main(String[] args) {
049: new ReverendFunBuilder();
050: }
051:
052: public ReverendFunBuilder() {
053: try {
054: File file = new File(
055: "../portal-impl/src/com/liferay/portlet/reverendfun/"
056: + "dependencies/dates.txt");
057:
058: String[] dates = StringUtil
059: .split(FileUtil.read(file), "\n");
060:
061: WebCacheItem wci = new ReverendFunWebCacheItem(dates[0]);
062:
063: Set moreDates = (Set) wci.convert("");
064:
065: if (moreDates.size() > 0) {
066: StringMaker sm = new StringMaker();
067:
068: Set datesSet = new HashSet();
069:
070: Iterator itr = moreDates.iterator();
071:
072: while (itr.hasNext()) {
073: String date = (String) itr.next();
074:
075: datesSet.add(date);
076:
077: sm.append(date);
078: sm.append("\n");
079: }
080:
081: for (int i = 0; i < dates.length; i++) {
082: String date = dates[i];
083:
084: if (!datesSet.contains(date)) {
085: datesSet.add(date);
086:
087: sm.append(dates[i]);
088:
089: if (i + 1 < dates.length) {
090: sm.append("\n");
091: }
092: }
093: }
094:
095: FileUtil.write(file, sm.toString(), true);
096: }
097: } catch (Exception e) {
098: }
099: }
100:
101: }
|