01: /*
02: * Copyright (c) 2000 Sun Microsystems. All Rights Reserved.
03: */
04:
05: package demo;
06:
07: import soif.AVPairs;
08: import soif.CSID;
09: import soif.Results;
10: import soif.SOIF;
11:
12: import communications.PostConnection;
13:
14: import java.applet.Applet;
15: import java.awt.Event;
16: import java.awt.AWTEvent;
17: import java.awt.FlowLayout;
18: import java.awt.TextArea;
19:
20: /**
21: * Applet for populating the Compass database. It uses the static
22: * strings defined below for input. The basic process is to convert
23: * the input to SOIF and then add it to the database using rdsubmit.
24: * If you are adding a lot of data, you will probably want to batch
25: * the input to rdsubmit. You are not limited to just the DB fields
26: * used in this example, you can add any fields that are defined in
27: * the schema.
28: */
29:
30: public class SubmitDemo extends Applet {
31: public static final String DATA_URL[] = { "http://url1",
32: "http://url2", "http://url3" };
33: public static final String DATA_CLASS[] = { "Cars", "Boats",
34: "Planes" };
35: public static final String DATA_DESC[] = { "Document 1",
36: "Document 2", "Document 3" };
37:
38: TextArea submitLog;
39: String CGILocation;
40: CSID csid;
41:
42: public void init() {
43: System.out.println("Compass Java RD Submit Demo");
44:
45: /* supply the path for the location of the
46: ** CGI directory of the hosting server,
47: ** needed to access rdsubmit.
48: */
49: CGILocation = getParameter("CGILocation");
50:
51: /* The Compass Server ID (CSID) needs to know:
52: ** 1) this page's codeBase
53: ** 2) CS host
54: ** 3) CS port
55: ** 4) CS name
56: */
57: csid = new CSID(getCodeBase().toString(), getParameter("host"),
58: getParameter("port"), getParameter("name"));
59:
60: submitLog = new TextArea(10, 60);
61: submitLog.setEditable(false);
62: setLayout(new FlowLayout(FlowLayout.LEFT));
63: add(submitLog);
64:
65: submitLog.append("Submit RDs Java API Demo - Adding...\n\n");
66:
67: StringBuffer sb = new StringBuffer();
68: String result = null;
69:
70: sb.append("@Request { -\n"
71: + AVPairs.toSOIF("submit-csid", csid.toString())
72: + AVPairs.toSOIF("submit-type", "nonpersistent")
73: + AVPairs.toSOIF("submit-operation", "merge")
74: + AVPairs.toSOIF("submit-view",
75: "classification,description") + "}\n");
76:
77: for (int i = 0; i < DATA_URL.length; i++) {
78: sb.append("\n" + "@DOCUMENT { " + DATA_URL[i] + "\n"
79: + AVPairs.toSOIF("classification", DATA_CLASS[i])
80: + AVPairs.toSOIF("description", DATA_DESC[i]) + "}"
81: + "\n");
82: submitLog.append(DATA_URL[i] + "\n");
83: }
84:
85: System.out.println(sb);
86: result = PostConnection.doWrite(CGILocation, sb.toString(),
87: true);
88: submitLog.append("\nDone - " + DATA_URL.length
89: + " RDs added.\n");
90: }
91:
92: /**
93: * Process event.
94: * @param e AWTEvent
95: */
96: public synchronized void processEvent(AWTEvent e) {
97: super.processEvent(e);
98: }
99: }
|