| 1 |
package ezvcard.property; |
| 2 |
|
| 3 |
import java.util.LinkedHashMap; |
| 4 |
import java.util.List; |
| 5 |
import java.util.Map; |
| 6 |
|
| 7 |
import com.github.mangstadt.vinnie.SyntaxStyle; |
| 8 |
import com.github.mangstadt.vinnie.validate.AllowedCharacters; |
| 9 |
import com.github.mangstadt.vinnie.validate.VObjectValidator; |
| 10 |
|
| 11 |
import ezvcard.VCard; |
| 12 |
import ezvcard.VCardDataType; |
| 13 |
import ezvcard.VCardVersion; |
| 14 |
import ezvcard.ValidationWarning; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public class RawProperty extends TextProperty { |
| 51 |
private String propertyName; |
| 52 |
private VCardDataType dataType; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public RawProperty(String propertyName, String value) { |
| 60 |
this(propertyName, value, null); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public RawProperty(String propertyName, String value, VCardDataType dataType) { |
| 70 |
super(value); |
| 71 |
this.propertyName = propertyName; |
| 72 |
this.dataType = dataType; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public RawProperty(RawProperty original) { |
| 80 |
super(original); |
| 81 |
propertyName = original.propertyName; |
| 82 |
dataType = original.dataType; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public String getPropertyName() { |
| 90 |
return propertyName; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public void setPropertyName(String propertyName) { |
| 98 |
this.propertyName = propertyName; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public VCardDataType getDataType() { |
| 106 |
return dataType; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public void setDataType(VCardDataType dataType) { |
| 114 |
this.dataType = dataType; |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
protected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard) { |
| 119 |
SyntaxStyle syntax = version.getSyntaxStyle(); |
| 120 |
AllowedCharacters allowed = VObjectValidator.allowedCharactersParameterName(syntax, true); |
| 121 |
if (!allowed.check(propertyName)) { |
| 122 |
if (syntax == SyntaxStyle.OLD) { |
| 123 |
AllowedCharacters notAllowed = allowed.flip(); |
| 124 |
warnings.add(new ValidationWarning(33, propertyName, notAllowed.toString(true))); |
| 125 |
} else { |
| 126 |
warnings.add(new ValidationWarning(24, propertyName)); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
protected Map<String, Object> toStringValues() { |
| 133 |
Map<String, Object> values = new LinkedHashMap<>(); |
| 134 |
values.put("propertyName", propertyName); |
| 135 |
values.put("dataType", dataType); |
| 136 |
values.put("value", value); |
| 137 |
return values; |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public RawProperty copy() { |
| 142 |
return new RawProperty(this); |
| 143 |
} |
| 144 |
|
| 145 |
@Override |
| 146 |
public int hashCode() { |
| 147 |
final int prime = 31; |
| 148 |
int result = super.hashCode(); |
| 149 |
result = prime * result + ((dataType == null) ? 0 : dataType.hashCode()); |
| 150 |
result = prime * result + ((propertyName == null) ? 0 : propertyName.toLowerCase().hashCode()); |
| 151 |
return result; |
| 152 |
} |
| 153 |
|
| 154 |
@Override |
| 155 |
public boolean equals(Object obj) { |
| 156 |
if (this == obj) return true; |
| 157 |
if (!super.equals(obj)) return false; |
| 158 |
RawProperty other = (RawProperty) obj; |
| 159 |
if (dataType == null) { |
| 160 |
if (other.dataType != null) return false; |
| 161 |
} else if (!dataType.equals(other.dataType)) return false; |
| 162 |
if (propertyName == null) { |
| 163 |
if (other.propertyName != null) return false; |
| 164 |
} else if (!propertyName.equalsIgnoreCase(other.propertyName)) return false; |
| 165 |
return true; |
| 166 |
} |
| 167 |
} |