Package org.docx4j.model.fields
Class FormattingSwitchHelper
java.lang.Object
org.docx4j.model.fields.FormattingSwitchHelper
Formats the string value of the field according to the three possible formatting switches:
+ date-and-time-formatting-switch: \@
+ numeric-formatting-switch: \#
+ general-formatting-switch: \*
Note that the general-formatting-switch arguments CHARFORMAT and MERGEFORMAT are not handled here.
It is the responsibility of the calling code to handle these.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal<Map<String,SimpleDateFormat>> static final intstatic final intprotected static final StringConversion of page number formats to fo as defined in w:fldSimple in w:pgNumType w:fmtprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprivate static org.slf4j.Loggerprotected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendDateItem(StringBuilder buffer, String dateItem) private static voidappendNumberItem(StringBuilder buffer, String dateItem) static StringapplyFormattingSwitch(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value) static StringapplyFormattingSwitch(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value, String lang) static StringconvertDatePattern(String wordDatePattern) findAllSwitchValues(String switchDef, List<String> fldParameters) static StringfindFirstSwitchValue(String switchDef, List<String> fldParameters, boolean ignoreMergeformat) static intfindSwitch(String switchDef, int startPos, List<String> fldParameters) private static Stringstatic StringformatDate(FldSimpleModel model) static StringformatDate(FldSimpleModel model, String format, Date date) private static StringformatDate(FldSimpleModel model, String format, Date date, String lang) static StringformatDate(FldSimpleModel model, Date date) private static StringformatGeneral(FldSimpleModel model, String format, String value) private static StringformatNumber(FldSimpleModel model, String wordNumberPattern, double dub, String lang) private static DategetDate(FldSimpleModel model, String dateStr) static StringgetFldSimpleName(String instr) static intgetFoPageNumberDecoration(String wordName) Check if the page number format has a decoration (eg.static StringgetFoPageNumberFormat(String wordName) Conversion of the word page number format to the fo page number format.private static doublegetNumber(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value) private static SimpleDateFormatgetSimpleDateFormat(String lang) static StringgetSwitchValue(int pos, List<String> fldParameters) static booleanprivate static booleanprivate static LocalelocaleforLanguageTag(String locale) Substitute for Java 7's Locale.forLanguageTag
-
Field Details
-
log
private static org.slf4j.Logger log -
DATE_FORMATS
-
DEFAULT_FORMAT_PAGE_TO_FO
Conversion of page number formats to fo as defined- in w:fldSimple
- in w:pgNumType w:fmt
- See Also:
-
NONE_STRING
-
FORMAT_PAGE_TO_FO
-
DECORATION_NONE
public static final int DECORATION_NONE- See Also:
-
DECORATION_DASH
public static final int DECORATION_DASH- See Also:
-
MERGEFORMAT
- See Also:
-
FO_PAGENUMBER_DECIMAL
- See Also:
-
FO_PAGENUMBER_LOWERALPHA
- See Also:
-
FO_PAGENUMBER_UPPERALPHA
- See Also:
-
FO_PAGENUMBER_LOWERROMAN
- See Also:
-
FO_PAGENUMBER_UPPERROMAN
- See Also:
-
DATE_FORMAT_ITEMS_TO_JAVA
-
-
Constructor Details
-
FormattingSwitchHelper
public FormattingSwitchHelper()
-
-
Method Details
-
applyFormattingSwitch
public static String applyFormattingSwitch(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value) throws Docx4JException - Throws:
Docx4JException
-
applyFormattingSwitch
public static String applyFormattingSwitch(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value, String lang) throws Docx4JException - Throws:
Docx4JException
-
getDate
private static Date getDate(FldSimpleModel model, String dateStr) throws FormattingSwitchHelper.FieldResultIsNotADateOrTimeException -
getNumber
private static double getNumber(WordprocessingMLPackage wmlPackage, FldSimpleModel model, String value) throws FormattingSwitchHelper.FieldResultIsNotANumberException -
formatNumber
private static String formatNumber(FldSimpleModel model, String wordNumberPattern, double dub, String lang) throws FieldFormattingException - Throws:
FieldFormattingException
-
localeforLanguageTag
Substitute for Java 7's Locale.forLanguageTag- Parameters:
locale-- Returns:
-
appendNumberItem
-
formatGeneral
-
firstCap
-
getFoPageNumberFormat
Conversion of the word page number format to the fo page number format.- Parameters:
wordName- word page number format- Returns:
- null if the wordName is null, the correspondig fo value if present or a default.
-
getFoPageNumberDecoration
Check if the page number format has a decoration (eg. dash).- Parameters:
wordName- word page number format- Returns:
- decoration type (one of the DECORATION_xxx constants).
-
getFldSimpleName
-
convertDatePattern
-
isAMPM
-
appendDateItem
-
formatDate
-
formatDate
-
formatDate
-
formatDate
-
hasSwitch
-
findFirstSwitchValue
-
getSwitchValue
-
findAllSwitchValues
-
findSwitch
-
getSimpleDateFormat
- Parameters:
language- abbreviation like "fr-CA",- Returns:
- SimpleDateFormat instance for specified language if null will @return SimpleDateFormat.getDateTimeInstance()
-