/** * Factory constructor. * * @param group property group * @param params property parameters * @param value string representation of a property value * @throws DecoderException if the specified string is not a valid key encoding * @throws URISyntaxException where the specified string is not a valid URI */ public Key(Group group, List<Parameter> params, String value) throws DecoderException, URISyntaxException { super(group, Id.KEY, params); final Parameter valueParameter = getParameter(Parameter.Id.VALUE); /* * in the relaxed parsing mode we allow the vcard 2.1-style VALUE=URL parameter */ if (Value.URI.equals(valueParameter) || valueParameter != null && CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING) && "URL".equalsIgnoreCase(valueParameter.getValue())) { this.uri = new URI(value); } else { final BinaryDecoder decoder = new Base64(); this.binary = decoder.decode(value.getBytes()); } }
/** * Factory constructor. * @param group property group * @param params property parameters * @param value string representation of a property value * @throws DecoderException if the specified string is not a valid key encoding * @throws URISyntaxException where the specified string is not a valid URI */ public Key(Group group, List<Parameter> params, String value) throws DecoderException, URISyntaxException { super(group, Id.KEY, params); final Parameter valueParameter = getParameter(Parameter.Id.VALUE); /* * in the relaxed parsing mode we allow the vcard 2.1-style VALUE=URL parameter */ if (valueParameter != null && Value.URI.equals(valueParameter) || valueParameter != null && CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING) && "URL".equalsIgnoreCase(valueParameter.getValue())) { this.uri = new URI(value); } else { final BinaryDecoder decoder = new Base64(); this.binary = decoder.decode(value.getBytes()); } }
/** * {@inheritDoc} */ @Override public String getValue() { final Parameter valueParameter = getParameter(Parameter.Id.VALUE); String stringValue = null; /* * in the relaxed parsing mode we allow the vcard 2.1-style VALUE=URL parameter */ if (Value.URI.equals(valueParameter) || valueParameter != null && CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING) && "URL".equalsIgnoreCase(valueParameter.getValue())) { stringValue = Strings.valueOf(uri); } else if (binary != null) { try { final BinaryEncoder encoder = new Base64(); stringValue = new String(encoder.encode(binary)); } catch (EncoderException ee) { log.error("Error encoding binary data", ee); } } return stringValue; }
/** * {@inheritDoc} */ @Override public String getValue() { final Parameter valueParameter = getParameter(Parameter.Id.VALUE); String stringValue = null; /* * in the relaxed parsing mode we allow the vcard 2.1-style VALUE=URL parameter */ if (valueParameter != null && Value.URI.equals(valueParameter) || valueParameter != null && CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING) && "URL".equalsIgnoreCase(valueParameter.getValue())) { stringValue = Strings.valueOf(uri); } else if (binary != null) { try { final BinaryEncoder encoder = new Base64(); stringValue = new String(encoder.encode(binary)); } catch (EncoderException ee) { log.error("Error encoding binary data", ee); } } return stringValue; }