summaryrefslogtreecommitdiffstats
path: root/common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java
blob: 864d79eb39ac2e0522eac4afc6167bf615a12b8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
/**
 * Created by ob0695 on 4/18/2018.
 */
import { NgModule } from "@angular/core";
import {SdcUiComponentsModule} from "sdc-ui/lib/angular/index";
import {CommonModule} from "@angular/common";
import {AutomatedUpgradeStatusComponent} from "./automated-upgrade-status/automated-upgrade-status.component";
import {AutomatedUpgradeComponent} from "./automated-upgrade.component";
import {UpgradeListItemComponent} from "./automated-upgrade-ui-components/upgrade-list-item/upgrade-list-item.component";
import {UpgradeListItemStatusComponent} from "./automated-upgrade-ui-components/upgrade-list-item-status/upgrade-list-status-item.component";
import {TranslateService} from "../../shared/translator/translate.service";
import {UpgradeListItemInnerContent} from "./automated-upgrade-ui-components/list-item-inner-content/list-item-inner-content.component";
import {UpgradeLineItemComponent} from "./automated-upgrade-ui-components/upgrade-line-item/upgrade-line-item.component";
import {UpgradeListItemOrderPipe} from "./automated-upgrade-ui-components/list-item-order-pipe/list-item-order-pipe";

@NgModule({
    declarations: [
        AutomatedUpgradeStatusComponent,
        UpgradeListItemComponent,
        UpgradeListItemStatusComponent,
        AutomatedUpgradeComponent,
        UpgradeListItemInnerContent,
        UpgradeLineItemComponent,
        UpgradeListItemOrderPipe
    ],
    imports: [CommonModule, SdcUiComponentsModule],
    exports: [],
    entryComponents: [
        AutomatedUpgradeComponent, AutomatedUpgradeStatusComponent
    ],
    providers: [TranslateService]
})
export class AutomatedUpgradeModule {
}   
='#n453'>453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.common.util;

import com.google.common.base.CharMatcher;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.jsoup.Jsoup;
import org.jsoup.helper.StringUtil;
import org.jsoup.safety.Whitelist;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

public class ValidationUtils {
	public final static Integer COMPONENT_NAME_MAX_LENGTH = 1024;
	public final static Pattern COMPONENT_NAME_PATTERN = Pattern
			.compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (COMPONENT_NAME_MAX_LENGTH-1) + "}$");
	public final static Integer ADDITIONAL_INFORMATION_KEY_MAX_LENGTH = 50;
	public final static Pattern ADDITIONAL_INFORMATION_KEY_PATTERN = Pattern
			.compile("^[\\w\\s\\.\\-\\_]{1," + COMPONENT_NAME_MAX_LENGTH + "}$");
	public final static Integer RSI_NAME_MAX_LENGTH = 1024;
	public final static Pattern RSI_NAME_PATTERN = Pattern
			.compile("^[\\w \\s\\.\\-\\_\\:\\+]{1," + RSI_NAME_MAX_LENGTH + "}$");
	public final static Integer COMMENT_MAX_LENGTH = 256;

	public final static Integer ICON_MAX_LENGTH = 25;
	public final static Pattern ICON_PATTERN = Pattern.compile("^[\\w\\-]{1," + ICON_MAX_LENGTH + "}$");
	public final static Integer PROJECT_CODE_MAX_LEGTH = 50;
	public final static Pattern PROJECT_CODE_PATTERN = Pattern.compile("^[\\s\\w_.-]{5,50}$");

	// USER_ID format : aannnX (where a=a-z or A-Z, n=0-9, and X=a-z,A-Z, or 0-9)
	public final static Integer CONNTACT_ID_MAX_LENGTH = 50;
