|
|
7.0.5 |
|
|
|
Breaks a URL into its component parts.
Beginning with version 9.0, util.crackURL can break a URL that uses Internet Protocol version 6 (IPv6) addressing. The return object for util.crackURL includes an additional property, nURLType, to help determine the IP type of the URL being passed to the argument of util.crackURL.
No effort is made to determine the IP type if a direct URL is not used and the corresponding DNS name is used.
cURL |
A string specifying the URL. |
An object containing the following properties:
Property |
Description |
---|---|
cScheme |
The scheme of the URL. It may be file, http or https. |
cUser |
(Optional) The user name specified in the URL. |
cPassword |
(Optional) The password specified in the URL. |
cHost |
The hostname of the URL. |
nPort |
The port number of the URL. |
cPath |
(Optional) The path portion of the URL. |
cQuery |
(Optional) The parameter string portion of the URL. |
cFragment |
(Optional) The fragments of the URL. |
nURLType |
(Version 9.0) An integer valued property that takes a value of 0 if cURL uses IPv4 and a value of 1 if cURL uses IPv6. (IPv4 and IPv6 refer to the Internet Protocol versions 4 and 6, respectively.) |
This method throws a parameter error if the parameter is missing, the URL is not well-formed, or the URL scheme is not file, http, or https.
The following code
util.crackURL("http://example.org/myPath?name0=value0&name1=value1#frag");
would return
{
cScheme: "http",
cHost: "example.org",
nPort: 80,
cPath: "/myPath",
cQuery: "name0=value0&name1=value1",
cFragment: "frag"
}
Version 9.0 can break a URL into its components when the URL uses version 6 Internet Protocol.
var a = util.crackURL("http://[2001:1890:110b:15ce:250:56ff:febb:6111]/Ex");
if ( a.nURLType == 1 )
console.println("host = [" + a.cHost + "]");
else
console.println("host = " + a.cHost);
7.0 |
|
|
|
Converts an XObject-based Icon object into an Icon Stream object.
oIcon |
An Icon object to be converted into an Icon Stream object. |
Icon Stream object
This method allows an icon obtained from the Doc importIcon or getIcon methods to be used in a method such as app.addToolButton, which would otherwise accept only an Icon Stream object as an input parameter.
Import an icon into the document-level named icons tree and add a toolbutton to the application.
this.importIcon("myIcon", "/C/temp/myIcon.jpg", 0);
var oIcon = util.iconStreamFromIcon(this.getIcon("myIcon"));
app.addToolButton({
cName: "myButton",
oIcon: oIcon,
cExec: "console.println('My Button!');",
cTooltext: "My button!",
nPos: 0
});
3.01 |
|
|
|
Returns a date using a specified format.
cFormat |
The date and time format. It can be one of the following types:
0 — PDF date format. Example: D:20000801145605+07'00' 1 — Universal. Example: D:20000801145605+07'00' 2 — Localized string. Example: 2000/08/01 14:56:05
|
oDate |
A Date object to format. Date objects can be obtained from the Date constructor of core JavaScript or from the util.scand method. |
bXFAPicture |
(optional, The default is false. |
The formatted date string.
String |
Effect |
Example |
---|---|---|
mmmm |
Long month |
September |
mmm |
Abbreviated month |
Sep |
mm |
Numeric month with leading zero |
09 |
m |
Numeric month without leading zero |
9 |
dddd |
Long day |
Wednesday |
ddd |
Abbreviated day |
Wed |
dd |
Numeric date with leading zero |
03 |
d |
Numeric date without leading zero |
3 |
yyyy |
Long year |
1997 |
yy |
Abbreviated Year |
97 |
HH |
24 hour time with leading zero |
09 |
H |
24 hour time without leading zero |
9 |
hh |
12 hour time with leading zero |
09 |
h |
12 hour time without leading zero |
9 |
MM |
minutes with leading zero |
08 |
M |
minutes without leading zero |
8 |
ss |
seconds with leading zero |
05 |
s |
seconds without leading zero |
5 |
tt |
am/pm indication |
am |
t |
single digit am/pm indication |
a |
j |
Japanese Emperor Year (abbreviated) Note:Introduced in |
|
jj |
Japanese Emperor Year Note:Introduced in |
|
\ |
use as an escape character |
|
Format the current date in long format:
var d = new Date();
console.println("Today is " + util.printd("mmmm dd, yyyy", d));
Display the date in a local format
console.println(util.printd(2, new Date() ));
Use the XFA-Picture Clause to write the current date to the console.
// Execute in console
console.println(
util.printd("EEE, 'the' D 'of' MMMM, YYYY", new Date(), true));
// The output on this day is
Tue, the 13 of July, 2004
Locale-Sensitive Picture Clauses. Normally processing of picture clauses occurs in the ambient locale. It is possible, however, to indicate that picture processing be done in a specific locale. This is of use when formatting or parsing data that is locale-specific and different from the ambient locale. The syntax for this extension to compound picture clauses is:
category-name(locale-name){picture-symbols}
The code executed in the console,
util.printd("date(fr){DD MMMM, YYYY}", new Date(), true)
yields the output on this day,
13 juillet, 2004
The XFA-Picture Clause gives extensive support for Chinese, Chinese (Taiwan), Japanese, and Korean (CCJK) times and dates. The example below, a custom format script of a text field, gives the current date formatted for a Japanese locale.
event.value = util.printd("date(ja){ggYY/M/D}", new Date(), true)
3.01 |
|
|
|
Formats one or more arguments as a string according to a format string. It is similar to the C function of the same name. This method converts and formats incoming arguments into a result string according to a format string (cFormat).
The format string consists of two types of objects:
Ordinary characters, which are copied to the result string.
Conversion specifications, each of which causes conversion and formatting of the next successive argument to printf.
Each conversion specification is constructed as follows:
%[,nDecSep][cFlags][nWidth][.nPrecision]cConvChar
The following table describes the components of a conversion specification.
nDecSep |
A comma character (,) followed by a digit that indicates the decimal/separator format: 0 — Comma separated, period decimal point 1 — No separator, period decimal point 2 — Period separated, comma decimal point 3 — No separator, comma decimal point |
cFlags |
Only valid for numeric conversions and consists of a number of characters (in any order), which will modify the specification: + — Specifies that the number will always be formatted with a sign. space — If the first character is not a sign, a space will be prefixed. 0 — Specifies padding to the field with leading zeros. # — Specifies an alternate output form. For f, the output will always have a decimal point. |
nWidth |
A number specifying a minimum field width. The converted argument is formatted to be at least this many characters wide, including the sign and decimal point, and may be wider if necessary. If the converted argument has fewer characters than the field width, it is padded on the left to make up the field width. The padding character is normally a space, but is 0 if the zero padding flag is present (cFlags contains 0). |
nPrecision |
A period character (.) followed by a number that specifies the number of digits after the decimal point for float conversions. |
cConvChar |
Indicates how the argument should be interpreted: d — Integer (truncating if necessary) f — Floating-point number s — String x — Integer (truncating if necessary) and formatted in unsigned hexadecimal notation |
cFormat |
The format string to use. |
arguments |
The optional arguments(s) that contain the data to be inserted in place of the % tags specified in the first parameter, the format string. The number of optional arguments must be the same as the number of % tags. |
Note:The util.printf function does not accept an object literal with properties that contain the arguments. Arguments are entered in the usual comma-delimited list.
A result string formatted as specified.
Take an irrational number and display it using various formats of util.printf.
var n = Math.PI * 100;
console.clear();
console.show();
console.println(util.printf("Decimal format: %d", n));
console.println(util.printf("Hex format: %x", n));
console.println(util.printf("Float format: %.2f", n));
console.println(util.printf("String format: %s", n));
The output of the above script is as follows:
Decimal format: 314
Hex format: 13A
Float format: 314.16
String format: 314.159265358979
3.01 |
|
|
|
Formats a source string, cSource, according to a formatting string, cFormat. A valid format for cFormat is any string that may contain special masking characters:
Value |
Effect |
---|---|
? |
Copy next character. |
X |
Copy next alphanumeric character, skipping any others. |
A |
Copy next alpha character, skipping any others. |
9 |
Copy next numeric character, skipping any others. |
* |
Copy the rest of the source string from this point on. |
\ |
Escape character. |
> |
Upper case translation until further notice. |
< |
Lower case translation until further notice. |
= |
Preserve case until further notice (default). |
cFormat |
The formatting string to use. |
cSource |
The source string to use. |
The formatted string.
Format a string as a U.S. telephone number.
var v = "aaa14159697489zzz";
v = util.printx("9 (999) 999-9999", v);
console.println(v);
10.0 |
|
|
|
.Loads an external file into a JavaScript stream, optionally base64 encodes it, and returns the content as a base64 encoded stream.
cDIPath |
(optional) A device-independent path to an arbitrary file on the user's hard drive. This path may be absolute or relative to the current document. If not specified, the user is presented with the File Open dialog to locate the file. If the cDIPath parameter is specified, this method can only be executed in privileged context, during a batch or console event (or when the document is certified with a certificate trusted to execute "embedded high privileged JavaScript"). |
bEncodeBase64 |
(optional) If true, base64-encode the file content. |
The File content as a ReadStream object that is optionally base 64-encoded.
Assume there is a text field myField in this document. This example reads the contents of a file c:/data/myData.txt in a ReadStream object, converts it to a string, and displays it in the multiline text field.
var rStream = util.readFileIntoStream("/c/data/myData.txt");
var cFile = util.stringFromStream(rStream);
this.getField("myTextField").value = cFile;
4.0 |
|
|
|
Converts a date into a JavaScript Date object according to the rules of a format string. This routine is much more flexible than using the date constructor directly.
Note:Given a two-digit year for input, scand uses the date horizon heuristic to resolve the ambiguity. If the year is less than 50, it is assumed to be in the 21st century (that is, add 2000). If it is greater than or equal to 50, it is in the 20th century (add 1900).
The supplied date cDate should be in the same format as described by cFormat.
cFormat |
The rules to use for formatting the date. cFormat uses the same syntax as found in printd. |
cDate |
The date to convert. |
The converted Date object, or null if the conversion fails.
/* Turn the current date into a string. */
var cDate = util.printd("mm/dd/yyyy", new Date());
console.println("Today’s date: " + cDate);
/* Parse it back into a date. */
var d = util.scand("mm/dd/yyyy", cDate);
/* Output it in reverse order. */
console.println("Yet again: " + util.printd("yyyy mmm dd", d));
Retrieve a text field value, see if it is a date of the acceptable format, then report results in an alert box or the console window.
The method returns null if the conversions fails, which can occur if the user inputs a data different than what is expected. In this case, test the return value for null.
var d= util.scand("mm/dd/yyyy", this.getField("myDate").value);
if ( d== null )
app.alert("Please enter a valid date of the form" +
" \"mm/dd/yyyy\".")
else {
console.println("You entered the date: "
+ util.printd("mmmm dd, yyyy",d));
}
6.0 |
|
|
|
Converts an array of Span objects into an XML(XFA) String as described in the
An array of Span objects |
An array of Span objects to be converted into an XML string. |
String
Get the value of a rich text field, turns all of the text blue, converts it to an XML string and then prints it to the console.
var f = getField("Text1");
var spans = f.richValue;
for(var index = 0; index < spans.length; index++)
spans[index].textColor = color.blue;
console.println(util.spansToXML(spans));
7.0 |
|
|
|
Converts a string to a ReadStream object.
cString |
The string to be converted into a ReadStream object. |
cCharSet |
(optional) The encoding for the string in cString. The options are utf-8, utf-16, Shift-JIS, BigFive, GBK, UHC. The default is utf-8. |
ReadStream object
Take the response given in a text field of this document and append it to an attached document.
var v = this.getField("myTextField").value;
var oFile = this.getDataObjectContents("MyNotes.txt");
var cFile = util.stringFromStream(oFile, "utf-8");
cFile += "\r\n" + cFile;
oFile = util.streamFromString( cFile, "utf-8");
this.setDataObjectContents("MyNotes.txt", oFile);
This example uses the Doc methods getDataObjectContents and setDataObjectContents and util.stringFromStream.
7.0 |
|
|
|
Converts a ReadStream object to a string.
oStream |
ReadStream object to be converted into a string. |
cCharSet |
(optional) The encoding for the string in oStream. The options are utf-8, utf-16, Shift-JIS, BigFive, GBK, UHC. The default is utf-8. |
String
Assume there is a text file embedded in this document. This example reads the contents of the attachment and displays it in the multiline text field.
var oFile = this.getDataObjectContents("MyNotes.txt");
var cFile = util.stringFromStream(oFile, "utf-8");
this.getField("myTextField").value = cFile;
This example uses getDataObjectContents to get the file stream of the attached document.
6.0 |
|
|
|
Converts an XML (XFA) string, as described in the
a string |
An XML (XFA) string to be converted to an array of Span objects. |
An Array of Span objects
Get the rich text string from “Text1”, convert it to XML, then convert it back to an array of Span objects and repopulate the text field.
var f = getField("Text1");
var spans = f.richValue;
var str = util.spansToXML(spans);
var spans = util.xmlToSpans(str);
f.richValue = spans;