Please check the API for explicit specifications of paramaters and return types! The document is available here.

Uploding/Opening a document to the server:

String documentHash = loadDocument(String filename, String document)

documentHash is the reference to the now open document on the server.

If the document or a similar document has already been loaded, the documentHash returned will be null. In this case, call getDocument(String document) to retrieve the documentHash for the original document on the server.

Closing a document on the server:

long response = closeDocument(String documentHash)

Downloading/Saving a document from the server:

String document = saveDocument(String documentHash)
You receive the title of the document, the latest sequence number, and the document itself.

Browse open documents:

String list = browse()



FILE DOCUMENT OPERATIONS:

All methods EXCEPT for locking and unlocking lines return either a error response code or a transaction/sequence number. The operation is performed, a sequence number is allocated to it. It is the client code's responsibility to make a request for any changes to the document at some interval. You can call updates() with your sequence number to get a list of all the changes to the document that have occured since the time represented by your sequence number. When you perform an operation and receive a sequence number representing the operation, the client should fetch the changes that have occured since the sequence number before the performed operation and the sequence number given for the current operation. If a change submitted conflicts with a previous change (i.e. you attempt to lock a line that someone just deleted), the system realizes that your unaware of the transaction that just occured (because your sequence number is < that transaction's sequence number) and the operation returns with an error indicating the appropriate error).

Lock/Unlock a line:

Why lock lines?
Prevents other from accessing the line and conflicting with your modifications to the line. It is recommended that you lock lines before editing them, but the methods that modify line contents will automatically lock lines for the user. If the operation spans over multiple lines and a lock cannot be obtained for any single line, the operation fails and the integrity of the document is maintained.
Do I have to lock lines?
No. If you don't manage locks, the system will do it for you - free of charge.
How do I know if a line is locked?
You can attempt to lock it OR you can call getLocks() or getLocksAndUIDs() to get a list of lines that are locked and their respective lock owners.
Could operations collide?
All operations are atomic and either complete or are aborted. The integrity of the document is maintained between transactions and while transactions occur concurrently.
To lock a line for exclusive editing for a period of time defined by <= LOCK_TIMEOUT,

long response = lockLine(String documentHash, long line, long uid, long sequenceNo)

To unlock a line for before the LOCK_TIMEOUT,

long response = unlockLine(String documentHash, long line, long uid, long sequenceNo)

Adding, Modifying and Deleting Lines:


Adding one or more consecutive lines

long response = addLine(String documentHash, long line, long userID, String toAdd, long sequenceNo)

Lines are terminated by a \n in toAdd. Threfore, toAdd = "line1\nline2\n" adds two consecutives lines starting at "line".
Modifying one line

long response = updateLine(String documentHash, long line, long userID, String toModify, long sequenceNo)

Deleting one line

long response = deleteLine(String documentHash, long line, long userID, long sequenceNo)

Insert (copy and paste) and Delete (cut):


Insert text into a text region

long response = insert(String documentHash, long line, long userID, int startPosition, int endPosition, String toInsert, long sequenceNo)

Replace the text between startPosition and endPosition with the text noted in toInsert on the line.
Delete text from a region

long response = delete(String documentHash, long line, long userID, int startPosition, int endPosition, long sequenceNo)

Remove the text between startPosition and endPosition on the line.

Sample Application:

user 55
user 77
user 99
Sequence Number Value BEFORE Operation Return Value Code Resulting Document
(for the client)
0 documentHash = "1234" //open document
service.loadDocument("file.txt","line 1\nline 2\nline 3\nline 4\n");
file.txt ==>
line 1\n
line 2\n
line 3\n
line 4\n
0 sequenceNo = 1 //insert "extended 2" in place of 2 on line 2
//we didn't even have to lock the line - assuming it isn't already locked, it will be locked for the operation
service.insert("1234"(documentHash),2(line),55(userID),5,6,"extended 2",0 (sequenceNo));
file.txt ==>
line 1\n
line extended 2\n
line 3\n
line 4\n
1 sequenceNo = 2 //delete line 3
service.deleteLine("1234"(documentHash),3(line),55(userID),1 (sequenceNo));
file.txt ==>
line 1\n
line extended 2\n
line 4\n
2 >= ErrorCodes.SUCCESS //let's lock line 1
service.lockLine("1234"(documentHash),1(line),55(userID),2 (sequenceNo));
file.txt ==>
line 1\n
line extended 2\n
line 4\n
2 ErrorCodes.CANNOT_LOCK //delete line 1 with a different userID < LOCK_TIMEOUT
service.deleteLine("1234"(documentHash),3(line),77(userID),2 (sequenceNo));
file.txt ==>
line 1\n
line extended 2\n
line 4\n
2 sequenceNo = 3 //Add a new chunk of lines
service.addLine("1234"(documentHash),3(line),55(userID),"new line\nanother new line\n",2 (sequenceNo));
file.txt ==>
line 1\n
line extended 2\n
new line\n
another new line\n
line 4\n
 another user comes online and wants to join the editing
0 '1234','file.txt','11-07-04'\n //browse the system
service.browse();
 
0 filename: file.txt\n
sequence number: 3\n
line 1\n
line extended 2\n
new line\n
another new line\n
line 4\n
//download the document
service.saveDocument("1234");
file.txt ==>
line 1\n
line extended 2\n
new line\n
another new line\n
line 4\n
3 sequenceNo = 4
//modify line 1
service.updateLine("1234" (documentHash), 1 (line), 55 (userID), "new line 1", 2 (sequenceNo));
file.txt ==>
new line 1\n
line extended 2\n
new line\n
another new line\n
line 4\n
3 sequenceNo = 5
//we add a new line between line 1 and 2
service.addLine("1234" (documentHash), 2 (line), 99 (userID), "new line 2", 2 (sequenceNo));
file.txt ==>
line 1\n
new line 2\n
line extended 2\n
new line\n
another new line\n
line 4\n
sequenceNo for the last transaction = 5, sequenceNo previous to last transaction = 3 5\n
'replace','4','1','new line 1'\n
'add','5','2','new line 2'\n
//the client reads the updates for sequence number 4. We don't apply sequence number 5 operation since it was the previous operation that we did. We are interested in the updates between our previous-to-last transaction to our last transaction.
service.updates("1234" (documentHash), 3 (sequenceNo));
file.txt ==>
new line 1\n
new line 2\n
line extended 2\n
new line\n
another new line\n
line 4\n