001: package com.sun.portal.proxylet.client.common;
002:
003: import com.sun.portal.proxylet.client.common.ui.ProxyletUI;
004: import com.sun.portal.proxylet.client.common.browser.BrowserHelper;
005:
006: import java.io.*;
007:
008: /**
009: * Created by IntelliJ IDEA.
010: * User: Administrator
011: * Date: Feb 17, 2005
012: * Time: 11:06:46 AM
013: * To change this template use File | Settings | File Templates.
014: */
015: public class regxwrapper {
016: private long connectionType;
017: private String autoConfigURL;
018: private String proxyserver;
019: private String proxybypass;
020: private String tempdirectory;
021: public static boolean dllloaded = false;
022: boolean binit = false;
023: private static final regxwrapper _theInstance = new regxwrapper();
024:
025: static {
026: try {
027: System.loadLibrary("regxwrapper");
028: dllloaded = true;
029: } catch (Throwable e) {
030: dllloaded = false;
031: }
032: }
033:
034: private regxwrapper() {
035: }
036:
037: void init() throws Exception {
038: try {
039: if (tempdirectory != null) {
040: if (new File(tempdirectory).isDirectory())
041: return;
042: }
043: tempdirectory = Param.getTempDirectory();
044: if (!dllloaded) {
045: Log.debug("Loading library explicitly");
046: loadExplicitly();
047: }
048: } catch (IOException e) {
049: System.out.println("Unable to create temp file");
050: ProxyletUI.setText(Param.getString("perr.8",
051: "ERR: Unable to write to disk"));
052: throw e;
053: }
054:
055: }
056:
057: public synchronized static regxwrapper getInstance() {
058: if (_theInstance.binit == false) {
059: try {
060: _theInstance.init();
061: } catch (Exception e) {
062: // Unable to create temp directory
063: String location = null;
064: location = BrowserHelper
065: .getNewfileLocation(ProxyletUI.frame);
066: _theInstance.setTempDir(location);
067: }
068: _theInstance.binit = true;
069:
070: }
071: return _theInstance;
072: }
073:
074: public void loadExplicitly() throws Exception {
075: //install dll
076: String location = extractResource("regxwrapper.dll");
077: try {
078: System.load(location);
079: dllloaded = true;
080: } catch (Exception e) {
081: dllloaded = false;
082: throw e;
083: }
084: }
085:
086: public void setConnectionType(long l) {
087: System.out.println("connection type " + l);
088: connectionType = l;
089:
090: }
091:
092: public void setAutoConfigURL(String s) {
093: System.out.println("autoconfigurl " + s);
094: autoConfigURL = s;
095: }
096:
097: public void setProxyServer(String s) {
098: System.out.println("proxyserver " + s);
099: proxyserver = s;
100: }
101:
102: public void setProxybypass(String s) {
103: System.out.println("proxybypass " + s);
104: proxybypass = s;
105: }
106:
107: public void setTempDir(String l) {
108: tempdirectory = l;
109: }
110:
111: public long getConnectionType() {
112: return connectionType;
113: }
114:
115: public String getAutoConfigURL() {
116: return autoConfigURL;
117: }
118:
119: public String getProxyServer() {
120: return proxyserver;
121: }
122:
123: public String getProxybypass() {
124: return proxybypass;
125: }
126:
127: public native boolean Unregister(String path);
128:
129: public native boolean Register(String path);
130:
131: public native boolean InitInstance();
132:
133: public native boolean UninitInstance();
134:
135: public native boolean ReadSettings();
136:
137: public native boolean restoreSettings(String autoConfigURL,
138: long ConnectionType);
139:
140: public native boolean updateSettings(String autoConfigURL);
141:
142: public String extractResource(String resourceName) throws Exception {
143: ClassLoader c1 = regxwrapper.class.getClassLoader();
144: InputStream is = c1.getResourceAsStream(resourceName);
145: File rFile = null;
146:
147: if (is != null) {
148: //generate a temporary name for the resource and write to temp file
149: BufferedInputStream istream = new BufferedInputStream(is);
150: rFile = new File(tempdirectory + resourceName);
151: if (rFile.exists()) {
152: rFile.delete();
153: rFile.createNewFile();
154: }
155:
156: System.out.println("Extracting resource " + resourceName
157: + " to directory " + tempdirectory);
158: rFile.deleteOnExit();
159: BufferedOutputStream ostream = new BufferedOutputStream(
160: new FileOutputStream(rFile));
161: int bsize = 2048;
162: int n = 0;
163: byte[] buffer = new byte[bsize];
164: while ((n = istream.read(buffer, 0, bsize)) != -1) {
165: ostream.write(buffer, 0, n);
166: }
167: istream.close();
168: ostream.close();
169:
170: }
171:
172: return rFile.getAbsolutePath();
173: }
174:
175: public static void main(String[] args) throws Exception {
176: regxwrapper r = new regxwrapper();
177: r.InitInstance();
178: r.Register("c:\\temp\\RegX.dll");
179: r.ReadSettings();
180: System.out.println("Connection Type =" + r.getConnectionType());
181: System.out.println("Autoconfig URL =" + r.getAutoConfigURL());
182: System.out.println("Proxy Server = " + r.getProxyServer());
183: System.out.println("Proxy bypass =" + r.getProxybypass());
184: r.restoreSettings("http://localhost:1234", 3);
185: r.Unregister("c:\\temp\\RegX.dll");
186:
187: }
188:
189: }
|