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