[daisy] Q : Java API - setPart Unhandled Exception

Bruno Dumon bruno at outerthought.org
Tue Jun 26 03:55:45 CDT 2007


On Mon, 2007-06-25 at 11:10 -0700, Brandt Solovij wrote:
> 
> Hey everyone, I'm a bit green to the Daisy Java API. My experience
> thus far with it is limited, though I have successfully read a huge
> text file, created 17k xml documents, then with the API imported them
> into my daisy instance with Field value pairs and such all correctly
> configured... 
> 
> which is why this is irking me : 
> 
> I'm trying to import an image via the Java API, but my IDE  (eclipse)
> keeps choking on an " Unhandled exception type
> DocumentTypeInconsistencyException" 
> 
> 
> Heres's my code : 
> 
>                 Document   _document = repory.createDocument(_title,
> "UGImage", "main", "default"); 
>                  File testFile = new java.io.File(_file); 
>                  FilePartDataSource _dataSource = new
>  FilePartDataSource(testFile); 
>                  String _docType = "UGImage"; 
>                  String _docName = "image/pjpeg"; 
>                  _document.setPart(_docType, _docName, _dataSource); 
>                  _document.setCustomField( _CustField, _CustValue ); 
>                  _document.addToCollection(OurCollection); 
>                  _document.save(); 
> 
> 
> all the variables if not init'd in that block are being passed into
> the method that contains this code.  the error occurs @ "
> _document.setPart(_docType, _docName, _dataSource); " 

If you get a DocumentTypeInconsistencyException when setting a part, it
can be because:

 - the part you are trying to add does not belong to the document type
of the document

 - the specified mime type argument (in your code the variable _docName)
is not allowed by the part type

> 
> And I also get an "Unhanlded Repository Exception" @
> "_document.save();" 

This can be because:

 - some required parts and fields are missing

 - or, if it is not a new document, and the document type has been
modified, the document contains some parts or fields which are not
allowed anymore by the document type

You can skip these checks by passing a boolean false to the save method:
_document.save(false)

Note that in all these cases, the message of the exception contains an
explanation of what exactly is wrong.

Hope this helps.

> 
> 
> I'm sure its something simple I've over looked, but I'm stumped - any
> insight would be much appreciated. ( Note : My collection and
> repository objects are making it into the method correctly, it just
> chokes when I'm setting the image part) 
> 
> Thanks!  -Brandt

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno at outerthought.org                          bruno at apache.org



More information about the daisy mailing list