Articles‎ > ‎

Livelink API Example - Fetch Document Example

posted Jan 23, 2009, 3:28 AM by Ossie Moore


The example program below reads the host, port, user, password, document node id and full path for file to be downloaded. Please note that is is sample code only and not intended to be used in a production environment.

Required Libraries

following libraries are required to compile the source:
  • Livelink API (lapi.jar)


java -cp "C:\\path\\to\\lapi.jar;." FetchDocumentExample [host] [port] [username] [password] [dataid] [downloadDocumentName]
java -cp "C:\\path\\to\\lapi.jar;." FetchDocumentExample myhost 2099 jsmith sup3Rsecre7 2415232 "c:\\MyDocument.doc"

java -cp "/path/to/api.jar:." FetchDocumentExample [host] [port] [username] [password] [dataid] [downloadDocumentName]
java -cp "/path/to/api.jar:." FetchDocumentExample myhost 2099 jsmith sup3Rsecre7 2415232 "/tmp/MyDocument.doc"


import com.opentext.api.LAPI_DOCUMENTS;
import com.opentext.api.LLSession;
import com.opentext.api.LLValue;

public class FetchDocumentExample {

private static final int ARG_HOST = 0;
private static final int ARG_PORT = 1;
private static final int ARG_USER = 2;
private static final int arg_PASS = 3;
private static final int ARG_NODE = 4;
private static final int ARG_DEST = 5;

public static void main(String[] args) {
if ((args != null) && (args.length == 6)) {

//read variables from arguments
String host = args[FetchDocumentExample.ARG_HOST];
int port = Integer.parseInt(args[FetchDocumentExample.ARG_PORT]);
String user = args[FetchDocumentExample.ARG_USER];
String pass = args[FetchDocumentExample.arg_PASS];
int node = Integer.parseInt(args[FetchDocumentExample.ARG_NODE]);
String dest = args[FetchDocumentExample.ARG_DEST];

FetchDocumentExample example = new FetchDocumentExample();
example.executeUsingSocketConnection(host, port, user, pass, node, dest);

} else {
System.err.println("Invalid arguments.");

public void executeUsingSocketConnection(String host, int port, String user, String pass, int node, String destination) {

//prepare Socket Livelink session
LLValue config = (new LLValue()).setAssocNotSet();
LLSession llSession = new LLSession(host, port, null, user, pass, config);

//instance document api
LAPI_DOCUMENTS apiDocument = new LAPI_DOCUMENTS(llSession);

//since we only have node id, we need to get object info so we can determine volume
LLValue docInfo = (new LLValue()).setAssocNotSet();
int result = apiDocument.GetObjectInfo(0, node, docInfo);
if (result != 0) {
throw new RuntimeException(llSession.getErrMsg());
int volumeId = docInfo.toInteger("VOLUMEID");

//Version 0 is always the current version
int versionNum = 0;

//fetch document from livelink
result = apiDocument.FetchVersion(volumeId, node, 0, destination);
if (result != 0) {
throw new RuntimeException(llSession.getErrMsg());
File out = new File(destination);
System.out.printf("File %1$s exitst? %2$s%n", destination, out.exists() && out.isFile());
Ossie Moore,
Jan 23, 2009, 3:55 AM