public static void setProperty(CoreSession session, DocumentModel doc, String key, String value) throws Exception { if ("ecm:acl".equals(key)) { setLocalAcl(session, doc, value); } Property p = doc.getProperty(key); if (value == null || value.length() == 0) { p.setValue(null); return; } Type type = p.getField().getType(); if (!type.isSimpleType()) { if (type.isListType()) { ListType ltype = (ListType) type; if (ltype.isScalarList()) { p.setValue(readStringList(value, (SimpleType) ltype.getFieldType())); return; } else if (ltype.getFieldType().isComplexType()) { Object val = ComplexTypeJSONDecoder.decodeList(ltype, value); p.setValue(val); return; } } else if (type.isComplexType()) { Object val = ComplexTypeJSONDecoder.decode((ComplexType) type, value); p.setValue(val); return; } throw new OperationException("Property type is not supported by this operation"); } else { p.setValue(((SimpleType) type).getPrimitiveType().decode(value)); } }
/** * Given a document property, updates its value with the given blob. The property can be a blob * list or a blob. If a blob list the blob is appended to the list, if a blob then it will be set * as the property value. Both blob list formats are supported: the file list (blob holder list) * and simple blob list. */ public static void addBlob(Property p, Blob blob) throws PropertyException { if (p.isList()) { // detect if a list of simple blobs or a list of files (blob // holder) Type ft = ((ListProperty) p).getType().getFieldType(); if (ft.isComplexType() && ((ComplexType) ft).getFieldsCount() == 2) { p.addValue(createBlobHolderMap(blob)); } else { p.addValue(blob); } } else { p.setValue(blob); } }