- From: Mark Friedman <mark@intraspect.com>
- Date: Fri, 26 Sep 1997 16:42:22 -0700
- To: Benoit Mahe <Benoit.Mahe@sophia.inria.fr>, www-jigsaw@w3.org, jigsaw@w3.org, bmahe@www43.inria.fr
Well I ended up figuring it out myself. It may not be optimum but here's
what I came up with to progamatically add extensions. Unfortunately a
couple of potentially useful methods (SampleContainer.getExtensions()
and DirectoryResource.getIndexer()) where "protected" so I had to cut
and paste code from them:
// Add extension resources
DirectoryResource dirRes = (DirectoryResource) rootRes;
ResourceContext context = server.getDefaultContext();
IndexerModule module =
(IndexerModule) context.getModule(IndexerModule.NAME);
SampleResourceIndexer indexer =
(SampleResourceIndexer) module.getIndexer(context);
SampleContainer extensions =
(SampleContainer)
(((SampleResourceIndexer)indexer).lookup("extensions"));
// Add extension resource for .bat
try {
if (extensions.lookup("bat") == null) {
// We used to use "application/x-msdownload" but
// "application/octet-stream" seems better
addExtension ("bat",
new MimeType ("application",
"octet-stream"),
extensions);
}
} catch (InvalidResourceException ex) {
System.out.println ("The extensions resource was invalid");
}
where addExtension is defined as:
static void addExtension (String extString,
MimeType type,
SampleContainer extensions) {
FileResource ext = new FileResource();
ext.setValue ("identifier", extString);
extensions.registerResource(extString, ext, null);
ext.setValue ("content-type", type);
System.out.println("Added " + extString +
" extension resource to Jigsaw");
}
-Mark
Received on Friday, 26 September 1997 19:46:25 UTC