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

The Util class supports some functions that do not need any user or file context. More...

Public Member Functions

var base64Decode (String value, boolean returnArray=true)
 Decodes a base64 string and returns a string or byte-array. More...
 
String base64Encode (var value, boolean urlStyle=false)
 Encodes a byte-array or string to base64 and returns the base 64 string. More...
 
void beep (int frequency, int duration)
 Plays a beep sound at the PortalServer's system. More...
 
String concatPDF (Array pdfFilePaths, boolean deleteSinglePdfs=false)
 
Concatenate the given PDFs together into one PDF. More...
 
String convertBlobToPDF (String sourceFilePath)
 Convert a file to a PDF file and return the path in the file system. More...
 
number convertDateToExcelDate (Date timeStamp)
 Convert a Date object to an Excel numeric date format. More...
 
String convertDateToString (Date timeStamp, String format)
 Convert a Date object representing a date into a String. More...
 
Date convertStringToDate (String dateOrTimeStamp, String format)
 Convert a String representing a date into a Date object. More...
 
String cryptPassword (String pwPlain)
 Encrypt a plain password into an MD5 hash. More...
 
String decodeUrlCompatible (String encodedParam)
 Decode URL parameter from DOCUMENTS Urls. More...
 
String decryptString (String input)
 Decrypts a String value hat was encrypted with the method Util.encryptString(String input) More...
 
String deleteFile (String filePath)
 Delete a file (file system object) at the PortalServer's system. More...
 
String encodeUrlCompatible (String param)
 Encode URL parameter for DOCUMENTS Urls. More...
 
String encryptString (String input)
 Encrypts a String value with the AES 256 CBC algorithm for symmetric encryption/decryption. More...
 
String fileCopy (String sourceFilePath, String targetFilePath)
 Copy a file (file system object) at the PortalServer's system. More...
 
String fileMove (String sourceFilePath, String targetFilePath)
 Move a file (file system object) at the PortalServer's system from a source file path to the target file path. More...
 
Int fileSize (String filePath)
 Retrieve the filesize of a file (file system object) at the PortalServer's system. More...
 
String generateChecksum (String input)
 
Creates a MD5 checksum for the String value More...
 
String getDir (String dirname, Array files, Array subDirs)
 Retrieving files and subdirectories of a specified directory. More...
 
String getEnvironment (String variableName)
 Reads an environment variable of the PortalServer's system. More...
 
String getFileContentAsString (String filePath)
 Get the content of a file at the PortalServer's system as string in base64 format. More...
 
String getQuoted (String input)
 Returns the input string enclosed in either double or single quotation marks. More...
 
String getSourceLineInfo ()
 Retrieve the scriptName with the current line no of this methed. More...
 
String getTmpPath ()
 Get the path to the temporary directory on the Portalserver. More...
 
String getUniqueId ()
 Get a unique id from the system. More...
 
number getUsedPrivateBytes ()
 Returns the current usage of private bytes memory of the documensserver process. More...
 
String hash (String filePath, String hashfunction)
 Generate the hash value for a file using the given hash function. More...
 
String hmac (String hashfunction, String key, String message, Boolean rawOutput=false)
 Generates a hash-based message authentication code (hmac) of a message string using a secret key. More...
 
boolean isEncryptedBlob (String blobFilePath)
 Checks, if the current blob is encrypted (Repository encryption) or not. More...
 
number length_u (String value)
 Returns the number of characters of a UTF-8 string. More...
 
 log (String output)
 Log a String to the DOCUMENTS server window. More...
 
String makeFullDir (String dirPath)
 Creates a directory with subdirectories at the PortalServer's file system. More...
 
String makeGACLValue (var val1, var val2,...)
 Makes a valid GACL value from the parameters. More...
 
String makeHTML (String val, boolean isUTF8=false)
 Masks all HTML-elements of a String. More...
 
 out (String output)
 Output a String to the Portalserver window. More...
 
String prepareJSON ()
 Converts JSON-Strings with Source Code entities e.g. More...
 
number searchInArray (Array theArray, String searchedString, number occurence=1)
 Search for a String in an Array. More...
 
String sha256 (String message)
 Generates the SHA256 hash of any string. More...
 
string sign (string algorithm, string privateKeyPEM, string pkPassword, var payload, boolean urlStyle=false)
 
Create a digital signature. More...
 
void sleep (number duration)
 Let the PortalScript sleep for a defined duration. More...
 
String substr_u (String value, int startIndex, int length)
 Returns a substring of a UTF-8 string. More...
 
