protected void setValue(DcObject dco, int fieldIdx, String value, IItemImporterClient listener) {
if (Utilities.isEmpty(value)) return;
DcField field = dco.getModule().getField(fieldIdx);
try {
if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
field.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE) {
DataManager.createReference(dco, field.getIndex(), value);
} else if (field.getFieldType() == ComponentFactory._TIMEFIELD) {
try {
dco.setValue(field.getIndex(), Long.valueOf(value));
} catch (NumberFormatException nfe) {
if (value.indexOf(":") > -1) {
int hours = Integer.parseInt(value.substring(0, value.indexOf(":")));
int minutes = Integer.parseInt(value.substring(value.indexOf(":") + 1, value.lastIndexOf(":")));
int seconds = Integer.parseInt(value.substring(value.lastIndexOf(":") + 1));
dco.setValue(field.getIndex(), Long.valueOf(seconds + (minutes *60) + (hours * 60 * 60)));
}
}
} else if (field.getFieldType() == ComponentFactory._RATINGCOMBOBOX ||
field.getFieldType() == ComponentFactory._FILESIZEFIELD) {
value = value.replaceAll("\\.", "");
try {
dco.setValue(field.getIndex(), Long.valueOf(value));
} catch (NumberFormatException nfe) {
String sValue = "";
for (char c : value.toCharArray()) {
if (Character.isDigit(c))
sValue += c;
else
break;
}
if (!Utilities.isEmpty(sValue))
dco.setValue(field.getIndex(), Long.valueOf(sValue));
}
} else if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
File file = getImagePath(value);
if (file.exists())
dco.setValue(field.getIndex(), new DcImageIcon(file));
} else if (field.getValueType() == DcRepository.ValueTypes._ICON) {
File file = getImagePath(value);
if (file.exists()) {
String s = Utilities.fileToBase64String(file);
s = Utilities.isEmpty(s) ? Utilities.fileToBase64String(new File(value)) : s;
dco.setValue(field.getIndex(), s);
} else {
dco.setValue(field.getIndex(), value);
}
} else if (field.getValueType() == DcRepository.ValueTypes._BOOLEAN) {
dco.setValue(field.getIndex(), Boolean.valueOf(value));
} else {
dco.setValue(field.getIndex(), value);
}
} catch (Exception e) {
String message = DcResources.getText("msgErrorWhileSettingValue", new String[] {value, field.getLabel()});
listener.notifyMessage(message);
logger.error(message, e);
}
}