KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > ui > EditorPath


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.ui;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 import org.springframework.util.Assert;
33
34 /**
35  *
36  */

37 public class EditorPath {
38
39     private LinkedList JavaDoc components = new LinkedList JavaDoc();
40
41     private String JavaDoc editorId;
42
43     private String JavaDoc objectId;
44
45     private String JavaDoc parentId;
46
47     private EditorReference subPage;
48     
49     public EditorPath() {
50     }
51     
52     public EditorPath(String JavaDoc editorId, String JavaDoc objectId, String JavaDoc parentId,
53             EditorReference lastComponent) {
54
55         this.editorId = editorId;
56         this.objectId = objectId;
57         this.parentId = parentId;
58
59         EditorReference comp = lastComponent;
60         while (comp != null) {
61             addComponent(comp);
62             comp = comp.getParent();
63         }
64     }
65
66     public void addComponent(EditorReference reference) {
67         if (components.isEmpty()) {
68             reference.setEnabled(false);
69         }
70         components.addFirst(reference);
71     }
72     
73     public void setSubPage(String JavaDoc title) {
74         if (title != null) {
75             if (subPage == null) {
76                 Assert.notEmpty(components);
77                 EditorReference lastRef = (EditorReference) components.getLast();
78                 lastRef.setEnabled(true);
79                 subPage = new EditorReference();
80                 subPage.setEnabled(false);
81                 subPage.setEditorType("custom");
82                 subPage.setParent(lastRef);
83                 components.addLast(subPage);
84             }
85             subPage.setLabel(title);
86         }
87         else if (subPage != null) {
88             subPage.getParent().setEnabled(false);
89             components.remove(subPage);
90         }
91     }
92
93     public String JavaDoc getEditorId() {
94         return editorId;
95     }
96
97     public String JavaDoc getObjectId() {
98         return objectId;
99     }
100
101     public String JavaDoc getParentId() {
102         return parentId;
103     }
104
105     public String JavaDoc getSubPage() {
106         if (subPage == null) {
107             return null;
108         }
109         return subPage.getLabel();
110     }
111     
112     public List JavaDoc getComponents() {
113         return components;
114     }
115
116     public void encodeUrls(HttpServletResponse JavaDoc response) {
117         Iterator JavaDoc it = components.iterator();
118         while (it.hasNext()) {
119             EditorReference comp = (EditorReference) it.next();
120             if (comp.getEditorUrl() != null) {
121                 String JavaDoc encodedUrl = response.encodeURL(comp.getEditorUrl());
122                 comp.setEditorUrl(encodedUrl);
123             }
124         }
125     }
126 }
127
Popular Tags