String transcode (String nameSourceEncoding, String text, String nameTargetEncoding)
 Transcode a String from encoding a to encoding b. More...
 
boolean unlinkFile (String filePath)
 Delete a physical file on the server's file system. More...
 

Public Attributes

number buildNo
 Build version number of the PortalServer. More...
 
String DB
 Database using by the PortalServer. More...
 
String memoryModel
 Memory model of the PortalServer. More...
 
number version
 Main version number of the PortalServer. More...
 

Detailed Description

The Util class supports some functions that do not need any user or file context.

These functions allow customizable Date/String conversions and other useful stuff. There is exactly ONE implicit object of the class Util which is named util.

Note
It is not possible to create objects of the class Util. There are no properties in this class, it supports only the help functions as documented below.

Member Function Documentation

◆ base64Decode()

var Util::base64Decode ( String  value,
boolean  returnArray = true 
)

Decodes a base64 string and returns a string or byte-array.

Parameters
valueString to decode
returnArrayboolean as an optional parameter to define if the return value must be a byte-array or string (default)
Returns
decoded string or byte-array
Since
DOCUMENTS 4.0c HF1
Example:
var b64Str = util.base64Encode("Hello World");
util.out(b64Str); // SGVsbG8gV29ybGQ=
var str = util.base64Decode(b64Str);
util.out(str); // Hello World
var byteArr = util.base64Decode(b64Str, true);
util.out(byteArr); // 72,101,108,108,111,32,87,111,114,108,100
b64Str = util.base64Encode(byteArr);
util.out(b64Str); // SGVsbG8gV29ybGQ=

◆ base64Encode()

String Util::base64Encode ( var  value,
boolean  urlStyle = false 
)

Encodes a byte-array or string to base64 and returns the base 64 string.

Parameters
valueString or byte-array to encode
urlStyleoptional boolean flag to request Base64URL encoding instead of standard Base64 encoding
Returns
base64 encoded string
Remarks
The URL style uses the characters '-' and '_' in place of '+' and '/', and it does not allow padding characters ('='). base64Decode() does actually not support this style.
Since
DOCUMENTS 4.0c HF1; urlStyle was added in 5.0d HF2.
Example:
var b64Str = util.base64Encode("Hello World");
util.out(b64Str); // SGVsbG8gV29ybGQ=
var str = util.base64Decode(b64Str);
util.out(str); // Hello World
var byteArr = util.base64Decode(b64Str, true);
util.out(byteArr); // 72,101,108,108,111,32,87,111,114,108,100
b64Str = util.base64Encode(byteArr);
util.out(b64Str); // SGVsbG8gV29ybGQ=

◆ beep()

void Util::beep ( int  frequency,
int  duration 
)

Plays a beep sound at the PortalServer's system.

For testing purposes a beep sound can be played at the server

Parameters
frequencyint with the frequency in hertz
durationint with the length of the sound in milliseconds (ms)
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
util.beep(1250, 3000);

◆ concatPDF()

String Util::concatPDF ( Array  pdfFilePaths,
boolean  deleteSinglePdfs = false 
)


Concatenate the given PDFs together into one PDF.

Parameters
pdfFilePathsArray containing the file paths of PDFs to be concatenated.
deleteSinglePdfsOptional boolean value to decide whether to delete the single PDFs on the server's filesystem after concatenating.
Returns
String with file path of the PDF, an empty string in case of any error.
Since
DOCUMENTS 4.0c
Example:
var arr = ["C:\\temp\\number1.pdf", "C:\\temp\\number2.pdf"];
var filePath = util.concatPDF(arr, false);
util.out("PDF file path: " + filePath);

◆ convertBlobToPDF()

String Util::convertBlobToPDF ( String  sourceFilePath)

Convert a file to a PDF file and return the path in the file system.

The different file types require the appropriate PDF filter programs to be installed and configured in DOCUMENTS.

Parameters
sourceFilePathString containing the path of the file to be converted.
Returns
String with file path of the PDF, an empty string in case of any error.
Since
DOCUMENTS 4.0d HF3
Example:
var pathPdfFile = util.convertBlobToPDF("C:\\tmp\\testFile.doc");
util.out(pathPdfFile);

◆ convertDateToExcelDate()

number Util::convertDateToExcelDate ( Date  timeStamp)

Convert a Date object to an Excel numeric date format.

Excel stores timestamp as a double value. This value exists by two parts. The pre-decimal position is the amount of days since 01.01.1900. The fractional part is the percential time in day.

  • e.g. 10.01.1900 12:00 => 10.5
  • e.g. 19.10.2018 14:30: => 43392.6042

