001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.win32;
021:
022: /**
023: * Licensed Material - Property of Salmon LLC
024: * (C) Copyright Salmon LLC. 1999 - All Rights Reserved
025: * For more information go to www.salmonllc.com
026: * *
027: * *************************************************************************
028: * DISCLAIMER:
029: * The following code has been created by Salmon LLC. The code is provided
030: * 'AS IS' , without warranty of any kind unless covered in another agreement
031: * between your corporation and Salmon LLC. Salmon LLC shall not be liable
032: * for any damages arising out of your use of this, even if they have been
033: * advised of the possibility of such damages.
034: * *************************************************************************
035: * *
036: * This class is used to set a key in the registry. Use the setRegistryEntry method. This class requires REGUPDATE.dll
037: * To be distributed with it.
038: * Creation date: (4/16/02 11:43:10 AM)
039: * @author: Fred Cahill
040: */
041: public class Registry {
042: public final static int HKEY_CLASSES_ROOT = 1;
043: public final static int HKEY_CURRENT_USER = 2;
044: public final static int HKEY_LOCAL_MACHINE = 3;
045: public final static int HKEY_USERS = 4;
046: private static boolean _isLoaded = false;
047:
048: private int _type;
049: private String _key;
050:
051: static {
052: loadJNILibrary("REGUPDATE");
053: }
054:
055: public Registry(int iType, String sKey) {
056: _type = iType;
057: _key = sKey;
058: }
059:
060: /**
061: * Use this method to get a registry value.
062: * @param iType int This is a constant representing the key type. HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS
063: * @param sKey java.lang.String This is a string representing the key. e.g. "Software\\Macromedia\\Dreamweaver\\Sites\\-Site0"
064: * @param sAttribute java.lang.String This is the attribute in that key to be gotten.
065: * @return The value of the attribute.
066: */
067: private static native int getDWordRegistryEntry(int iType,
068: String sKey, String sAttribute);
069:
070: /**
071: * Use this method to get a registry value.
072: * @param iType int This is a constant representing the key type. HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS
073: * @param sKey java.lang.String This is a string representing the key. e.g. "Software\\Macromedia\\Dreamweaver\\Sites\\-Site0"
074: * @param sAttribute java.lang.String This is the attribute in that key to be gotten.
075: * @return The value of the attribute.
076: */
077: private static native String getRegistryEntry(int iType,
078: String sKey, String sAttribute);
079:
080: /**
081: * This method specifies the JNI Secure ID dll to use.
082: * @param sLibrary The name of the dll to be loaded.
083: */
084: public static synchronized void loadJNILibrary(String sLibrary) {
085: try {
086: System.err.println("Start to load the library");
087: System.loadLibrary(sLibrary);
088: System.err.println("Library loaded");
089: _isLoaded = true;
090: } catch (Error err) {
091: System.out.println(err);
092: }
093: }
094:
095: /**
096: * Insert the method's description here.
097: * Creation date: (4/16/02 12:00:24 PM)
098: * @param args java.lang.String[]
099: */
100: public static void main(String[] args) {
101: setRegistryEntry(HKEY_CURRENT_USER, "Software\\Test",
102: "TestKey", "TestValue");
103: System.out.println(getDWordRegistryEntry(HKEY_CURRENT_USER,
104: "Software\\Macromedia\\Dreamweaver 4\\Sites\\-Summary",
105: "Number of Sites"));
106: }
107:
108: /**
109: * Use this method to set a registry value.
110: * @param iType int This is a constant representing the key type. HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS
111: * @param sKey java.lang.String This is a string representing the key. e.g. "Software\\Macromedia\\Dreamweaver\\Sites\\-Site0"
112: * @param sAttribute java.lang.String This is the attribute in that key to be set.
113: * @param iValue int This is the value to set the attribute to.
114: */
115: private static native void setDWordRegistryEntry(int iType,
116: String sKey, String sAttribute, int iValue);
117:
118: /**
119: * Use this method to set a registry value.
120: * @param iType int This is a constant representing the key type. HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS
121: * @param sKey java.lang.String This is a string representing the key. e.g. "Software\\Macromedia\\Dreamweaver\\Sites\\-Site0"
122: * @param sAttribute java.lang.String This is the attribute in that key to be set.
123: * @param sValue java.lang.String This is the value to set the attribute to.
124: */
125: private static native void setRegistryEntry(int iType, String sKey,
126: String sAttribute, String sValue);
127:
128: /**
129: * Use this method to get a registry value.
130: * @param sAttribute java.lang.String This is the attribute in the key to be gotten.
131: * @return The value of the attribute.
132: */
133: public String getStringAttribute(String sAttribute)
134: throws RegistryException {
135: if (!_isLoaded)
136: throw new RegistryException(
137: "REGUPDATE.DLL has not been loaded.");
138: return getRegistryEntry(_type, _key, sAttribute);
139: }
140:
141: /**
142: * Use this method to get a registry value.
143: * @param sAttribute java.lang.String This is the attribute in the key to be gotten.
144: * @return The value of the attribute.
145: */
146: public int getIntAttribute(String sAttribute)
147: throws RegistryException {
148: if (!_isLoaded)
149: throw new RegistryException(
150: "REGUPDATE.DLL has not been loaded.");
151: return getDWordRegistryEntry(_type, _key, sAttribute);
152: }
153:
154: /**
155: * Use this method to set a registry value.
156: * @param sAttribute java.lang.String This is the attribute in the key to be set.
157: * @param iValue int This is the value to set the attribute to.
158: */
159:
160: public void setIntAttribute(String sAttribute, int iValue)
161: throws RegistryException {
162: if (!_isLoaded)
163: throw new RegistryException(
164: "REGUPDATE.DLL has not been loaded.");
165: setDWordRegistryEntry(_type, _key, sAttribute, iValue);
166: }
167:
168: /**
169: * Use this method to set a registry value.
170: * @param sAttribute java.lang.String This is the attribute in the key to be set.
171: * @param sValue java.lang.String This is the value to set the attribute to.
172: */
173:
174: public void setStringAttribute(String sAttribute, String sValue)
175: throws RegistryException {
176: if (!_isLoaded)
177: throw new RegistryException(
178: "REGUPDATE.DLL has not been loaded.");
179: setRegistryEntry(_type, _key, sAttribute, sValue);
180: }
181:
182: }
|