DOCUMENTS 5 - PortalScripting API
|
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... | |
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
.
Util
. There are no properties in this class, it supports only the help functions as documented below. var Util::base64Decode | ( | String | value, |
boolean | returnArray = true |
||
) |
Decodes a base64 string and returns a string or byte-array.
value | String to decode |
returnArray | boolean as an optional parameter to define if the return value must be a byte-array or string (default) |
String Util::base64Encode | ( | var | value, |
boolean | urlStyle = false |
||
) |
Encodes a byte-array or string to base64 and returns the base 64 string.
value | String or byte-array to encode |
urlStyle | optional boolean flag to request Base64URL encoding instead of standard Base64 encoding |
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
frequency | int with the frequency in hertz |
duration | int with the length of the sound in milliseconds (ms) |
String Util::concatPDF | ( | Array | pdfFilePaths, |
boolean | deleteSinglePdfs = false |
||
) |
Concatenate the given PDFs together into one PDF.
pdfFilePaths | Array containing the file paths of PDFs to be concatenated. |
deleteSinglePdfs | Optional boolean value to decide whether to delete the single PDFs on the server's filesystem after concatenating. |
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.
sourceFilePath | String containing the path of the file to be converted. |
String
with file path of the PDF, an empty string in case of any error. 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.
A date before 01.03.1900 can not be converted. The method will return -1.0.
timeStamp | Date object representing the desired date |
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.
timeStamp | Date object representing the desired date |
format | String defining the date format of the output String, e.g. "dd.mm.yyyy". The possible format parts are:
|
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.
dateOrTimeStamp | String representing a date, e.g. "19.09.1974" |
format | String defining the date format of the input String, e.g. "dd.mm.yyyy". The possible format parts are:
|
String Util::cryptPassword | ( | String | pwPlain | ) |
Encrypt a plain password into an MD5 hash.
pwPlain | String containing the plain password |
String Util::decodeUrlCompatible | ( | String | encodedParam | ) |
Decode URL parameter from DOCUMENTS Urls.
encodedParam | String containing the encoded URL param |
String
with decoded URL param. String Util::decryptString | ( | String | input | ) |
Decrypts a String value hat was encrypted with the method Util.encryptString(String input)
input | The string that will be decrypted |
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.
filePath | String with the file path |
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.
param | String containing the value to encode |
String
with encoded value. 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.
input | The string that will be encrypted |
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.
sourceFilePath | String with the source file path |
targetFilePath | String with the target file path |
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.
sourceFilePath | String with the source file path |
targetFilePath | String with the target file path |
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.
filePath | String with the file path |
String Util::generateChecksum | ( | String | input | ) |
Creates a MD5 checksum for the String value
input | The string for that the checksum will be generated |
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.
dirname | String containing the name of the wanted directory | |
[out] | files | Empty array for the filenames |
[out] | subDirs | Empty array for the subdirectory names |
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.
variableName | String with the name of the variable |
String Util::getFileContentAsString | ( | String | filePath | ) |
Get the content of a file at the PortalServer's system as string in base64 format.
filePath | String with the file path. |
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.
input | The string to be enclosed |
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
String Util::getTmpPath | ( | ) |
Get the path to the temporary directory on the Portalserver.
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.
number Util::getUsedPrivateBytes | ( | ) |
Returns the current usage of private bytes memory of the documensserver process.
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
filePath | String containing the path of the file to be hashed. |
hashfunction | String containing the name of the hash function. |
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"
hashfunction | Name of the hash function. |
key | Secret key. |
message | Message string to be hashed. |
rawOutput | Optional 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 . |
boolean Util::isEncryptedBlob | ( | String | blobFilePath | ) |
Checks, if the current blob is encrypted (Repository encryption) or not.
blobFilePath | String containing the path of the file to be checked. |
boolean
value that indicates if the blob is encrypted. 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.
value | UTF-8 String of which the number of characters will be counted |
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.
output | String you want to output to the Portalserver Window |
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.
dirPath | String with the directory path |
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
val1 | String or Array |
val2 | String or Array |
... |
String Util::makeHTML | ( | String | val, |
boolean | isUTF8 = false |
||
) |
Masks all HTML-elements of a String.
This function masks the following characters for HTML output:
> | > |
< | < |
\n | <br> |
& | & |
" | " |
If the String is in UTF-8 Format, all UTF-8 characters will be replaced with the according HTML entities.
val | String to be masked |
isUTF8 | boolean flag, if the val is in UTF-8 format |
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.
output | String you want to output to the Portalserver Window |
String Util::prepareJSON | ( | ) |
Converts JSON-Strings with Source Code entities e.g.
\u00FA to UTF-8 Strings representation
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.
theArray | Array in that the String will be searched |
searchedString | String that will be searched |
occurence | Integer that define the wanted position at a multi-occurence of the String in the Array |
String Util::sha256 | ( | String | message | ) |
Generates the SHA256 hash of any string.
message | Message string to be hashed. |
string Util::sign | ( | string | algorithm, |
string | privateKeyPEM, | ||
string | pkPassword, | ||
var | payload, | ||
boolean | urlStyle = false |
||
) |
Create a digital signature.
algorithm | string 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. |
privateKeyPEM | string with a (usually encrypted) private key in PEM format. |
pkPassword | string The password to decrypt the private key. |
payload | any The text or data to sign. Allowed data types are "String", "Array of Bytes (Integer 0..255)" and "ArrayBuffer". |
urlStyle | boolean to request the result Base64URL-encoded |
void Util::sleep | ( | number | duration | ) |
Let the PortalScript sleep for a defined duration.
duration | Integer containing the duration in milliseconds |
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.
value | UTF-8 String of which the substring is wanted |
startIndex | int with the 0-based start index of the substring |
length | int with the length in characters of the substring |
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
nameSourceEncoding | String containing the name of the source encoding |
text | String containing the text to transcode |
nameTargetEncoding | String containing the name of the target encoding |
boolean Util::unlinkFile | ( | String | filePath | ) |
Delete a physical file on the server's file system.
filePath | String containing the full path and filename to the desired physical file |
true
if successful, false
in case of any error 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.
String Util::DB |
Database using by the PortalServer.
The following databases are supported by the PortalServer:
oracle
mysql
mssql
String Util::memoryModel |
Memory model of the PortalServer.
There are two possible memory models available : x64 or x86.
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: