all-050311a-beforeStart: of impl. userSettings
2 * Created on Aug 16, 2003
6 import isac.browserdialog.BDialog;
7 import isac.session.OManager;
8 import isac.session.SDialog;
10 import java.io.IOException;
11 import java.net.MalformedURLException;
12 import java.rmi.Naming;
13 import java.rmi.NotBoundException;
14 import java.rmi.RemoteException;
15 import java.util.Vector;
17 import org.apache.xmlrpc.XmlRpcClient;
18 import org.apache.xmlrpc.XmlRpcException;
21 * @author Andreas Griesmayer
23 * The InformationProcessor builds the bridge between BrowserFrontend and
24 * BrowserDialog. It encapsulates all tasks regarding communication and connects
25 * to the proper dialog-modules.
27 * Because the final communication-protocol is not fixed yet, it provides
28 * methods to communicate via RMI as well as XML-RPC
30 public class InformationProcessor {
33 * Performes an login on the session dialog using the XML-RPC protocol. It
34 * assumes that the SessionDialog is running its XML-RPC-handler on port
35 * 1050 of the local machine.
38 * username of the user who wants to login.
40 * corresponding password for the user.
41 * @return the id of the current sesson the user logged in or null if the
42 * login did not succeed
43 * @throws NullPointerException
44 * carrying the error-message if an communication error occured.
46 static protected String xmlLogin(String username, String password) {
48 XmlRpcClient sdialog = new XmlRpcClient("http://localhost:1050");//WN fixed port
49 Vector params = new Vector();
52 Vector response = (Vector) sdialog.execute("SDialog.login", params);
53 if (response.size() > 0)
54 return (String) response.elementAt(0);
55 } catch (MalformedURLException e) {
56 throw new NullPointerException(
57 getErrorXML("Sorry, MalformedURLException while accessing the SDialog to login - is the SDialog runnig ?"
59 } catch (XmlRpcException e) {
60 throw new NullPointerException(
61 getErrorXML("Sorry, XmlRpcException while accessing the SDialog to login - is the SDialog runnig ?"
63 } catch (IOException e) {
64 throw new NullPointerException(
65 getErrorXML("Sorry, IOException while accessing the SDialog to login - is the SDialog runnig ?"
72 * Performes a login on the Session dialog using RMI. It assumes the
73 * SessionDialog to be found at //localhost/isac-ObjectManager
76 * username of the user who wants to login.
78 * corresponding password for the user.
79 * @return the id of the current sesson the user logged in or null if the
80 * login did not succeed
81 * @throws NullPointerException
82 * carrying the error-message if an communication error occured.
84 static public String login(String username, String password) {
85 SDialog sd = getSDialog();
88 //if username != pwd -> empty Vector
89 Vector v = sd.login(username, password);
93 return (String) v.elementAt(0);
95 } catch (RemoteException e) {
96 throw new NullPointerException(
97 getErrorXML("Sorry, RemoteEcxeption while accessing the SDialog to login - is the SDialog runnig ?"
102 public static BDialog getBDialog(String session) {
103 String name = "//localhost/isac-ObjectManager";
105 System.out.println("connect to ObjectManager" + name);
106 Object lookup = Naming.lookup(name);
107 return ((OManager) lookup).getBrowserDialog(session);
108 } catch (RemoteException exc) {
109 System.err.println("no rmiregistry runing on server " + name
110 + " no connection possible --- try later");
111 System.err.println("serverCom exception: " + exc.getMessage());
112 } catch (NotBoundException exc) {
113 System.err.println("servercom: notboundexc: " + exc.getMessage());
114 System.err.println("server not found - try to connect to Proxy");
115 } catch (java.net.MalformedURLException exc) {
116 System.err.println("servercom: MalformedURLException: "
118 exc.printStackTrace();
123 public static SDialog getSDialog() {
124 String name = "//localhost/isac-ObjectManager";
126 System.out.println("connect to ObjectManager: " + name);
127 Object lookup = Naming.lookup(name);
128 return ((OManager) lookup).getSessionDialog();
129 } catch (RemoteException exc) {
130 System.err.println("no rmiregistry runing on server " + name
131 + " no connection possible --- try later");
132 System.err.println("serverCom exception: " + exc.getMessage());
133 } catch (NotBoundException exc) {
134 System.err.println("servercom: notboundexc: " + exc.getMessage());
135 System.err.println("server not found - try to connect to Proxy");
136 } catch (java.net.MalformedURLException exc) {
137 System.err.println("servercom: MalformedURLException: "
139 exc.printStackTrace();
145 * static protected String oldloadString(String function, Vector parameter){
146 * XmlRpcClient bdialog; String xmlsource=""; try { bdialog = new
147 * XmlRpcClient("http://localhost:1040"); Vector result = (Vector)
148 * bdialog.execute(function, parameter); xmlsource =
149 * (String)result.firstElement(); } catch (MalformedURLException e) {
150 * e.printStackTrace(); } catch (XmlRpcException e) { e.printStackTrace(); }
151 * catch (IOException e) { e.printStackTrace(); } return xmlsource; }
154 * static protected Vector oldloadVector(String function, Vector parameter){
155 * Vector return_vect=new Vector(); XmlRpcClient bdialog; String
156 * xmlsource=""; try { bdialog = new XmlRpcClient("http://localhost:1040");
157 * return_vect = (Vector) bdialog.execute(function, parameter); } catch
158 * (MalformedURLException e) { e.printStackTrace(); } catch (XmlRpcException
159 * e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
160 * return return_vect; }
164 * Loads the hierarchy for the information-type <code>type</type>
165 * @param session session to identify on the SessionDialog
166 * @param type type of the hierarchy to load
167 * @return the requested hierarchy in its XML-representation, in case of an RemoteException, a XML-code
168 * carrying the error-message is returned
170 static public String loadHierarchy(String session, String type) {
171 BDialog bd = getBDialog(session);
173 return bd.loadHierarchy(type);
174 } catch (RemoteException e) {
175 return getErrorXML("Sorry, RemoteEcxeption while accessing the BDialog to login - is the BDialog runnig ?"
181 * Loads binary files from the KE-Base
184 * session to identify on the SessionDialog
186 * to identify the location of the binary file. An id has only to
187 * be unique within a type, although a globally unique id should
190 * Id of the binary-file to load
191 * @return the requested binary-file as byte-array, in case of an
192 * RemoteException, an empty array is returned
194 static public byte[] loadBinary(String session, String type,
196 BDialog bd = getBDialog(session);
198 return bd.loadBinary(type, content_id);
199 } catch (RemoteException e) {
204 static public String loadXML(String session, String type, Vector idvect) {
205 BDialog bd = getBDialog(session);
207 return bd.loadContent(type, idvect);
208 } catch (RemoteException e) {
209 return getErrorXML("Sorry, RemoteException while accessing the BDialog to fetch your content");
214 * Loads content-files from the KE-Base
217 * session to identify on the SessionDialog
219 * to identify the location of the KE-Object. An id has only to
220 * be unique within a type, although a globally unique id should
223 * Id of the KE-Object to load
224 * @return the requested KE-Object in its XML-representation, in case of an
225 * RemoteException, a XML-code carrying the error-message is
228 static public String loadXML(String session, String type, String content_id) {
229 BDialog bd = getBDialog(session);
231 return bd.loadContent(type, content_id);
232 } catch (RemoteException e) {
233 return getErrorXML("Sorry, RemoteException while accessing the BDialog to fetch your file \""
234 + content_id + "\" is the BDialog running?");
239 * Evaluates the requested content in the given worksheet using the
243 * session to identify on the SessionDialog
245 * to identify the location of the KE-Object. An id has only to
246 * be unique within a type, although a globally unique id should
249 * Id of the KE-Object to load
251 * id of the worksheet the contanct for evaluating
252 * @return the requested KE-Object in its XML-representation, in case of an
253 * RemoteException, a XML-code carrying the error-message is
255 * @see BDialog#evaluateContent
257 static public String evaluateXML(String session, String type,
258 String content_id, String wd_id) {
259 BDialog bd = getBDialog(session);
261 return bd.evaluateContent(type, content_id, wd_id);
262 } catch (RemoteException e) {
263 return getErrorXML("Sorry, RemoteException while accessing the BDialog to evaluate \""
264 + content_id + "\" is the BDialog running?");
269 * static protected Reader loadsKEObject(String function, Vector parameter){
270 * XmlRpcClient bdialog; String xmlsource=""; try { bdialog = new
271 * XmlRpcClient("http://localhost:1040"); Vector result = (Vector)
272 * bdialog.execute(function, parameter); if(result.size()>0) xmlsource =
273 * (String)result.firstElement(); else xmlsource = ""; } catch
274 * (MalformedURLException e) { return new StringReader(getErrorXML("Sorry,
275 * MalformedURLException while accessing the KEStore")); } catch
276 * (XmlRpcException e) { return new StringReader(getErrorXML("Sorry,
277 * XmlRpcException while accessing the KEStore")); } catch (IOException e) {
278 * return new StringReader(getErrorXML("Sorry, IOException while accessing
279 * the KEStore")); } return new StringReader(xmlsource); }
283 * Get the corresponding user for a session.
286 * id of the session to identify the user
287 * @return username or null if an invalid sessionid was given
288 * @throws NullPointerException
289 * carrying the error-message if an RemoteException occures.
291 public static String getUsername(String session_id) {
292 SDialog sd = getSDialog();
295 if ((username = sd.getUsername(session_id)).equals(""))
298 } catch (RemoteException e) {
299 throw new NullPointerException(
300 getErrorXML("Sorry, RemoteException while accesing the SDialog - is it running ?"));
308 private static String xmlGetUsername(String session_id) {
309 XmlRpcClient bdialog;
310 String xmlsource = "";
311 Vector parameter = new Vector();
312 parameter.add(session_id);
314 bdialog = new XmlRpcClient("http://localhost:1050");
315 String result = (String) bdialog.execute("SDialog.getUsername",
317 if (result.equals(""))
320 } catch (MalformedURLException e) {
321 return getErrorXML("Sorry, MalformedURLException while accesing the SDialog - is it running ?");
322 } catch (XmlRpcException e) {
323 return getErrorXML("Sorry, XmlRpcException while accesing the SDialog - is it running ?");
324 } catch (IOException e) {
325 return getErrorXML("Sorry, IOException while accesing the SDialog - is it running ?");
329 private static String getErrorXML(String string) {
330 return "<ERROR><DESCRIPTION> <h1> Error in file InformationPrecessor.java </h1>"
331 + string + "</DESCRIPTION></ERROR>";