@Test public void testEnsureCorrectFileName() throws Exception { assertEquals("somefile_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_a.png", "SHOP10", "SHOP_IMAGE0")); assertEquals("somefile_SHOP10_b.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_b.png", "SHOP10", "SHOP_IMAGE1")); assertEquals("somefile_SHOP10_b_en.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_b_en.png", "SHOP10", "SHOP_IMAGE1_en")); assertEquals("somefile_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("somefile.png", "SHOP10", "SHOP_IMAGE0")); assertEquals("somefile_SHOP10_b.png", VoIOSupportImpl.ensureCorrectFileName("somefile.png", "SHOP10", "SHOP_IMAGE1")); assertEquals("somefile_SHOP10_b_en.png", VoIOSupportImpl.ensureCorrectFileName("somefile.png", "SHOP10", "SHOP_IMAGE1_en")); assertEquals("somefile_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_c.png", "SHOP10", "SHOP_IMAGE0")); assertEquals("somefile_SHOP10_b.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_c_ru.png", "SHOP10", "SHOP_IMAGE1")); assertEquals("somefile_SHOP10_b_en.png", VoIOSupportImpl.ensureCorrectFileName("somefile_SHOP10_c_en.png", "SHOP10", "SHOP_IMAGE1_en")); assertEquals("some-fi-le_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("some fi le_SHOP10_a.png", "SHOP10", "SHOP_IMAGE0")); assertEquals("some-fi-le_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("some fi le.png", "SHOP10", "SHOP_IMAGE0")); assertEquals("some-fi-le_SHOP10_a.png", VoIOSupportImpl.ensureCorrectFileName("some fi le_SHOP10_c.png", "SHOP10", "SHOP_IMAGE0")); }
static String ensureCorrectFileName(final String fileName, final String objectCode, final String attributeImageCode) { String formatted = fileName; if (StringUtils.isNotBlank(objectCode)) { final String codePlaceholder = "_" + objectCode + "_"; if (fileName.contains(codePlaceholder)) { final int placeholderPos = fileName.lastIndexOf(codePlaceholder); final int extPos = fileName.lastIndexOf('.'); String name = fileName.substring(0, extPos).toLowerCase(); name = name.substring(0, placeholderPos); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } else { final int extPos = fileName.lastIndexOf('.'); final String name = fileName.substring(0, extPos).toLowerCase(); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } } return formatted.replace(' ', '-'); }
VoIOSupportImpl implements VoIOSupport { static String ensureCorrectFileName(final String fileName, final String objectCode, final String attributeImageCode) { String formatted = fileName; if (StringUtils.isNotBlank(objectCode)) { final String codePlaceholder = "_" + objectCode + "_"; if (fileName.contains(codePlaceholder)) { final int placeholderPos = fileName.lastIndexOf(codePlaceholder); final int extPos = fileName.lastIndexOf('.'); String name = fileName.substring(0, extPos).toLowerCase(); name = name.substring(0, placeholderPos); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } else { final int extPos = fileName.lastIndexOf('.'); final String name = fileName.substring(0, extPos).toLowerCase(); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } } return formatted.replace(' ', '-'); } }
VoIOSupportImpl implements VoIOSupport { static String ensureCorrectFileName(final String fileName, final String objectCode, final String attributeImageCode) { String formatted = fileName; if (StringUtils.isNotBlank(objectCode)) { final String codePlaceholder = "_" + objectCode + "_"; if (fileName.contains(codePlaceholder)) { final int placeholderPos = fileName.lastIndexOf(codePlaceholder); final int extPos = fileName.lastIndexOf('.'); String name = fileName.substring(0, extPos).toLowerCase(); name = name.substring(0, placeholderPos); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } else { final int extPos = fileName.lastIndexOf('.'); final String name = fileName.substring(0, extPos).toLowerCase(); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } } return formatted.replace(' ', '-'); } VoIOSupportImpl(final DtoImageService dtoImageService,
                           final DtoFileService dtoFileService,
                           final SystemService systemService); }
VoIOSupportImpl implements VoIOSupport { static String ensureCorrectFileName(final String fileName, final String objectCode, final String attributeImageCode) { String formatted = fileName; if (StringUtils.isNotBlank(objectCode)) { final String codePlaceholder = "_" + objectCode + "_"; if (fileName.contains(codePlaceholder)) { final int placeholderPos = fileName.lastIndexOf(codePlaceholder); final int extPos = fileName.lastIndexOf('.'); String name = fileName.substring(0, extPos).toLowerCase(); name = name.substring(0, placeholderPos); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } else { final int extPos = fileName.lastIndexOf('.'); final String name = fileName.substring(0, extPos).toLowerCase(); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } } return formatted.replace(' ', '-'); } VoIOSupportImpl(final DtoImageService dtoImageService,
                           final DtoFileService dtoFileService,
                           final SystemService systemService); @Override String addFileToRepository(final String fileName,
                                      final String code,
                                      final String attributeFileCode,
                                      final String base64URL,
                                      final String storagePrefix); @Override String addSystemFileToRepository(final String fileName,
                                            final String code,
                                            final String attributeFileCode,
                                            final String base64URL,
                                            final String storagePrefix); @Override String addImageToRepository(final String fileName,
                                       final String code,
                                       final String attributeImageCode,
                                       final String base64URL,
                                       final String storagePrefix); @Override String getImageAsBase64(final String fileName,
                                   final String code,
                                   final String storagePrefix); }
VoIOSupportImpl implements VoIOSupport { static String ensureCorrectFileName(final String fileName, final String objectCode, final String attributeImageCode) { String formatted = fileName; if (StringUtils.isNotBlank(objectCode)) { final String codePlaceholder = "_" + objectCode + "_"; if (fileName.contains(codePlaceholder)) { final int placeholderPos = fileName.lastIndexOf(codePlaceholder); final int extPos = fileName.lastIndexOf('.'); String name = fileName.substring(0, extPos).toLowerCase(); name = name.substring(0, placeholderPos); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } else { final int extPos = fileName.lastIndexOf('.'); final String name = fileName.substring(0, extPos).toLowerCase(); final String ext = fileName.substring(extPos + 1).toLowerCase(); final String suffix = determineFileSuffix(attributeImageCode); formatted = name + "_" + objectCode + "_" + suffix + "." + ext; } } return formatted.replace(' ', '-'); } VoIOSupportImpl(final DtoImageService dtoImageService,
                           final DtoFileService dtoFileService,
                           final SystemService systemService); @Override String addFileToRepository(final String fileName,
                                      final String code,
                                      final String attributeFileCode,
                                      final String base64URL,
                                      final String storagePrefix); @Override String addSystemFileToRepository(final String fileName,
                                            final String code,
                                            final String attributeFileCode,
                                            final String base64URL,
                                            final String storagePrefix); @Override String addImageToRepository(final String fileName,
                                       final String code,
                                       final String attributeImageCode,
                                       final String base64URL,
                                       final String storagePrefix); @Override String getImageAsBase64(final String fileName,
                                   final String code,
                                   final String storagePrefix);  }