1
/***********************************************************************
4
* Copyright (C) 2004 Novell, Inc.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* Author: Boyd Timothy <btimothy@novell.com>
22
***********************************************************************/
24
package com.novell.simias.storebrowser;
26
import java.net.MalformedURLException;
27
import java.text.MessageFormat;
31
import com.novell.simias.browser.Browser_x0020_ServiceLocator;
32
import com.novell.simias.browser.Browser_x0020_ServiceSoap;
35
* @author Boyd Timothy <boyd@timothy.ws>
37
public class SwingStoreBrowser {
39
public SwingStoreBrowser()
44
public static void main(String[] args) {
45
StoreBrowserWindow sbWin = new StoreBrowserWindow();
46
sbWin.setSize(800,600);
48
sbWin.setVisible(true);
51
public static Browser_x0020_ServiceSoap getSoapService(String serviceURL, String username, String password) throws MalformedURLException
55
Browser_x0020_ServiceLocator locator =
56
new Browser_x0020_ServiceLocator();
58
URL url = new URL(serviceURL);
60
Browser_x0020_ServiceSoap service = null;
63
// make sure that the axis client knows to use a session
64
locator.setMaintainSession(true);
66
service = locator.getBrowser_x0020_ServiceSoap(url);
69
((org.apache.axis.client.Stub) service).setUsername(username);
71
((org.apache.axis.client.Stub) service).setPassword(password);
73
// if we make it here without exceptions, we've found a valid server
84
public static Browser_x0020_ServiceSoap getLocalSoapService()
86
String username = null;
87
String password = null;
89
URL url = getLocalServiceURL();
93
SimiasCredentials credentials = SimiasCredentials.getLocalSimiasCredentials();
94
if (credentials != null)
96
username = credentials.getUsername();
97
password = credentials.getPassword();
102
return getSoapService(url.toString(), username, password);
104
catch (MalformedURLException e)
106
// Intentionally left blank
112
private static URL getLocalServiceURL()
114
String userHomePath = System.getProperty("user.home");
115
String fileSeparator = System.getProperty("file.separator");
117
if (userHomePath == null || fileSeparator == null)
120
String configFilePath =
121
MessageFormat.format("{0}{1}.local{1}share{1}simias{1}Simias.config",
122
new Object[] {userHomePath, fileSeparator});
126
BufferedReader br = new BufferedReader(new FileReader(configFilePath));
128
String line = br.readLine();
131
int settingPos = line.indexOf("<setting name=\"WebServiceUri\"");
134
// Attempt to parse out the URL
135
int valuePos = line.indexOf("value=\"", settingPos + 1);
138
int closingQuotePos = line.indexOf("\"", valuePos + 7);
139
if (closingQuotePos >= 0)
141
String urlString = line.substring(valuePos + 7, closingQuotePos);
144
return new URL(urlString + fileSeparator + "SimiasBrowser.asmx");
146
catch (MalformedURLException e)
148
System.err.println("Couldn't parse WebServiceUri from Simias.config");
155
line = br.readLine();
160
catch (IOException ioe)
162
System.err.println("Couldn't open: " + configFilePath);
163
ioe.printStackTrace();
168
System.err.println("Parse error: " + configFilePath);
175
private static class SimiasCredentials
180
public SimiasCredentials(String username, String password)
182
this.username = username;
183
this.password = password;
186
public String getUsername()
191
public String getPassword()
196
public static SimiasCredentials getLocalSimiasCredentials()
198
// Read the Simias Credentials from the disk and return
199
// a SimiasCredentials Object
200
String username = System.getProperty("user.name");
201
String userHomePath = System.getProperty("user.home");
202
String fileSeparator = System.getProperty("file.separator");
203
String password = null;
205
if (username == null || userHomePath == null || fileSeparator == null)
208
String passwordFilePath =
209
MessageFormat.format("{0}{1}.local{1}share{1}simias{1}.local.if",
210
new Object[] {userHomePath, fileSeparator});
214
BufferedReader br = new BufferedReader(new FileReader(passwordFilePath));
216
password = br.readLine();
225
return new SimiasCredentials(username, password);