1 /** 2 * This file Copyright (c) 2010-2015 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.module.blossom.annotation; 35 36 import info.magnolia.rendering.template.type.DefaultTemplateTypes; 37 38 import java.lang.annotation.ElementType; 39 import java.lang.annotation.Retention; 40 import java.lang.annotation.RetentionPolicy; 41 import java.lang.annotation.Target; 42 43 /** 44 * Used on a Spring Web MVC controller to expose it as a template. A template is either used to render a page or a 45 * component. 46 * <p/> 47 * The title of the template is set with this annotation while the description is set using 48 * {@link info.magnolia.module.blossom.annotation.TemplateDescription}. 49 * <p/> 50 * A component is added to a page using a dialog. A controller that uses this annotation automatically becomes a factory 51 * for its dialog. This dialog is automatically assigned an id and you do not need to add the 52 * {@link info.magnolia.module.blossom.annotation.DialogFactory} annotation. The functionality for creating the dialog 53 * is identical to the functionality of classes that use {@link info.magnolia.module.blossom.annotation.DialogFactory}. 54 * More specifically you can use {@link TabFactory} and {@link TabOrder}. 55 * <p/> 56 * If you prefer using a dialog created by a {@link DialogFactory} or one configured in Magnolia you can override this 57 * behaviour by setting the 'dialog' field. 58 * <p/> 59 * The class will also be scanned for methods annotated with {@link DialogFactory}. This makes it possible to declare 60 * dialogs in the same template that they're used for. 61 * <p/> 62 * It is possible to restrict on which pages a template can be used by using the 63 * {@link info.magnolia.module.blossom.annotation.Available} annotation. 64 * <p/> 65 * You can use {@link info.magnolia.module.blossom.annotation.I18nBasename} to specify which resource bundle should be 66 * used for localization of the template's title and description. 67 * <p/> 68 * For example this template will be exposed with the id "mainTemplate": 69 * <pre> 70 * @Controller 71 * @Template(title = "Main", id = "moduleName:pages/main") 72 * public class MainTemplate { 73 * 74 * @RequestMapping("/mainTemplate") 75 * public String render() { 76 * return "mainTemplate.jsp"; 77 * } 78 * 79 * @TabFactory("Content") 80 * public void contentTab(UiConfig cfg, TabBuilder tab) { 81 * tab.fields(cfg.fields.richText("body").label("Text")); 82 * } 83 * } 84 * </pre> 85 * 86 * @see info.magnolia.module.blossom.annotation.TemplateDescription 87 * @see info.magnolia.module.blossom.annotation.Area 88 * @see info.magnolia.module.blossom.annotation.TabOrder 89 * @see info.magnolia.module.blossom.annotation.TabFactory 90 * @see info.magnolia.module.blossom.annotation.Available 91 * @see info.magnolia.module.blossom.annotation.I18nBasename 92 * @see info.magnolia.module.blossom.annotation.DialogFactory 93 * @since 1.0 94 */ 95 @Retention(RetentionPolicy.RUNTIME) 96 @Target(ElementType.TYPE) 97 public @interface Template { 98 99 /** 100 * Id of the template. Templates intended to be used for pages must have an id in the format 101 * <code><moduleName>:pages/*</code> or if it's intended to be a component 102 * <code><moduleName>:components/*</code>. For example: <code>myModule:pages/mainTemplate</code> and 103 * <code>myModule:components/textAndImage</code>. 104 */ 105 String id(); 106 107 /** 108 * Title of the template. 109 */ 110 String title(); 111 112 /** 113 * Id of a dialog to be used for this template. By default the controller itself will be responsible for 114 * creating the dialog. 115 */ 116 String dialog() default ""; 117 118 /** 119 * Defines the visibility of the template. When set to false the template is never presented in the user interface. 120 * This is useful for templates that are only used for pages that are created by scheduled jobs rather than by 121 * editors. 122 */ 123 boolean visible() default true; 124 125 /** 126 * Specifies the template type, e.g. "home", "section", etc. 127 * 128 * @see info.magnolia.rendering.template.type.DefaultTemplateTypes 129 */ 130 String type() default DefaultTemplateTypes.CONTENT; 131 132 /** 133 * Specifies the template subtype, such as specific features, e.g. "news", etc. 134 */ 135 String subtype() default ""; 136 }