source: trunk/gsdl3/src/java/org/greenstone/gsdl3/Library2.java@ 3341

Last change on this file since 3341 was 3292, checked in by kjdon, 22 years ago

more functionality

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/*
2 * Library2.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3;
20
21import org.greenstone.gsdl3.core.*;
22import org.greenstone.gsdl3.util.*;
23
24import java.io.BufferedReader;
25import java.io.InputStreamReader;
26import java.io.File;
27import java.io.IOException;
28/**
29 * A program to take XML strings from the command line and send
30 * them to the system.
31 *
32 * @author <a href="mailto:[email protected]">Katherine Don</a>
33 * @version $Revision: 3292 $
34 */
35final public class Library2 {
36
37 public static void main(String args[]) {
38
39 if (args.length != 2) {
40 System.out.println("Usage: Library2 <gsdl3home> <sitehome>");
41 System.exit(1);
42 }
43 String gsdl_home = args[0];
44 String transform_home = GSFile.xmlTransformDir(gsdl_home);
45 String site_home = args[1];
46
47 MessageRouter mr = new MessageRouter();
48 mr.setSiteHome(site_home);
49 mr.configure();
50
51 // for doing xslt transforms
52 XMLTransformer transformer = new XMLTransformer();
53
54 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
55 String query=null;
56 String request=null;
57 String result=null;
58 String collect=null;
59 String service=null;
60 String info=null;
61 String content=null;
62 while (true) {
63 System.out.println("Please enter a query type (choose from: describe, query) or 'exit' to quit");
64 try {
65 query = br.readLine();
66 query.trim();
67
68 if (query.startsWith("exit")) {
69 System.exit(1);
70 }
71 if (query.equals("describe")|| query.equals("query")) {
72 System.out.println("\nPlease enter a collection name (or <enter> for no collection)");
73 collect = br.readLine();
74 collect.trim();
75 System.out.println("\nPlease enter a service name (or <enter> for no service)");
76 service = br.readLine();
77 service.trim();
78 if (query.equals("describe")) {
79
80 System.out.println("\nPlease enter an info name (or <enter> for no info)");
81 info = br.readLine();
82 info.trim();
83
84 } else if (query.equals("query") ) {
85 System.out.println("\nPlease enter the content to your query (in xml, all on one line - sorry about that)");
86 content=br.readLine();
87 content.trim();
88 }
89
90 request = "<message><request type='"+query+"' to='";
91
92 if (!collect.equals ("")) {
93 request += collect+"/";
94 }
95 if (!service.equals("")) {
96 request += service+"/";
97 }
98 request += "'";
99 if (query.equals("describe") && !info.equals("")) {
100 request += " info='"+info+"'/>";
101 }
102 else if (query.equals("query") && !content.equals("")) {
103 request +=">"+content+"</request>";
104 } else {
105 request += "/>";
106 }
107
108
109 request += "</message>";
110
111 System.out.println("Sending message to MessageRouter:\n"+request);
112 result = mr.process(request);
113
114 System.out.println("Raw Result:\n"+result+"\n");
115
116 // transform the result
117
118 // select a stylesheet
119 String stylesheet = null;
120 if (query.equals("describe")) {
121 if (collect.equals("")&&service.equals("")) {
122 stylesheet = transform_home+File.separatorChar+"home.xsl";
123 } else if (!collect.equals("")) {
124 stylesheet = transform_home+File.separatorChar+"collect_about.xsl";
125 } else if (!service.equals("")) {
126 stylesheet = transform_home+File.separatorChar+"service_about.xsl";
127 }
128 } else if (query.equals("query")) {
129 stylesheet = transform_home+File.separatorChar+"query_result.xsl";
130 }
131 if (stylesheet != null) {
132 File style = new File(stylesheet);
133 if (!style.exists()) {
134 System.err.println("stylesheet doesn't exist");
135 } else {
136
137 String transformed_result = transformer.transform(stylesheet, result);
138 System.out.println("Transformed result:\n"+transformed_result);
139 }
140 } else {
141 System.out.println("no appropriate stylesheet found");
142 }
143 } else {
144 System.out.println("your request was not understood, sorry");
145 }
146
147 } catch (IOException e) {
148 System.err.println("Library2 IO exception:"+e.getMessage());
149 }
150
151 } // while (true
152 }
153
154}
155
156
Note: See TracBrowser for help on using the repository browser.