1 24 package org.riotfamily.riot.editor.ui; 25 26 import java.util.Iterator ; 27 import java.util.LinkedList ; 28 import java.util.List ; 29 30 import javax.servlet.http.HttpServletResponse ; 31 32 import org.springframework.util.Assert; 33 34 37 public class EditorPath { 38 39 private LinkedList components = new LinkedList (); 40 41 private String editorId; 42 43 private String objectId; 44 45 private String parentId; 46 47 private EditorReference subPage; 48 49 public EditorPath() { 50 } 51 52 public EditorPath(String editorId, String objectId, String 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 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 getEditorId() { 94 return editorId; 95 } 96 97 public String getObjectId() { 98 return objectId; 99 } 100 101 public String getParentId() { 102 return parentId; 103 } 104 105 public String getSubPage() { 106 if (subPage == null) { 107 return null; 108 } 109 return subPage.getLabel(); 110 } 111 112 public List getComponents() { 113 return components; 114 } 115 116 public void encodeUrls(HttpServletResponse response) { 117 Iterator it = components.iterator(); 118 while (it.hasNext()) { 119 EditorReference comp = (EditorReference) it.next(); 120 if (comp.getEditorUrl() != null) { 121 String encodedUrl = response.encodeURL(comp.getEditorUrl()); 122 comp.setEditorUrl(encodedUrl); 123 } 124 } 125 } 126 } 127 | Popular Tags |