001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bstefanescu 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.webengine.model; 021 022import java.io.File; 023import java.io.IOException; 024import java.util.List; 025import java.util.Map; 026 027import javax.ws.rs.core.MediaType; 028 029import org.nuxeo.ecm.webengine.ResourceBinding; 030import org.nuxeo.ecm.webengine.WebEngine; 031import org.nuxeo.ecm.webengine.model.exceptions.WebSecurityException; 032import org.nuxeo.ecm.webengine.scripting.ScriptFile; 033 034/** 035 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 036 */ 037public interface Module extends MessagesProvider { 038 039 String getName(); 040 041 File getRoot(); 042 043 Resource getRootObject(WebContext ctx); 044 045 WebEngine getEngine(); 046 047 void flushCache(); 048 049 Module getSuperModule(); 050 051 String getTemplateFileExt(); 052 053 String getMediaTypeId(MediaType mt); 054 055 Map<String, String> getMessages(String language); 056 057 Messages getMessages(); 058 059 List<ResourceBinding> getResourceBindings(); 060 061 /** 062 * Gets a file using the configured directory stack. Each directory in the stack is asked for the file until a file 063 * is found. If no file is found, returns null. 064 * <p> 065 * Note that the implementation may cache the results. To clear any cached data, you should call the 066 * {@link #flushCache()} method. 067 * 068 * @param path the file path 069 * @return null if no file found otherwise the file 070 */ 071 ScriptFile getFile(String path); 072 073 /** 074 * Gets a skin resource input stream. This must not cache resources. This method is using the module stacking 075 * directory to find the resource. 076 */ 077 ScriptFile getSkinResource(String path) throws IOException; 078 079 /** 080 * Loads a class given its name. 081 * <p> 082 * The scripting class loader will be used to load the class. 083 * 084 * @param className the class name 085 * @return the class instance 086 */ 087 Class<?> loadClass(String className) throws ClassNotFoundException; 088 089 /** 090 * Gets a {@link ResourceType} instance given its name. 091 * <p> 092 * The web type lookup is performed in the following order: 093 * <ol> 094 * <li>First the annotated Groovy classes are checked. (web/ directory) 095 * <li>Then the configuration type registry corresponding 096 * </ol> 097 * 098 * @param typeName the type name 099 * @return the web type instance 100 * @throws TypeNotFoundException if no such web type was defined 101 */ 102 ResourceType getType(String typeName); 103 104 /** 105 * Gets the types registered within this module. 106 * 107 * @return the types. Cannot be null. 108 */ 109 ResourceType[] getTypes(); 110 111 /** 112 * Gets the adapters registered within this module. 113 * 114 * @return the adapters. Cannot be null. 115 */ 116 AdapterType[] getAdapters(); 117 118 /** 119 * Gets the named adapter definition for the given resource. 120 * 121 * @param ctx the target resource 122 * @param name the adapter name 123 * @return the adapter if any adapter with that name applies for that resource otherwise throws an exception 124 * @throws WebSecurityException if the adapter exists but cannot be accessed in the context of that resource 125 * @throws AdapterNotFoundException if no such adapter exists for that resource 126 */ 127 AdapterType getAdapter(Resource ctx, String name); 128 129 /** 130 * Gets the list of adapters that applies to the given resource. 131 * 132 * @param ctx the context resource 133 * @return the list of adapters Cannot be null. 134 */ 135 List<AdapterType> getAdapters(Resource ctx); 136 137 /** 138 * Gets the list of adapter names that applies to the given resource. 139 * 140 * @param ctx the context resource 141 * @return the list of adapters Cannot be null. 142 */ 143 List<String> getAdapterNames(Resource ctx); 144 145 /** 146 * Gets the list of adapters that are enabled for the given context. 147 * <p> 148 * Enabled adapters are those adapters which can be accessed in the current security context. 149 * 150 * @param ctx the context resource 151 * @return the list of adapter.s Cannot be null. 152 */ 153 List<AdapterType> getEnabledAdapters(Resource ctx); 154 155 /** 156 * Gets the list of adapter names that are enabled for the given context. 157 * <p> 158 * Enabled services are those adapters which can be accessed in the current security context. 159 * 160 * @param ctx the context resource 161 * @return the list of adapters. Cannot be null. 162 */ 163 List<String> getEnabledAdapterNames(Resource ctx); 164 165 List<LinkDescriptor> getLinks(String category); 166 167 List<LinkDescriptor> getActiveLinks(Resource context, String category); 168 169 /** 170 * Get the path prefix to be used from templates to prepend to links to static resources. 171 * <p> 172 * This prefix is exposed to templates as ${skinPath}. 173 * 174 * @return the skin path prefix. never null. 175 */ 176 String getSkinPathPrefix(); 177 178 boolean isDerivedFrom(String moduleName); 179 180}