/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { Object } from "../../types/java/lang/Object"; import type { String } from "../../types/java/lang/String"; import type { List } from "../../types/java/util/List"; import type { Locale } from "../../types/java/util/Locale"; import type { Date } from "../../types/java/util/Date"; import type { Calendar } from "../../types/java/util/Calendar"; import type { Collection } from "../../types/java/util/Collection"; /** * Scripting utility interface that might be needed when using a limited scripting or template language (such as Velocity). * *
* An instance of the Sitevision class implementing this interface can be obtained via {@link senselogic.sitevision.api.Utils#getScriptUtil()}.
* See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface.
*
true
*/
getTrue(): boolean;
/**
* Gets the boolean false primitive.
* @return false
*/
getFalse(): boolean;
/**
* Gets the null reference.
* @return null
*/
getNull(): unknown;
/**
* Gets an object that is ensured not to be null.
*
* * This is a convenience method that can be used to avoid unnecessary subsequent method invocations in Velocity. *
* *
* Velocity ignores null assignments and trying to assign a null reference will be logged as a WARNING message.
* A common strategy to work around this is to use the the Velocity #if clause. It allows for easy non-null
* checks - a null object is considered to be false. The downside with this strategy is that it
* requires two subsequent method invocations. That can of course be a really bad thing if the method does costly things. This method
* can be used to avoid such problems.
*
* An example
* This Velocity code:
*
#if ($anObject.getPersonOrNull())
* #set ($person = $anObject.getPersonOrNull())
* $person.getName()
* ...
* #end
* Can be better utilized as:
* #set ($scriptUtil = ...)
*
* #set ($person = $scriptUtil.getNonNull(${anObject.getPersonOrNull()}))
* #if ($person)
* $person.getName()
* ...
* #end
*
* @param anObject the object that might be null
* @return anObject if non-null, Boolean.FALSE otherwise
* @see #getNonNull(Object, Object)
* @see #getNonBlank(String)
* @since Sitevision 2.6.2
*/
getNonNull(anObject: unknown): unknown;
/**
* Gets an object that is ensured not to be null or a whitespace only string.
*
* * This is a convenience method that can be used to avoid unnecessary subsequent method invocations in Velocity. *
* *
* Velocity ignores null assignments and trying to assign a null reference will be logged as a WARNING message.
* A common strategy to work around this is to use the the Velocity #if clause. It allows for easy non-null
* checks - a null object is considered to be false. The downside with this strategy is that it
* requires two subsequent method invocations. That can of course be a really bad thing if the method does costly things. This method
* can be used to avoid such problems.
*
* An example
* This Velocity code:
*
#if ($anObject.getPersonNameThatCanBeNullOrEmptyOrWhitespaceOnly())
* #set ($name = $anObject.getPersonNameThatCanBeNullOrEmptyOrWhitespaceOnly())
* #if ($name.trim().length() > 0)
* <p>
* $name
* </p>
* #end
* #end
* Can be better utilized as:
* #set ($scriptUtil = ...)
*
* #set ($name = $scriptUtil.getNonBlank(${anObject.getPersonNameThatCanBeNullOrEmptyOrWhitespaceOnly()}))
* #if ($name)
* <p>
* $name
* </p>
* #end
*
*
*
* A typical example when using {@link senselogic.sitevision.api.property.PropertyUtil} and whitespace is an issue
* This Velocity code:
*
#if ($propertyUtil.getString($theNode, 'thePropertyName'))
* #set ($propertyValue = $propertyUtil.getString($theNode, 'thePropertyName'))
* #if ($propertyValue.trim().length() > 0)
* <p>
* $propertyValue
* </p>
* #end
* #end
* Can be better utilized as:
* #set ($scriptUtil = ...)
*
* #set ($propertyValue = $scriptUtil.getNonBlank(${propertyUtil.getString($theNode, 'thePropertyName')}))
* #if ($propertyValue)
* <p>
* $propertyValue
* </p>
* #end
*
* @param aString the string that might be null or whitespace only
* @return aString if aString is non-null and not whitespace only, Boolean.FALSE otherwise
* @see #getNonBlank(String, Object)
* @since Sitevision 3.6
*/
getNonBlank(aString: String | string): unknown;
/**
* Gets a default value if an object is null.
* @param anObject the object that might be null
* @param aDefaultValue the default value to return if anObject is null
* @return anObject if non-null, aDefaultValue otherwise
* @see #getNonNull(Object)
* @since Sitevision 2.6.2
*/
getNonNull(anObject: unknown, aDefaultValue: unknown): unknown;
/**
* Gets a default value if a string is null or whitespace only.
* @param aString the string that might be null or whitespace only
* @param aDefaultValue the default value to return if aString is null or whitespace only
* @return aString if aString is non-null and not whitespace only, aDefaultValue otherwise
* @see #getNonBlank(String)
* @since Sitevision 3.6
*/
getNonBlank(aString: String | string, aDefaultValue: unknown): unknown;
/**
* Checks if a string is not null and not empty.
* @param aString the string to check
* @return true if aString is not null and not empty, false otherwise
* @see #isNotBlank(String)
* @since Sitevision 2.6
*/
isNotEmpty(aString: String | string): boolean;
/**
* Checks if a string is null or empty.
* @param aString the string to check
* @return true if aString is null or empty, false otherwise
* @see #isBlank(String)
* @since Sitevision 3.6.2
*/
isEmpty(aString: String | string): boolean;
/**
* Checks if a string is not null, not empty and not whitespace only.
* @param aString the string to check
* @return true if aString is not null, not empty and not whitespace only - false otherwise
* @see #isNotEmpty(String)
* @since Sitevision 2.6
*/
isNotBlank(aString: String | string): boolean;
/**
* Checks if a string is null, empty or whitespace only.
* @param aString the string to check
* @return true if aString is null, empty or whitespace only - false otherwise
* @see #isEmpty(String)
* @since Sitevision 3.6.2
*/
isBlank(aString: String | string): boolean;
/**
* Gets a system property. This method invokes the getProperty method of the java.lang.System class, i.e System.getProperty(String).
*
*
* Important note!
* This method can be used to reveal potential sensitive information about the server.
*
* Allowed properties: *
*
* A legacy mode that enables the API to return all properties can be enabled using the following system property:
* sitevision.api.scriptutil.legacy_system_properties=true
*
* A tip if you need to do backward compatibility workarounds: The Sitevision version is accessible as a system property * named sitevision.version. *
* @param aName the name of the system property * @return the value of the system property, ornull if indeterminable (e.g. no accessible property named aName exist)
* @since Sitevision 2.6_02
* @deprecated Exposes server information and will therefore be removed in future releases of Sitevision
*/
getSystemProperty(aName: String | string): string;
/**
* Creates and returns an instance of a Java class.
* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages)
* @return an instance of the class, or null if an instance can not be created
* @deprecated Use {@link senselogic.sitevision.api.script.factory.InstanceCreatorUtil#getDefaultInstance(String)} instead
*/
getInstance(aQualifiedClassName: String | string): unknown;
/**
* Methods that wraps an array in a List. Arrays are sub optimal in Velocity and JavaScript.
* @param anArray an array that needs to be wrapped
* @return a list containing the array elements. If the array is null, null is returned
* @since Sitevision 2.6_06
*/
getList(anArray: unknown[]): List;
/**
* Gets the date format pattern used in the Sitevision editor for a specific Locale.
* @param aLocale the Locale that specifies the date format pattern
* @return the date format pattern used in the Sitevision editor that corresponds to aLocale.
If aLocale is null then the current locale (as of
{@link senselogic.sitevision.api.context.PortletContextUtil#getCurrentLocale()})
is used to locate the format pattern. If no pattern exist for aLocale then the pattern that corresponds to
Locale.ENGLISH will be returned.
* @since Sitevision 2.6.1_02
* @deprecated use {@link senselogic.sitevision.api.date.DateUtil#getEditorFormatPattern(java.util.Locale)} instead
*/
getFormatPattern(aLocale: Locale): string;
/**
* Methods that formats a date according to a SimpleDateFormat pattern
* @param aFormatPattern date to string pattern according to SimpleDateFormat. If null
is specified the default format is used
* @param aDate the Date
* @return returns a String representation of aDate according to aFormatPattern.
Returns null if aDate is null.
* @since Sitevision 2.6_06
* @deprecated use {@link senselogic.sitevision.api.date.DateUtil#getDateAsString(String, java.util.Date)} instead
*/
getDateAsString(aFormatPattern: String | string, aDate: Date): string;
/**
* Methods that formats the date of a calendar according to a SimpleDateFormat pattern
* @param aFormatPattern date to string pattern according to SimpleDateFormat. If null
is specified the default format is used
* @param aCalendar the Calendar
* @return returns a String representation of the date of aCalendar according to aFormatPattern.
Returns null if aDate is null.
* @since Sitevision 2.6.1_02
* @deprecated use {@link senselogic.sitevision.api.date.DateUtil#getCalendarAsString(String, java.util.Calendar)} instead
*/
getCalendarAsString(
aFormatPattern: String | string,
aCalendar: Calendar
): string;
/**
* Methods that returns a human presentable size with an appropriate byte-suffix (bytes/kB/MB/GB/TB).
*
* Note! This method uses two significant digits and 1024 as base. Some examples:
* 126 -> "130 bytes"
* 126975 -> "120 kB"
* 456456456 -> "440 MB"
*
aSize is less than 0 or larger than
1125899906842624 (1024 TB), an empty String will be returned.
* @since Sitevision 2.6.1_04
*/
getHumanPresentableSize(aSize: number): string;
/**
* Method that converts a string to an int.
* @param aString the string to be converted
* @return aString as int. If aString is null or can't be converted, -1 is returned
* @since Sitevision 2.6.1_04
*/
stringToInt(aString: String | string): number;
/**
* Method that converts a string to a long.
* @param aString the string to be converted
* @return aString as long. If aString is null or can't be converted, -1 is returned
* @since Sitevision 2.6.1_04
*/
stringToLong(aString: String | string): number;
/**
* Method that converts a string to a double.
* @param aString the string to be converted
* @return aString as double. If aString is null or can't be converted, -1.0 is returned
* @since Sitevision 2.6.1_04
*/
stringToDouble(aString: String | string): number;
/**
* Method that converts a string to a float.
* @param aString the string to be converted
* @return aString as float. If aString is null or can't be converted, -1.0 is returned
* @since Sitevision 2.6.1_04
*/
stringToFloat(aString: String | string): number;
/**
* Method that returns true for values that can be interpreted as the true value.
* @param anObject an Object that might be interpreted as a true value
* @return returns true if anObject is a Boolean with a true value
or a String with a "true" value, false otherwise.
* @since Sitevision 2.6.1_04
*/
isTrue(anObject: unknown): boolean;
/**
* Method that returns true for values that can be interpreted as the false value.
* @param anObject an Object that might be interpreted as a false value
* @return returns true if anObject is a Boolean with a false value
or a String with a "false" value, false otherwise.
* @since Sitevision 2.6.1_04
*/
isFalse(anObject: unknown): boolean;
/**
* Joins the elements of an array to a single String.
*
* Some examples:
*
* joinArray(["one", "two", "three"], ";") -> "one;two;three"
* joinArray(["a", myTwoInteger], "-") -> "a-2"
* joinArray(["", null, "three"], "-") -> "--three"
* joinArray([], "-") -> ""
* joinArray(null, "-") -> null
*
* @param anArray the array that should be joined to a single string. null elements will be treated as empty
("") and for non-String elements toString()
will be invoked on the element to get a string representation.
* @param aSeparator the separator that should delimit the elements of anArray in the resulting joined string.
null will be treated as empty ("")
* @return the joined String. If anArray is null, null will be returned
* @see #joinCollection(java.util.Collection, String)
* @since Sitevision 2.6.1_04
*/
joinArray(anArray: unknown[], aSeparator: String | string): string;
/**
* Joins the items of a Collection to a single String.
*
* * For examples, see {@link #joinArray(Object[], String)} *
* @param aCollection the collection that should be joined to a single string.null items will be treated as empty
("") and for non-String items toString()
will be invoked on the item to get a string representation.
* @param aSeparator the separator that should delimit the items of aCollection in the resulting joined string.
null will be treated as empty ("")
* @return the joined String. If aCollection is null, null will be returned
* @see #joinArray(Object[], String)
* @since Sitevision 2.6.1_04
*/
joinCollection(
aCollection: Collection | unknown[],
aSeparator: String | string
): string;
/**
* A utility method to get a formatted string based on a pattern and some pattern arguments.
*
* * A Velocity example: *
*
* #set ($instanceCreatorUtil = ...)
* #set ($scriptUtil = ...)
* #set ($searchPhrase = ...)
*
* ## Determine pattern
* #if ($language == 'sv')
* #set ($pattern = 'Din sökning {0} gav inga träffar')
* #else
* #set ($pattern = 'No hits for your search {0}')
* #end
*
* ## Set up pattern argument(s)
* #set ($argsList = $instanceCreatorUtil.list)
* $scriptUtil.swallow(${argsList.add($searchPhrase)})
*
* ## Format and print result
* <p>$scriptUtil.messageFormat($pattern, $argsList)</p>
*
* @param aMessageFormatPattern a pattern accepted by the Java
MessageFormat class
* @param anArguments arguments needed by the pattern
* @return the result of the pattern evaluation or null if evaluation fails. Returns null if
aMessageFormatPattern is null or if anArguments doesn't contain any arguments.
* @since Sitevision 3.0
*/
messageFormat(
aMessageFormatPattern: String | string,
anArguments: List | unknown[]
): string;
/**
* A utility method that can be used to prevent method invocation return values to be added to the Velocity output.
*
*
* An example:
This Velocity code:
*
* #set ($myList = $instanceCreatorUtil.list)
* $myList.add("Magnus Lövgren")
* $myList.add("Mikael Wikblom")
*
* will result in the following Velocity output (the add method of ArrayList returns a boolean):
* true true
*
* If a non-void method is invoked and the return value isn't handled, it will be part of the Velocity output.
* The swallow method can be used to prevent that (i.e. use it to "swallow" the result):
*
* #set ($myList = $instanceCreatorUtil.list)
* $scriptUtil.swallow(${myList.add("Magnus Lövgren")})
* $scriptUtil.swallow(${myList.add("Mikael Wikblom")})
* * Note! The code above is just an example that illustrates a common problem. When creating and working with a * List from Velocity, you should probably use a {@link senselogic.sitevision.api.script.factory.ListWrapper} instead *
* @param anObject the object that should be "swallowed" * @since Sitevision 3.0 */ swallow(anObject: unknown): void; /** * Removes leading and ending control characters (char <= 32) from a String and returns the result (null
* if the string is empty or null).
*
*
* The String is trimmed using String.trim()
*
null if aString is null or the trimmed String is empty.
* @since Sitevision 2.6.1_04
*/
trimToNull(aString: String | string): string;
/**
* Removes leading and ending control characters (char <= 32) from a String and returns the result (empty String ("")
* if the string is empty or null).
*
*
* The String is trimmed using String.trim()
*
"") if aString is null or the trimmed String is empty.
* @since Sitevision 2.6.1_04
*/
trimToEmpty(aString: String | string): string;
/**
* Flattens a multi-lined string to a trimmed single-line string.
*
* * This method replaces all whitespace (space, line break and such) with a space, but will never add multiple spaces. *
* @param aString the multi-lined string * @return a single-line trimmed string with sequential whitespace removed, ornull if aString is null.
* @since Sitevision 3.6
*/
flatten(aString: String | string): string;
}
declare namespace ScriptUtil {}
declare var scriptUtil: ScriptUtil;
export default scriptUtil;