001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.riot.editor;
025:
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.riotfamily.common.i18n.AdvancedMessageCodesResolver;
032: import org.riotfamily.common.xml.ConfigurationEventListener;
033: import org.riotfamily.forms.factory.FormRepository;
034: import org.riotfamily.riot.list.ListRepository;
035: import org.riotfamily.riot.runtime.RiotRuntime;
036: import org.riotfamily.riot.runtime.RiotRuntimeAware;
037: import org.springframework.util.Assert;
038:
039: /**
040: *
041: */
042: public class EditorRepository implements RiotRuntimeAware {
043:
044: private static Log log = LogFactory.getLog(EditorRepository.class);
045:
046: private Map editorDefinitions = new HashMap();
047:
048: private GroupDefinition rootGroupDefinition;
049:
050: private ListRepository listRepository;
051:
052: private FormRepository formRepository;
053:
054: private AdvancedMessageCodesResolver messageCodesResolver;
055:
056: private String riotServletPrefix;
057:
058: public String getRiotServletPrefix() {
059: return riotServletPrefix;
060: }
061:
062: public void setRiotRuntime(RiotRuntime runtime) {
063: riotServletPrefix = runtime.getServletPrefix();
064: }
065:
066: public GroupDefinition getRootGroupDefinition() {
067: return this .rootGroupDefinition;
068: }
069:
070: public void setRootGroupDefinition(
071: GroupDefinition rootGroupDefinition) {
072: this .rootGroupDefinition = rootGroupDefinition;
073: }
074:
075: protected Map getEditorDefinitions() {
076: return this .editorDefinitions;
077: }
078:
079: public void addEditorDefinition(EditorDefinition editorDefinition) {
080: String id = editorDefinition.getId();
081: Assert.notNull(id, "Editor must have an id.");
082: EditorDefinition existingEditor = getEditorDefinition(id);
083: if (existingEditor != null) {
084: log.info("Overwriting editor " + id);
085: if (existingEditor.getParentEditorDefinition() instanceof GroupDefinition) {
086: GroupDefinition oldGroup = (GroupDefinition) existingEditor
087: .getParentEditorDefinition();
088: oldGroup.getEditorDefinitions().remove(existingEditor);
089: }
090: }
091: editorDefinitions.put(id, editorDefinition);
092: }
093:
094: public EditorDefinition getEditorDefinition(String editorId) {
095: if (editorId == null) {
096: return rootGroupDefinition;
097: }
098: return (EditorDefinition) editorDefinitions.get(editorId);
099: }
100:
101: public ListDefinition getListDefinition(String editorId) {
102: return (ListDefinition) getEditorDefinition(editorId);
103: }
104:
105: public FormDefinition getFormDefinition(String editorId) {
106: return (FormDefinition) getEditorDefinition(editorId);
107: }
108:
109: public GroupDefinition getGroupDefinition(String editorId) {
110: return (GroupDefinition) getEditorDefinition(editorId);
111: }
112:
113: public ListRepository getListRepository() {
114: return listRepository;
115: }
116:
117: public void setListRepository(ListRepository listRepository) {
118: this .listRepository = listRepository;
119: }
120:
121: public FormRepository getFormRepository() {
122: return this .formRepository;
123: }
124:
125: public void setFormRepository(FormRepository formRepository) {
126: this .formRepository = formRepository;
127: }
128:
129: public AdvancedMessageCodesResolver getMessageCodesResolver() {
130: return this .messageCodesResolver;
131: }
132:
133: public void setMessageCodesResolver(
134: AdvancedMessageCodesResolver messageKeyResolver) {
135: this .messageCodesResolver = messageKeyResolver;
136: }
137:
138: /**
139: * Subclasses may overwrite this method to allow the registration of
140: * {@link ConfigurationEventListener ConfigurationEventListeners}.
141: * The default implementation does nothing.
142: * @since 6.5
143: */
144: public void addListener(ConfigurationEventListener listener) {
145: }
146:
147: }
|