DOCUMENTS 5 - PortalScripting API
Public Member Functions | Public Attributes | List of all members
Document Class Reference

The Document class has been added to the DOCUMENTS PortalScripting API to gain full access to the documents stored on registers of a DOCUMENTS file by scripting means. More...

Public Member Functions

boolean deleteDocument ()
 Delete the Document object. More...
 
boolean doOCR ()
 Execute OCR for the current document. More...
 
String downloadDocument (String filePath="", String version="")
 Download the Document to the server's filesystem for further use. More...
 
String getAsPDF ()
 Create a PDF file containing the current Document's contents and return the path in the file system. More...
 
String getAttribute (String attribute)
 Get the String value of an attribute of the Document. More...
 
String getLastError ()
 Function to get the description of the last error that occurred. More...
 
String getOID (boolean oidLow=false)
 Returns the object-id. More...
 
Register getRegister ()
 Returns the Register the Document belongs to. More...
 
String hash (String hashfunction, String version="")
 Generate the hash value for the Document using the given hash function. More...
 
boolean moveToRegister (Register regObj)
 Move the Document to another document Register of the file. More...
 
boolean reindexBlob ()
 Reindex the blob located in an active file. More...
 
boolean setAttribute (String attribute, String value)
 Set the String value of an attribute of the Document to the desired value. More...
 
boolean setDocumentName (String nameWithExt)
 
Set the name of the current document. More...
 
boolean uploadDocument (String sourceFilePath, boolean versioning=true)
 Upload a file stored on the server's filesystem for replacing or versioning this Document. More...
 

Public Attributes

String bytes
 The file size of the Document object. More...
 
String comment
 The comment of the Document object. More...
 
boolean encrypted
 Info, if the blob is encrypted in the repository. More...
 
String extension
 The extension of the Document object. More...
 
String fullname
 The complete filename (name plus extension) of the Document object. More...
 
String id
 The id of the Document object. More...
 
String name
 The name (without extension) of the Document object. More...
 
String size
 The file size of the Document object. More...
 

Detailed Description

The Document class has been added to the DOCUMENTS PortalScripting API to gain full access to the documents stored on registers of a DOCUMENTS file by scripting means.

Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

Member Function Documentation

◆ deleteDocument()

boolean Document::deleteDocument ( )

Delete the Document object.

With the necessary rights you can delete a document of the file. Do this only on scratch copies (startEdit, commit)

Note
It is strictly forbidden to access the Document object after this function has been executed successfully; if you try to access it, your script will fail, because the Document does not exist any longer in DOCUMENTS.
Returns
true if successful, false in case of any error
Since
ELC 3.60b / otrisPORTAL 6.0b
ELC 3.60i / otrisPORTAL 6.0i available for archive files
Example:
// Deletion of the first document of the register "docs"
var myFile = context.file;
if (!myFile)
{
util.out("missing file");
return -1;
}
if (!myFile.startEdit())
{
util.out("Unable to create scratch copy: " + myFile.getLastError());
return -1;
}
var myReg = myFile.getRegisterByName("docs");
if (!myReg)
{
util.out("missing >docs< register");
return -1;
}
var firstDoc = myReg.getDocuments().first();
if (!firstDoc)
{
return 0; // Nothing to do
}
if (!firstDoc.deleteDocument())
{
util.out(firstDoc.getLastError());
myFile.abort();
return -1;
}
if (!myFile.commit())
{
util.out("commit failed: " + myFile.getLastError());
myFile.abort();
return -1;
}
return 0;

◆ doOCR()

boolean Document::doOCR ( )

Execute OCR for the current document.

Returns
true if successful, false in case of any error
Since
DOCUMENTS 5.0e

◆ downloadDocument()

String Document::downloadDocument ( String  filePath = "",
String  version = "" 
)

Download the Document to the server's filesystem for further use.