//	public final static Pattern CONTACT_ID_PATTERN = Pattern
//			.compile("[mM]{1}[0-9]{5}|[a-zA-Z]{2}[0-9]{4}|[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{1}");
	public final static Pattern CONTACT_ID_PATTERN = Pattern.compile("^[\\s\\w_.-]{1,50}$");
	public final static Pattern OCTET_PATTERN = Pattern.compile("%[a-fA-F0-9]{2}");
	public final static Pattern NONE_UTF8_PATTERN = Pattern.compile("[^\\x00-\\x7F]+");
	public final static Pattern URL_INVALIDE_PATTERN = Pattern.compile("[,#?&@$<>~^`\\\\\\[\\]{}|\")(*!+=;%]+");// ,#?&@$<>~^`\\[]{}|")(*!

	public final static Pattern ENGLISH_PATTERN = Pattern.compile("^[\\p{Graph}\\x20]+$");
	public final static Integer COMPONENT_DESCRIPTION_MAX_LENGTH = 1024;
	public final static Integer SERVICE_TYPE_MAX_LENGTH = 400;
	public final static Integer SERVICE_ROLE_MAX_LENGTH = 400;

	public final static Integer TAG_MAX_LENGTH = 1024;
	public final static Integer TAG_LIST_MAX_LENGTH = 1024;
	public final static Integer VENDOR_NAME_MAX_LENGTH = 60;
	public final static Pattern VENDOR_NAME_PATTERN = Pattern
			.compile("^[\\x20-\\x21\\x23-\\x29\\x2B-\\x2E\\x30-\\x39\\x3B\\x3D\\x40-\\x5B\\x5D-\\x7B\\x7D-\\xFF]+$");
	public final static Integer VENDOR_RELEASE_MAX_LENGTH = 25;
	public final static Pattern VENDOR_RELEASE_PATTERN = Pattern
			.compile("^[\\x20-\\x21\\x23-\\x29\\x2B-\\x2E\\x30-\\x39\\x3B\\x3D\\x40-\\x5B\\x5D-\\x7B\\x7D-\\xFF]+$");
	public final static Integer RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH = 65;

	public final static Pattern CLEAN_FILENAME_PATTERN = Pattern.compile("[\\x00-\\x1f\\x80-\\x9f\\x5c/<?>\\*:|\"/]+");

	public final static Pattern DASH_PATTERN = Pattern.compile("[-]+");
	public final static Pattern UNDERSCORE_PATTERN = Pattern.compile("[_]+");
	public final static Pattern PLUS_PATTERN = Pattern.compile("[+]+");
	public final static Pattern SPACE_PATTERN = Pattern.compile("[ ]+");
	public final static Pattern AMP_PATTERN = Pattern.compile("[&]+");
	public final static Pattern DOT_PATTERN = Pattern.compile("[\\.]+");
	public final static Pattern APOST_PATTERN = Pattern.compile("[']+");
	public final static Pattern HASHTAG_PATTERN = Pattern.compile("[#]+");
	public final static Pattern EQUAL_PATTERN = Pattern.compile("[=]+");
	public final static Pattern COLON_PATTERN = Pattern.compile("[:]+");
	public final static Pattern AT_PATTERN = Pattern.compile("[@]+");
	public final static Pattern AND_PATTERN = Pattern.compile(" [aA][Nn][Dd] ");
	protected final static Set<String> CATEGORY_CONJUNCTIONS = new HashSet<String>(
			Arrays.asList("of", "to", "for", "as", "a", "an", "the"));

	public final static Pattern COST_PATTERN = Pattern.compile("^[0-9]{1,5}\\.[0-9]{1,3}$");
	public final static Pattern ARTIFACT_LABEL_PATTERN = Pattern.compile("^[a-zA-Z0-9 \\-+]+$");
	public final static Integer ARTIFACT_LABEL_LENGTH = 255;
	public final static Pattern ARTIFACT_DISPLAY_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9 &\\.'#=:@_\\-+]+$");
	public final static Pattern CATEGORY_LABEL_PATTERN = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9 &\\.'#=:@_\\-+]+$");
	public final static Integer CATEGORY_LABEL_MIN_LENGTH = 4;
	public final static Integer CATEGORY_LABEL_MAX_LENGTH = 25;

	public final static Pattern COMPONENT_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-\\_]+");
	public final static Pattern COMPONENT_INCTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+");
	public final static Pattern PRODUCT_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-\\_&=#@':\\[\\]\\+]+");
	public final static Integer CONSUMER_NAME_MAX_LENGTH = 255;
	// public final static Pattern CONSUMER_NAME_PATTERN =
	// Pattern.compile("^[\\w]{1}?[\\w\\.\\-]{0," + CONSUMER_NAME_MAX_LENGTH +
	// "}?$");
	public final static Pattern CONSUMER_NAME_PATTERN = Pattern.compile("^[\\w]+[\\w\\.\\-]*$");
	public final static Integer CONSUMER_SALT_LENGTH = 32;
	public final static Integer CONSUMER_PASSWORD_LENGTH = 64;
	public final static Pattern CONSUMER_PASS_SALT_PATTERN = Pattern.compile("^[a-z0-9]+$");
	public final static Pattern FLOAT_PATTERN = Pattern.compile("^[\\d]+[\\.]{1}[\\d]+$");
	public final static Pattern CERTIFIED_VERSION_PATTERN = Pattern.compile("^[1-9][0-9]*\\.0$");
	public final static Pattern MINOR_VERSION_PATTERN = Pattern.compile("^0\\.[1-9][0-9]*$");
	public final static Pattern TAGS_PATTERN = Pattern.compile("<[^><]*>");

	public final static Integer ARTIFACT_NAME_LENGTH = 255;
	public final static Integer API_URL_LENGTH = 100;
	public final static Integer ARTIFACT_DESCRIPTION_MAX_LENGTH = 256;

	public final static Integer PRODUCT_FULL_NAME_MIN_LENGTH = 4;
	public final static Integer PRODUCT_FULL_NAME_MAX_LENGTH = 100;
	public static final Integer FORWARDING_PATH_NAME_MAX_LENGTH = 100;
	public final static Pattern FORWARDING_PATH_NAME_PATTERN = Pattern.compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (FORWARDING_PATH_NAME_MAX_LENGTH-1) + "}$");
	
	public final static Integer POLICY_MAX_LENGTH = 1024;
	public final static Pattern POLICY_NAME_PATTERN = Pattern
			.compile("^[\\w][\\w \\.\\-\\_\\:\\+]{0," + (POLICY_MAX_LENGTH-1) + "}$");

	public static boolean validateArtifactLabel(String label) {
		return ARTIFACT_LABEL_PATTERN.matcher(label).matches();
	}
	
	public static boolean validateArtifactDisplayName(String displayName) {
		return ARTIFACT_DISPLAY_NAME_PATTERN.matcher(displayName).matches();
	}

	public static boolean validateCategoryDisplayNameFormat(String label) {
		boolean res = true;
		if (label != null) {
			label = label.trim();
			res = CATEGORY_LABEL_PATTERN.matcher(label).matches();
		}
		return res;
	}

	public static String normalizeCategoryName4Display(String str) {
		if (str != null) {
			str = str.trim();
			str = DASH_PATTERN.matcher(str).replaceAll("-");
			str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
			str = AMP_PATTERN.matcher(str).replaceAll("&");
			str = PLUS_PATTERN.matcher(str).replaceAll("+");
			str = DOT_PATTERN.matcher(str).replaceAll(".");
			str = APOST_PATTERN.matcher(str).replaceAll("'");
			str = HASHTAG_PATTERN.matcher(str).replaceAll("#");
			str = EQUAL_PATTERN.matcher(str).replaceAll("=");
			str = COLON_PATTERN.matcher(str).replaceAll(":");
			str = AT_PATTERN.matcher(str).replaceAll("@");
			str = normaliseWhitespace(str);
			str = AND_PATTERN.matcher(str).replaceAll(" & ");

			// Case normalizing
			StringBuilder sb = new StringBuilder();
			String[] split = str.split(" ");
			for (int i = 0; i < split.length; i++) {
				String splitted = split[i];
				String lowerCase = splitted.toLowerCase();
				// BANK OF AMERICA --> BANK of AMERICA ("of" is lowercased), but
				// OF BANK OF AMERICA --> OF BANK of AMERICA (first "OF" is not
				// lowercased because it's first word)
				// Agreed with Ella, 26/11/15
				if ((i > 0) && CATEGORY_CONJUNCTIONS.contains(lowerCase)) {
					sb.append(lowerCase);
				} else {
					sb.append(WordUtils.capitalize(splitted));
				}
				sb.append(" ");
			}
			str = sb.toString().trim();
		}
		return str;
	}

	public static String normalizeCategoryName4Uniqueness(String str) {
		return str.toLowerCase();
	}

	public static boolean validateCategoryDisplayNameLength(String label) {
		return (label != null && label.length() >= CATEGORY_LABEL_MIN_LENGTH
				&& label.length() <= CATEGORY_LABEL_MAX_LENGTH);
	}

	public static boolean validateProductFullNameLength(String fullName) {
		return (fullName != null && fullName.length() >= PRODUCT_FULL_NAME_MIN_LENGTH
				&& fullName.length() <= PRODUCT_FULL_NAME_MAX_LENGTH);
	}

	public static boolean validateArtifactLabelLength(String label) {
		return label.length() > 0 && label.length() <= ARTIFACT_LABEL_LENGTH;
	}

	public static boolean validateResourceInstanceNameLength(String resourceInstanceName) {
		return resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH;
	}

	public static boolean validateResourceInstanceName(String resourceInstanceName) {
		return RSI_NAME_PATTERN.matcher(resourceInstanceName).matches();
	}

	public static boolean validateUrlLength(String url) {
		return url.length() <= API_URL_LENGTH;
	}

	public static boolean validateArtifactNameLength(String artifactName) {
		return (artifactName.length() <= ARTIFACT_NAME_LENGTH && artifactName.length() > 0);
	}

	public static boolean validateComponentNamePattern(String componentName) {
		return COMPONENT_NAME_PATTERN.matcher(componentName).matches();
	}

	public static boolean validateComponentNameLength(String componentName) {
		return componentName.length() <= COMPONENT_NAME_MAX_LENGTH;
	}

	public static boolean validateIcon(String icon) {
		return ICON_PATTERN.matcher(icon).matches();
	}

	public static boolean validateIconLength(String icon) {
		return icon.length() <= ICON_MAX_LENGTH;
	}

	public static boolean validateProjectCode(String projectCode) {
		return PROJECT_CODE_PATTERN.matcher(projectCode).matches();
	}

	public static boolean validateProjectCodeLegth(String projectCode) {
		return projectCode.length() <= PROJECT_CODE_MAX_LEGTH;
	}

	public static boolean validateContactId(String contactId) {
		return CONTACT_ID_PATTERN.matcher(contactId).matches();
	}

	public static boolean validateCost(String cost) {
		return COST_PATTERN.matcher(cost).matches();
	}

	public static String removeHtmlTags(String str) {
		return Jsoup.clean(str, Whitelist.none());
	}

	public static String removeAllTags(String htmlText) {

		String stripped = TAGS_PATTERN.matcher(htmlText).replaceAll("").trim();
		return stripped;
	}

	public static String normaliseWhitespace(String str) {
		return StringUtil.normaliseWhitespace(str);
	}

	public static String stripOctets(String str) {
		return OCTET_PATTERN.matcher(str).replaceAll("");
	}

	public static String removeNoneUtf8Chars(String input) {
		return NONE_UTF8_PATTERN.matcher(input).replaceAll("");
	}

	public static boolean validateIsEnglish(String input) {
		return ENGLISH_PATTERN.matcher(input).matches();
	}

	public static boolean validateIsAscii(String input) {

		boolean isAscii = CharMatcher.ASCII.matchesAllOf(input);

		return isAscii;
	}

	public static String convertHtmlTagsToEntities(String input) {
		return StringEscapeUtils.escapeHtml4(input);
	}

	public static List<String> removeDuplicateFromList(List<String> list) {
		Set<String> hs = new LinkedHashSet<>(list);
		list.clear();
		list.addAll(hs);
		return list;

	}

	public static boolean validateTagLength(String tag) {
		if (tag != null) {
			return tag.length() <= TAG_MAX_LENGTH;
		}
		return false;
	}

	public static boolean validateTagListLength(int tagListLength) {
		return tagListLength <= TAG_LIST_MAX_LENGTH;
	}

	public static boolean validateDescriptionLength(String description) {
		return description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH;
	}

	public static boolean validateStringNotEmpty(String value) {
		if ((value == null) || (value.isEmpty())) {
			return false;
		}
		return true;
	}

	public static boolean validateListNotEmpty(List<?> list) {
		if ((list == null) || (list.isEmpty())) {
			return false;
		}
		return true;
	}

	public static boolean validateVendorName(String vendorName) {
		return VENDOR_NAME_PATTERN.matcher(vendorName).matches();
	}

	public static boolean validateVendorNameLength(String vendorName) {
		return vendorName.length() <= VENDOR_NAME_MAX_LENGTH;
	}

	public static boolean validateResourceVendorModelNumberLength(String resourceVendorModelNumber) {
		return resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH;
	}
	
	public static boolean validateVendorRelease(String vendorRelease) {
		return VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches();
	}

	public static boolean validateVendorReleaseLength(String vendorRelease) {
		return vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH;
	}
	
	public static boolean validateServiceTypeLength(String serviceType) {
		return serviceType.length() <= SERVICE_TYPE_MAX_LENGTH;
	}
	
	public static boolean validateServiceRoleLength(String serviceRole) {
		return serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH;
	}



	public static boolean hasBeenCertified(String version) {
		return NumberUtils.toDouble(version) >= 1;
	}

	public static String normaliseComponentName(String name) {
		String[] split = splitComponentName(name);
		StringBuffer sb = new StringBuffer();
		for (String splitElement : split) {
			sb.append(splitElement);
		}
		return sb.toString();

	}

	public static String normalizeComponentInstanceName(String name) {
		String[] split = splitComponentInstanceName(name);
		StringBuffer sb = new StringBuffer();
		for (String splitElement : split) {
			sb.append(splitElement);
		}
		return sb.toString();

	}

	private static String[] splitComponentName(String name) {
		String normalizedName = name.toLowerCase();
		normalizedName = COMPONENT_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
		String[] split = normalizedName.split(" ");
		return split;
	}

	private static String[] splitComponentInstanceName(String name) {
		String normalizedName = name.toLowerCase();
		normalizedName = COMPONENT_INCTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
		String[] split = normalizedName.split(" ");
		return split;
	}

	public static String convertToSystemName(String name) {
		String[] split = splitComponentName(name);
		StringBuffer sb = new StringBuffer();
		for (String splitElement : split) {
			String capitalize = WordUtils.capitalize(splitElement);
			sb.append(capitalize);
		}
		return sb.toString();
	}

	public static String normalizeFileName(String filename) {
		// String[] split = filename.split(Pattern.quote(File.separator));
		// String name = "";
		//
		// name = split[split.length - 1];
		return cleanFileName(filename);

	}

	private static String cleanFileName(String str) {
		str = CLEAN_FILENAME_PATTERN.matcher(str).replaceAll("");
		str = normaliseWhitespace(str);
		str = SPACE_PATTERN.matcher(str).replaceAll("-");
		str = DASH_PATTERN.matcher(str).replaceAll("-");
		str = StringUtils.strip(str, "-_ .");

		return str;
	}

	public static boolean validateUrl(String url) {

		UrlValidator urlValidator = new UrlValidator();
		if (!urlValidator.isValid(url)) {
			return false;
		}
		if (NONE_UTF8_PATTERN.matcher(url).find()) {
			return false;
		}

		if (URL_INVALIDE_PATTERN.matcher(url).find()) {
			return false;
		}
		return true;

	}

	public static String cleanArtifactDisplayName(String strIn) {
		String str = DASH_PATTERN.matcher(strIn).replaceAll("-");
		str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
		str = PLUS_PATTERN.matcher(str).replaceAll("+");
		str = normaliseWhitespace(str);
		str = str.trim();
		// str = str.replaceAll(" ", "");

		return str;
	}

	public static String normalizeArtifactLabel(String strIn) {

		String str = DASH_PATTERN.matcher(strIn).replaceAll("");
		str = UNDERSCORE_PATTERN.matcher(str).replaceAll("");
		str = PLUS_PATTERN.matcher(str).replaceAll("");
		str = SPACE_PATTERN.matcher(str).replaceAll("");
		str = DOT_PATTERN.matcher(str).replaceAll("");
		str = str.toLowerCase();

		return str;
	}

	public static boolean validateAdditionalInformationKeyName(String str) {
		return ADDITIONAL_INFORMATION_KEY_PATTERN.matcher(str).matches();
	}

	public static String normalizeAdditionalInformation(String str) {
		if (str != null) {
			str = DASH_PATTERN.matcher(str).replaceAll("-");
			str = UNDERSCORE_PATTERN.matcher(str).replaceAll("_");
			str = normaliseWhitespace(str);
		}
		return str;
	}

	public static boolean validateLength(String str, int length) {
		if (str == null) {
			return true;
		}
		return str.length() <= length;
	}

	public static boolean validateConsumerName(String consumerName) {
		return CONSUMER_NAME_PATTERN.matcher(consumerName).matches();
	}

	public static boolean isUTF8Str(String str) {
		if (NONE_UTF8_PATTERN.matcher(str).find()) {
			return false;
		}
		return true;
	}

	public static boolean validateConsumerPassSalt(String consumerSalt) {
		return CONSUMER_PASS_SALT_PATTERN.matcher(consumerSalt).matches();
	}

	public static boolean isFloatNumber(String number) {
		return FLOAT_PATTERN.matcher(number).matches();
	}

	public static boolean validateCertifiedVersion(String version) {
		return (version != null && CERTIFIED_VERSION_PATTERN.matcher(version).matches());
	}

	public static boolean validateMinorVersion(String version) {
		return (version != null && MINOR_VERSION_PATTERN.matcher(version).matches());
	}

	public static String normaliseProductName(String name) {
		String[] split = splitComponentName(PRODUCT_NAME_DELIMETER_PATTERN, name);
		StringBuffer sb = new StringBuffer();
		for (String splitElement : split) {
			sb.append(splitElement);
		}
		return sb.toString();

	}

	private static String[] splitComponentName(Pattern pattern, String name) {
		String normalizedName = name.toLowerCase();
		normalizedName = pattern.matcher(normalizedName).replaceAll(" ");
		String[] split = normalizedName.split(" ");
		return split;
	}

	public static String removeHtmlTagsOnly(String htmlText) {
		String stripped = HtmlCleaner.stripHtml(htmlText, false);
		return stripped;
	}

	public static boolean validateForwardingPathNamePattern(String forwardingPathName) {
		return FORWARDING_PATH_NAME_PATTERN.matcher(forwardingPathName).matches();
	}
}