~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to src/au/gov/naa/digipres/xena/kernel/guesser/GuesserManager.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        private PluginManager pluginManager;
60
60
 
61
61
        private Map<String, FileTypeDescriptor> extensionToDescriptorMap = new HashMap<String, FileTypeDescriptor>();
62
 
        private Map<String, Type> extensionToTypeMap = new HashMap<String, Type>();
63
62
        private int maximumMagicNumberSize = 3; // Default magic number size is 3
64
63
 
65
64
        public GuesserManager(PluginManager pluginManager) {
87
86
                                String[] extensionArr = descriptor.getExtensionArr();
88
87
                                for (String extension : extensionArr) {
89
88
                                        extensionToDescriptorMap.put(extension, descriptor);
90
 
                                        extensionToTypeMap.put(extension, guesser.getType());
91
89
                                }
92
90
                        }
93
91
                }
274
272
         * we have the correct type without having to iterate through all the guessers.
275
273
         * 
276
274
         * @param source
277
 
         * @return
 
275
         * @return matched Type, or null if an exact match could not be found.
278
276
         * @throws IOException 
279
277
         */
280
 
        private Type getExactMatch(XenaInputSource source) throws IOException {
 
278
        public Type getExactMatch(XenaInputSource source) throws IOException {
281
279
                Type type = null;
282
280
                String extension = source.getFileNameExtension();
283
281
                if (extension != null) {
289
287
                                sourceStream.read(header);
290
288
                                if (descriptor.magicNumberMatch(header)) {
291
289
                                        // We have a match
292
 
                                        type = extensionToTypeMap.get(extension);
 
290
                                        type = descriptor.getType();
293
291
                                }
294
292
                                sourceStream.close();
295
293
 
299
297
        }
300
298
 
301
299
        /**
 
300
         * Checks a hash map (populated when guessers are registered with the GuesserManager)
 
301
         * for a match of file extension. Return the matching type, or null of there is no match.
 
302
         * 
 
303
         * @param source
 
304
         * @return matched Type, or null if an exact match could not be found.
 
305
         * @throws IOException 
 
306
         */
 
307
        public Type getExtensionMatch(XenaInputSource source) {
 
308
                Type type = null;
 
309
                String extension = source.getFileNameExtension();
 
310
                if (extension != null) {
 
311
                        FileTypeDescriptor descriptor = extensionToDescriptorMap.get(extension);
 
312
                        if (descriptor != null) {
 
313
                                type = descriptor.getType();
 
314
                        }
 
315
                }
 
316
                return type;
 
317
        }
 
318
 
 
319
        /**
302
320
         * Get the best guess for the given XIS, while making as few guesses as possible.
303
321
         * The guessers are first sorted in order of the maximum ranking that each can
304
322
         * produce. The guessers then guess the type in turn, with guessers with the higher