OScript API/Built-in Package Index |
The built-in functions in the Web package offers a set of Web-related format translation and file services. The major functionalities offered in the Web Package are the following:
A String consisting of carriage return (ASCII 13) and line feed (ASCII 10).
An integer that is used for selecting the JavaScript encodeURI() function.
An integer that is used for selecting the JavaScript encodeURIComponent() function.
An integer that is used for selecting the JavaScript escape() function.
Tracks the number of bytes written in the response to the browser.
Decodes a string which was encoded using CookieEncode.
Encodes a cookie for security purposes.
Returns an unescaped decoding of the specified new URL-encoded String.
Returns a new URL-encoded conversion of the specified String by converting non-ASCII characters to UTF-8 then escaping non-alphanumeric characters.
Returns a URL-encoded conversion of the specified String by escaping non-alphanumeric characters.
Returns a new encoded conversion of the specified String by converting some non-ASCII characters, depending on the mode selected, to UTF-8 then escaping non-alphanumeric characters.
Converts a specified string to HTML format by escaping special characters.
Returns a copy of the given string that has been escaped for JSON.
Converts a specified string to XML compatible format by escaping special characters.
Converts a specified string to XML compatible format by escaping special and control characters.
Writes the specified file to the output context.
Formats a list of values based on a specified formatting string.
Deserializes a value from a given JSON string.
Serializes the given value to a JSON string.
Returns an unescaped decoding of the specified URL-encoded String.
Returns a copy of the given JSON string that has been unescaped.
Writes the specified value to the output context.
Writes a valid HTTP status line and headers to the output context.
A String consisting of carriage return (ASCII 13) and line feed (ASCII 10). It is generally used with HTTP headers.
An integer (2) that is used for selecting the JavaScript encodeURI() function.
An integer (3) that is used for selecting the JavaScript encodeURIComponent() function.
An integer (1) that is used for selecting the JavaScript escape() function.
This function is used internally to track the size of the response written to the browser. An internal byte counter accumulates the number of bytes written by the Web.Write() function. This function returns the current value of the byte counter and reset the value of the byte counter with the optional parameter bytecount.
Optional parameter to set the byte counter to a new value
Return the current byte count.
Integer responseSize // reset the byte counter to 0 Web.BytesWritten( 0 ) ... // process the request Web.Write( "This is the first response string" ) Web.Write( "This is the second response string" ) ... // retrieve the size of the response responseSize = Web.BytesWritten() //responseSize should be 68
Decodes a string which was encoded using CookieEncode. The ipAddress and salt arguments must contain the same values as were passed to CookieEncode.
The cookie string to be decoded.
The IP address of the workstation from which this cookie was received.
An optional unique integer; must be the same as was passed to CookieEncode.
The decoded cookie string.
Encodes a cookie for security purposes.
The cookie string to be encoded.
The IP address of the workstation to which this cookie will be sent.
An optional unique integer which is factored into the encoding algorithm.
The encoded cookie string.
Decodes a previously encoded string. The plus-sign character ("+") will be converted to a space and hexadecimal non-alphanumeric characters (represented by "%xx", where xx is hexadecimal notation) will be converted to their ASCII equivalent. In addition if the server is not using UTF-8, the UTF-8 encoded characters will be converted.
The String to be unescaped.
The converted string.
Here is an example:
echo( Web.Unescape ( "http%3A%2F%2Fjoe%2Efred%2Ecom" ) )
The output of the example is:
http://joe.fred.com
Converts a specified String to new URL format. First represent each non-ASCII character in UTF-8 then by escaping non-alphanumeric characters into URL hexadecimal sequences and spaces in to the plus-sign ("+") character.
The string to convert.
The converted string.
When passing arguments to a CGI script, this function can be used to make the arguments URL compatible by escaping non-alphanumeric characters to a format recognizable by a CGI script. This is equivalent to the Javascript EncodeURIComponent and to the Java URLDecoder.encode(). Here is an example:
String text = "A ü URL_example" String site = "http://www.bogus.com/somefile" String query = "/search/query?site=%1&text=%2" Echo( "Escaped String: ", Web.EncodeForURL( text ) ) Echo( "Encoded URL: ", Str.Format( query, Web.EncodeForURL( site ), web.EncodeForURL( text ) ) )
The output is:
Escaped String: A+%C3%BC+URL_example Escaped URL: /search/query?site=http%3A%2F%2Fwww%2Ebogus%2Ecom%2Fsomefile&text=A+%C3%BC+URL_example
Converts a specified String to URL format by escaping non-alphanumeric characters into URL hexadecimal sequences and spaces in to the plus-sign ("+") character.
The string to convert.
The converted string.
When passing arguments to a CGI script, this function can be used to make the arguments URL compatible by escaping non-alphanumeric characters to a format recognizable by a CGI script. Here is an example:
String text = "A URL_example" String site = "http://www.bogus.com/somefile" String query = "/search/query?site=%1&text=%2" Echo( "Escaped String: ", Web.Escape( text ) ) Echo( "Escaped URL: ", Str.Format( query, Web.Escape( site ), web.Escape( text ) ) )
The output is:
Escaped String: A+URL%5Fexample Escaped URL: /search/query?site=http%3A%2F%2Fwww%2Ebogus%2Ecom%2Fsomefile&text=A+URL%5Fexample
Converts a specified string to the format that is compatible with one of the JavaScript escape methods: escape(), escapeURI, and escapeURIComponent.
The string to be escaped.
The mode for selecting which JavaScript escape fuction to encode the string specified. * mode = WEB.JS_ESCAPE for JavaScript's escape(), which does not encode: @/+ * mode = WEB.JS_ENCODEURI for JavaScript's encodeURI(), which does not encode: ~!@#$&()=:/,;?+' * mode = WEB.JS_ENCODEURICOMPONENT JavaScript's encodeURIComponent(), which does not encode: ~!*()'.
The converted string.
Here are some examples:
Echo( Web.EscapeForJS('"joe+B,smith"@example.com', WEB.JS_ESCAPE) ) Echo( Web.EscapeForJS('"joe+B,smith"@example.com', WEB.JS_ENCODEURI) ) Echo( Web.EscapeForJS('"joe+B,smith"@example.com', WEB.JS_ENCODEURICOMPONENT ) )
The outputs are:
%22joe+B%2Csmith%22@example%2Ecom %22joe+B,smith%22@example%2Ecom %22joe%2BB%2Csmith%22%40example%2Ecom
Converts a specified string to HTML format by escaping special characters, such as greater-than, less-than, and ampersand.
The string to be escaped.
The converted string.
Here is an example:
Echo( Web.EscapeHTML("<Hello>") )
The output is:
<Hello>
Converts a specified String to JSON format.
The string to convert.
TRUE if leading and trailing whitespace should be removed; FALSE otherwise. The default is TRUE.
The converted string.
Converts a specified string to XML compatible format by escaping special characters, such as greater-than, less-than, ampersand and apostrophe.
The difference between EscapeHTML and EscapeXML is a single quotation ' (or apostrophe) is escaped as '
The string to be escaped.
The converted string.
Here is an example:
Echo( Web.EscapeXML("<JOE>"This '&' That"</JOE>") )
The output is:
<JOE>"This '&' That"</JOE>
Converts a specified string to XML compatible format by escaping special and control characters, such as greater-than, less-than, ampersand and apostrophe. illegal control chars and del (0x7f) are replaced by substitute char 0xfffd
The string to be escaped.
The converted string.
Here is an example: ^z means ctl-z hex 1A
Echo( Web.EscapeXMLNoCC("<&^z"))
The output is:
<&�
Writes the specified file to the output context. The output context may either be a socket, which will then send the file to the Web browser, or a file.
The output context.
The server file path of the file to be sent to the output context.
An optional data string specifying the MIME type of the data in filePath. If this parameter is specified, the HTTP headers are also sent as part of the file.
TRUE if successful; FALSE if not.
Here is a short example:
File fin = File.Open( "in.txt", File.WriteMode ) File fout = File.Open( "out.txt", File.WriteMode ) File.Write( fin, "Some string of text data." ) File.Close( fin ) Web.File( fout, "in.txt", "text/plain" ) File.Close( fout )
The output for the example in file "out.txt" is the following (where each end-of-line before the file data, "Some string..." is actually a Web.CRLF):
HTTP/1.0 200 Content-Type: text/plain Some string of text data.
Web-formats a list of values based on a specified formatting string. This is useful for generating HTML, since Format() applies either HTML-escaping, URL-escaping, or no escaping (literal) to the substitution strings upon substitution. Formatting is marked in the format string by the backtick (`), instead of the percent symbol (%) as usual, since the percent symbol is used to escape URLs.
The text and placeholders. Format strings are:
Value | Description |
` | A backtick (`), consumes no substitution String. |
`L | Literal (String is not escaped). |
`H | HTML (calls [[EscapeHTML()]] on the String) |
'U | URL (calls [[Escape()]] on the String) |
A list of Strings to substitute into the format.
The formatted String.
A maximum of 20 format specifications can be made. Here is a short example:
Echo( Web.Format( "` `L `H `U", {"<Joe1>", "<Joe2>", "<Joe3>"} ) ) )
The output is:
` <Joe1> <Joe2> %3CJoe3%3E
Deserializes an object from the specified string in JSON format.
The string to deserialize from JSON.
The deserialized object.
Serializes the specified object to JSON format.
The object to serialize to JSON.
TRUE if leading and trailing whitespace should be removed from String values; FALSE otherwise. The default is TRUE.
The JSON representation of the object.
Unescapes a previously escaped string. The plus-sign character ("+") will be converted to a space and hexadecimal non-alphanumeric characters (represented by "%xx", where xx is hexadecimal notation) will be converted to their ASCII equivalent.
The String to be unescaped.
The converted string.
Here is an example:
echo( Web.Unescape ( "http%3A%2F%2Fjoe%2Efred%2Ecom" ) )
The output of the example is:
http://joe.fred.com
Converts a specified String from JSON format.
The string to convert.
The converted string.
Writes the specified value to the output context. The output context may either be a socket, as connected to a Web browser, or a file.
The output context.
The value to write. The value must be type Bytes or String.
An optional format. If this parameter is specified, the second and third parameters are passed to the Web.Format function and the resulting string is written to the output context.
TRUE if successful; FALSE if not.
Here is a short example of Web.Write() and Web.WriteHeaders():
String fname = "c:\tmp\s.txt" File f = File.Open( fname, File.WriteMode ) String headers = "Content-type: text/plain" + Web.CRLF + \ "Cookie: This is a cookie" + Web.CRLF Web.WriteHeaders( f, "s.txt", headers ) Web.Write( f, "This is some text." ) File.Close( f ) Echo( Str.FileToString( fname ) )
The output of the example is:
HTTP/1.0 s.txt Content-type: text/plain Cookie: This is a cookie This is some text.
Writes a valid HTTP status line and headers to the output context (either a socket or a file).
The output context.
The return header status.
Additional HTTP headers; this must include carriage returns and line feeds (Web.CRLF).
TRUE if successful; FALSE if not.
See File.Write() for an example.
Copyright © 2022 OpenText Corporation. All rights reserved. |