java-spring-framework-remove-non-free.patch
| 1 | From 03942913eb3b3a6458030856bfecc8a6927ab1ba Mon Sep 17 00:00:00 2001 |
| 2 | From: Julien Lepiller <julien@lepiller.eu> |
| 3 | Date: Sat, 15 Sep 2018 10:27:46 +0200 |
| 4 | Subject: [PATCH] Remove dependency on jsr354 (javax.currency). |
| 5 | |
| 6 | jsr354 is a non-free package: |
| 7 | https://github.com/JavaMoney/jsr354-api/blob/master/EVALUATION-LICENCE.txt |
| 8 | --- |
| 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 |
| 19 | |
| 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 |
| 21 | deleted file mode 100644 |
| 22 | index d3f4749..0000000 |
| 23 | --- a/spring-context/src/main/java/org/springframework/format/number/money/CurrencyUnitFormatter.java |
| 24 | +++ /dev/null |
| 25 | @@ -1,44 +0,0 @@ |
| 26 | -/* |
| 27 | - * Copyright 2002-2015 the original author or authors. |
| 28 | - * |
| 29 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
| 30 | - * you may not use this file except in compliance with the License. |
| 31 | - * You may obtain a copy of the License at |
| 32 | - * |
| 33 | - * http://www.apache.org/licenses/LICENSE-2.0 |
| 34 | - * |
| 35 | - * Unless required by applicable law or agreed to in writing, software |
| 36 | - * distributed under the License is distributed on an "AS IS" BASIS, |
| 37 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 38 | - * See the License for the specific language governing permissions and |
| 39 | - * limitations under the License. |
| 40 | - */ |
| 41 | - |
| 42 | -package org.springframework.format.number.money; |
| 43 | - |
| 44 | -import java.util.Locale; |
| 45 | -import javax.money.CurrencyUnit; |
| 46 | -import javax.money.Monetary; |
| 47 | - |
| 48 | -import org.springframework.format.Formatter; |
| 49 | - |
| 50 | -/** |
| 51 | - * Formatter for JSR-354 {@link javax.money.CurrencyUnit} values, |
| 52 | - * from and to currency code Strings. |
| 53 | - * |
| 54 | - * @author Juergen Hoeller |
| 55 | - * @since 4.2 |
| 56 | - */ |
| 57 | -public class CurrencyUnitFormatter implements Formatter<CurrencyUnit> { |
| 58 | - |
| 59 | - @Override |
| 60 | - public String print(CurrencyUnit object, Locale locale) { |
| 61 | - return object.getCurrencyCode(); |
| 62 | - } |
| 63 | - |
| 64 | - @Override |
| 65 | - public CurrencyUnit parse(String text, Locale locale) { |
| 66 | - return Monetary.getCurrency(text); |
| 67 | - } |
| 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; |
| 93 | - |
| 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; |
| 102 | - |
| 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; |
| 114 | - |
| 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"; |
| 127 | - |
| 128 | - |
| 129 | - @Override |
| 130 | - @SuppressWarnings("unchecked") |
| 131 | - public Set<Class<?>> getFieldTypes() { |
| 132 | - return (Set) Collections.singleton(MonetaryAmount.class); |
| 133 | - } |
| 134 | - |
| 135 | - @Override |
| 136 | - public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) { |
| 137 | - return configureFormatterFrom(annotation); |
| 138 | - } |
| 139 | - |
| 140 | - @Override |
| 141 | - public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) { |
| 142 | - return configureFormatterFrom(annotation); |
| 143 | - } |
| 144 | - |
| 145 | - |
| 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 | - } |
| 163 | - |
| 164 | - |
| 165 | - private static class NumberDecoratingFormatter implements Formatter<MonetaryAmount> { |
| 166 | - |
| 167 | - private final Formatter<Number> numberFormatter; |
| 168 | - |
| 169 | - public NumberDecoratingFormatter(Formatter<Number> numberFormatter) { |
| 170 | - this.numberFormatter = numberFormatter; |
| 171 | - } |
| 172 | - |
| 173 | - @Override |
| 174 | - public String print(MonetaryAmount object, Locale locale) { |
| 175 | - return this.numberFormatter.print(object.getNumber(), locale); |
| 176 | - } |
| 177 | - |
| 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(); |
| 183 | - } |
| 184 | - } |
| 185 | - |
| 186 | - |
| 187 | - private static class PatternDecoratingFormatter implements Formatter<MonetaryAmount> { |
| 188 | - |
| 189 | - private final String pattern; |
| 190 | - |
| 191 | - public PatternDecoratingFormatter(String pattern) { |
| 192 | - this.pattern = pattern; |
| 193 | - } |
| 194 | - |
| 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); |
| 201 | - } |
| 202 | - |
| 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(); |
| 212 | - } |
| 213 | - |
| 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 | - } |
| 235 | - } |
| 236 | - } |
| 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 | - */ |
| 260 | - |
| 261 | -package org.springframework.format.number.money; |
| 262 | - |
| 263 | -import java.util.Locale; |
| 264 | -import javax.money.MonetaryAmount; |
| 265 | -import javax.money.format.MonetaryAmountFormat; |
| 266 | -import javax.money.format.MonetaryFormats; |
| 267 | - |
| 268 | -import org.springframework.format.Formatter; |
| 269 | - |
| 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> { |
| 280 | - |
| 281 | - private String formatName; |
| 282 | - |
| 283 | - |
| 284 | - /** |
| 285 | - * Create a locale-driven MonetaryAmountFormatter. |
| 286 | - */ |
| 287 | - public MonetaryAmountFormatter() { |
| 288 | - } |
| 289 | - |
| 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 | - |
| 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; |
| 308 | - } |
| 309 | - |
| 310 | - |
| 311 | - @Override |
| 312 | - public String print(MonetaryAmount object, Locale locale) { |
| 313 | - return getMonetaryAmountFormat(locale).format(object); |
| 314 | - } |
| 315 | - |
| 316 | - @Override |
| 317 | - public MonetaryAmount parse(String text, Locale locale) { |
| 318 | - return getMonetaryAmountFormat(locale).parse(text); |
| 319 | - } |
| 320 | - |
| 321 | - |
| 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); |
| 337 | - } |
| 338 | - } |
| 339 | - |
| 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 |
| 379 | -- |
| 380 | 2.18.0 |
| 381 | |
| 382 |