A date before 01.03.1900 can not be converted. The method will return -1.0.

Parameters
timeStampDate object representing the desired date
Returns
double as excel date representation
Since
DOCUMENTS 5.0e
Example:
var now = new Date();
var excelDate = util.convertDateToExcelDate(now);
if (excelDate < 0.0)
util.out("I can only convert dates that are after 01.03.1900")
else
util.out(excelDate + " is now a numeric value");

◆ convertDateToString()

String Util::convertDateToString ( Date  timeStamp,
String  format 
)

Convert a Date object representing a date into a String.

The output String may have any format you like. The second parameter defines the format to configure which part of the date String should match the according properties of the Date object.

Parameters
timeStampDate object representing the desired date
formatString defining the date format of the output String, e.g. "dd.mm.yyyy".
The possible format parts are:
  • dd = two digit day
  • mm = two digit month
  • yy = two digit year
  • yyyy = four digit year
  • HH = two digit hour (24 hour format)
  • MM = two digit minute
  • SS = two digit second
Special formats:
Returns
String representing the desired date
Since
ELC 3.50e / otrisPORTAL 5.0e
DOCUMENTS 5.0a (new: Special formats @date and @timestamp)
Example:
var format = "dd.mm.yyyy HH:MM";
var now = new Date();
util.out(util.convertDateToString(now, format));
See also
Util.convertStringToDate(String dateOrTimeStamp, String format)
Context.convertDateToString(Date timeStamp, String locale)

◆ convertStringToDate()

Date Util::convertStringToDate ( String  dateOrTimeStamp,
String  format 
)

Convert a String representing a date into a Date object.

The String may contain a date or timestamp in any date format you like. The second parameter defines the format to configure which part of the date String should match the according properties of the Date object.

Parameters
dateOrTimeStampString representing a date, e.g. "19.09.1974"
formatString defining the date format of the input String, e.g. "dd.mm.yyyy".
The possible format parts are:
  • dd = two digit day
  • mm = two digit month
  • yy = two digit year
  • yyyy = four digit year
  • HH = two digit hour (24 hour format)
  • MM = two digit minute
  • SS = two digit second
Special formats:
Returns
Date object representing the desired date
Since
ELC 3.50e / otrisPORTAL 5.0e
DOCUMENTS 5.0a (new: Special formats @date and @timestamp)
Example:
var format = "dd.mm.yyyy HH:MM";
var dateString = "19.09.1974";
var birthDay = util.convertStringToDate(dateString, format);
See also
Util.convertDateToString(Date timeStamp, String format)

◆ cryptPassword()

String Util::cryptPassword ( String  pwPlain)

Encrypt a plain password into an MD5 hash.

Parameters
pwPlainString containing the plain password
Returns
String containing the encrypted password
Since
ELC 3.50o / otrisPORTAL 5.0o
Example:
var cryptPW = util.cryptPassword("Hello World");
util.out(cryptPW);

◆ decodeUrlCompatible()

String Util::decodeUrlCompatible ( String  encodedParam)

Decode URL parameter from DOCUMENTS Urls.

Parameters
encodedParamString containing the encoded URL param
Returns
String with decoded URL param.
Example:
// URL with an archive key
var encUrl = "http://localhost:8080/documents/UserLoginSuccessAction.act;cnvid=n0RIshUTRnOH3qAn?
pri=easyhr&lang=de#fi_96:3020/
id_{ehrmEmployeeDocument$EAstore2$HMUnit$DNDefault$CPInstance$DNDefault$CPPool$DNAdaptive
$CPPool$DNAdaptive02$CPDocument$DNADAPTIVE$CO060C8A9C3A1811E6B75A000C29E0A93B}
/ri_FileCover/di_easyhrdc0000000000000497";
var decUrl = util.decodeUrlCompatible(encUrl);
decUrl == "http://localhost:8080/documents/UserLoginSuccessAction.act;cnvid=n0RIshUTRnOH3qAn
?pri=easyhr&lang=de#fi_96:3020/
id_{ehrmEmployeeDocument@store2|Unit=Default/Instance=Default/Pool=Adaptive/Pool=
Adaptive02/Document=ADAPTIVE.060C8A9C3A1811E6B75A000C29E0A93B}
/ri_FileCover/di_easyhrdc0000000000000497";
See also
Util.encodeUrlCompatible(String param)
Since
DOCUMENTS 5.0a

◆ decryptString()

String Util::decryptString ( String  input)

Decrypts a String value hat was encrypted with the method Util.encryptString(String input)

