001package org.nuxeo.template.context; 002 003import org.nuxeo.ecm.core.api.DocumentModel; 004import org.nuxeo.ecm.core.api.model.Property; 005import org.nuxeo.ecm.platform.rendering.fm.adapters.SchemaTemplate; 006 007public class SimpleSchemaWrapper { 008 009 private final DocumentModel doc; 010 011 private final String schemaName; 012 013 public SimpleSchemaWrapper(SchemaTemplate.DocumentSchema schema) { 014 this.doc = schema.doc; 015 this.schemaName = schema.schemaName; 016 } 017 018 public Object get(String name) { 019 if (doc.isPrefetched(schemaName, name)) { 020 // simple value already available, don't load DocumentPart 021 return doc.getProperty(schemaName, name); 022 } else { 023 // use normal Property lookup in Part 024 return wrap(doc.getPart(schemaName).get(name)); 025 } 026 } 027 028 protected Object wrap(Property prop) { 029 if (prop == null || prop.getValue() == null) { 030 return null; 031 } 032 return prop.getValue(); 033 } 034 035}