Updates
java-spring-framework-remove-non-free.patch
1 | - | From 45ff8f9aff1ce08546b091505a706b1baf1bcb7b Mon Sep 17 00:00:00 2001 | |
1 | + | From 03942913eb3b3a6458030856bfecc8a6927ab1ba Mon Sep 17 00:00:00 2001 | |
2 | 2 | From: Julien Lepiller <julien@lepiller.eu> | |
3 | - | Date: Sat, 15 Sep 2018 00:09:39 +0200 | |
3 | + | Date: Sat, 15 Sep 2018 10:27:46 +0200 | |
4 | 4 | Subject: [PATCH] Remove dependency on jsr354 (javax.currency). | |
5 | 5 | ||
6 | 6 | jsr354 is a non-free package: | |
7 | 7 | https://github.com/JavaMoney/jsr354-api/blob/master/EVALUATION-LICENCE.txt | |
8 | 8 | --- | |
9 | - | .../DefaultFormattingConversionService.java | 10 - | |
10 | - | .../number/money/MoneyFormattingTests.java | 272 ------------------ | |
11 | - | 2 files changed, 282 deletions(-) | |
12 | - | delete mode 100644 spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java | |
9 | + | .../number/money/CurrencyUnitFormatter.java | 44 ----- | |
10 | + | ...umberFormatAnnotationFormatterFactory.java | 163 ------------------ | |
11 | + | .../number/money/MonetaryAmountFormatter.java | 96 ----------- | |
12 | + | .../format/number/money/package-info.java | 4 - | |
13 | + | .../DefaultFormattingConversionService.java | 10 -- | |
14 | + | 5 files changed, 317 deletions(-) | |
15 | + | delete mode 100644 spring-context/src/main/java/org/springframework/format/number/money/CurrencyUnitFormatter.java | |
16 | + | delete mode 100644 spring-context/src/main/java/org/springframework/format/number/money/Jsr354NumberFormatAnnotationFormatterFactory.java | |
17 | + | delete mode 100644 spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java | |
18 | + | delete mode 100644 spring-context/src/main/java/org/springframework/format/number/money/package-info.java | |
13 | 19 | ||
14 | - | diff --git a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
15 | - | index 2c7c60a..5e38006 100644 | |
16 | - | --- a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
17 | - | +++ b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
18 | - | @@ -21,9 +21,6 @@ import org.springframework.format.FormatterRegistry; | |
19 | - | import org.springframework.format.datetime.DateFormatterRegistrar; | |
20 | - | import org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar; | |
21 | - | import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; | |
22 | - | -import org.springframework.format.number.money.CurrencyUnitFormatter; | |
23 | - | -import org.springframework.format.number.money.Jsr354NumberFormatAnnotationFormatterFactory; | |
24 | - | -import org.springframework.format.number.money.MonetaryAmountFormatter; | |
25 | - | import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; | |
26 | - | import org.springframework.util.ClassUtils; | |
27 | - | import org.springframework.util.StringValueResolver; | |
28 | - | @@ -104,13 +101,6 @@ public class DefaultFormattingConversionService extends FormattingConversionServ | |
29 | - | // Default handling of number values | |
30 | - | formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); | |
31 | - | ||
32 | - | - // Default handling of monetary values | |
33 | - | - if (jsr354Present) { | |
34 | - | - formatterRegistry.addFormatter(new CurrencyUnitFormatter()); | |
35 | - | - formatterRegistry.addFormatter(new MonetaryAmountFormatter()); | |
36 | - | - formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory()); | |
37 | - | - } | |
38 | - | - | |
39 | - | // Default handling of date-time values | |
40 | - | if (jsr310Present) { | |
41 | - | // just handling JSR-310 specific date and time types | |
42 | - | diff --git a/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java b/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java | |
20 | + | diff --git a/spring-context/src/main/java/org/springframework/format/number/money/CurrencyUnitFormatter.java b/spring-context/src/main/java/org/springframework/format/number/money/CurrencyUnitFormatter.java | |
43 | 21 | deleted file mode 100644 | |
44 | - | index 28df446..0000000 | |
45 | - | --- a/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java | |
22 | + | index d3f4749..0000000 | |
23 | + | --- a/spring-context/src/main/java/org/springframework/format/number/money/CurrencyUnitFormatter.java | |
46 | 24 | +++ /dev/null | |
47 | - | @@ -1,272 +0,0 @@ | |
25 | + | @@ -1,44 +0,0 @@ | |
48 | 26 | -/* | |
49 | 27 | - * Copyright 2002-2015 the original author or authors. | |
50 | 28 | - * | |
… | |||
65 | 43 | - | |
66 | 44 | -import java.util.Locale; | |
67 | 45 | -import javax.money.CurrencyUnit; | |
68 | - | -import javax.money.MonetaryAmount; | |
69 | - | - | |
70 | - | -import org.junit.After; | |
71 | - | -import org.junit.Before; | |
72 | - | -import org.junit.Test; | |
46 | + | -import javax.money.Monetary; | |
73 | 47 | - | |
74 | - | -import org.springframework.beans.MutablePropertyValues; | |
75 | - | -import org.springframework.context.i18n.LocaleContextHolder; | |
76 | - | -import org.springframework.format.annotation.NumberFormat; | |
77 | - | -import org.springframework.format.support.DefaultFormattingConversionService; | |
78 | - | -import org.springframework.format.support.FormattingConversionService; | |
79 | - | -import org.springframework.validation.DataBinder; | |
80 | - | - | |
81 | - | -import static org.junit.Assert.*; | |
48 | + | -import org.springframework.format.Formatter; | |
82 | 49 | - | |
83 | 50 | -/** | |
51 | + | - * Formatter for JSR-354 {@link javax.money.CurrencyUnit} values, | |
52 | + | - * from and to currency code Strings. | |
53 | + | - * | |
84 | 54 | - * @author Juergen Hoeller | |
85 | 55 | - * @since 4.2 | |
86 | 56 | - */ | |
87 | - | -public class MoneyFormattingTests { | |
57 | + | -public class CurrencyUnitFormatter implements Formatter<CurrencyUnit> { | |
88 | 58 | - | |
89 | - | - private final FormattingConversionService conversionService = new DefaultFormattingConversionService(); | |
90 | - | - | |
91 | - | - | |
92 | - | - @Before | |
93 | - | - public void setUp() { | |
94 | - | - LocaleContextHolder.setLocale(Locale.US); | |
59 | + | - @Override | |
60 | + | - public String print(CurrencyUnit object, Locale locale) { | |
61 | + | - return object.getCurrencyCode(); | |
95 | 62 | - } | |
96 | 63 | - | |
97 | - | - @After | |
98 | - | - public void tearDown() { | |
99 | - | - LocaleContextHolder.setLocale(null); | |
64 | + | - @Override | |
65 | + | - public CurrencyUnit parse(String text, Locale locale) { | |
66 | + | - return Monetary.getCurrency(text); | |
100 | 67 | - } | |
101 | 68 | - | |
69 | + | -} | |
70 | + | diff --git a/spring-context/src/main/java/org/springframework/format/number/money/Jsr354NumberFormatAnnotationFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/number/money/Jsr354NumberFormatAnnotationFormatterFactory.java | |
71 | + | deleted file mode 100644 | |
72 | + | index 6cec059..0000000 | |
73 | + | --- a/spring-context/src/main/java/org/springframework/format/number/money/Jsr354NumberFormatAnnotationFormatterFactory.java | |
74 | + | +++ /dev/null | |
75 | + | @@ -1,163 +0,0 @@ | |
76 | + | -/* | |
77 | + | - * Copyright 2002-2015 the original author or authors. | |
78 | + | - * | |
79 | + | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
80 | + | - * you may not use this file except in compliance with the License. | |
81 | + | - * You may obtain a copy of the License at | |
82 | + | - * | |
83 | + | - * http://www.apache.org/licenses/LICENSE-2.0 | |
84 | + | - * | |
85 | + | - * Unless required by applicable law or agreed to in writing, software | |
86 | + | - * distributed under the License is distributed on an "AS IS" BASIS, | |
87 | + | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
88 | + | - * See the License for the specific language governing permissions and | |
89 | + | - * limitations under the License. | |
90 | + | - */ | |
91 | + | - | |
92 | + | -package org.springframework.format.number.money; | |
102 | 93 | - | |
103 | - | - @Test | |
104 | - | - public void testAmountAndUnit() { | |
105 | - | - MoneyHolder bean = new MoneyHolder(); | |
106 | - | - DataBinder binder = new DataBinder(bean); | |
107 | - | - binder.setConversionService(conversionService); | |
108 | - | - | |
109 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
110 | - | - propertyValues.add("amount", "USD 10.50"); | |
111 | - | - propertyValues.add("unit", "USD"); | |
112 | - | - binder.bind(propertyValues); | |
113 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
114 | - | - assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount")); | |
115 | - | - assertEquals("USD", binder.getBindingResult().getFieldValue("unit")); | |
116 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
117 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
118 | - | - | |
119 | - | - LocaleContextHolder.setLocale(Locale.CANADA); | |
120 | - | - binder.bind(propertyValues); | |
121 | - | - LocaleContextHolder.setLocale(Locale.US); | |
122 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
123 | - | - assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount")); | |
124 | - | - assertEquals("USD", binder.getBindingResult().getFieldValue("unit")); | |
125 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
126 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
127 | - | - } | |
94 | + | -import java.text.ParseException; | |
95 | + | -import java.util.Collections; | |
96 | + | -import java.util.Currency; | |
97 | + | -import java.util.Locale; | |
98 | + | -import java.util.Set; | |
99 | + | -import javax.money.CurrencyUnit; | |
100 | + | -import javax.money.Monetary; | |
101 | + | -import javax.money.MonetaryAmount; | |
128 | 102 | - | |
129 | - | - @Test | |
130 | - | - public void testAmountWithNumberFormat1() { | |
131 | - | - FormattedMoneyHolder1 bean = new FormattedMoneyHolder1(); | |
132 | - | - DataBinder binder = new DataBinder(bean); | |
133 | - | - binder.setConversionService(conversionService); | |
134 | - | - | |
135 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
136 | - | - propertyValues.add("amount", "$10.50"); | |
137 | - | - binder.bind(propertyValues); | |
138 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
139 | - | - assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount")); | |
140 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
141 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
142 | - | - | |
143 | - | - LocaleContextHolder.setLocale(Locale.CANADA); | |
144 | - | - binder.bind(propertyValues); | |
145 | - | - LocaleContextHolder.setLocale(Locale.US); | |
146 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
147 | - | - assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount")); | |
148 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
149 | - | - assertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode()); | |
150 | - | - } | |
103 | + | -import org.springframework.context.support.EmbeddedValueResolutionSupport; | |
104 | + | -import org.springframework.format.AnnotationFormatterFactory; | |
105 | + | -import org.springframework.format.Formatter; | |
106 | + | -import org.springframework.format.Parser; | |
107 | + | -import org.springframework.format.Printer; | |
108 | + | -import org.springframework.format.annotation.NumberFormat; | |
109 | + | -import org.springframework.format.annotation.NumberFormat.Style; | |
110 | + | -import org.springframework.format.number.CurrencyStyleFormatter; | |
111 | + | -import org.springframework.format.number.NumberStyleFormatter; | |
112 | + | -import org.springframework.format.number.PercentStyleFormatter; | |
113 | + | -import org.springframework.util.StringUtils; | |
151 | 114 | - | |
152 | - | - @Test | |
153 | - | - public void testAmountWithNumberFormat2() { | |
154 | - | - FormattedMoneyHolder2 bean = new FormattedMoneyHolder2(); | |
155 | - | - DataBinder binder = new DataBinder(bean); | |
156 | - | - binder.setConversionService(conversionService); | |
157 | - | - | |
158 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
159 | - | - propertyValues.add("amount", "10.50"); | |
160 | - | - binder.bind(propertyValues); | |
161 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
162 | - | - assertEquals("10.5", binder.getBindingResult().getFieldValue("amount")); | |
163 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
164 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
165 | - | - } | |
115 | + | -/** | |
116 | + | - * Formats {@link javax.money.MonetaryAmount} fields annotated | |
117 | + | - * with Spring's common {@link NumberFormat} annotation. | |
118 | + | - * | |
119 | + | - * @author Juergen Hoeller | |
120 | + | - * @since 4.2 | |
121 | + | - * @see NumberFormat | |
122 | + | - */ | |
123 | + | -public class Jsr354NumberFormatAnnotationFormatterFactory extends EmbeddedValueResolutionSupport | |
124 | + | - implements AnnotationFormatterFactory<NumberFormat> { | |
125 | + | - | |
126 | + | - private static final String CURRENCY_CODE_PATTERN = "\u00A4\u00A4"; | |
166 | 127 | - | |
167 | - | - @Test | |
168 | - | - public void testAmountWithNumberFormat3() { | |
169 | - | - FormattedMoneyHolder3 bean = new FormattedMoneyHolder3(); | |
170 | - | - DataBinder binder = new DataBinder(bean); | |
171 | - | - binder.setConversionService(conversionService); | |
172 | - | - | |
173 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
174 | - | - propertyValues.add("amount", "10%"); | |
175 | - | - binder.bind(propertyValues); | |
176 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
177 | - | - assertEquals("10%", binder.getBindingResult().getFieldValue("amount")); | |
178 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 0.1d); | |
179 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
128 | + | - | |
129 | + | - @Override | |
130 | + | - @SuppressWarnings("unchecked") | |
131 | + | - public Set<Class<?>> getFieldTypes() { | |
132 | + | - return (Set) Collections.singleton(MonetaryAmount.class); | |
180 | 133 | - } | |
181 | 134 | - | |
182 | - | - @Test | |
183 | - | - public void testAmountWithNumberFormat4() { | |
184 | - | - FormattedMoneyHolder4 bean = new FormattedMoneyHolder4(); | |
185 | - | - DataBinder binder = new DataBinder(bean); | |
186 | - | - binder.setConversionService(conversionService); | |
187 | - | - | |
188 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
189 | - | - propertyValues.add("amount", "010.500"); | |
190 | - | - binder.bind(propertyValues); | |
191 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
192 | - | - assertEquals("010.500", binder.getBindingResult().getFieldValue("amount")); | |
193 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
194 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
135 | + | - @Override | |
136 | + | - public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) { | |
137 | + | - return configureFormatterFrom(annotation); | |
195 | 138 | - } | |
196 | 139 | - | |
197 | - | - @Test | |
198 | - | - public void testAmountWithNumberFormat5() { | |
199 | - | - FormattedMoneyHolder5 bean = new FormattedMoneyHolder5(); | |
200 | - | - DataBinder binder = new DataBinder(bean); | |
201 | - | - binder.setConversionService(conversionService); | |
202 | - | - | |
203 | - | - MutablePropertyValues propertyValues = new MutablePropertyValues(); | |
204 | - | - propertyValues.add("amount", "USD 10.50"); | |
205 | - | - binder.bind(propertyValues); | |
206 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
207 | - | - assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount")); | |
208 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
209 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
210 | - | - | |
211 | - | - LocaleContextHolder.setLocale(Locale.CANADA); | |
212 | - | - binder.bind(propertyValues); | |
213 | - | - LocaleContextHolder.setLocale(Locale.US); | |
214 | - | - assertEquals(0, binder.getBindingResult().getErrorCount()); | |
215 | - | - assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount")); | |
216 | - | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); | |
217 | - | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); | |
140 | + | - @Override | |
141 | + | - public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) { | |
142 | + | - return configureFormatterFrom(annotation); | |
218 | 143 | - } | |
219 | 144 | - | |
220 | 145 | - | |
221 | - | - public static class MoneyHolder { | |
146 | + | - private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) { | |
147 | + | - if (StringUtils.hasLength(annotation.pattern())) { | |
148 | + | - return new PatternDecoratingFormatter(resolveEmbeddedValue(annotation.pattern())); | |
149 | + | - } | |
150 | + | - else { | |
151 | + | - Style style = annotation.style(); | |
152 | + | - if (style == Style.NUMBER) { | |
153 | + | - return new NumberDecoratingFormatter(new NumberStyleFormatter()); | |
154 | + | - } | |
155 | + | - else if (style == Style.PERCENT) { | |
156 | + | - return new NumberDecoratingFormatter(new PercentStyleFormatter()); | |
157 | + | - } | |
158 | + | - else { | |
159 | + | - return new NumberDecoratingFormatter(new CurrencyStyleFormatter()); | |
160 | + | - } | |
161 | + | - } | |
162 | + | - } | |
222 | 163 | - | |
223 | - | - private MonetaryAmount amount; | |
224 | 164 | - | |
225 | - | - private CurrencyUnit unit; | |
165 | + | - private static class NumberDecoratingFormatter implements Formatter<MonetaryAmount> { | |
226 | 166 | - | |
227 | - | - public MonetaryAmount getAmount() { | |
228 | - | - return amount; | |
229 | - | - } | |
167 | + | - private final Formatter<Number> numberFormatter; | |
230 | 168 | - | |
231 | - | - public void setAmount(MonetaryAmount amount) { | |
232 | - | - this.amount = amount; | |
169 | + | - public NumberDecoratingFormatter(Formatter<Number> numberFormatter) { | |
170 | + | - this.numberFormatter = numberFormatter; | |
233 | 171 | - } | |
234 | 172 | - | |
235 | - | - public CurrencyUnit getUnit() { | |
236 | - | - return unit; | |
173 | + | - @Override | |
174 | + | - public String print(MonetaryAmount object, Locale locale) { | |
175 | + | - return this.numberFormatter.print(object.getNumber(), locale); | |
237 | 176 | - } | |
238 | 177 | - | |
239 | - | - public void setUnit(CurrencyUnit unit) { | |
240 | - | - this.unit = unit; | |
178 | + | - @Override | |
179 | + | - public MonetaryAmount parse(String text, Locale locale) throws ParseException { | |
180 | + | - CurrencyUnit currencyUnit = Monetary.getCurrency(locale); | |
181 | + | - Number numberValue = this.numberFormatter.parse(text, locale); | |
182 | + | - return Monetary.getDefaultAmountFactory().setNumber(numberValue).setCurrency(currencyUnit).create(); | |
241 | 183 | - } | |
242 | 184 | - } | |
243 | 185 | - | |
244 | 186 | - | |
245 | - | - public static class FormattedMoneyHolder1 { | |
187 | + | - private static class PatternDecoratingFormatter implements Formatter<MonetaryAmount> { | |
246 | 188 | - | |
247 | - | - @NumberFormat | |
248 | - | - private MonetaryAmount amount; | |
189 | + | - private final String pattern; | |
249 | 190 | - | |
250 | - | - public MonetaryAmount getAmount() { | |
251 | - | - return amount; | |
191 | + | - public PatternDecoratingFormatter(String pattern) { | |
192 | + | - this.pattern = pattern; | |
252 | 193 | - } | |
253 | 194 | - | |
254 | - | - public void setAmount(MonetaryAmount amount) { | |
255 | - | - this.amount = amount; | |
195 | + | - @Override | |
196 | + | - public String print(MonetaryAmount object, Locale locale) { | |
197 | + | - CurrencyStyleFormatter formatter = new CurrencyStyleFormatter(); | |
198 | + | - formatter.setCurrency(Currency.getInstance(object.getCurrency().getCurrencyCode())); | |
199 | + | - formatter.setPattern(this.pattern); | |
200 | + | - return formatter.print(object.getNumber(), locale); | |
256 | 201 | - } | |
257 | - | - } | |
258 | 202 | - | |
259 | - | - | |
260 | - | - public static class FormattedMoneyHolder2 { | |
261 | - | - | |
262 | - | - @NumberFormat(style = NumberFormat.Style.NUMBER) | |
263 | - | - private MonetaryAmount amount; | |
264 | - | - | |
265 | - | - public MonetaryAmount getAmount() { | |
266 | - | - return amount; | |
203 | + | - @Override | |
204 | + | - public MonetaryAmount parse(String text, Locale locale) throws ParseException { | |
205 | + | - CurrencyStyleFormatter formatter = new CurrencyStyleFormatter(); | |
206 | + | - Currency currency = determineCurrency(text, locale); | |
207 | + | - CurrencyUnit currencyUnit = Monetary.getCurrency(currency.getCurrencyCode()); | |
208 | + | - formatter.setCurrency(currency); | |
209 | + | - formatter.setPattern(this.pattern); | |
210 | + | - Number numberValue = formatter.parse(text, locale); | |
211 | + | - return Monetary.getDefaultAmountFactory().setNumber(numberValue).setCurrency(currencyUnit).create(); | |
267 | 212 | - } | |
268 | 213 | - | |
269 | - | - public void setAmount(MonetaryAmount amount) { | |
270 | - | - this.amount = amount; | |
214 | + | - private Currency determineCurrency(String text, Locale locale) { | |
215 | + | - try { | |
216 | + | - if (text.length() < 3) { | |
217 | + | - // Could not possibly contain a currency code -> | |
218 | + | - // try with locale and likely let it fail on parse. | |
219 | + | - return Currency.getInstance(locale); | |
220 | + | - } | |
221 | + | - else if (this.pattern.startsWith(CURRENCY_CODE_PATTERN)) { | |
222 | + | - return Currency.getInstance(text.substring(0, 3)); | |
223 | + | - } | |
224 | + | - else if (this.pattern.endsWith(CURRENCY_CODE_PATTERN)) { | |
225 | + | - return Currency.getInstance(text.substring(text.length() - 3)); | |
226 | + | - } | |
227 | + | - else { | |
228 | + | - // A pattern without a currency code... | |
229 | + | - return Currency.getInstance(locale); | |
230 | + | - } | |
231 | + | - } | |
232 | + | - catch (IllegalArgumentException ex) { | |
233 | + | - throw new IllegalArgumentException("Cannot determine currency for number value [" + text + "]", ex); | |
234 | + | - } | |
271 | 235 | - } | |
272 | 236 | - } | |
273 | 237 | - | |
238 | + | -} | |
239 | + | diff --git a/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java b/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java | |
240 | + | deleted file mode 100644 | |
241 | + | index 8d949ac..0000000 | |
242 | + | --- a/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java | |
243 | + | +++ /dev/null | |
244 | + | @@ -1,96 +0,0 @@ | |
245 | + | -/* | |
246 | + | - * Copyright 2002-2015 the original author or authors. | |
247 | + | - * | |
248 | + | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
249 | + | - * you may not use this file except in compliance with the License. | |
250 | + | - * You may obtain a copy of the License at | |
251 | + | - * | |
252 | + | - * http://www.apache.org/licenses/LICENSE-2.0 | |
253 | + | - * | |
254 | + | - * Unless required by applicable law or agreed to in writing, software | |
255 | + | - * distributed under the License is distributed on an "AS IS" BASIS, | |
256 | + | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
257 | + | - * See the License for the specific language governing permissions and | |
258 | + | - * limitations under the License. | |
259 | + | - */ | |
274 | 260 | - | |
275 | - | - public static class FormattedMoneyHolder3 { | |
261 | + | -package org.springframework.format.number.money; | |
276 | 262 | - | |
277 | - | - @NumberFormat(style = NumberFormat.Style.PERCENT) | |
278 | - | - private MonetaryAmount amount; | |
263 | + | -import java.util.Locale; | |
264 | + | -import javax.money.MonetaryAmount; | |
265 | + | -import javax.money.format.MonetaryAmountFormat; | |
266 | + | -import javax.money.format.MonetaryFormats; | |
279 | 267 | - | |
280 | - | - public MonetaryAmount getAmount() { | |
281 | - | - return amount; | |
282 | - | - } | |
268 | + | -import org.springframework.format.Formatter; | |
283 | 269 | - | |
284 | - | - public void setAmount(MonetaryAmount amount) { | |
285 | - | - this.amount = amount; | |
286 | - | - } | |
287 | - | - } | |
270 | + | -/** | |
271 | + | - * Formatter for JSR-354 {@link javax.money.MonetaryAmount} values, | |
272 | + | - * delegating to {@link javax.money.format.MonetaryAmountFormat#format} | |
273 | + | - * and {@link javax.money.format.MonetaryAmountFormat#parse}. | |
274 | + | - * | |
275 | + | - * @author Juergen Hoeller | |
276 | + | - * @since 4.2 | |
277 | + | - * @see #getMonetaryAmountFormat | |
278 | + | - */ | |
279 | + | -public class MonetaryAmountFormatter implements Formatter<MonetaryAmount> { | |
288 | 280 | - | |
281 | + | - private String formatName; | |
289 | 282 | - | |
290 | - | - public static class FormattedMoneyHolder4 { | |
291 | 283 | - | |
292 | - | - @NumberFormat(pattern = "#000.000#") | |
293 | - | - private MonetaryAmount amount; | |
284 | + | - /** | |
285 | + | - * Create a locale-driven MonetaryAmountFormatter. | |
286 | + | - */ | |
287 | + | - public MonetaryAmountFormatter() { | |
288 | + | - } | |
294 | 289 | - | |
295 | - | - public MonetaryAmount getAmount() { | |
296 | - | - return amount; | |
297 | - | - } | |
290 | + | - /** | |
291 | + | - * Create a new MonetaryAmountFormatter for the given format name. | |
292 | + | - * @param formatName the format name, to be resolved by the JSR-354 | |
293 | + | - * provider at runtime | |
294 | + | - */ | |
295 | + | - public MonetaryAmountFormatter(String formatName) { | |
296 | + | - this.formatName = formatName; | |
297 | + | - } | |
298 | 298 | - | |
299 | - | - public void setAmount(MonetaryAmount amount) { | |
300 | - | - this.amount = amount; | |
301 | - | - } | |
299 | + | - | |
300 | + | - /** | |
301 | + | - * Specify the format name, to be resolved by the JSR-354 provider | |
302 | + | - * at runtime. | |
303 | + | - * <p>Default is none, obtaining a {@link MonetaryAmountFormat} | |
304 | + | - * based on the current locale. | |
305 | + | - */ | |
306 | + | - public void setFormatName(String formatName) { | |
307 | + | - this.formatName = formatName; | |
302 | 308 | - } | |
303 | 309 | - | |
304 | 310 | - | |
305 | - | - public static class FormattedMoneyHolder5 { | |
311 | + | - @Override | |
312 | + | - public String print(MonetaryAmount object, Locale locale) { | |
313 | + | - return getMonetaryAmountFormat(locale).format(object); | |
314 | + | - } | |
306 | 315 | - | |
307 | - | - @NumberFormat(pattern = "\u00A4\u00A4 #000.000#") | |
308 | - | - private MonetaryAmount amount; | |
316 | + | - @Override | |
317 | + | - public MonetaryAmount parse(String text, Locale locale) { | |
318 | + | - return getMonetaryAmountFormat(locale).parse(text); | |
319 | + | - } | |
309 | 320 | - | |
310 | - | - public MonetaryAmount getAmount() { | |
311 | - | - return amount; | |
312 | - | - } | |
313 | 321 | - | |
314 | - | - public void setAmount(MonetaryAmount amount) { | |
315 | - | - this.amount = amount; | |
322 | + | - /** | |
323 | + | - * Obtain a MonetaryAmountFormat for the given locale. | |
324 | + | - * <p>The default implementation simply calls | |
325 | + | - * {@link javax.money.format.MonetaryFormats#getAmountFormat} | |
326 | + | - * with either the configured format name or the given locale. | |
327 | + | - * @param locale the current locale | |
328 | + | - * @return the MonetaryAmountFormat (never {@code null}) | |
329 | + | - * @see #setFormatName | |
330 | + | - */ | |
331 | + | - protected MonetaryAmountFormat getMonetaryAmountFormat(Locale locale) { | |
332 | + | - if (this.formatName != null) { | |
333 | + | - return MonetaryFormats.getAmountFormat(this.formatName); | |
334 | + | - } | |
335 | + | - else { | |
336 | + | - return MonetaryFormats.getAmountFormat(locale); | |
316 | 337 | - } | |
317 | 338 | - } | |
318 | 339 | - | |
319 | 340 | -} | |
341 | + | diff --git a/spring-context/src/main/java/org/springframework/format/number/money/package-info.java b/spring-context/src/main/java/org/springframework/format/number/money/package-info.java | |
342 | + | deleted file mode 100644 | |
343 | + | index d19fccf..0000000 | |
344 | + | --- a/spring-context/src/main/java/org/springframework/format/number/money/package-info.java | |
345 | + | +++ /dev/null | |
346 | + | @@ -1,4 +0,0 @@ | |
347 | + | -/** | |
348 | + | - * Integration with the JSR-354 <code>javax.money</code> package. | |
349 | + | - */ | |
350 | + | -package org.springframework.format.number.money; | |
351 | + | diff --git a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
352 | + | index 2c7c60a..5e38006 100644 | |
353 | + | --- a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
354 | + | +++ b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java | |
355 | + | @@ -21,9 +21,6 @@ import org.springframework.format.FormatterRegistry; | |
356 | + | import org.springframework.format.datetime.DateFormatterRegistrar; | |
357 | + | import org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar; | |
358 | + | import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; | |
359 | + | -import org.springframework.format.number.money.CurrencyUnitFormatter; | |
360 | + | -import org.springframework.format.number.money.Jsr354NumberFormatAnnotationFormatterFactory; | |
361 | + | -import org.springframework.format.number.money.MonetaryAmountFormatter; | |
362 | + | import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; | |
363 | + | import org.springframework.util.ClassUtils; | |
364 | + | import org.springframework.util.StringValueResolver; | |
365 | + | @@ -104,13 +101,6 @@ public class DefaultFormattingConversionService extends FormattingConversionServ | |
366 | + | // Default handling of number values | |
367 | + | formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); | |
368 | + | ||
369 | + | - // Default handling of monetary values | |
370 | + | - if (jsr354Present) { | |
371 | + | - formatterRegistry.addFormatter(new CurrencyUnitFormatter()); | |
372 | + | - formatterRegistry.addFormatter(new MonetaryAmountFormatter()); | |
373 | + | - formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory()); | |
374 | + | - } | |
375 | + | - | |
376 | + | // Default handling of date-time values | |
377 | + | if (jsr310Present) { | |
378 | + | // just handling JSR-310 specific date and time types | |
320 | 379 | -- | |
321 | 380 | 2.18.0 | |
322 | 381 |
more/packages/geo.scm
28 | 28 | #:use-module (gnu packages boost) | |
29 | 29 | #:use-module (gnu packages compression) | |
30 | 30 | #:use-module (gnu packages databases) | |
31 | + | #:use-module (gnu packages datastructures) | |
32 | + | #:use-module (gnu packages documentation) | |
31 | 33 | #:use-module (gnu packages geo) | |
32 | 34 | #:use-module (gnu packages image) | |
33 | 35 | #:use-module (gnu packages lua) | |
… | |||
67 | 69 | delivered to any client.") | |
68 | 70 | (license license:expat))) | |
69 | 71 | ||
72 | + | (define-public protozero | |
73 | + | (package | |
74 | + | (name "protozero") | |
75 | + | (version "1.6.3") | |
76 | + | (source | |
77 | + | (origin | |
78 | + | (method url-fetch) | |
79 | + | (uri (string-append "https://github.com/mapbox/protozero/archive/v" | |
80 | + | version ".tar.gz")) | |
81 | + | (file-name (string-append name "-" version ".tar.gz")) | |
82 | + | (sha256 | |
83 | + | (base32 | |
84 | + | "1xaj4phz1r7xn0vgdfvfkz8b0bizgb6mavjky1zqcvdmbwgwgly5")))) | |
85 | + | (build-system cmake-build-system) | |
86 | + | (home-page "https://github.com/mapbox/protozero") | |
87 | + | (synopsis "Minimalistic protocol buffer decoder and encoder in C++") | |
88 | + | (description "Protozero is a minimalistic protocol buffer decored and | |
89 | + | encoder in C++. The developer using protozero has to manually translate the | |
90 | + | @file{.proto} description into code.") | |
91 | + | (license (list | |
92 | + | license:asl2.0; for folly | |
93 | + | license:bsd-2)))) | |
94 | + | ||
95 | + | (define-public libosmium | |
96 | + | (package | |
97 | + | (name "libosmium") | |
98 | + | (version "2.14.2") | |
99 | + | (source | |
100 | + | (origin | |
101 | + | (method url-fetch) | |
102 | + | (uri (string-append "https://github.com/osmcode/libosmium/archive/v" | |
103 | + | version ".tar.gz")) | |
104 | + | (file-name (string-append name "-" version ".tar.gz")) | |
105 | + | (sha256 | |
106 | + | (base32 | |
107 | + | "0d9b46qiw7zkw1h9lygjdwqxnbhm3c7v8kydzw9f9f778cyagc94")))) | |
108 | + | (build-system cmake-build-system) | |
109 | + | (inputs | |
110 | + | `(("boost" ,boost) | |
111 | + | ("expat" ,expat) | |
112 | + | ("gdal" ,gdal) | |
113 | + | ("geos" ,geos) | |
114 | + | ("proj.4" ,proj.4) | |
115 | + | ("protozero" ,protozero) | |
116 | + | ("sparsehash" ,sparsehash) | |
117 | + | ("zlib" ,zlib))) | |
118 | + | (native-inputs | |
119 | + | `(("doxygen" ,doxygen))) | |
120 | + | (home-page "https://osmcode.org/libosmium") | |
121 | + | (synopsis "C++ library for working with OpenStreetMap data") | |
122 | + | (description "Libosmium is a fast and flexible C++ library for working with | |
123 | + | OpenStreetMap data.") | |
124 | + | (license license:boost1.0))) | |
125 | + | ||
70 | 126 | (define-public imposm3 | |
71 | 127 | (package | |
72 | 128 | (name "imposm3") | |
… | |||
146 | 202 | "08y7776r4l9v9177a4q6cfdri0lpirky96m6g699hwl7v1vhw0mn")))) | |
147 | 203 | (build-system cmake-build-system) | |
148 | 204 | (arguments | |
149 | - | ;; failure :/ | |
205 | + | ;; failure | |
150 | 206 | `(#:tests? #f)) | |
151 | 207 | (inputs | |
152 | 208 | `(("boost" ,boost) |
more/packages/java.scm
1254 | 1254 | (define-public java-josm | |
1255 | 1255 | (package | |
1256 | 1256 | (name "java-josm") | |
1257 | - | (version "14066") | |
1257 | + | (version "14178") | |
1258 | 1258 | (source (origin | |
1259 | 1259 | (method svn-fetch) | |
1260 | 1260 | (uri (svn-reference | |
… | |||
1262 | 1262 | (revision (string->number version)))) | |
1263 | 1263 | (sha256 | |
1264 | 1264 | (base32 | |
1265 | - | "1kf7cr80n2y9dwjabn8l9r5n64kjf8vk0ial1fzc870gg785s7cw")) | |
1265 | + | "1k03g6kxzs8gwswc48cgx6m689sssg73m1yfjdqc8zsky75fmz2d")) | |
1266 | 1266 | (file-name (string-append name "-" version)) | |
1267 | 1267 | (modules '((guix build utils))) | |
1268 | 1268 | (snippet | |
… | |||
5820 | 5820 | (native-inputs | |
5821 | 5821 | `(("icedtea-8" ,icedtea-8) | |
5822 | 5822 | ("icedtea-8:jdk" ,icedtea-8 "jdk") | |
5823 | - | ("gcc" ,gcc) | |
5824 | 5823 | ("unzip" ,unzip) | |
5825 | 5824 | ("which" ,which) | |
5826 | 5825 | ("zip" ,zip))) |