Parameters
inputThe string that will be decrypted
Returns
String decrypted value
Since
DOCUMENTS 5.0b
Example:
var text = "I'm a secret password";
var encryptedText = util.encryptString(text);
util.out(encryptedText); // NABPIGCGBHEBBOMECMJHDBHIIHOCDNOMODEILCABDKOLJBMFBKDDOFDABNAMCLJC
var decryptedText = util.decryptString(encryptedText);
util.out(decryptedText); // I'm a secret password
See also
Util.encryptString(String input);

◆ deleteFile()

String Util::deleteFile ( String  filePath)

Delete a file (file system object) at the PortalServer's system.

This functions provides a simple delete method for files on the server's file system.

Parameters
filePathString with the file path
Returns
empty String if successful, the error message in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var errMsg = util.deleteFile("c:\\Test.log");
if (errMsg.length > 0)
util.out(errMsg);
else
util.out("Ok.");

◆ encodeUrlCompatible()

String Util::encodeUrlCompatible ( String  param)

Encode URL parameter for DOCUMENTS Urls.

Some parameters in DOCUMENTS urls must be encoded. E.g. the archive keys can contain invalid characters like / etc.

Parameters
paramString containing the value to encode
Returns
String with encoded value.
Example:
// URL with an archive key
var url = "http://localhost:8080/documents/UserLoginSuccessAction.act;cnvid=n0RIshUTRnOH3qAn?
pri=easyhr&lang=de#fi_96:3020/
id_{ehrmEmployeeDocument@store2|Unit=Default/Instance=Default/Pool=Adaptive/Pool=
Adaptive02/Document=ADAPTIVE.060C8A9C3A1811E6B75A000C29E0A93B}
/ri_FileCover/di_easyhrdc0000000000000497";
// The archive key is the value between id_{ }
// "ehrmEmployeeDocument@store2|Unit=Default/Instance=Default/Pool=
// Adaptive/Pool=Adaptive02/Document=ADAPTIVE.060C8A9C3A1811E6B75A000C29E0A93B"
// this key must be encoded
var encUrl = encodeURL(url);
encUrl == "http://localhost:8080/documents/UserLoginSuccessAction.act;cnvid=n0RIshUTRnOH3qAn?
pri=easyhr&lang=de#fi_96:3020/
id_{ehrmEmployeeDocument$EAstore2$HMUnit$DNDefault$CPInstance$DNDefault$CPPool$DNAdaptive
$CPPool$DNAdaptive02$CPDocument$DNADAPTIVE$CO060C8A9C3A1811E6B75A000C29E0A93B}
/ri_FileCover/di_easyhrdc0000000000000497";
function encodeURL(url)
{
// RegEx to split the url in it's parts
var reg = /(.*id_{)(.*)(}.*)/
if (!completeURL.match(reg))
throw "unable to encode";
var part1 = RegExp.$1;
var partKey = RegExp.$2;
var part3 = RegExp.$3;
return encoded = part1 + util.encodeUrlCompatible(partKey) + part3;
}
See also
Util.decodeUrlCompatible(String encodedParam)
Since
DOCUMENTS 5.0a

◆ encryptString()

String Util::encryptString ( String  input)

Encrypts a String value with the AES 256 CBC algorithm for symmetric encryption/decryption.

The length of the input String is limited to 1024 bytes. The encrypted value depends on the principal name. Usage is e.g. storing of passwords in the database for authorization against 3rd party web services.

Parameters
inputThe string that will be encrypted
Returns
String encrypted value
Since
DOCUMENTS 5.0b
Example:
var text = "I'm a secret password";
var encryptedText = util.encryptString(text);
util.out(encryptedText); // NABPIGCGBHEBBOMECMJHDBHIIHOCDNOMODEILCABDKOLJBMFBKDDOFDABNAMCLJC
var decryptedText = util.decryptString(encryptedText);
util.out(decryptedText); // I'm a secret password
See also
Util.decryptString(String input);

◆ fileCopy()

String Util::fileCopy ( String  sourceFilePath,
String  targetFilePath 
)

Copy a file (file system object) at the PortalServer's system.

This functions provides a simple copy method for files on the server's file system.

Parameters
sourceFilePathString with the source file path
targetFilePathString with the target file path
Returns
empty String if successful, the error message in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var errMsg = util.fileCopy("c:\\Test.log", "d:\\Test.log");
if (errMsg.length > 0)
util.out(errMsg);
else
util.out("Ok.");
See also
Util.fileMove(String sourceFilePath, String targetFilePath)

◆ fileMove()

String Util::fileMove ( String  sourceFilePath,
String  targetFilePath 
)

