Programming tasks

Library

Recover the libraries

From the publication module, you may recover every library present on the server.

public void server_getLibraries( ILibraryModule libraryModule, IContext context ) throws LibraryModuleException {
	// recovering every libraries
	Collection<ILibrary> libraries = libraryModule.getLibraries( context );
	for ( ILibrary library : libraries ) {
		System.out.println( library.getName() );
	}
}

Recover a library

In the publication module, you may recover one library by its name.

public void server_getLibrary( ILibraryModule libraryModule, IContext context ) throws LibraryModuleException {
	// recovering a library
	ILibrary library = libraryModule.getLibrary( context, "test-library" );
	System.out.println( library.getName() );
}

Create a library

In the publication module, you may create new libraries.

public void server_createLibrary( ILibraryModule libraryModule, IContext context ) throws LibraryModuleException {
	ILibrary library = libraryModule.createLibrary( context, "test-library" );

	// position some properties
	library.setForbiddenExtensions( "bat, js" );
}

Category

Recover the categories

This example shows how to recover the library categories.

public void server_getCategories( ILibraryModule libraryModule, IContext context, ILibrary library ) throws LibraryModuleException {
	// recovering categories placed at the library root
	Collection<ICategory> categories = libraryModule.getCategories( context, library, false );
	for ( ICategory category : categories ) {
		System.out.println( category.getName() );
	}
}

Recover the sub-categories

This example shows how to recover the sub-categories.

public void server_getSubCategories( ILibraryModule libraryModule, IContext context, ICategory category ) throws LibraryModuleException {
	// recovering categories from a parent category
	Collection<ICategory> categories = libraryModule.getCategories( context, category, false );
}

Create categories

This example shows how to create new categories and sub-categories.

public void server_createCategory( ILibraryModule libraryModule, IContext context, ILibrary library ) throws LibraryModuleException {
	// creating a category
	ICategory category = libraryModule.createCategory( context, library, "test-category" );
	
	// creating a sub-category
	ICategory subCategory = libraryModule.createCategory( context, category, "test-sub-category" );
}

Folder

Create a folder

This example shows how to create folders on the library level.

public void library_createFolder( ILibraryModule libraryModule, IContext context, ILibrary library ) throws LibraryModuleException {
	IFolder folder = libraryModule.createFolder( context, library, "test-folder" );
	folder.setDescription( "test-folder description" );
}

Create a sub-folder

This example shows how to create sub-folders.

public void library_createFolder( ILibraryModule libraryModule, IContext context, IFolder parent ) throws LibraryModuleException {
	IFolder folder = libraryModule.createFolder( context, parent, "test-sub-folder" );
	folder.setDescription( "test-sub-folder description" );
}

Definition

Recover the definitions

This example enables to recover definition from a library.

public void library_getDefinitions( ILibraryModule libraryModule, IContext context, ILibrary library ) throws LibraryModuleException {
	// recovering every definitions
	Collection<IResourceDefinition> definitions = libraryModule.getResourceDefinitions( context, library );
	for ( IResourceDefinition definition : definitions ) {
		System.out.println( definition.getLabel() + " [" + definition.getName() + "]" );
	}
}

Recover a definition

This example shows how to recover a definition

public void library_getDefinition( ILibraryModule libraryModule, IContext context, ILibrary library ) throws LibraryModuleException {
	// recovering a definition
	IResourceDefinition definition = libraryModule.getResourceDefinition( context, library, "test-definition" );
	System.out.println( definition.getLabel() + " [" + definition.getName() + "]" );
}

Property

Recover the properties

This example shows how to recover the definition properties.

public void library_getProperties( ILibraryModule libraryModule, IContext context, IResourceDefinition definition ) throws LibraryModuleException {
	// recover all the properties
	for ( IProperty property : definition.getProperties() ) {
		System.out.println( property.getLabel() + " [" + property.getName() + "]" );
	}
}

Document

Create 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 );
}

Recover 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" ) ) );
}

Recover 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<IAttachment> attachments = libraryModule.getAttachments( file );

	for ( IAttachment attachment : attachments ) {
		System.out.println( attachment.getShortName() + " : " + attachment.getPath() );
	}

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

Recover 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 ) {
		// ...
	}
}