Parameters
filePathOptional string specifying where the downloaded Document to be stored.
Note: A file path containing special characters can be modified due to the encoding problem. The modified file path will be returned.
versionOptional string value specifying which version of this Document to be downloaded (e.g. "2.0"). The default value is the active version.
Note: This parameter is ignored for an archive document.
Returns
String containing full path and file name of the downloaded Document, an empty string in case of any error.
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files
DOCUMENTS 4.0 (new parameter filePath)
DOCUMENTS 4.0d (new parameter version)
Example:
// Example 1
var docFile = context.file;
var reg = docFile.getRegisterByName("Documents");
var docIter = reg.getDocuments();
if (docIter && docIter.size() > 0)
{
var doc = docIter.first();
var docPath = doc.downloadDocument();
var txtFile = new File(docPath, "r+t");
if (txtFile.ok())
{
var stringVar = txtFile.readLine(); // read the first line
txtFile.close();
}
}
Example:
// Example 2
var docFile = context.file;
var reg = docFile.getRegisterByName("Documents");
var docIter = reg.getDocuments();
if (docIter && docIter.size() > 0)
{
var doc = docIter.first();
var docPath = "C:\\tmp\\test.txt";
docPath = doc.downloadDocument(docPath, "2.0"); // since DOCUMENTS 4.0d
if (docPath == "")
util.out(doc.getLastError());
}

◆ getAsPDF()

String Document::getAsPDF ( )

Create a PDF file containing the current Document's contents and return the path in the file system.

The different document types of your documents require the appropriate PDF filter programs to be installed and configured in DOCUMENTS.

Returns
String with file path of the PDF, an empty string in case of any error.
Since
DOCUMENTS 4.0c
Example:
var docFile = context.file;
var reg = docFile.getRegisterByName("Doc1");
var docIt = reg.getDocuments();
for (doc = docIt.first(); doc; doc = docIt.next())
{
var pathPdfFile = doc.getAsPDF();
if (pathPdfFile == "")
util.out(doc.getLastError());
else
util.out("File path: " + pathPdfFile);
}

◆ getAttribute()

String Document::getAttribute ( String  attribute)

Get the String value of an attribute of the Document.

Parameters
attributeString containing the name of the desired attribute
Returns
String containing the value of the desired attribute
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

◆ getLastError()

String Document::getLastError ( )

Function to get the description of the last error that occurred.

Returns
Text of the last error as String
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files
See also
DocFile.getLastError()

◆ getOID()

String Document::getOID ( boolean  oidLow = false)

Returns the object-id.

Parameters
oidLowOptional flag:
If true only the id of the Document object (m_oid) will be returned.
If false the id of the Document object will be returned together with the id of the corresponding class in the form class-id:m_oid.
The default value is false.
Returns
String with the object-id
Since
ELC 3.60c / otrisPORTAL 6.0c
ELC 3.60i / otrisPORTAL 6.0i available for archive files
DOCUMENTS 5.0 (new parameter oidLow)

◆ getRegister()

Register Document::getRegister ( )

Returns the Register the Document belongs to.

Returns
Register object or null if missing
Since
DOCUMENTS 5.0c HF1
Example:
var file = context.file;
var reg1 = file.getRegisterByName("RegisterA");
var firstDoc = reg1.getDocuments().first();
if (firstDoc)
{
var reg = firstDoc.getRegister();
if (reg)
util.out(reg.name); // "RegisterA"
}

◆ hash()

String Document::hash ( String  hashfunction,
String  version = "" 
)

Generate the hash value for the Document using the given hash function.

These hash functions are supported:

  • sha1
  • sha224
  • sha256
  • sha384
  • sha512
  • md4
  • md5
  • whirlpool
  • ripemd160
Parameters
hashfunctionString containing the name of the hash function.
versionOptional string value specifying which version of this Document to be hashed (e.g. "2.0"). The default value is the active version.
Note: This parameter is ignored for an archive document.
Returns
String with the hash value of the Document, an empty string in case of any error.
Since
DOCUMENTS 5.0e
Example:
var file = context.file;
var reg1 = file.getRegisterByName("RegisterA");
var firstDoc = reg1.getDocuments().first();
if (firstDoc)
{
try
{
var hashValue = firstDoc.hash("sha256", "2.0");
if (hashValue == "")
util.out(firstDoc.getLastError());
}
catch (ex)
{
util.out(ex);
}
}
See also
Util.hash(String filePath, String hashfunction)

◆ moveToRegister()

boolean Document::moveToRegister ( Register  regObj)

Move the Document to another document Register of the file.

With the necessary rights you can move the Document to another document Register of the file.

Note
This operation is not available for a Document located in an archive file.
Parameters
regObjThe Register this Document will be moved to.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0c
Example:
var file = context.file;
if (!file.isArchiveFile())
{
var regDoc1 = file.getRegisterByName("Doc1");
var regDoc2 = file.getRegisterByName("Doc2");
var docIt = regDoc2.getDocuments();
for (var doc = docIt.first(); doc; doc = docIt.next())
{
if (!doc.moveToRegister(regDoc1))
util.out(doc.getLastError());
}
}

