class XMLUtil {

	@Pure
	@SuppressWarnings({"checkstyle:magicnumber", "checkstyle:npathcomplexity"})
	public static int parseColor(String xmlColor) throws ColorFormatException {
		if (xmlColor == null || "".equals(xmlColor)) { //$NON-NLS-1$
			return 0;
		}
		if (xmlColor.startsWith("#")) { //$NON-NLS-1$
			try {
				final String str = xmlColor.substring(1);
				if (str.length() == 6) {
					return 0xFF000000 | decodeHexInteger(str.toString());
				}
				return decodeHexInteger(str.toString());
			} catch (NumberFormatException e) {
				throw new ColorFormatException(xmlColor);
			}
		}
		Matcher matcher = HTML_RGB_PATTERN.matcher(xmlColor);
		if (matcher.find()) {
			final int red = decodeDecInteger(matcher.group(1));
			final int green = decodeDecInteger(matcher.group(2));
			final int blue = decodeDecInteger(matcher.group(3));
			return encodeRgbaColor(red, green, blue, 0xFF);
		}
		matcher = HTML_RGBA_PATTERN.matcher(xmlColor);
		if (matcher.find()) {
			final int red = decodeDecInteger(matcher.group(1));
			final int green = decodeDecInteger(matcher.group(2));
			final int blue = decodeDecInteger(matcher.group(3));
			final int alpha = decodeDecInteger(matcher.group(4));
			return encodeRgbaColor(red, green, blue, alpha);
		}
		matcher = HTML_HSL_PATTERN.matcher(xmlColor);
		if (matcher.find()) {
			final double hue = decodeFactor(matcher.group(1));
			final double saturation = decodeFactor(matcher.group(2));
			final double lightness = decodeFactor(matcher.group(3));
			return encodeHslaColor(hue, saturation, lightness, 0xFF);
		}
		matcher = HTML_HSLA_PATTERN.matcher(xmlColor);
		if (matcher.find()) {
			final double hue = decodeFactor(matcher.group(1));
			final double saturation = decodeFactor(matcher.group(2));
			final double lightness = decodeFactor(matcher.group(3));
			final int alpha = decodeDecInteger(matcher.group(4));
			return encodeHslaColor(hue, saturation, lightness, alpha);
		}
		final Integer color = ColorNames.getColorFromName(xmlColor);
		if (color != null) {
			return color.intValue();
		}
		throw new ColorFormatException(xmlColor);
	}

	private  XMLUtil();

}