1 package org.apache.turbine.services.pull.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.time.ZoneId;
23 import java.time.format.DateTimeFormatter;
24 import java.time.format.DateTimeParseException;
25 import java.time.temporal.TemporalAccessor;
26 import java.util.Locale;
27
28 import org.apache.logging.log4j.LogManager;
29 import org.apache.logging.log4j.Logger;
30 import org.apache.turbine.annotation.TurbineService;
31 import org.apache.turbine.services.ServiceManager;
32 import org.apache.turbine.services.TurbineServices;
33 import org.apache.turbine.services.localization.DateTimeFormatterInterface;
34 import org.apache.turbine.services.localization.DateTimeFormatterService;
35 import org.apache.turbine.services.pull.ApplicationTool;
36
37
38
39
40
41
42
43
44
45
46
47 public class DateTimeFormatterTool
48 implements ApplicationTool, DateTimeFormatterInterface
49 {
50
51 @TurbineService
52 private DateTimeFormatterService dtfs;
53
54 private static final Logger log = LogManager.getLogger(DateTimeFormatterTool.class);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 @Override
71 public void init(Object data)
72 {
73 log.info("Initialized DateTimeFormatterTool with service {}",
74 dtfs);
75 if (dtfs == null)
76 {
77 ServiceManager serviceManager = TurbineServices.getInstance();
78 dtfs = (DateTimeFormatterService)serviceManager.getService(DateTimeFormatterService.SERVICE_NAME);
79 }
80
81 }
82
83 public DateTimeFormatterService getDtfs() {
84 return dtfs;
85 }
86
87
88
89
90
91
92
93
94 @Override
95 public void refresh()
96 {
97
98 }
99
100 public DateTimeFormatter getDefaultFormat()
101 {
102 return getDtfs().getDefaultFormat();
103 }
104
105 public String getDateTimeFormatPattern() {
106 return getDtfs().getDateTimeFormatPattern();
107 }
108
109
110
111
112
113
114
115
116 public <T extends TemporalAccessor> String format(T temporalAccessor)
117 {
118 return getDtfs().getDefaultFormat().format(temporalAccessor);
119 }
120
121 public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString)
122 {
123 return getDtfs().format(temporalAccessor, dateFormatString, null);
124 }
125
126 public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale)
127 {
128 return getDtfs().format(temporalAccessor, dateFormatString, locale);
129 }
130
131 public String map( String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern)
132 {
133 return getDtfs().map(src, outgoingFormatPattern, locale, incomingFormatPattern);
134 }
135
136 public String map( String src, java.time.format.DateTimeFormatter outgoingFormat, Locale locale,
137 java.time.format.DateTimeFormatter incomingFormat)
138 {
139 return getDtfs().map(src, outgoingFormat, locale, incomingFormat);
140 }
141
142 public String mapTo( String src, DateTimeFormatter outgoingFormat )
143 {
144 return getDtfs().map( src, outgoingFormat, null, getDtfs().getDefaultFormat() );
145 }
146
147 public String mapFrom( String src, DateTimeFormatter incomingFormat )
148 {
149 return getDtfs().map( src, getDtfs().getDefaultFormat(), null, incomingFormat );
150 }
151
152 public String map( String src, DateTimeFormatter outgoingFormat, Locale locale )
153 {
154 return getDtfs().map( src, outgoingFormat, locale, getDtfs().getDefaultFormat() );
155 }
156 }