001package org.nuxeo.template.context;
002
003import org.nuxeo.ecm.core.api.DocumentModel;
004import org.nuxeo.ecm.platform.rendering.api.DefaultDocumentView;
005import org.nuxeo.ecm.platform.rendering.fm.adapters.SchemaTemplate;
006
007public class SimpleDocumentWrapper {
008
009    protected final DocumentModel doc;
010
011    public SimpleDocumentWrapper(DocumentModel doc) {
012        this.doc = doc;
013    }
014
015    public Object get(String key) {
016        Object value = DefaultDocumentView.DEFAULT.get(doc, key);
017        if (value != DefaultDocumentView.UNKNOWN) {
018            return wrap(value);
019        }
020        return null;
021    }
022
023    protected Object wrap(Object obj) {
024        if (obj instanceof SchemaTemplate.DocumentSchema) {
025            return new SimpleSchemaWrapper((SchemaTemplate.DocumentSchema) obj);
026        }
027        return obj;
028    }
029}