KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > EditorRepository


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.editor;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.riotfamily.common.i18n.AdvancedMessageCodesResolver;
32 import org.riotfamily.common.xml.ConfigurationEventListener;
33 import org.riotfamily.forms.factory.FormRepository;
34 import org.riotfamily.riot.list.ListRepository;
35 import org.riotfamily.riot.runtime.RiotRuntime;
36 import org.riotfamily.riot.runtime.RiotRuntimeAware;
37 import org.springframework.util.Assert;
38
39 /**
40  *
41  */

42 public class EditorRepository implements RiotRuntimeAware {
43
44     private static Log log = LogFactory.getLog(EditorRepository.class);
45
46     private Map JavaDoc editorDefinitions = new HashMap JavaDoc();
47
48     private GroupDefinition rootGroupDefinition;
49
50     private ListRepository listRepository;
51
52     private FormRepository formRepository;
53
54     private AdvancedMessageCodesResolver messageCodesResolver;
55
56     private String JavaDoc riotServletPrefix;
57
58     public String JavaDoc getRiotServletPrefix() {
59         return riotServletPrefix;
60     }
61
62     public void setRiotRuntime(RiotRuntime runtime) {
63         riotServletPrefix = runtime.getServletPrefix();
64     }
65
66     public GroupDefinition getRootGroupDefinition() {
67         return this.rootGroupDefinition;
68     }
69
70     public void setRootGroupDefinition(GroupDefinition rootGroupDefinition) {
71         this.rootGroupDefinition = rootGroupDefinition;
72     }
73
74     protected Map JavaDoc getEditorDefinitions() {
75         return this.editorDefinitions;
76     }
77
78     public void addEditorDefinition(EditorDefinition editorDefinition) {
79         String JavaDoc id = editorDefinition.getId();
80         Assert.notNull(id, "Editor must have an id.");
81         EditorDefinition existingEditor = getEditorDefinition(id);
82         if (existingEditor != null) {
83             log.info("Overwriting editor " + id);
84             if (existingEditor.getParentEditorDefinition() instanceof GroupDefinition) {
85                 GroupDefinition oldGroup = (GroupDefinition) existingEditor.getParentEditorDefinition();
86                 oldGroup.getEditorDefinitions().remove(existingEditor);
87             }
88         }
89         editorDefinitions.put(id, editorDefinition);
90     }
91
92     public EditorDefinition getEditorDefinition(String JavaDoc editorId) {
93         if (editorId == null) {
94             return rootGroupDefinition;
95         }
96         return (EditorDefinition) editorDefinitions.get(editorId);
97     }
98
99     public ListDefinition getListDefinition(String JavaDoc editorId) {
100         return (ListDefinition) getEditorDefinition(editorId);
101     }
102
103     public FormDefinition getFormDefinition(String JavaDoc editorId) {
104         return (FormDefinition) getEditorDefinition(editorId);
105     }
106
107     public GroupDefinition getGroupDefinition(String JavaDoc editorId) {
108         return (GroupDefinition) getEditorDefinition(editorId);
109     }
110
111     public ListRepository getListRepository() {
112         return listRepository;
113     }
114
115     public void setListRepository(ListRepository listRepository) {
116         this.listRepository = listRepository;
117     }
118
119     public FormRepository getFormRepository() {
120         return this.formRepository;
121     }
122
123     public void setFormRepository(FormRepository formRepository) {
124         this.formRepository = formRepository;
125     }
126
127     public AdvancedMessageCodesResolver getMessageCodesResolver() {
128         return this.messageCodesResolver;
129     }
130
131     public void setMessageCodesResolver(AdvancedMessageCodesResolver messageKeyResolver) {
132         this.messageCodesResolver = messageKeyResolver;
133     }
134
135     /**
136      * Subclasses may overwrite this method to allow the registration of
137      * {@link ConfigurationEventListener ConfigurationEventListeners}.
138      * The default implementation does nothing.
139      * @since 6.5
140      */

141     public void addListener(ConfigurationEventListener listener) {
142     }
143
144 }
145
Popular Tags