source: trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java@ 3387

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

added in applet action

  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1package org.greenstone.gsdl3.core;
2
3import org.greenstone.gsdl3.util.*;
4import org.greenstone.gsdl3.action.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11// other java classes
12import java.io.File;
13import java.util.HashMap;
14
15public class Receptionist implements ModuleInterface {
16
17 /** the set up variables */
18 protected ConfigVars config_=null;
19
20 /** the cgi args converter */
21 protected CGIArgConverter cgi_=null;
22
23 /** container Document to create XML Nodes */
24 protected Document doc_=null;
25 /** a converter class to parse XML and create Docs */
26 protected XMLConverter converter_=null;
27
28 /** the message router that it talks to */
29 protected ModuleInterface mr_=null;
30
31 /** the list of actions */
32 protected HashMap action_map_=null;
33
34 protected Translate translation_=null;
35 public Receptionist() {
36 converter_ = new XMLConverter();
37 doc_ = converter_.newDOM();
38 action_map_= new HashMap();
39 translation_ = new Translate();
40 cgi_ = new CGIArgConverter();
41 }
42
43 /** the set up vars must be set before configure called*/
44 public void setConfigVars(ConfigVars config) {
45 config_ = config;
46 translation_.setConfigVars(config);
47 }
48 /** sets the message router - it should already be created and
49 * configured before being passed to the receptionist*/
50 public void setMessageRouter(ModuleInterface m) {
51 mr_ = m;
52 }
53
54 public boolean configure() {
55
56 if (config_==null) {
57 System.err.println("You must set the config variables before calling configure");
58 return false;
59 }
60 if (mr_==null) {
61 System.err.println("You must set the mr before calling configure");
62 return false;
63 }
64
65 // for now, assume default is en, so load that
66 translation_.setDefaultLanguage("en");
67 // for now, just statically add in the actions
68 // actions may disappear if xslt is all that is needed
69 // or they should be dynamically loaded
70 Action a = new PageAction();
71 a.setConfigVars(config_);
72 a.setMessageRouter(mr_);
73 a.setCGIConverter(cgi_);
74 a.configure();
75 action_map_.put("p", a);
76
77 a = new QueryAction();
78 a.setConfigVars(config_);
79 a.setCGIConverter(cgi_);
80 a.setMessageRouter(mr_);
81 a.configure();
82 action_map_.put("q", a);
83
84 a = new BrowseAction();
85 a.setConfigVars(config_);
86 a.setCGIConverter(cgi_);
87 a.setMessageRouter(mr_);
88 a.configure();
89 action_map_.put("b", a);
90
91 a = new ResourceAction();
92 a.setConfigVars(config_);
93 a.setCGIConverter(cgi_);
94 a.setMessageRouter(mr_);
95 a.configure();
96 action_map_.put("r", a);
97
98 a = new AppletAction();
99 a.setConfigVars(config_);
100 a.setCGIConverter(cgi_);
101 a.setMessageRouter(mr_);
102 a.configure();
103 action_map_.put("a", a);
104 return true;
105 }
106
107 public String process(String xml_in) {
108
109 Document message_doc = converter_.getDOM(xml_in);
110 Element message = message_doc.getDocumentElement();
111
112 NodeList requests = message.getElementsByTagName("request");
113 if (requests.getLength()==0) {
114 return GSHTML.errorPage("no requests in the message");
115 }
116
117 // should only be one request
118 Element req = (Element)requests.item(0);
119 String type = req.getAttribute("type"); // returns "" if no att of this name
120 if (!type.equals("action")) {
121 return GSHTML.errorPage("wrong type in request - should be action");
122 }
123 String info = req.getAttribute("info");
124 String action = GSPath.getFirstLink(info);
125 if (action.equals("")) {
126 return GSHTML.errorPage(" no action specified");
127 }
128 // pass to appropriate action
129
130 Action a = (Action)action_map_.get(action);
131 if (a==null) {
132 return GSHTML.errorPage("no action for "+action);
133 }
134
135 // add in the translation bit - should we do it here? or give the actions access to the translation object?
136 String lang = message.getAttribute("lang");
137 Element trans = translation_.getLanguageTree(lang);
138 message.appendChild(message_doc.importNode(trans, true));
139
140 // add in the system vars bit
141 message.appendChild(message_doc.importNode(config_.config_xml_, true));
142
143 String page = a.process(message);
144 return page;
145 // just pass a string for now - better to pass the doc cos already
146 // parsed it, but we want a string back
147 //String page = mi.process(xml_in);
148
149 // output the page
150 //return page;
151 }
152
153 public Node process(Node xml_in) {
154 return xml_in; // for now
155
156 }
157
158
159}
Note: See TracBrowser for help on using the repository browser.