Package com.adobe.xfa.ut
Class PictureFmt
- java.lang.Object
-
- com.adobe.xfa.ut.PictureFmt
-
public final class PictureFmt extends java.lang.Object
The PictureFmt class defines methods to parse and format data according to XFA picture patterns. Here's a snippet of code illustrating its use to format a date string:import com.adobe.xfa.ut.PictureFmt; ... StringBufer sResult = new StringBuilder(); PictureFmt oFmt = new PictureFmt("en"); if (oFmt.parse("28/2/2000", "D/M/YYYY", sResult)) oFmt.format(sResult.toString(), "EEEE', the 'D' of 'MMMM', 'YYYY", sResult) ...
PictureFmt also defines methods to validate picture patterns. Specifically, the methods
-
isDatePictureValid(String)
, -
isTimePictureValid(String)
, -
isNumericPictureValid(String)
, -
isTextPictureValid(String)
,
isZeroPictureValid(String)
, and,isNullPictureValid(String)
. are used for validating the syntax of the given source for each of the six categories of pictures. This includes validating the well-formedness of patterns likecategory{subpicture}
andcategory(locale){subpicture}
, validating the well-formedness of literals, and ensuring the given source symbols all belong to one category of picture. As an example, the time picture pattern:
is syntactically invalid - a quote is missing and X is not a valid time picture symbol.h:MM:SS 'o'clock 'A X
PictureFmt also defines methods to semantically validate picture patterns. The methods
are used for semantially validating the given picture. This means that the combination of XFA symbols constitutes a valid XFA picture pattern. A time picture pattern like:
is semantically invalid when used to parse time input -- requesting a time from a 12-hour clock without the meridiem could never yield a correct time value. A date picture pattern like: EEEE, MMMM YYYY is semantically invalid when used to parse date input -- requesting a date without the day of the month could never yield a correct date value.h:MM:SS 'o''clock 'Z
Do note however, that semantically invalid pictures patterns are used in output formatting in acceptable circumstances. So apply these method with discretion.
-
-
-
Constructor Summary
Constructors Constructor Description PictureFmt(java.lang.String sLocale)
Instantiates an PictureFmt object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
FF99ToXFA(java.lang.String sPicture)
Converts a F99 picture to an equivalent XFA picture.boolean
format(java.lang.String sSource, java.lang.String sPicture, java.lang.StringBuilder sResult)
Formats a given data source according to the given picture.static boolean
formatCompound(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given compound picture under the given locale.static boolean
formatDate(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given date picture under the given locale.static boolean
formatDateTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sDateMask, java.lang.String sTimeMask, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given datetime picture under the given locale.static boolean
formatNull(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given null picture under the given locale.static boolean
formatNumeric(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given numeric picture under the given locale.static boolean
formatText(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given text picture under the given locale.static boolean
formatTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given time picture under the given locale.static boolean
formatZero(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given zero picture under the given locale.static boolean
getAlternates(java.lang.String sSource, java.util.List<java.lang.String> oAlternates)
Gets all the picture alternatives.static boolean
getLocaleFromPicture(java.lang.String sPicture, java.lang.String sCategory, java.lang.StringBuilder sLocale)
Gets the locale given a valid picture and category.static boolean
hasSubPicture(java.lang.String sPicture, int nPictIndex, java.lang.StringBuilder sCategory, java.lang.StringBuilder sLocale, java.lang.StringBuilder sSubMask)
Determines if the given picture has a sub-picture.static boolean
isDatePicture(java.lang.String sPicture)
Determines if the given picture is a date picture.static boolean
isDatePictureValid(java.lang.String sPicture)
Determines if the given date picture is (semantically) valid.static boolean
isDateTimePicture(java.lang.String sPicture, java.lang.StringBuilder sDateMask, java.lang.StringBuilder sTimeMask)
Determines if the given picture is a date time picture.static boolean
isDateTimePictureValid(java.lang.String sPicture)
Determimes if the given datetime picture is (semantically) valid.static boolean
isEmptyPicture(java.lang.String sPicture)
Determines if the given picture is an empty picture.static boolean
isNullPicture(java.lang.String sPicture)
Determines if the given picture is a null picture.static boolean
isNullPictureValid(java.lang.String sPicture)
Determimes if the given null picture is (semantically) valid.static boolean
isNumericPicture(java.lang.String sPicture)
Determimes if the given picture is a numeric picture.static boolean
isNumericPictureValid(java.lang.String sPicture)
Determimes if the given numeric picture is (semantically) valid.static boolean
isSubPicture(java.lang.String sPicture, int nPictIndex, java.lang.StringBuilder sCategory, java.lang.StringBuilder sLocale, java.lang.StringBuilder sSubMask)
Determimes if the given picture has a sub-picture, and if so, returns the picture's category, locale, and sub-picture.static boolean
isTextPicture(java.lang.String sPicture)
Determines if the given picture is a text picture.static boolean
isTextPictureValid(java.lang.String sPicture)
Determines if the given text picture is (semantically) valid.static boolean
isTimePicture(java.lang.String sPicture)
Determines if the given picture is a time picture.static boolean
isTimePictureValid(java.lang.String sPicture)
Determines if the given time picture is (semantically) valid.static boolean
isZeroPicture(java.lang.String sPicture)
Determines if the given picture is a zero picture.static boolean
isZeroPictureValid(java.lang.String sPicture)
Determines if the given zero picture is (semantically) valid.java.lang.String
parse(java.lang.String sSource, java.lang.String sPicture, BooleanHolder pbSuccess)
Parses a given data source according to the given picture.static boolean
parseCompound(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given compound picture under the given locale.static boolean
parseDate(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given date picture under the given locale.static boolean
parseDateTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sDateMask, java.lang.String sTimeMask, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given datetime picture under the given locale.static boolean
parseNull(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given null picture under the given locale.static boolean
parseNumeric(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given numeric picture under the given locale.static boolean
parseText(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given text picture under the given locale.static boolean
parseTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given time picture under the given locale.static boolean
parseZero(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given zero picture under the given locale.static java.awt.Point
resolveRange(java.lang.String s, int startIndex, int endIndex)
-
-
-
Method Detail
-
resolveRange
public static java.awt.Point resolveRange(java.lang.String s, int startIndex, int endIndex)
-
format
public boolean format(java.lang.String sSource, java.lang.String sPicture, java.lang.StringBuilder sResult)
Formats a given data source according to the given picture.- Parameters:
sSource
- the source data in canonical format.sPicture
- the formatting picture.sResult
- the resulting string, which may be empty upon error.- Returns:
- boolean true if successful and false otherwise.
-
parse
public java.lang.String parse(java.lang.String sSource, java.lang.String sPicture, BooleanHolder pbSuccess)
Parses a given data source according to the given picture.- Parameters:
sSource
- the source data.sPicture
- the parsing picture.pbSuccess
- the canonical result.- Returns:
- the string result.
-
FF99ToXFA
public static java.lang.String FF99ToXFA(java.lang.String sPicture)
Converts a F99 picture to an equivalent XFA picture. F99 pictures contain either double quote enclosed literals, or single quote enclosed literals. Change all to single quote enclosed literals, suitably escaping any embedded double quotes.- Parameters:
sPicture
- the source picture.- Returns:
- the equivalent XFA picture.
-
formatCompound
public static boolean formatCompound(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given compound picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the compound picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.- Returns:
- This method is not operational!
-
formatDate
public static boolean formatDate(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given date picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the date picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.bAsLocal
- interpret the source data as a local date when true, and a GMT date when false.- Returns:
- boolean true upon success and false otherwise.
-
formatDateTime
public static boolean formatDateTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sDateMask, java.lang.String sTimeMask, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given datetime picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the datetime picture.sDateMask
- the date sub-picture.sTimeMask
- the time sub-picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.bAsLocal
- interpret the data source as locale datetime when true, and GMT datetime when false.- Returns:
- boolean true upon success and false otherwise.
-
formatNull
public static boolean formatNull(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given null picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the null picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
formatNumeric
public static boolean formatNumeric(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given numeric picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the numeric picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
formatText
public static boolean formatText(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given text picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the text picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
formatTime
public static boolean formatTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult, boolean bAsLocal)
Formats a given data source according to the given time picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the time picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.bAsLocal
- interpret the data source as local time when true, and a GMT time when false.- Returns:
- boolean true upon success and false otherwise.
-
formatZero
public static boolean formatZero(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, java.lang.StringBuilder sResult)
Formats a given data source according to the given zero picture under the given locale.- Parameters:
sSource
- the source data. It must be empty or zero!sPicture
- the zero picture.sLocale
- the locale name.sResult
- the resulting string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
getAlternates
public static boolean getAlternates(java.lang.String sSource, java.util.List<java.lang.String> oAlternates)
Gets all the picture alternatives.- Parameters:
sSource
- the source picture. Alternate pictures are each separated by the vertical bar '|' character.oAlternates
- the object to be populated with all the alternate pictures found in the source.- Returns:
- boolean true upon success and false if the source picture is invalid.
-
getLocaleFromPicture
public static boolean getLocaleFromPicture(java.lang.String sPicture, java.lang.String sCategory, java.lang.StringBuilder sLocale)
Gets the locale given a valid picture and category.- Parameters:
sPicture
- the valid picture.sCategory
- the picture category: one of "date", "time", "num", "text", "null" or "zero".sLocale
- the returned locale.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
hasSubPicture
public static boolean hasSubPicture(java.lang.String sPicture, int nPictIndex, java.lang.StringBuilder sCategory, java.lang.StringBuilder sLocale, java.lang.StringBuilder sSubMask)
Determines if the given picture has a sub-picture. If so, the sub-picture's components are returned. Subpictures are of the form:category{subpicture}
orcategory(locale){subpicture}
.- Parameters:
sPicture
- the picture.nPictIndex
- the starting picture index.sCategory
- the picture's category.sLocale
- the picture's locale.sSubMask
- the picture's sub-picture.- Returns:
- boolean true if there's a sub-picture, and false otherwise.
-
isDatePicture
public static boolean isDatePicture(java.lang.String sPicture)
Determines if the given picture is a date picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isDatePictureValid
public static boolean isDatePictureValid(java.lang.String sPicture)
Determines if the given date picture is (semantically) valid.- Parameters:
sPicture
- the date picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isDateTimePicture
public static boolean isDateTimePicture(java.lang.String sPicture, java.lang.StringBuilder sDateMask, java.lang.StringBuilder sTimeMask)
Determines if the given picture is a date time picture.- Parameters:
sPicture
- the source picture.sDateMask
- the returned date picture found in the given source picture.sTimeMask
- the returned time picture found in the given source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isDateTimePictureValid
public static boolean isDateTimePictureValid(java.lang.String sPicture)
Determimes if the given datetime picture is (semantically) valid.- Parameters:
sPicture
- the datetime picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isNullPicture
public static boolean isNullPicture(java.lang.String sPicture)
Determines if the given picture is a null picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isEmptyPicture
public static boolean isEmptyPicture(java.lang.String sPicture)
Determines if the given picture is an empty picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isNullPictureValid
public static boolean isNullPictureValid(java.lang.String sPicture)
Determimes if the given null picture is (semantically) valid.- Parameters:
sPicture
- the null picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isNumericPicture
public static boolean isNumericPicture(java.lang.String sPicture)
Determimes if the given picture is a numeric picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isNumericPictureValid
public static boolean isNumericPictureValid(java.lang.String sPicture)
Determimes if the given numeric picture is (semantically) valid.- Parameters:
sPicture
- the numeric picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isSubPicture
public static boolean isSubPicture(java.lang.String sPicture, int nPictIndex, java.lang.StringBuilder sCategory, java.lang.StringBuilder sLocale, java.lang.StringBuilder sSubMask)
Determimes if the given picture has a sub-picture, and if so, returns the picture's category, locale, and sub-picture.- Parameters:
sPicture
- the source picture.nPictIndex
- the starting character index within the given source picture.sCategory
- the picture's category.sLocale
- the picture's locale.sSubMask
- the picture's sub-picture.- Returns:
- boolean true if the picture is a locale sensitive picture and false otherwise.
-
isTextPicture
public static boolean isTextPicture(java.lang.String sPicture)
Determines if the given picture is a text picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isTextPictureValid
public static boolean isTextPictureValid(java.lang.String sPicture)
Determines if the given text picture is (semantically) valid.- Parameters:
sPicture
- the text picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isTimePicture
public static boolean isTimePicture(java.lang.String sPicture)
Determines if the given picture is a time picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isTimePictureValid
public static boolean isTimePictureValid(java.lang.String sPicture)
Determines if the given time picture is (semantically) valid.- Parameters:
sPicture
- the time picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
isZeroPicture
public static boolean isZeroPicture(java.lang.String sPicture)
Determines if the given picture is a zero picture.- Parameters:
sPicture
- the source picture.- Returns:
- boolean true if the source picture is syntactically valid, and false otherwise.
-
isZeroPictureValid
public static boolean isZeroPictureValid(java.lang.String sPicture)
Determines if the given zero picture is (semantically) valid.- Parameters:
sPicture
- the zero picture.- Returns:
- boolean true if the source picture is semantically valid, and false otherwise.
-
parseCompound
public static boolean parseCompound(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given compound picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the compound picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
parseDate
public static boolean parseDate(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given date picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the date picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.bAsLocal
- return the canonical result as a local date when true, and as a GMT date when false.- Returns:
- boolean true upon success and false otherwise.
-
parseDateTime
public static boolean parseDateTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sDateMask, java.lang.String sTimeMask, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given datetime picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the datetime picture.sDateMask
- the date sub-picture.sTimeMask
- the time sub-picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.bAsLocal
- return the canonical result as a local datetime when true, and as a GMT datetime value when false.- Returns:
- boolean true upon success and false otherwise.
-
parseNull
public static boolean parseNull(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given null picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the null picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
parseNumeric
public static boolean parseNumeric(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given numeric picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the numeric picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
parseText
public static boolean parseText(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given text picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the text picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
parseTime
public static boolean parseTime(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult, boolean bAsLocal)
Parses a given data source according to the given time picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the time picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
parseZero
public static boolean parseZero(java.lang.String sSource, java.lang.String sPicture, java.lang.String sLocale, StringHolder sResult)
Parses a given data source according to the given zero picture under the given locale.- Parameters:
sSource
- the source data.sPicture
- the zero picture.sLocale
- the locale name.sResult
- the resulting canonical string, which may be empty upon error.- Returns:
- boolean true upon success and false otherwise.
-
-