001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.rdmgr;
007:
008: import java.io.*;
009: import java.util.*;
010:
011: import com.sun.portal.search.soif.*;
012:
013: /**
014: * Convert the 301CSP1 migration.soif to 6.2 discussion.soif format
015: */
016: class DiscussionMigrate {
017:
018: private static String parents;
019:
020: public DiscussionMigrate(String[] args) {
021:
022: if (args.length == 0) {
023:
024: System.out
025: .println("\nUsage: DiscussionMigrate <filename1> <filename2> <filename3>\n");
026: System.out
027: .println("<filename1> is the 301CSP1 migration.soif\n");
028: System.out
029: .println("<filename2> is the migrated 6.2 migration.soif\n");
030: System.out
031: .println("<filename3> is the migrated 6.2 discussion.soif\n");
032: System.exit(1);
033: }
034:
035: }
036:
037: private static boolean IsAURL(String url) {
038:
039: int i = url.indexOf("http");
040: if (i >= 0) {
041: return true;
042: } else {
043: return false;
044: }
045:
046: }
047:
048: private static String getCommentID(String cid) {
049:
050: int i = cid.indexOf("cid=");
051: if (i > 0) {
052: return (cid.substring(i + 4));
053: } else {
054: return (cid);
055: }
056:
057: }
058:
059: private static void FindParents(SOIF s, Map m) {
060:
061: if (!(s.getURL()).equals(s.getValue("gv-discussion-id"))) {
062:
063: FindParents((SOIF) m.get(s.getValue("rd-reference-id")), m);
064: }
065:
066: parents = parents.concat(s.getURL()).concat(" ");
067:
068: }
069:
070: public static void main(String[] args) throws Exception {
071:
072: if (args.length < 3) {
073:
074: System.out
075: .println("\nUsage: DiscussionMigrate <filename1> <filename2> <filename3>\n");
076: System.out
077: .println("<filename1> is the 301CSP1 migration.soif\n");
078: System.out
079: .println("<filename2> is the migrated 6.2 migration.soif\n");
080: System.out
081: .println("<filename3> is the migrated 6.2 discussion.soif\n");
082: System.exit(1);
083:
084: }
085:
086: if (args.length > 2) {
087:
088: String filename1 = args[0];
089: String filename2 = args[1];
090: String filename3 = args[2];
091:
092: //perhaps check the existence or permission of the file1 here
093:
094: Map discussion = new HashMap();
095: SOIFOutputStream doc = new SOIFOutputStream(filename2);
096: SOIFOutputStream sos = new SOIFOutputStream(filename3);
097: SOIFInputStream sis = new SOIFInputStream(
098: new DataInputStream(new BufferedInputStream(
099: new FileInputStream(filename1))));
100: SOIF s;
101:
102: while ((s = sis.readSOIF()) != null) {
103:
104: if (s.contains("gv-last-modified")) {
105: s.rename("gv-last-modified", "rd-last-changed");
106: }
107:
108: if (s.contains("gv-reference-id")) {
109: s.rename("gv-reference-id", "rd-reference-id");
110: }
111:
112: if (s.contains("gv-num-rating")) {
113: s.rename("gv-num-rating", "rd-num-rating");
114: }
115:
116: if (s.contains("gv-sum-rating")) {
117: s.rename("gv-sum-rating", "rd-sum-rating");
118: }
119:
120: if (s.contains("gv-peak-rating")) {
121: s.rename("gv-peak-rating", "rd-peak-rating");
122: }
123:
124: if (s.contains("gv-rating")) {
125: s.rename("gv-rating", "rd-rating");
126: }
127:
128: if (s.contains("gv_depth")) {
129: s.remove("gv_depth");
130: }
131:
132: if (!s.contains("gv-discussion-id")) {
133: doc.write(s);
134: } else {
135:
136: if (!s.contains("rd-reference-id")) {
137: String did = null;
138: if (IsAURL(s.getURL())) {
139: did = s.getValue("gv-discussion-id");
140: s.remove("gv-discussion-id");
141: doc.write(s);
142: s.insert("gv-discussion-id", did);
143: }
144: } else {
145: s.replace("rd-reference-id", getCommentID(s
146: .getValue("rd-reference-id")));
147: }
148: s.replace("gv-discussion-id", getCommentID(s
149: .getValue("gv-discussion-id")));
150: String key = getCommentID(s.getURL());
151: s.setURL(key);
152: discussion.put(key, s);
153:
154: }
155:
156: } // end of while-loop
157:
158: doc.close();
159:
160: Map refIDs = new HashMap();
161: Set keys = discussion.keySet();
162: for (Iterator i = keys.iterator(); i.hasNext();) {
163: String url = (String) i.next();
164: SOIF disSOIF = (SOIF) discussion.get(url);
165: parents = new String(); // clean it up
166: FindParents(disSOIF, discussion);
167:
168: if ((disSOIF.getURL()).equals(disSOIF
169: .getValue("gv-discussion-id"))) {
170: parents = "ROOT ".concat(parents);
171: } else {
172: if ((disSOIF.getValue("rd-reference-id"))
173: .equals(disSOIF
174: .getValue("gv-discussion-id"))) {
175:
176: if (IsAURL(disSOIF.getValue("gv-discussion-id"))) {
177:
178: disSOIF.insert("rd-reference-url", disSOIF
179: .getValue("gv-discussion-id"));
180: }
181: }
182: }
183:
184: refIDs.put(url, parents);
185:
186: } // end of for loop
187:
188: // write them out
189: for (Iterator i = keys.iterator(); i.hasNext();) {
190: SOIF disSOIF = (SOIF) discussion.get(i.next());
191: disSOIF.replace("rd-reference-id", (String) refIDs
192: .get(disSOIF.getURL()));
193: disSOIF.remove("gv-discussion-id");
194: sos.write(disSOIF);
195: }
196:
197: sos.close();
198:
199: }
200:
201: } // end of main
202:
203: }
|