Property type closed choice

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Property type closed choice

Allison, Timothy B.
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
Reply | Threaded
Open this post in threaded view
|

Re: Property type closed choice

Nick Burch-2
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
Reply | Threaded
Open this post in threaded view
|

RE: Property type closed choice

Allison, Timothy B.
Thank you, Nick.  Will open trivial issue and fix.

-----Original Message-----
From: Nick Burch [mailto:[hidden email]]
Sent: Tuesday, May 20, 2014 5:27 PM
To: [hidden email]
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