Jukka Zitting schrieb:
Hi,

On Mon, Aug 25, 2008 at 9:06 AM, Michael Wechner
<[EMAIL PROTECTED]> wrote:
I think this is where the problem is, I mean the getParser(String) method.

I would like to overwrite this method by implementing my own chain of
responsibility.

How about the following:

    public class MyCustomParser extends CompositeParser {

        public MyCustomParser throws TikaException {
            setConfig(TikaConfig.getDefaultConfig());
            // or whatever config you want
        }

        protected Parser getParser(Metadata metadata) {
            // Custom code to select an appropriate parser
            // based on the input metadata (mime type,
            // document path, whatever) passed by the client.
            // Or fallback to:
            return super.getParser(metadata);
        }

    }

Your client code would then look like:

    private Parser parser = new MyCustomParser();

    Metadata metadata = new Metadata();
    metadata.set(Metadata.CONTENT_TYPE);
    // plus whatever other metadata you need in MyCustomParser

    parser.parse(stream, handler, metadata);

One of my design goals for the current Parser interface was was that
you can encapsulate this sort of functionality inside it.

thanks for the suggestions. Will give it a try and keep you posted on my findings.

Thanks

Michael
BR,

Jukka Zitting

Reply via email to