Move a file (file system object) at the PortalServer's system from a source file path to the target file path.

This functions provides a simple move method for files on the server's file system.

Parameters
sourceFilePathString with the source file path
targetFilePathString with the target file path
Returns
empty String if successful, the error message in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var errMsg = util.fileMove("c:\\Test.log", "d:\\Test.log");
if (errMsg.length > 0)
util.out(errMsg);
else
util.out("Ok.");
See also
Util.fileCopy(String sourceFilePath, String targetFilePath)

◆ fileSize()

Int Util::fileSize ( String  filePath)

Retrieve the filesize of a file (file system object) at the PortalServer's system.

This functions returns the filesize of a file.

Parameters
filePathString with the file path
Returns
Int with file size if successful, the value -1 in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var size = util.fileSize("c:\\Test.log");
if (size < 0)
util.out("File does not exist.");
else
util.out(size);

◆ generateChecksum()

String Util::generateChecksum ( String  input)


Creates a MD5 checksum for the String value

Parameters
inputThe string for that the checksum will be generated
Returns
String with the checksum
Since
DOCUMENTS 4.0c
Example:
var text = "I'm some type of text";
var md5 = util.generateChecksum(text);
if (md5 != "a77c16d60b9939295c0af4c7242b6c02")
util.out("wrong md5!");

◆ getDir()

String Util::getDir ( String  dirname,
Array  files,
Array  subDirs 
)

Retrieving files and subdirectories of a specified directory.

This function retrieve the content (files, subdirectories) of a specified directory of the PortalServer's file system. It expected two empty Arrays, which the function fill with the filenames and subdirectory names. The names will not contain the full path, only the name itself. This function will not work recursively.

Parameters
dirnameString containing the name of the wanted directory
[out]filesEmpty array for the filenames
[out]subDirsEmpty array for the subdirectory names
Returns
empty String if successful, the error message in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var files = new Array();
var dirs = new Array();
util.getDir("c:\\Test", files, dirs);
var i=0;
for (i=0; i < files.length; i++)
util.out(files[i])
for (i=0; i < dirs.length; i++)
util.out(dirs[i])

◆ getEnvironment()

String Util::getEnvironment ( String  variableName)

Reads an environment variable of the PortalServer's system.

With this function an environment variable in the server's context can be read.

Parameters
variableNameString with the name of the variable
Returns
Environment value as String
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
util.out(util.getEnvironment("HOME"));

◆ getFileContentAsString()

String Util::getFileContentAsString ( String  filePath)

Get the content of a file at the PortalServer's system as string in base64 format.

Parameters
filePathString with the file path.
Returns
String containing the file content in base64 format.
Since
DOCUMENTS 4.0c

◆ getQuoted()

String Util::getQuoted ( String  input)

Returns the input string enclosed in either double or single quotation marks.

