Re: Beta API questions (adding an extension)

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