◆ reindexBlob()

boolean Document::reindexBlob ( )

Reindex the blob located in an active file.

This method is only allowed if at the filetype the option 'automatic document indexing' is enabled.

Returns
true if successful, false in case of any error
Since
DOCUMENTS 5.0e HF2

◆ setAttribute()

boolean Document::setAttribute ( String  attribute,
String  value 
)

Set the String value of an attribute of the Document to the desired value.

Parameters
attributeString containing the name of the desired attribute
valueString containing the desired value of the attribute
Returns
true if successful, false in case of any error
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

◆ setDocumentName()

boolean Document::setDocumentName ( String  nameWithExt)


Set the name of the current document.

This method is only allowed for documents at a scratch copy (startEdit, commit).

Parameters
nameWithExtString containing the document name with extension.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 5.0e HF2
Example:
// Rename the first document of the register "docs"
var myFile = context.file;
if (!myFile)
{
util.out("missing file");
return -1;
}
if (!myFile.startEdit())
{
util.out("Unable to create scratch copy: " + myFile.getLastError());
return -1;
}
var myReg = myFile.getRegisterByName("docs");
if (!myReg)
{
util.out("missing >docs< register");
return -1;
}
var firstDoc = myReg.getDocuments().first();
if (!firstDoc)
{
return 0; // Nothing to do
}
if (!firstDoc.setDocumentName("newName.txt"))
{
util.out(firstDoc.getLastError());
myFile.abort();
return -1;
}
if (!myFile.commit())
{
util.out("commit failed: " + myFile.getLastError());
myFile.abort();
return -1;
}
return 0;

◆ uploadDocument()

boolean Document::uploadDocument ( String  sourceFilePath,
boolean  versioning = true 
)

Upload a file stored on the server's filesystem for replacing or versioning this Document.

Note
After successful upload of the Document the source file on the server's directory structure is removed!
Parameters
sourceFilePathString containing the path of the desired file to be uploaded.
Note: Backslashes contained in the filepath must be quoted with a leading backslash, since the backslash is a special char in ECMAScript!
versioningOptional flag: true for versioning the Document and false for replacing it.
Returns
true if successful, false in case of any error
Since
DOCUMENTS 4.0d
Example:
var docFile = context.file;
var reg = docFile.getRegisterByName("Documents");
var docIter = reg.getDocuments();
if (docIter && docIter.size() > 0)
{
var doc = docIter.first();
if (!doc.uploadDocument("c:\\tmp\\test.txt", true))
util.out(doc.getLastError());
}

Member Data Documentation

◆ bytes

String Document::bytes

The file size of the Document object.

Returns
Integer containing the file size of the Document in Byte
Note
This property is readonly.
Since
DOCUMENTS 4.0e

◆ comment

String Document::comment

The comment of the Document object.

Returns
String containing the comment of the Document
Note
This property is readonly.
Since
DOCUMENTS 5.0d HF1

◆ encrypted

boolean Document::encrypted

Info, if the blob is encrypted in the repository.

Returns
boolean value indicating whether the blob is encyrpted or not
Note
This property is readonly.
Since
DOCUMENTS 4.0d HF3

◆ extension

String Document::extension

The extension of the Document object.

Returns
String containing the filename's extension of the Document
Note
This property is readonly.
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

◆ fullname

String Document::fullname

The complete filename (name plus extension) of the Document object.

Returns
String containing the complete filename of the Document
Note
This property is readonly.
Since
ELC 3.60i / otrisPORTAL 6.0i available for archive files
ELC 3.50n / otrisPORTAL 5.0n

◆ id

String Document::id

The id of the Document object.

Returns
String containing the unique id of the Document
Note
This property is readonly.
Since
DOCUMENTS 5.0e

◆ name

String Document::name

The name (without extension) of the Document object.

Returns
String containing the filename of the Document without extension
Note
This property is readonly.
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

◆ size

String Document::size

The file size of the Document object.

Returns
String containing the formatted file size of the Document
Note
This property is readonly.
Since
ELC 3.50n / otrisPORTAL 5.0n
ELC 3.60i / otrisPORTAL 6.0i available for archive files

This documentation refers DOCUMENTS 5.0e (2105).
Created at 11-09-2019. - © 1998-2019 otris software AG, Königswall 21, D-44137 Dortmund. support@otris.de