You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "Allison, Timothy B." <ta...@mitre.org> on 2014/05/20 20:26:22 UTC

Property type closed choice

In working on Tika-1294, I thought that I'd try adding the following to TikaCoreProperties:

public static final Property EMBEDDED_RESOURCE_TYPE = 
          Property.internalClosedChoise("embedded_resource_type", 
                new String[]{"attachment", "inline"});

When I run this:
       Property attach = TikaCoreProperties.EMBEDDED_RESOURCE_TYPE;
       Metadata m = new Metadata();
       m.add(attach, "blah");       
       m.set(attach, "blah");

I don't get an exception.  Should metadata be throwing an exception when a user tries to set a value that isn't in the closed set?  Or, am I misunderstanding the purpose of closed choice?

Thank you.

        Best,

               Tim

RE: Property type closed choice

Posted by "Allison, Timothy B." <ta...@mitre.org>.
Thank you, Nick.  Will open trivial issue and fix.

-----Original Message-----
From: Nick Burch [mailto:apache@gagravarr.org] 
Sent: Tuesday, May 20, 2014 5:27 PM
To: dev@tika.apache.org
Subject: Re: Property type closed choice

On Tue, 20 May 2014, Allison, Timothy B. wrote:
> When I run this:
>       Property attach = TikaCoreProperties.EMBEDDED_RESOURCE_TYPE;
>       Metadata m = new Metadata();
>       m.add(attach, "blah");
>       m.set(attach, "blah");
>
> I don't get an exception.  Should metadata be throwing an exception when 
> a user tries to set a value that isn't in the closed set?

IIRC, the idea was that
   Metadata.set(String, String)
would trust you to be doing the right thing, while
   Metadata.set(Property, TypedValueOfSorts)
would sanity check what you asked of it

For example, if you look at the code for Metadata.set(Property,int) you'll 
see the sanity check logic + exception throwing

So, I'd say that if Metadata.set(Property, TypedValueOfSorts) with an 
invalid value isn't triggering an exception, then that's a bug. 
set(String,String) would be a different matter however

Nick

Re: Property type closed choice

Posted by Nick Burch <ap...@gagravarr.org>.
On Tue, 20 May 2014, Allison, Timothy B. wrote:
> When I run this:
>       Property attach = TikaCoreProperties.EMBEDDED_RESOURCE_TYPE;
>       Metadata m = new Metadata();
>       m.add(attach, "blah");
>       m.set(attach, "blah");
>
> I don't get an exception.  Should metadata be throwing an exception when 
> a user tries to set a value that isn't in the closed set?

IIRC, the idea was that
   Metadata.set(String, String)
would trust you to be doing the right thing, while
   Metadata.set(Property, TypedValueOfSorts)
would sanity check what you asked of it

For example, if you look at the code for Metadata.set(Property,int) you'll 
see the sanity check logic + exception throwing

So, I'd say that if Metadata.set(Property, TypedValueOfSorts) with an 
invalid value isn't triggering an exception, then that's a bug. 
set(String,String) would be a different matter however

Nick