Catalog alignment
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / util / ValidationUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.common.util;
22
23 import com.google.common.base.CharMatcher;
24 import org.apache.commons.collections.CollectionUtils;
25 import org.apache.commons.lang3.StringEscapeUtils;
26 import org.apache.commons.lang3.StringUtils;
27 import org.apache.commons.lang3.math.NumberUtils;
28 import org.apache.commons.lang3.text.WordUtils;
29 import org.apache.commons.validator.routines.UrlValidator;
30 import org.jsoup.Jsoup;
31 import org.jsoup.helper.StringUtil;
32 import org.jsoup.safety.Whitelist;
33
34 import java.util.*;
35 import java.util.regex.Pattern;
36
37 public class ValidationUtils {
38         public final static Integer COMPONENT_NAME_MAX_LENGTH = 1024;
39         public final static Pattern COMPONENT_NAME_PATTERN = Pattern
40                         .compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (COMPONENT_NAME_MAX_LENGTH-1) + "}$");
41         public final static Integer ADDITIONAL_INFORMATION_KEY_MAX_LENGTH = 50;
42         public final static Pattern ADDITIONAL_INFORMATION_KEY_PATTERN = Pattern
43                         .compile("^[\\w\\s\\.\\-\\_]{1," + COMPONENT_NAME_MAX_LENGTH + "}$");
44         public final static Integer RSI_NAME_MAX_LENGTH = 1024;
45         public final static Pattern RSI_NAME_PATTERN = Pattern
46                         .compile("^[\\w \\s\\.\\-\\_\\:\\+]{1," + RSI_NAME_MAX_LENGTH + "}$");
47         public final static Integer COMMENT_MAX_LENGTH = 256;
48
49         public final static Integer ICON_MAX_LENGTH = 25;
50         public final static Pattern ICON_PATTERN = Pattern.compile("^[\\w\\-]{1," + ICON_MAX_LENGTH + "}$");
51         public final static Integer PROJECT_CODE_MAX_LEGTH = 50;
52         public final static Pattern PROJECT_CODE_PATTERN = Pattern.compile("^[\\s\\w_.-]{5,50}$");
53
54         // USER_ID format : aannnX (where a=a-z or A-Z, n=0-9, and X=a-z,A-Z, or 0-9)
55         public final static Integer CONNTACT_ID_MAX_LENGTH = 50;
56         //      public final static Pattern CONTACT_ID_PATTERN = Pattern
57 //                      .compile("[mM]{1}[0-9]{5}|[a-zA-Z]{2}[0-9]{4}|[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{1}");
58         public final static Pattern CONTACT_ID_PATTERN = Pattern.compile("^[\\s\\w_.-]{1,50}$");
59         public final static Pattern OCTET_PATTERN = Pattern.compile("%[a-fA-F0-9]{2}");
60         public final static Pattern NONE_UTF8_PATTERN = Pattern.compile("[^\\x00-\\x7F]+");
61         public final static Pattern URL_INVALIDE_PATTERN = Pattern.compile("[,#?&@$<>~^`\\\\\\[\\]{}|\")(*!+=;%]+");// ,#?&@$<>~^`\\[]{}|")(*!
62
63         public final static Pattern ENGLISH_PATTERN = Pattern.compile("^[\\p{Graph}\\x20]+$");
64         public final static Pattern COMMENT_PATTERN = Pattern.compile("^[\\u0000-\\u00BF]{1,1024}$");
65         public final static Pattern SERVICE_METADATA_PATTERN = Pattern.compile("^[\\x20-\\x21\\x23-\\x29\\x2B-\\x2E\\x30-\\x39\\x3B\\x3D\\x40-\\x5B\\x5D-\\x7B\\x7D-\\xFF]{1,256}");
66         public final static Integer COMPONENT_DESCRIPTION_MAX_LENGTH = 1024;
67         public final static Integer SERVICE_TYPE_MAX_LENGTH = 256;
68         public final static Integer SERVICE_ROLE_MAX_LENGTH = 256;
69         public final static Integer SERVICE_FUNCTION_MAX_LENGTH = 256;
70         public final static Integer SERVICE_NAMING_POLICY_MAX_SIZE = 100;
71
72         public final static Integer TAG_MAX_LENGTH = 1024;
73         public final static Integer TAG_LIST_MAX_LENGTH = 1024;
74         public final static Integer VENDOR_NAME_MAX_LENGTH = 60;
75         public final static Pattern VENDOR_NAME_PATTERN = Pattern
76                         .compile("^[\\x20-\\x21\\x23-\\x29\\x2B-\\x2E\\x30-\\x39\\x3B\\x3D\\x40-\\x5B\\x5D-\\x7B\\x7D-\\xFF]+$");
77         public final static Integer VENDOR_RELEASE_MAX_LENGTH = 25;
78         public final static Pattern VENDOR_RELEASE_PATTERN = Pattern
79                         .compile("^[\\x20-\\x21\\x23-\\x29\\x2B-\\x2E\\x30-\\x39\\x3B\\x3D\\x40-\\x5B\\x5D-\\x7B\\x7D-\\xFF]+$");
80         public final static Integer RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH = 65;
81
82         public final static Pattern CLEAN_FILENAME_PATTERN = Pattern.compile("[\\x00-\\x1f\\x80-\\x9f\\x5c/<?>\\*:|\"/]+");
83
84         public final static Pattern DASH_PATTERN = Pattern.compile("[-]+");
85         public final static Pattern UNDERSCORE_PATTERN = Pattern.compile("[_]+");
86         public final static Pattern PLUS_PATTERN = Pattern.compile("[+]+");
87         public final static Pattern SPACE_PATTERN = Pattern.compile("[ ]+");
88         public final static Pattern AMP_PATTERN = Pattern.compile("[&]+");
89         public final static Pattern DOT_PATTERN = Pattern.compile("[\\.]+");
90         public final static Pattern APOST_PATTERN = Pattern.compile("[']+");
91         public final static Pattern HASHTAG_PATTERN = Pattern.compile("[#]+");
92         public final static Pattern EQUAL_PATTERN = Pattern.compile("[=]+");
93         public final static Pattern COLON_PATTERN = Pattern.compile("[:]+");
94         public final static Pattern AT_PATTERN = Pattern.compile("[@]+");
95         public final static Pattern AND_PATTERN = Pattern.compile(" [aA][Nn][Dd] ");
96         public final static Set<String> CATEGORY_CONJUNCTIONS = new HashSet<>(
97                         Arrays.asList("of", "to", "for", "as", "a", "an", "the"));
98
99         public final static Pattern COST_PATTERN = Pattern.compile("^[0-9]{1,5}\\.[0-9]{1,3}$");
100         public final static Pattern ARTIFACT_LABEL_PATTERN = Pattern.compile("^[a-zA-Z0-9 \\-+]+$");
101         public final static Integer ARTIFACT_LABEL_LENGTH = 255;
102         public final static Pattern ARTIFACT_DISPLAY_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9 &\\.'#=:@_\\-+]+$");
103         public final static Pattern CATEGORY_LABEL_PATTERN = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9 &\\.'#=:@_\\-+]+$");
104         public final static Integer CATEGORY_LABEL_MIN_LENGTH = 3;
105         public final static Integer CATEGORY_LABEL_MAX_LENGTH = 25;
106
107         public final static Pattern COMPONENT_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-\\_]+");
108         public final static Pattern COMPONENT_INCTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+");
109         public final static Pattern PRODUCT_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-\\_&=#@':\\[\\]\\+]+");
110         public final static Integer CONSUMER_NAME_MAX_LENGTH = 255;
111         // public final static Pattern CONSUMER_NAME_PATTERN =
112         // Pattern.compile("^[\\w]{1}?[\\w\\.\\-]{0," + CONSUMER_NAME_MAX_LENGTH +
113         // "}?$");
114         public final static Pattern CONSUMER_NAME_PATTERN = Pattern.compile("^[\\w]+[\\w\\.\\-]*$");
115         public final static Integer CONSUMER_SALT_LENGTH = 32;
116         public final static Integer CONSUMER_PASSWORD_LENGTH = 64;
117         public final static Pattern CONSUMER_PASS_SALT_PATTERN = Pattern.compile("^[a-z0-9]+$");
118         public final static Pattern FLOAT_PATTERN = Pattern.compile("^[\\d]+[\\.]{1}[\\d]+$");
119         public final static Pattern CERTIFIED_VERSION_PATTERN = Pattern.compile("^[1-9][0-9]*\\.0$");
120         public final static Pattern MINOR_VERSION_PATTERN = Pattern.compile("^0\\.[1-9][0-9]*$");
121         public final static Pattern TAGS_PATTERN = Pattern.compile("<[^><]*>");
122         public final static Pattern TAG_PATTERN = Pattern.compile("^[\\s\\w_.-]{1,1024}$");
123
124         public final static Integer ARTIFACT_NAME_LENGTH = 255;
125         public final static Integer API_URL_LENGTH = 100;
126         public final static Integer ARTIFACT_DESCRIPTION_MAX_LENGTH = 256;
127
128         public final static Integer PRODUCT_FULL_NAME_MIN_LENGTH = 4;
129         public final static Integer PRODUCT_FULL_NAME_MAX_LENGTH = 100;
130         public static final Integer FORWARDING_PATH_NAME_MAX_LENGTH = 100;
131         public final static Pattern FORWARDING_PATH_NAME_PATTERN = Pattern.compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (FORWARDING_PATH_NAME_MAX_LENGTH-1) + "}$");
132
133         public final static Integer POLICY_MAX_LENGTH = 1024;
134         public final static Pattern POLICY_NAME_PATTERN = Pattern
135                         .compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (POLICY_MAX_LENGTH-1) + "}$");
136
137         public static boolean validateArtifactLabel(String label) {
138                 return ARTIFACT_LABEL_PATTERN.matcher(label).matches();
139         }
140
141         public static boolean validateArtifactDisplayName(String displayName) {
142                 return ARTIFACT_DISPLAY_NAME_PATTERN.matcher(displayName).matches();
143         }
144
145         public static String cleanUpText(String text){
146                 text = removeNoneUtf8Chars(text);
147                 text = normaliseWhitespace(text);
148                 text = stripOctets(text);
149                 text = removeHtmlTagsOnly(text);
150                 return text;
151         }
152
153         public static boolean validateTagPattern(String tag) {
154                 return TAG_PATTERN.matcher(tag).matches();
155         }
156
157         public static boolean validateServiceMetadata(String metadataField) {
158                 return SERVICE_METADATA_PATTERN.matcher(metadataField).matches();
159         }
160
161         public static boolean validateCommentPattern(String comment) {
162                 return COMMENT_PATTERN.matcher(comment).matches();
163         }
164
165         public static boolean validateCategoryDisplayNameFormat(String label) {
166                 boolean res = true;
167                 if (label != null) {
168                         label = label.trim();
169                         res = CATEGORY_LABEL_PATTERN.matcher(label).matches();
170                 }
171                 return res;
172         }
173
174         public static String normalizeCategoryName4Display(String str) {
175                 if (str != null) {
176                         str = str.trim();
177                         str = DASH_PATTERN.matcher(str).replaceAll("-");
178                         str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
179                         str = AMP_PATTERN.matcher(str).replaceAll("&");
180                         str = PLUS_PATTERN.matcher(str).replaceAll("+");
181                         str = DOT_PATTERN.matcher(str).replaceAll(".");
182                         str = APOST_PATTERN.matcher(str).replaceAll("'");
183                         str = HASHTAG_PATTERN.matcher(str).replaceAll("#");
184                         str = EQUAL_PATTERN.matcher(str).replaceAll("=");
185                         str = COLON_PATTERN.matcher(str).replaceAll(":");
186                         str = AT_PATTERN.matcher(str).replaceAll("@");
187                         str = normaliseWhitespace(str);
188                         str = AND_PATTERN.matcher(str).replaceAll(" & ");
189
190                         // Case normalizing
191                         StringBuilder sb = new StringBuilder();
192                         String[] split = str.split(" ");
193                         for (int i = 0; i < split.length; i++) {
194                                 String splitted = split[i];
195                                 String lowerCase = splitted.toLowerCase();
196                                 // BANK OF AMERICA --> BANK of AMERICA ("of" is lowercased), but
197                                 // OF BANK OF AMERICA --> OF BANK of AMERICA (first "OF" is not
198                                 // lowercased because it's first word)
199                                 // Agreed with Ella, 26/11/15
200                                 if ((i > 0) && CATEGORY_CONJUNCTIONS.contains(lowerCase)) {
201                                         sb.append(lowerCase);
202                                 } else {
203                                         sb.append(WordUtils.capitalize(splitted));
204                                 }
205                                 sb.append(" ");
206                         }
207                         str = sb.toString().trim();
208                 }
209                 return str;
210         }
211
212         public static String normalizeCategoryName4Uniqueness(String str) {
213                 return str.toLowerCase();
214         }
215
216         public static boolean validateCategoryDisplayNameLength(String label) {
217                 return (label != null && label.length() >= CATEGORY_LABEL_MIN_LENGTH
218                                 && label.length() <= CATEGORY_LABEL_MAX_LENGTH);
219         }
220
221         public static boolean validateProductFullNameLength(String fullName) {
222                 return (fullName != null && fullName.length() >= PRODUCT_FULL_NAME_MIN_LENGTH
223                                 && fullName.length() <= PRODUCT_FULL_NAME_MAX_LENGTH);
224         }
225
226         public static boolean validateArtifactLabelLength(String label) {
227                 return label.length() > 0 && label.length() <= ARTIFACT_LABEL_LENGTH;
228         }
229
230         public static boolean validateResourceInstanceNameLength(String resourceInstanceName) {
231                 return resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH;
232         }
233
234         public static boolean validateResourceInstanceName(String resourceInstanceName) {
235                 return RSI_NAME_PATTERN.matcher(resourceInstanceName).matches();
236         }
237
238         public static boolean validateUrlLength(String url) {
239                 return url.length() <= API_URL_LENGTH;
240         }
241
242         public static boolean validateArtifactNameLength(String artifactName) {
243                 return (artifactName.length() <= ARTIFACT_NAME_LENGTH && artifactName.length() > 0);
244         }
245
246         public static boolean validateComponentNamePattern(String componentName) {
247                 return COMPONENT_NAME_PATTERN.matcher(componentName).matches();
248         }
249
250         public static boolean validateComponentNameLength(String componentName) {
251                 return componentName.length() <= COMPONENT_NAME_MAX_LENGTH;
252         }
253
254         public static boolean validateIcon(String icon) {
255                 return ICON_PATTERN.matcher(icon).matches();
256         }
257
258         public static boolean validateIconLength(String icon) {
259                 return icon.length() <= ICON_MAX_LENGTH;
260         }
261
262         public static boolean validateProjectCode(String projectCode) {
263                 return PROJECT_CODE_PATTERN.matcher(projectCode).matches();
264         }
265
266         public static boolean validateProjectCodeLegth(String projectCode) {
267                 return projectCode.length() <= PROJECT_CODE_MAX_LEGTH;
268         }
269
270         public static boolean validateContactId(String contactId) {
271                 return CONTACT_ID_PATTERN.matcher(contactId).matches();
272         }
273
274         public static boolean validateCost(String cost) {
275                 return COST_PATTERN.matcher(cost).matches();
276         }
277
278         public static String removeHtmlTags(String str) {
279                 return Jsoup.clean(str, Whitelist.none());
280         }
281
282         public static String removeAllTags(String htmlText) {
283
284                 return TAGS_PATTERN.matcher(htmlText).replaceAll("").trim();
285         }
286
287         public static String normaliseWhitespace(String str) {
288                 StringBuilder sb = new StringBuilder(str.length());
289                 appendNormalisedWhitespace(sb, str, false);
290                 return sb.toString();
291         }
292
293         private static void appendNormalisedWhitespace(StringBuilder accum, String string, boolean stripLeading) {
294                 boolean lastWasWhite = false;
295                 boolean reachedNonWhite = false;
296
297                 int len = string.length();
298                 int c;
299                 for (int i = 0; i < len; i+= Character.charCount(c)) {
300                         c = string.codePointAt(i);
301                         if (isWhitespace(c)) {
302                                 if ((stripLeading && !reachedNonWhite) || lastWasWhite)
303                                         continue;
304                                 accum.append(' ');
305                                 lastWasWhite = true;
306                         }
307                         else {
308                                 accum.appendCodePoint(c);
309                                 lastWasWhite = false;
310                                 reachedNonWhite = true;
311                         }
312                 }
313         }
314
315         private static boolean isWhitespace(int c){
316                 return c == ' ';
317         }
318
319         public static String stripOctets(String str) {
320                 return OCTET_PATTERN.matcher(str).replaceAll("");
321         }
322
323         public static String removeNoneUtf8Chars(String input) {
324                 return NONE_UTF8_PATTERN.matcher(input).replaceAll("");
325         }
326
327         public static boolean validateIsEnglish(String input) {
328                 return ENGLISH_PATTERN.matcher(input).matches();
329         }
330
331         public static boolean validateIsAscii(String input) {
332
333                 return CharMatcher.ASCII.matchesAllOf(input);
334         }
335
336         public static String convertHtmlTagsToEntities(String input) {
337                 return StringEscapeUtils.escapeHtml4(input);
338         }
339
340         public static List<String> removeDuplicateFromList(List<String> list) {
341                 Set<String> hs = new LinkedHashSet<>(list);
342                 list.clear();
343                 list.addAll(hs);
344                 return list;
345
346         }
347
348         public static boolean validateTagLength(String tag) {
349                 if (tag != null) {
350                         return tag.length() <= TAG_MAX_LENGTH;
351                 }
352                 return false;
353         }
354
355         public static boolean validateTagListLength(int tagListLength) {
356                 return tagListLength <= TAG_LIST_MAX_LENGTH;
357         }
358
359         public static boolean validateDescriptionLength(String description) {
360                 return description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH;
361         }
362
363         public static boolean validateStringNotEmpty(String value) {
364                 if ((value == null) || (value.isEmpty())) {
365                         return false;
366                 }
367                 return true;
368         }
369
370         public static boolean validateListNotEmpty(List<?> list) {
371                 if ((list == null) || (list.isEmpty())) {
372                         return false;
373                 }
374                 return true;
375         }
376
377         public static boolean validateVendorName(String vendorName) {
378                 return VENDOR_NAME_PATTERN.matcher(vendorName).matches();
379         }
380
381         public static boolean validateVendorNameLength(String vendorName) {
382                 return vendorName.length() <= VENDOR_NAME_MAX_LENGTH;
383         }
384
385         public static boolean validateResourceVendorModelNumberLength(String resourceVendorModelNumber) {
386                 return resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH;
387         }
388
389         public static boolean validateVendorRelease(String vendorRelease) {
390                 return VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches();
391         }
392
393         public static boolean validateVendorReleaseLength(String vendorRelease) {
394                 return vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH;
395         }
396
397         public static boolean validateServiceTypeLength(String serviceType) {
398                 return serviceType.length() <= SERVICE_TYPE_MAX_LENGTH;
399         }
400
401         public static boolean validateServiceRoleLength(String serviceRole) {
402                 return serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH;
403         }
404
405         public static boolean validateServiceFunctionLength(String serviceFunction) {
406                 return serviceFunction.length() <= SERVICE_FUNCTION_MAX_LENGTH;
407         }
408
409         public static boolean validateServiceNamingPolicyLength(String namingPolicy) {
410                 return namingPolicy.length() <= SERVICE_NAMING_POLICY_MAX_SIZE;
411         }
412         public static boolean hasBeenCertified(String version) {
413                 return NumberUtils.toDouble(version) >= 1;
414         }
415
416     public static String normaliseComponentName(String name) {
417         String[] split = splitComponentName(name);
418         StringBuilder sb = new StringBuilder();
419         for (String splitElement : split) {
420             sb.append(splitElement);
421         }
422         return sb.toString();
423
424         }
425
426     public static String normalizeComponentInstanceName(String name) {
427         String[] split = splitComponentInstanceName(name);
428         StringBuilder sb = new StringBuilder();
429         for (String splitElement : split) {
430             sb.append(splitElement);
431         }
432         return sb.toString();
433
434         }
435
436         private static String[] splitComponentName(String name) {
437                 String normalizedName = name.toLowerCase();
438                 normalizedName = COMPONENT_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
439                 return normalizedName.split(" ");
440         }
441
442         private static String[] splitComponentInstanceName(String name) {
443                 String normalizedName = name.toLowerCase();
444                 normalizedName = COMPONENT_INCTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
445                 return normalizedName.split(" ");
446         }
447
448     public static String convertToSystemName(String name) {
449         String[] split = splitComponentName(name);
450         StringBuilder sb = new StringBuilder();
451         for (String splitElement : split) {
452             String capitalize = WordUtils.capitalize(splitElement);
453             sb.append(capitalize);
454         }
455         return sb.toString();
456     }
457
458         public static String normalizeFileName(String filename) {
459                 // String[] split = filename.split(Pattern.quote(File.separator));
460                 // String name = "";
461                 //
462                 // name = split[split.length - 1];
463                 return cleanFileName(filename);
464
465         }
466
467         private static String cleanFileName(String str) {
468                 str = CLEAN_FILENAME_PATTERN.matcher(str).replaceAll("");
469                 str = normaliseWhitespace(str);
470                 str = SPACE_PATTERN.matcher(str).replaceAll("-");
471                 str = DASH_PATTERN.matcher(str).replaceAll("-");
472                 str = StringUtils.strip(str, "-_ .");
473
474                 return str;
475         }
476
477         public static boolean validateUrl(String url) {
478
479                 UrlValidator urlValidator = new UrlValidator();
480                 if (!urlValidator.isValid(url)) {
481                         return false;
482                 }
483                 if (NONE_UTF8_PATTERN.matcher(url).find()) {
484                         return false;
485                 }
486
487                 if (URL_INVALIDE_PATTERN.matcher(url).find()) {
488                         return false;
489                 }
490                 return true;
491
492         }
493
494         public static String cleanArtifactDisplayName(String strIn) {
495                 String str = DASH_PATTERN.matcher(strIn).replaceAll("-");
496                 str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
497                 str = PLUS_PATTERN.matcher(str).replaceAll("+");
498                 str = normaliseWhitespace(str);
499                 str = str.trim();
500                 // str = str.replaceAll(" ", "");
501
502                 return str;
503         }
504
505         public static String normalizeArtifactLabel(String strIn) {
506
507                 String str = DASH_PATTERN.matcher(strIn).replaceAll("");
508                 str = UNDERSCORE_PATTERN.matcher(str).replaceAll("");
509                 str = PLUS_PATTERN.matcher(str).replaceAll("");
510                 str = SPACE_PATTERN.matcher(str).replaceAll("");
511                 str = DOT_PATTERN.matcher(str).replaceAll("");
512                 str = str.toLowerCase();
513
514                 return str;
515         }
516
517         public static boolean validateAdditionalInformationKeyName(String str) {
518                 return ADDITIONAL_INFORMATION_KEY_PATTERN.matcher(str).matches();
519         }
520
521         public static String normalizeAdditionalInformation(String str) {
522                 if (str != null) {
523                         str = DASH_PATTERN.matcher(str).replaceAll("-");
524                         str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
525                         str = normaliseWhitespace(str);
526                 }
527                 return str;
528         }
529
530         public static boolean validateLength(String str, int length) {
531                 if (str == null) {
532                         return true;
533                 }
534                 return str.length() <= length;
535         }
536
537         public static boolean validateConsumerName(String consumerName) {
538                 return CONSUMER_NAME_PATTERN.matcher(consumerName).matches();
539         }
540
541         public static boolean isUTF8Str(String str) {
542                 if (NONE_UTF8_PATTERN.matcher(str).find()) {
543                         return false;
544                 }
545                 return true;
546         }
547
548         public static boolean validateConsumerPassSalt(String consumerSalt) {
549                 return CONSUMER_PASS_SALT_PATTERN.matcher(consumerSalt).matches();
550         }
551
552         public static boolean isFloatNumber(String number) {
553                 return FLOAT_PATTERN.matcher(number).matches();
554         }
555
556         public static boolean validateCertifiedVersion(String version) {
557                 return (version != null && CERTIFIED_VERSION_PATTERN.matcher(version).matches());
558         }
559
560         public static boolean validateMinorVersion(String version) {
561                 return (version != null && MINOR_VERSION_PATTERN.matcher(version).matches());
562         }
563
564         public static boolean validateCategoryIconNotEmpty(List<String> categoryIcons) {
565                 return CollectionUtils.isEmpty(categoryIcons);
566         }
567
568         public static String normaliseProductName(String name) {
569                 String[] split = splitComponentName(PRODUCT_NAME_DELIMETER_PATTERN, name);
570                 StringBuilder sb = new StringBuilder();
571                 for (String splitElement : split) {
572                         sb.append(splitElement);
573                 }
574                 return sb.toString();
575
576         }
577
578         private static String[] splitComponentName(Pattern pattern, String name) {
579                 String normalizedName = name.toLowerCase();
580                 normalizedName = pattern.matcher(normalizedName).replaceAll(" ");
581                 return normalizedName.split(" ");
582         }
583
584         public static String removeHtmlTagsOnly(String htmlText) {
585                 return HtmlCleaner.stripHtml(htmlText, false);
586         }
587
588         public static boolean validateForwardingPathNamePattern(String forwardingPathName) {
589                 return FORWARDING_PATH_NAME_PATTERN.matcher(forwardingPathName).matches();
590         }
591 }