This function is designed to simplify the composition of filter expressions for a FileResultSet or an ArchiveFileResultSet. If the input string does not contain any double quotation mark ("), the function returns the input enclosed in double quotation marks. Otherwise the function tests if it can use single quotation marks (') instead. If both quotation styles are already used within the input, the function throws an exception.

Parameters
inputThe string to be enclosed
Returns
String with quotation marks around.
Since
DOCUMENTS 4.0b

◆ getSourceLineInfo()

String Util::getSourceLineInfo ( )

Retrieve the scriptName with the current line no of this methed.

This functions returns the scriptName and line no for debugging or logging purposes

Returns
String with the scriptName and line no
Since
DOCUMENTS 5.0a

◆ getTmpPath()

String Util::getTmpPath ( )

Get the path to the temporary directory on the Portalserver.

Returns
String containing the complete path to the temporary directory
Since
ELC 3.51 / otrisPORTAL 5.1
Example:
util.out(util.getTmpPath());

◆ getUniqueId()

String Util::getUniqueId ( )

Get a unique id from the system.

The length of the id is 40 characters and the id contains only the characters 'a-z','-','0-9'. This unique id can e.g. be used for file names etc.

Returns
String containing the unique id
Since
ELC 3.60 / otrisPORTAL 6.0
Example:
var uniqueId = util.getUniqueId();
util.out(uniqueId);

◆ getUsedPrivateBytes()

number Util::getUsedPrivateBytes ( )

Returns the current usage of private bytes memory of the documensserver process.

Returns
integer value with the used memory in KBytes
Since
DOCUMENTS 5.0b

◆ hash()

String Util::hash ( String  filePath,
String  hashfunction 
)

Generate the hash value for a file using the given hash function.

These hash functions are supported:

  • sha1
  • sha224
  • sha256
  • sha384
  • sha512
  • md4
  • md5
  • whirlpool
  • ripemd160
Parameters
filePathString containing the path of the file to be hashed.
hashfunctionString containing the name of the hash function.
Returns
String with the hash value of the file, an empty string in case of any error.
Since
DOCUMENTS 5.0e
Example:
try
{
var hashValue = util.hash("c:/tmp/dok1.pdf", "sha256");
util.out(hashValue);
}
catch (ex)
{
util.out(ex);
}
See also
Document.hash(String hashfunction, String version)

◆ hmac()

String Util::hmac ( String  hashfunction,
String  key,
String  message,
Boolean  rawOutput = false 
)

Generates a hash-based message authentication code (hmac) of a message string using a secret key.

These hash functions are supported:

  • "sha1"
  • "sha224"
  • "sha256"
  • "sha384"
  • "sha512"
  • "md4"
  • "md5"
Parameters
hashfunctionName of the hash function.
keySecret key.
messageMessage string to be hashed.
rawOutputOptional flag:
If set to true, the function outputs the raw binary representation of the hmac.
If set to false, the function outputs the hexadecimal representation of the hmac.
The default value is false.
Returns
String containing the hash-based message authentication code (hmac) of the message (see rawOutput for representation).
Since
DOCUMENTS 5.0a HF2
Example:
var key = "MySecretKey";
var msg = "Hello world!";
var hmac = util.hmac("sha1", key, msg);
util.out(hmac);

◆ isEncryptedBlob()

boolean Util::isEncryptedBlob ( String  blobFilePath)

Checks, if the current blob is encrypted (Repository encryption) or not.

Parameters
blobFilePathString containing the path of the file to be checked.
Returns
boolean value that indicates if the blob is encrypted.
Since
DOCUMENTS 4.0d HF3

◆ length_u()

number Util::length_u ( String  value)

Returns the number of characters of a UTF-8 string.

You can use this function in a x64 / UTF-8 server to count the characters in a UTF-8 string.

Parameters
valueUTF-8 String of which the number of characters will be counted
Returns
Integer with the length in characters
Since
DOCUMENTS 4.0a HF1
Note
for use in x64 / UTF-8 versions
Example:
var text = "Köln is a german city";
util.out(text.length); // => 22 bytes
util.out(util.length_u(text)); // => 21 characters

◆ log()

Util::log ( String  output)

Log a String to the DOCUMENTS server window.

Same as util.out() with additional debugging information (script name and line number) You may output whatever information you want. This function is useful especially for debugging purposes. Be aware that you should run the Portalserver as an application if you want to make use of the out() function, otherwise the output is stored in the Windows Eventlog instead.

Parameters
outputString you want to output to the Portalserver Window
Since
ELC 3.50e / otrisPORTAL 5.0e
Example:
util.log("Hello World");

◆ makeFullDir()

String Util::makeFullDir ( String  dirPath)

Creates a directory with subdirectories at the PortalServer's file system.

This functions provides a simple method for directory creation on the file system.

Parameters
dirPathString with the directory path
Returns
empty String if successful, the error message in case of any error
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
var errMsg = util.makeFullDir("c:\\log\\ELC");
if (errMsg.length > 0)
util.out(errMsg);
else
util.out("Ok.");

◆ makeGACLValue()

String Util::makeGACLValue ( var  val1,
var  val2,
  ... 
)

Makes a valid GACL value from the parameters.

This method helps to create valid GACL values when set by PortalScripting.

As separator for the single GACL values a \r\n (%CRLF%) will be used. The values will be trimed (leading and ending whitespaces) and multiple values will be removed.

The method returns a String value in the format \r\n AP1 \r\n AP2 \r\n .... \r\n APx \r\n

Parameters
val1String or Array
val2String or Array
...
Returns
String containing the GACL value.
Since
DOCUMENTS 5.0c HF2
Example:
var sep = context.getAutoText("%CRLF%"); // \r\n
var val1 = ["AP1", "AP2"];
var val2 = "AP3" + sep + "AP4";
var val3 = " AP5";
var val4 = "AP3";
var gaclVal = util.makeGACLValue(val1, val2, val3, val4);
util.out(gaclVal);
=>
AP1
AP2
AP3
AP4
AP5
<=

◆ makeHTML()

String Util::makeHTML ( String  val,
boolean  isUTF8 = false 
)

Masks all HTML-elements of a String.

This function masks the following characters for HTML output:

>&gt;
<&lt;
\n<br>
&&amp;
"&quot;

If the String is in UTF-8 Format, all UTF-8 characters will be replaced with the according HTML entities.

Parameters
valString to be masked
isUTF8boolean flag, if the val is in UTF-8 format
Returns
HTML-String
Since
ELC 3.60e / otrisPORTAL 6.0e

◆ out()

Util::out ( String  output)

Output a String to the Portalserver window.

You may output whatever information you want. This function is useful especially for debugging purposes. Be aware that you should run the Portalserver as an application if you want to make use of the out() function, otherwise the output is stored in the Windows Eventlog instead.

Parameters
outputString you want to output to the Portalserver Window
Since
ELC 3.50e / otrisPORTAL 5.0e
Example:
util.out("Hello World");

◆ prepareJSON()

String Util::prepareJSON ( )

Converts JSON-Strings with Source Code entities e.g.

\u00FA to UTF-8 Strings representation

Returns
String with UTF-8 representation
Since
DOCUMENTS 5.0e HF2

◆ searchInArray()

number Util::searchInArray ( Array  theArray,
String  searchedString,
number  occurence = 1 
)

Search for a String in an Array.

This functions provides a simple search method for Arrays to find the position of a string in an array.

Parameters
theArrayArray in that the String will be searched
searchedStringString that will be searched
occurenceInteger that define the wanted position at a multi-occurence of the String in the Array
Returns
Integer with the position of the String in the array, -1 in case of the String isn't found
Since
ELC 3.60e / otrisPORTAL 6.0e
Example:
enumval[0] = "This";
enumval[1] = "is";
enumval[2] = "a";
enumval[3] = "sample";
var pos = util.searchInArray(enumval, "is");
util.out(pos); // should be the value 1

◆ sha256()

String Util::sha256 ( String  message)

Generates the SHA256 hash of any string.

Parameters
messageMessage string to be hashed.
Returns
SHA256 hash of the message.
Since
DOCUMENTS 5.0a HF2

◆ sign()

string Util::sign ( string  algorithm,
string  privateKeyPEM,
string  pkPassword,
var  payload,
boolean  urlStyle = false 
)


Create a digital signature.

Parameters
algorithmstring Short identification of used algorithms, for example "RSASHA256". The first three characters specify an encryption standard. Actually only "RSA" is supported. The other characters select a hash algorithm, for example SHA1, SHA256.
privateKeyPEMstring with a (usually encrypted) private key in PEM format.
pkPasswordstring The password to decrypt the private key.
payloadany The text or data to sign. Allowed data types are "String", "Array of Bytes (Integer 0..255)" and "ArrayBuffer".
urlStyleboolean to request the result Base64URL-encoded
Returns
string Base64- or Base64URL-encoded String with signature data.
Note
Signing strings with characters, which are not in the 7-Bit ASCII-Charset, may require a transcoded string. This depends on how the string was created or received. See transcode().
The list of available hash algorithms depends on the linked OpenSSL libraries, not on DOCUMENTS itself.
About Arraybuffers
Passing a TypedArray (UInt8Array, Int16Array etc.) instead of an ArrayBuffer is possible, but not recommended. The actual implementation always sends the complete associated buffer. The result can be unexpected, if the TypedArray covers only a section of a bigger buffer. This behaviour might change in future releases.
Since
DOCUMENTS 5.0d HF2
Example:
// Load a private key in PEM-Format for digital signing.
// The file should look like this:
// -----BEGIN ENCRYPTED PRIVATE KEY-----
// <Base64-encoded binary data; usually 64 Characters per line>
// -----END ENCRYPTED PRIVATE KEY-----
//
// The openssl command-line tool, for instance, can be used in the
// following way to generate a private key-file for RSA enccryption.
// > openssl.exe genpkey -out testPK.pem -outform PEM -pass pass:myKeyPassword -des3 -algorithm RSA -pkeyopt rsa_keygen_bits:2048
// The next command extracts the public parts of the key and stores
// them in a separate PEM-file. A signature validator will require it.
// > openssl pkey -in testPK.pem -passin pass:myKeyPassword -out testPub.pem -pubout
function loadMyPrivateKey()
{
var f = new File("E:\\testPK.pem");
var text;
if(f.ok())
{
var text = f.read(10000);
f.close();
return text;
}
throw new Error("Keyfile not found");
}
function signMyData() {
var results = {};
var privateKey = loadMyPrivateKey();
var pkPassword = "myKeyPassword";
// 1) Sign a string.
var data = "This message needs to be signed.";
results.data1 = data;
results.signature1 = util.sign("RSASHA256", privateKey, pkPassword, data);
// 2) Sign a sequence of bytes, passed as a conventional array.
// Use the simpler SHA1 hash this time.
data = [65, 70, 70, 69, 0];
results.data2 = data;
results.signature2 = util.sign("RSASHA1", privateKey, pkPassword, data);
// 3) Sign a sequence of bytes, passes as an ArrayBuffer
data = new Uint8Array(4);
data[0] = 192;
data[1] = 168;
data[2] = 6;
data[3] = 101;
results.data3 = data;
results.signature3 = results.signature1 = util.sign("RSASHA256", privateKey, pkPassword, data.buffer);
return JSON.stringify(results);
}
return signMyData();

◆ sleep()

void Util::sleep ( number  duration)

Let the PortalScript sleep for a defined duration.

Parameters
durationInteger containing the duration in milliseconds
Since
DOCUMENTS 5.0a

◆ substr_u()

String Util::substr_u ( String  value,
int  startIndex,
int  length 
)

Returns a substring of a UTF-8 string.

You can use this function in a x64 / UTF-8 server to get a substring of a UTF-8 string.

Parameters
valueUTF-8 String of which the substring is wanted
startIndexint with the 0-based start index of the substring
lengthint with the length in characters of the substring
Returns
UTF-8 String with the wanted substring
Since
DOCUMENTS 4.0a HF1
Note
for use in x64 / UTF-8 versions
Example:
var text = "Köln is a german city";
util.out(util.substr_u(text, 0, 4)); // => Köln
util.out(util.substr_u(text, 5)); // => is a german city
// but
util.out(text.substr(0, 4)); // => Köl

◆ transcode()

String Util::transcode ( String  nameSourceEncoding,
String  text,
String  nameTargetEncoding 
)

Transcode a String from encoding a to encoding b.

This method performs an transcoding for a String from a source encoding to a target encoding.

The following encodings are supported:

  • Local: The standard system encoding for Windows systems is Windows-1252 and for Linux systems ISO-8859-1 or UTF-8.
  • UTF-8: Unicode-characterset as ASCII-compatible 8-Bit-coding.
  • ISO-8859-1: West-European characterset without Euro-Symbol.
  • ISO-8859-15: West-European characterset with Euro-Symbol.
  • Windows-1252
  • Windows-1250
Parameters
nameSourceEncodingString containing the name of the source encoding
textString containing the text to transcode
nameTargetEncodingString containing the name of the target encoding
Returns
String containing the transcoded text
Since
ELC 3.60d / otrisPORTAL 6.0d
Example:
var text = "Köln is a german city"
var utf8Text = util.transcode("windows-1252", text, "UTF-8");
util.out(utf8Text);
text = util.transcode("UTF-8", utf8Text, "windows-1252");
util.out(text);

◆ unlinkFile()

boolean Util::unlinkFile ( String  filePath)

Delete a physical file on the server's file system.

Parameters
filePathString containing the full path and filename to the desired physical file
Returns
true if successful, false in case of any error
Since
ELC 3.51 / otrisPORTAL 5.1
Example:
var success = util.unlinkFile("c:\\tmp\\tempfile.txt");

Member Data Documentation

◆ buildNo

number Util::buildNo

Build version number of the PortalServer.

This property allows to retrieve the build version number of the PortalServer to customize your PortalScripts in dependence of the used PortalServer.

Returns
Integer with the build version number
Note
This property is readonly.
Since
ELC 3.50 / otrisPORTAL 5.0
Example:
if (util.buildNo > 1826)
{
// do update
}

◆ DB

String Util::DB

Database using by the PortalServer.

The following databases are supported by the PortalServer:

  • oracle
  • mysql
  • mssql
Returns
String with the used database
Note
This property is readonly.
Since
DOCUMENTS 4.0

◆ memoryModel

String Util::memoryModel

Memory model of the PortalServer.

There are two possible memory models available : x64 or x86.

Returns
String with the memory model
Note
This property is readonly.
Since
DOCUMENTS 4.0

◆ version

number Util::version

Main version number of the PortalServer.

This property allows to retrieve the version number of the PortalServer to customize your PortalScripts in dependence of the used PortalServer. For example:

  • otrisPORTAL 5.1 / ELC 3.51 returns 5100
  • otrisPORTAL 6.0 / ELC 3.60 returns 6000
  • DOCUMENTS 4.0 returns 7000
Returns
Integer with the main version number
Note
This property is readonly.
Since
ELC 3.50 / otrisPORTAL 5.0
Example:
if (util.version < 6000)
{
// do update
}

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