net.proxy.sunproxy
Class NSRegistry

java.lang.Object
  extended by net.proxy.sunproxy.NSRegistry

public class NSRegistry
extends java.lang.Object

Provides simple read-only access to the (binary) Netscape registry file. The registry file, typically C:\WINNT\nsreg.dat on windows or ~/.netscape/registry on Unix, contains configuration information for Netscape applications. The registry is organized like the windows registry: it's tree structured and nodes (called "keys") have a list of name/value pairs called entries.

The format of the file doesn't seem to be officially documented however it's not complicated and can be easily derived from the Mozilla sources that provide access to it. See the references below for more information.

To use this class you must create an NSRegistry object and open a valid registry file. To look up a value (the value of an "entry") you provide it's path; here's an example that prints the current version of Communicator.

 NSRegistry reg = new NSRegistry().open(new File("c:\WINNT\nsreg.dat"));
 System.out.println(reg.get("Version Registry/Netscape/Communicator/Version"));
 reg.close();
 
The NSRegistry.dump() method prints the contents of the entire registry.

Version:
1.5, 07/11/02

Constructor Summary
NSRegistry()
           
 
Method Summary
 void close()
          Close the Netscape registry file.
 void dump()
          Dump the contents of the registry to the standard output.
 java.lang.String get(java.lang.String path)
          Return the value of the specified path.
 NSRegistry open(java.io.File regFile)
          Open the (binary) Netscape registry file (usually C:\WINNT\nsreg.dat on Windows) and read its header.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NSRegistry

public NSRegistry()
Method Detail

open

public NSRegistry open(java.io.File regFile)
Open the (binary) Netscape registry file (usually C:\WINNT\nsreg.dat on Windows) and read its header. Return this if the file was opened and the header was read successfully, null otherwise. This method must be called, before calling anything else.

The layout of the file header is only documented in the Mozilla sources, see

source/modules/libreg/src/reg.h

Here's the header struct itself: typedef struct _hdr { uint32 magic; // must equal MAGIC_NUMBER uint16 verMajor; // major version number uint16 verMinor; // minor version number REGOFF avail; // next available offset REGOFF root; // root object } REGHDR;


close

public void close()
Close the Netscape registry file.


get

public java.lang.String get(java.lang.String path)
Return the value of the specified path. A path resembles a UNIX file path, forward slashes ('/') are used to separate path elements. The elements of the path must match the names of registry keys and the final path element must match the name of a registry entry. Paths always implicitly begin with a slash. Here's an example that returns the version of Navigator:
 NSRegistry reg = new NSRegistry().open();
 reg.get("Version Registry/Netscape/Communicator/Version");
 reg.close();
 


dump

public void dump()
Dump the contents of the registry to the standard output. The name of each key is, indented to show its level in the tree. Entries are indented similarly and are formatted like this:
 [name = value]
 


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object