/** * Updates an existing document. */ protected DocumentModel updateDocument(ExportedDocument xdoc, DocumentModel doc) { // load schemas data loadSchemas(xdoc, doc, xdoc.getDocument()); loadFacetsInfo(doc, xdoc.getDocument()); beforeSaveDocument(doc); doc = session.saveDocument(doc); unsavedDocuments += 1; saveIfNeeded(); return doc; }
loadFacetsInfo(doc, xdoc.getDocument()); loadSchemas(xdoc, doc, xdoc.getDocument()); beforeCreateDocument(doc); doc = session.createDocument(doc); loadSystemInfo(doc, xdoc.getDocument()); saveIfNeeded();
while (it.hasNext()) { Element el = it.next(); list.add(getElementData(xdoc, el, ltype.getFieldType())); Class klass = getFieldClass(ftype); if (klass.isPrimitive()) { return PrimitiveArrays.toPrimitiveArray(list, klass); Element el = it.next(); String name = el.getName(); Object value = getElementData(xdoc, el, ctype.getField(el.getName()).getType()); map.put(name, value);
@SuppressWarnings("unchecked") protected static void loadSchema(ExportedDocument xdoc, Schema schema, DocumentModel doc, Element schemaElement) { String schemaName = schemaElement.attributeValue(ExportConstants.NAME_ATTR); Map<String, Object> data = new HashMap<>(); Iterator<Element> it = schemaElement.elementIterator(); while (it.hasNext()) { Element element = it.next(); String name = element.getName(); Field field = schema.getField(name); if (field == null) { throw new NuxeoException( "Invalid input document. No such property was found " + name + " in schema " + schemaName); } Object value = getElementData(xdoc, element, field.getType()); data.put(name, value); } doc.setProperties(schemaName, data); }
protected static Class getFieldClass(Type fieldType) { Class klass = JavaTypes.getClass(fieldType); // for enumerated SimpleTypes we may need to lookup on the supertype // we do the recursion here and not in JavaTypes to avoid potential impacts if (klass == null) { assert fieldType.getSuperType() != null; return getFieldClass(fieldType.getSuperType()); } return klass; }
@SuppressWarnings("unchecked") protected void loadSchemas(ExportedDocument xdoc, DocumentModel docModel, Document doc) { SchemaManager schemaMgr = Framework.getService(SchemaManager.class); Iterator<Element> it = doc.getRootElement().elementIterator(ExportConstants.SCHEMA_TAG); while (it.hasNext()) { Element element = it.next(); String schemaName = element.attributeValue(ExportConstants.NAME_ATTR); Schema schema = schemaMgr.getSchema(schemaName); if (schema == null) { log.warn("The document " + docModel.getName() + " with id=" + docModel.getId() + " and type=" + docModel.getDocumentType() + " contains the schema '" + schemaName + "', which is not registered as available in the schemaManager. This schema will be ignored."); if (log.isDebugEnabled()) { log.debug("Available schemas: " + Arrays.toString(schemaMgr.getSchemas())); } continue; } loadSchema(xdoc, schema, docModel, element); } }