parent = checkoutNode(parent);
if (!StringUtils.isEmpty(mixinType) && !parent.isNodeType(mixinType)) {
parent.addMixin(mixinType);
}
ExtendedPropertyDefinition propertyDefinition = null;
propertyDefinition = parent.getApplicablePropertyDefinition(propertyName);
if (propertyDefinition == null) {
return false;
}
if (propertyDefinition.isProtected()) {
// System.out.println("protected : " + propertyName);
return false;
}
Node n = parent;
// System.out.println("setting " + propertyName);
if (value != null && value.length() != 0 && !value.equals("<empty>")) {
switch (propertyDefinition.getRequiredType()) {
case PropertyType.DATE:
GregorianCalendar cal = new GregorianCalendar();
try {
DateFormat df = new SimpleDateFormat(ImportExportService.DATE_FORMAT);
Date d = df.parse(value);
cal.setTime(d);
n.setProperty(propertyName, cal);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
break;
default:
switch (propertyDefinition.getSelector()) {
case SelectorType.CATEGORY: {
String[] cats = value.split(",");
List<Value> values = new ArrayList<Value>();
for (int i = 0; i < cats.length; i++) {
String cat = cats[i];
Query q = session.getWorkspace().getQueryManager().createQuery("select * from [jnt:category] as cat where NAME(cat) = '"+cat+"'", Query.JCR_SQL2);
NodeIterator ni = q.execute().getNodes();
if (ni.hasNext()) {
values.add(session.getValueFactory().createValue(ni.nextNode()));
}
}
n.setProperty(propertyName, values.toArray(new Value[values.size()]));
break;
}
case SelectorType.RICHTEXT: {
n.setProperty(propertyName, value);
break;
}
default: {
String[] vcs = propertyDefinition.getValueConstraints();
List<String> constraints = Arrays.asList(vcs);
if (!propertyDefinition.isMultiple()) {
if (value.startsWith("<jahia-resource")) {
value = ResourceBundleMarker.parseMarkerValue(value)
.getResourceKey();
if (value.startsWith(propertyDefinition.getResourceBundleKey())) {
value = value.substring(propertyDefinition
.getResourceBundleKey().length() + 1);
}
}
value = baseType != null && mapping != null ? mapping.getMappedPropertyValue(baseType,
localName, value) : value;
if (constraints.isEmpty() || constraints.contains(value)) {
try {
n.setProperty(propertyName, value);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
String[] strings = value.split("\\$\\$\\$");
List<Value> values = new ArrayList<Value>();
for (int i = 0; i < strings.length; i++) {
String string = strings[i];
if (string.startsWith("<jahia-resource")) {
string = ResourceBundleMarker.parseMarkerValue(string)
.getResourceKey();
if (string.startsWith(propertyDefinition
.getResourceBundleKey())) {
string = string.substring(propertyDefinition
.getResourceBundleKey().length() + 1);
}
}
value = baseType != null ? mapping.getMappedPropertyValue(
baseType, localName, value) : value;
if (constraints.isEmpty() || constraints.contains(value)) {
values.add(new ValueImpl(string, propertyDefinition
.getRequiredType()));
}
}
;
n.setProperty(propertyName,