001: /*
002: Copyright (c) 2003 eInnovation Inc. All rights reserved
003:
004: This library is free software; you can redistribute it and/or modify it under the terms
005: of the GNU Lesser General Public License as published by the Free Software Foundation;
006: either version 2.1 of the License, or (at your option) any later version.
007:
008: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
009: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: See the GNU Lesser General Public License for more details.
011: */
012:
013: package com.openedit.webui.tree;
014:
015: import org.openedit.repository.ContentItem;
016: import org.openedit.repository.Repository;
017: import org.openedit.repository.RepositoryException;
018:
019: import com.openedit.OpenEditException;
020: import com.openedit.OpenEditRuntimeException;
021: import com.openedit.PageAccessListener;
022: import com.openedit.page.Page;
023: import com.openedit.page.manage.PageManager;
024:
025: /**
026: * This model represents a tree of site content.
027: *
028: * @author Matt Avery, mavery@einnovation.com
029: */
030: public class RepositoryTreeModel extends DefaultWebTreeModel implements
031: PageAccessListener {
032: protected Repository fieldRepository;
033: protected String fieldRootPath;
034: protected PageManager fieldPageManager;
035:
036: /**
037: * Constructor for PageTreeModel.
038: *
039: * @param inSiteContext DOCUMENT ME!
040: */
041: public RepositoryTreeModel(Repository inRepository) {
042: this (inRepository, "/");
043: }
044:
045: public RepositoryTreeModel(Repository inRepository,
046: String inRootPath) {
047: super ();
048: fieldRepository = inRepository;
049: fieldRootPath = inRootPath;
050: }
051:
052: /* (non-Javadoc)
053: * @see TreeModel#getRoot()
054: */
055: public Object getRoot() {
056: if (fieldRoot == null) {
057: reload();
058: }
059:
060: return fieldRoot;
061: }
062:
063: /**
064: * Find the page tree node at the given path. This method will not automatically expand any
065: * node in the tree if it is not already expanded.
066: *
067: * @param inPath The path (e.g. "abc/def/ghi.html")
068: *
069: * @return The node at the given path, or <code>null</code> if no node could be found that
070: * matched the given path
071: */
072: public RepositoryTreeNode findNode(String inPath) {
073: return ((RepositoryTreeNode) getRoot()).findNode(inPath);
074: }
075:
076: /**
077: *
078: */
079: public void reload() {
080: ContentItem rootItem;
081: try {
082: rootItem = getRepository().get(getRootPath());
083: //TODO: Add all the ignore paths depending on permissions
084: //At least handle directory level permissions _site.xconf
085: //TODO: Add user, page manager create basewebrequests
086: } catch (RepositoryException e) {
087: throw new OpenEditRuntimeException(e);
088: }
089: RepositoryTreeNode newRoot = new RepositoryTreeNode(
090: getRepository(), rootItem);
091: if (newRoot != null) {
092: newRoot.fieldFilter = getFilter();
093: newRoot.fieldPageManager = getPageManager();
094: }
095: fieldRoot = newRoot;
096:
097: }
098:
099: public Repository getRepository() {
100: return fieldRepository;
101: }
102:
103: public void setRepository(Repository repository) {
104: fieldRepository = repository;
105: }
106:
107: public String getRootPath() {
108: return fieldRootPath;
109: }
110:
111: public void setRootPath(String rootPath) {
112: fieldRootPath = rootPath;
113: }
114:
115: /**
116: * DOCUMENT ME!
117: *
118: * @param inPage
119: * @param inRevision
120: *
121: * @throws OpenEditException
122: */
123: public void pageAdded(Page inPage) {
124: reload();
125: }
126:
127: /**
128: * DOCUMENT ME!
129: *
130: * @param inPage
131: * @param inRevision
132: *
133: * @throws OpenEditException
134: */
135: public void pageModified(Page inPage) {
136: reload();
137: }
138:
139: /**
140: * DOCUMENT ME!
141: *
142: * @param inPage
143: * @param inRevision
144: *
145: * @throws OpenEditException
146: */
147: public void pageRemoved(Page inPage) {
148: reload();
149: }
150:
151: /**
152: * DOCUMENT ME!
153: *
154: * @param inPage
155: *
156: * @throws OpenEditException
157: */
158: public void pageRequested(Page inPage) {
159: // do nothing
160: }
161:
162: protected boolean hasLoadedChildren(Object inRoot) {
163: //Only look in nodes with already loaded children
164: RepositoryTreeNode parent = (RepositoryTreeNode) inRoot;
165: if (parent.fieldChildren == null) {
166: return false;
167: }
168:
169: return true;
170: }
171:
172: public PageManager getPageManager() {
173: return fieldPageManager;
174: }
175:
176: public void setPageManager(PageManager inPageManager) {
177: fieldPageManager = inPageManager;
178: }
179:
180: }
|