Transforms a Well Formed string into a formatted string (see CPE 2.3
specification).

@param value the component value to encode
@return the formatted string
420819
public static String wellFormedToFS(String value) {
        if (value == null || value.isEmpty()) {
            return LogicalValue.ANY.getAbbreviation();
        }
        if (LogicalValue.ANY.getAbbreviation().equals(value) || LogicalValue.NA.getAbbreviation().equals(value)) {
            return value;
        }
        //unquote '.', '_', and '-'
        //return value.replaceAll("\\\\([._-])", "$1");
        StringBuilder buffer = new StringBuilder(value);
        char p = ' ';
        for (int x = 0; x < buffer.length() - 1; x++) {
            char c = buffer.charAt(x);
            if ((c == '.' || c == '_' || c == '-') && p == '\\') {
                buffer.delete(x - 1, x);
                x -= 1;
            }
            p = c;
        }
        return buffer.toString();
    }
1119473
public String normalize(String value) {
        if (!value.matches("[\\d,.]+([eE]\\d+)?")) {
            throw new InvalidValueException(value, NUMBER);
        }
        Locale locale = guessLocale(value);
        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale);
        df.setParseBigDecimal(true);
        try {
            return df.parse(value).toString();
        } catch (ParseException ex) {
            throw new InvalidValueException(value, NUMBER, ex);
        }
    }
1263192
private String urlEncode(Object value)
	{
		try {
			return URLEncoder.encode(value.toString(), UTF8.name());
		} catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }
	}
1153922
protected String getHeaderValueText(Object value) {
        if (value == null) {
            return null;
        }

        // TODO: Type conversion based on provided config
        if (value.getClass() == String.class) {
            return (String) value;
        } else if (value instanceof List) {
            List<?> list = (List<?>) value;
            if (list.size() == 1) {
                return getHeaderValueText(list.get(0));
            } else {
                return list.toString();
            }
        }

        return null;
    }
415529
protected V decode(String value) {
    return valueSerializer.decode(BaseEncoding.base16().decode(value));
  }
672337
public static Status formattedString(String value) {
        boolean result = true;
        try {
            Cpe23PartIterator instance;
            try {
                instance = new Cpe23PartIterator(value);
            } catch (CpeParsingException ex) {
                LOG.warn("The CPE (" + value + ") is invalid as it is not in the formatted string format");
                return Status.INVALID;
            }
            try {
                //part
                Part.getEnum(instance.next());
            } catch (CpeParsingException ex) {
                LOG.warn("The CPE (" + value + ") is invalid as it has an invalid part attribute");
                return Status.INVALID_PART;
            }
            Status status;
            //vendor
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid vendor - " + status.getMessage());
                return status;
            }
            //product
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid product - " + status.getMessage());
                return status;
            }
            //version
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an version version - " + status.getMessage());
                return status;
            }
            //update
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid update - " + status.getMessage());
                return status;
            }
            //edition
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid edition - " + status.getMessage());
                return status;
            }
            //language
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid language - " + status.getMessage());
                return status;
            }
            //swEdition
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid swEdition - " + status.getMessage());
                return status;
            }
            //targetSw
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid targetSw - " + status.getMessage());
                return status;
            }
            //targetHw
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid targetHw - " + status.getMessage());
                return status;
            }
            //other
            status = Validate.component(instance.next());
            if (!status.isValid()) {
                LOG.warn("The CPE (" + value + ") has an invalid other attribute - " + status.getMessage());
                return status;
            }
            if (instance.hasNext()) {
                LOG.warn(Status.TOO_MANY_ELEMENTS.getMessage());
                return Status.TOO_MANY_ELEMENTS;
            }
        } catch (NoSuchElementException ex) {
            LOG.warn(Status.TOO_FEW_ELEMENTS.getMessage());
            return Status.TOO_FEW_ELEMENTS;
        }
        return Status.VALID;
    }
1195996
public static String enumToString(final Enum<?> value) {

    if (value == null) {
      return null;
    }

    final String underscored = value.name();

    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < underscored.length(); i++) {
      final char c = underscored.charAt(i);
      if (c == '_') {
        sb.append(Character.toUpperCase(underscored.charAt(++i)));
      } else {
        sb.append(Character.toLowerCase(c));
      }
    }
    return sb.toString();
  }
1144975
public static String format(Object value, Type type) {
        value = decode(value, type);
        switch (type.getTag()) {
        case BYTE:      return formatByte((Byte) value);
        case LONG:      return formatLong((Long) value);
        case FLOAT:     return formatFloat((Float) value);
        case DOUBLE:    return formatDouble((Double) value);
        case CHAR:      return formatChar((Character) value);
        }
        if (value instanceof String)
            return formatString((String) value);
        return value + "";
    }
1273727
@SuppressWarnings({"unchecked", "rawtypes"})
    public U encode(Object value) {
        requireNonNull(value, "Value for encoding can not be null");

        TypeEncoder encoder = classMapping.get(value.getClass());
        if (encoder != null)
            return (U) encoder.encode(value);

        throw new TypeEncodingException("An unknown type [" + value.getClass() + "] was encountered");
    }
263226
private static double convertStringToDouble(final String value) {
    double doubleValue = 0;
    if(!StringUtils.isBlank(value)) {
      try {
        doubleValue = Double.parseDouble(value.trim());
      }
      catch(Exception e) {
        // do nothing
      }
    }
    return doubleValue;
  }
1345649
public static String encode(String value, Charset charset) {
    return encodeReserved(value, FragmentType.URI, charset);
  }
143288
public static String encodeUrlSafeBase64(String value) {
        return new String(UrlSafeBase64.encode(value.getBytes(Charsets.UTF_8)));
    }
1031088
public static String encode(String value) {
        if (value == null) {
            return value;
        }
        try {
            value = URLEncoder.encode(value, Constants.UTF_8);
        } catch (UnsupportedEncodingException e) {
            // Do nothing - UTF-8 should always be supported
        }
        return value;
    }
102280
@Override
    public String tagValue(String value) {
        String formattedValue = StringEscapeUtils.escapeJson(delegate.tagValue(value));
        return StringUtils.truncate(formattedValue, TAG_VALUE_MAX_LENGTH);
    }
1140078
public final Object encode(Val value) {
      if (value == null) {
         return null;
      }
      return encode(value.get());
   }
846704
public static String encodeString(String value) {
    if (value == null) {
      return null;
    }
    StringBuilder encoded = new StringBuilder();
    int len = value.length();
    for (int i = 0; i < len; i++) {
      char c = value.charAt(i);
      switch (c) {
        case ARRAY_DELIMITER_CHAR:
        case KEY_VALUE_DELIMITER_CHAR:
        case ESCAPE_CHAR:
          encoded.append(ESCAPE_CHAR);
          break;
        default:
          // just append char
      }
      encoded.append(c);
    }
    return encoded.toString();
  }
837505
protected String convertDigestEncoding(String value) {

        byte[] data = new byte[value.length() / 2];

        for (int i = 0; i < data.length; i++) {
            data[i] = (byte)(Integer.parseInt(value.substring(i * 2, (i * 2) + 2), 16) - 128);
        }
        return new String(Base64.encodeBase64(data));
    }