ItemSimpleItemAttributeDetail itemAttributeDetails[] = new ItemSimpleItemAttributeDetail[counterItemAttributeDetail + 1];
for (int i = 0; i < itemAttributeDetails.length; i++) {
itemAttributeDetails[i] = new ItemSimpleItemAttributeDetail();
}
itemSimple.setItemAttributeDetails(itemAttributeDetails);
ItemSimpleImage itemImages[] = new ItemSimpleImage[counterItemImages + 1];
for (int i = 0; i < itemImages.length; i++) {
itemImages[i] = new ItemSimpleImage();
}
itemSimple.setItemImages(itemImages);
String tokens[] = this.fromCsv(input);
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("tokens", tokens);
engine.put("value", "");
int count = 0;
for (ItemSimpleCsvMapping definition : mappings) {
if (definition.getIeProfilePosition() == null && definition.getIeProfileFieldValue() == null) {
continue;
}
boolean isGroup = false;
if (!Format.isNullOrEmpty(definition.getIeProfileGroupName())) {
isGroup = true;
}
Object object = itemSimple;
if (isGroup) {
String ieProfileGroupName = definition.getIeProfileGroupName();
String methodName = "get" + ieProfileGroupName.substring(0, 1).toUpperCase() + ieProfileGroupName.substring(1);
Method method = ItemSimple.class.getMethod(methodName, (Class[]) null);
Object parameters[] = {};
Object arrays[] = (Object[]) method.invoke(itemSimple, parameters);
object = Array.get(arrays, definition.getIeProfileGroupIndex());
}
String ieProfileFieldName = definition.getIeProfileFieldName();
String methodName = "set" + ieProfileFieldName.substring(0, 1).toUpperCase() + ieProfileFieldName.substring(1);
Class<?> types[] = new Class[1];
Field f = object.getClass().getDeclaredField(ieProfileFieldName);
types[0] = f.getType();
Method method = object.getClass().getMethod(methodName, types);
Object parameters[] = {null};
String fieldValue = "";
if (definition.getIeProfilePosition() != null) {
fieldValue = tokens[definition.getIeProfilePosition().intValue() - 1];
}
if (!Format.isNullOrEmpty(definition.getIeProfileFieldValue())) {
try {
engine.eval(definition.getIeProfileFieldValue());
}
catch (javax.script.ScriptException e) {
String message = "[" + definition.getIeProfileFieldValue() + "] - [" + e.getMessage() + "]";
throw new ItemCsvTransformationException(message);
}
Object result = engine.get("value");
if (result instanceof String) {
fieldValue = (String) result;
}
else {
NativeJavaObject javaObject = (NativeJavaObject) result;
fieldValue = (String) Context.jsToJava(javaObject, String.class);
}
}
if (definition.getIeProfileFieldName().equals("itemImageLocation")) {
if (!Format.isNullOrEmpty(fieldValue)) {
ItemSimpleImage itemSimpleImage = (ItemSimpleImage) object;
itemSimpleImage.setImageValue(getImage(fieldValue));
}
}
boolean foundType = true;
try {