001: /**
002: *
003: */package com.openedit.webui.tab;
004:
005: import com.openedit.OpenEditException;
006: import com.openedit.WebPageRequest;
007: import com.openedit.modules.BaseModule;
008: import com.openedit.page.manage.PageManager;
009: import org.apache.commons.logging.Log;
010: import org.apache.commons.logging.LogFactory;
011:
012: /**
013: * @author coke
014: *
015: */
016: public class TabModule extends BaseModule {
017: private static final Log log = LogFactory.getLog(TabModule.class);
018: public static final String PARAMETER_KEY = "tabName";
019: protected PageManager fieldPageManager;
020: protected String fieldTabName;
021:
022: public PageManager getPageManager() {
023: return fieldPageManager;
024: }
025:
026: public void setPageManager(PageManager pageManager) {
027: fieldPageManager = pageManager;
028: }
029:
030: public WebTab getTab(WebPageRequest inRequest)
031: throws OpenEditException {
032: String tabId = inRequest.getRequestParameter("tab-id");
033: String tabName = inRequest.findValue("tab-name");
034: //if( tabName == null) {tabName = inRequest.findValue("WebTreeName");}
035: if (tabId == null) {
036: tabId = tabName + "_" + inRequest.getUserName();
037: }
038: WebTab webTab = (WebTab) inRequest.getSessionValue(tabId);
039: if (webTab == null && tabName != null) {
040: // The root is applicable to our model only
041: //String root = findValue("root",inRequest);
042:
043: //RepositoryTreeModel model = null;
044: DefaultWebTabModel model = null;
045:
046: //if ((root == null) || root.equals("/")) {root = "/";}
047:
048: //model = new RepositoryTreeModel(getPageManager().getRepository(), root );
049: model = new DefaultWebTabModel();
050:
051: getPageManager().addPageAccessListener(model);
052:
053: //AndFilter and = new AndFilter();
054:
055: /*
056: String ignore = (String) findValue("excludes", inRequest);
057: if (ignore != null)
058: {
059: String[] types = ignore.split(",");
060: Filter[] not = new Filter[types.length];
061: for (int i = 0; i < types.length; i++)
062: {
063: not[i] = new NotFilter( new PathMatchesFilter(types[i].trim() ) );
064: }
065: and.setFilters(not);
066: }
067: */
068: /*
069: User user = inRequest.getUser();
070: if( user != null && user.hasPermission("oe.filemanager.editall") )
071: {
072:
073: }
074: else
075: {
076: //Look for hidden paths at the top level tree
077: populateRestrictedPaths(and, inRequest, root);
078: }
079: */
080: model.setPageManager(getPageManager());
081: //model.setFilter(and);
082: webTab = new WebTab(model);
083: webTab.setName(tabName);
084: webTab.setId(tabId);
085:
086: // setup the renderer
087: HtmlTabRenderer renderer = new HtmlTabRenderer(webTab);
088: /*
089: WebTreeNodeTreeRenderer renderero = new WebTreeNodeTreeRenderer(webTree);
090: String prefix = findValue( "url-prefix",inRequest);
091: if (prefix != null)
092: {
093: renderero.setUrlPrefix(prefix);
094: }
095: String friendly = findValue( "friendlyNames",inRequest);
096: if (friendly != null)
097: {
098: renderero.setFriendlyNames(Boolean.valueOf(friendly).booleanValue());
099: }
100: String home = (String) inRequest.getPageValue( "home" );
101: renderero.setHome(home);
102: */
103: webTab.setTabRenderer(renderer);
104: inRequest.putSessionValue(tabId, webTab);
105: }
106: if (webTab != null) {
107: inRequest.putPageValue("pageManager", getPageManager());
108: inRequest.putPageValue(tabName, webTab);
109: }
110: return webTab;
111: }
112:
113: public void addNode(WebPageRequest inRequest)
114: throws OpenEditException {
115: WebTab webTab = getTab(inRequest);
116: if (webTab == null) {
117: return;
118: }
119: DefaultWebTabNode node = findNode(inRequest
120: .getRequestParameter("node-id"), webTab);
121: DefaultWebTabNode parent = findNode(inRequest
122: .getRequestParameter("parent-node-id"), webTab);
123: if (node != null || parent == null) {
124: //The node exist, can't be added
125: return;
126: }
127: //create the new node
128: String nodeName = inRequest.getRequestParameter("node-name");
129: String nodeContentUrl = inRequest
130: .getRequestParameter("node-content-url");
131: node = new DefaultWebTabNode(nodeName);
132: node.setContentUrl(nodeContentUrl);
133: node.setParent(parent);
134: // WebTree tree = PageTree.getPageTree( getSiteContext() );
135: //add the new node
136: webTab.getTabRenderer().addNode(parent, node);
137: }
138:
139: public void removeNode(WebPageRequest inRequest)
140: throws OpenEditException {
141: WebTab webTab = getTab(inRequest);
142: if (webTab == null) {
143: return;
144: }
145: DefaultWebTabNode node = findNode(inRequest
146: .getRequestParameter("node-id"), webTab);
147: DefaultWebTabNode parent = findNode(inRequest
148: .getRequestParameter("parent-node-id"), webTab);
149: //TODO no deberia ser necesario el parent (remover)
150: if (node == null || parent == null) {
151: log
152: .error("Need specify nodeID and parentID for remove tab node");
153: return;
154: }
155: webTab.getTabRenderer().removeNode(parent, node);
156:
157: }
158:
159: protected DefaultWebTabNode findNode(String id, WebTab webTab) {
160: //String id = inRequest.getRequestParameter("nodeID");
161: if (id != null) {
162: DefaultWebTabNode node = webTab.getModel().getNodeById(id);
163: if (node != null) {
164: return node;
165: }
166: }
167: return null;
168: }
169:
170: public void reloadTab(WebPageRequest inRequest)
171: throws OpenEditException {
172: WebTab webTab = getTab(inRequest);
173: if (webTab != null) {
174: inRequest.removeSessionValue(webTab.getId());
175: inRequest.redirect(inRequest.getPath());
176: }
177: }
178:
179: }
|