Document tasks

Creating a document

This example shows how to create a document, position its definition, enter the properties and assign categories.

public void library_createFile( ILibraryModule libraryModule, IContext context, IFolder folder ) throws LibraryModuleException
{
        String contentAsBytes = "This is a dymmy content";
        IFile file = libraryModule.createFile( context, folder, "test-file", "test-file description", contentAsBytes.getBytes() );

        IResourceDefinition definition = null; //...

        // assigning the file to the definition
        file.setDefinition( definition );

        // position some properties
        file.setValue( "fldText", "dummy text" );
        file.setValue( "fldNumber", new Float( 1 ) );
        file.setValue( "fldDate", new Date() );

        ICategory category = null; //...

        file.addCategory( category );
}
        

Recovering a document

Example of recovering a document

public void library_getFile( ILibraryModule libraryModule, IContext context, IFolder folder ) throws LibraryModuleException
{
        IFile file = libraryModule.getFile( context, folder, "test-file" );

        System.out.println( file.getValue( "fldText" ) );
        System.out.println( file.getValue( "fldNumber" ) );
        System.out.println( new SimpleDateFormat( "yyyy-MM-dd" ).format( file.getValue( "fldDate" ) ) );
}

Recovering the document attachments

Example of recovering a document attachment

public void library_getAttachments( ILibraryModule libraryModule, IContext context, IFile file ) throws LibraryModuleException
{
        // recovering all the attachments of a file
        Collection attachments = libraryModule.getAttachments( file );

        for ( Iterator iterator = attachments.iterator() ; iterator.hasNext() ; )
        {
                IAttachment attachment = (IAttachment)iterator.next();
                System.out.println( attachment.getShortName() + " : " + attachment.getPath() );
        }

        // recovering a particular attachment by its name
        IAttachment attachment = libraryModule.getAttachment( file, "test-file" );
}

Recovering the attachment content

Example of recovering the attachment content.

public void library_getContent( ILibraryModule libraryModule, IContext context, IAttachment attachment ) throws LibraryModuleException
{
        try
        {
                // copying the attachment content on a disk file
                FileOutputStream outputStream = new FileOutputStream( new File( "output.sdk" ) );
                attachment.getContent( outputStream );
        }
        catch( FileNotFoundException e )
        {
                // ...
        }
}