001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.site.tree2;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.apache.lenya.cms.site.Link;
024: import org.apache.lenya.cms.site.SiteException;
025: import org.apache.lenya.cms.site.SiteNode;
026: import org.apache.lenya.cms.site.SiteStructure;
027: import org.apache.lenya.cms.site.tree.SiteTreeNode;
028:
029: /**
030: * Site tree node which delegates all operations to a shared tree node.
031: */
032: public class DelegatingNode implements TreeNode {
033:
034: private SiteNode node;
035: private DelegatingSiteTree tree;
036:
037: /**
038: * @param tree The tree.
039: * @param delegate The delegate node.
040: */
041: public DelegatingNode(DelegatingSiteTree tree, SiteNode delegate) {
042: this .node = delegate;
043: this .tree = tree;
044: }
045:
046: public void delete() {
047: throw new UnsupportedOperationException();
048: }
049:
050: private List children;
051: private List preOrder;
052:
053: public SiteNode[] getChildren() {
054: if (this .children == null) {
055: SiteNode[] delegateChildren = this .node.getChildren();
056: this .children = new ArrayList();
057: for (int i = 0; i < delegateChildren.length; i++) {
058: this .children.add(this .tree
059: .getNode(delegateChildren[i]));
060: }
061: }
062: return (SiteNode[]) this .children
063: .toArray(new SiteNode[this .children.size()]);
064: }
065:
066: public String getHref() {
067: return this .node.getHref();
068: }
069:
070: public String[] getLanguages() {
071: return this .node.getLanguages();
072: }
073:
074: public Link getLink(String language) throws SiteException {
075: return this .tree.getLink(this .node.getLink(language));
076: }
077:
078: public String getName() {
079: return this .node.getName();
080: }
081:
082: public SiteNode getParent() throws SiteException {
083: return this .tree.getNode(this .node.getParent());
084: }
085:
086: public String getPath() {
087: return this .node.getPath();
088: }
089:
090: public SiteStructure getStructure() {
091: return this .tree;
092: }
093:
094: public String getSuffix() {
095: return this .node.getSuffix();
096: }
097:
098: public String getUuid() {
099: return this .node.getUuid();
100: }
101:
102: public boolean hasLink(String language) {
103: return this .node.hasLink(language);
104: }
105:
106: public boolean hasLink() {
107: return this .node.hasLink();
108: }
109:
110: public boolean isTopLevel() {
111: return this .node.isTopLevel();
112: }
113:
114: public boolean isVisible() {
115: return this .node.isVisible();
116: }
117:
118: public void setVisible(boolean visibleInNav) {
119: throw new UnsupportedOperationException();
120: }
121:
122: public SiteNode addChild(String name, boolean visible) {
123: throw new UnsupportedOperationException();
124: }
125:
126: public SiteNode addChild(String nodeName, String followingNodeName,
127: boolean visible) {
128: throw new UnsupportedOperationException();
129: }
130:
131: public SiteTreeImpl getTree() {
132: throw new UnsupportedOperationException();
133: }
134:
135: public void moveDown(String name) {
136: throw new UnsupportedOperationException();
137: }
138:
139: public void moveUp(String name) {
140: throw new UnsupportedOperationException();
141: }
142:
143: public SiteNode[] preOrder() {
144: if (this .preOrder == null) {
145: SiteNode[] delegates = ((TreeNode) this .node).preOrder();
146: this .preOrder = new ArrayList();
147: for (int i = 0; i < delegates.length; i++) {
148: this .preOrder.add(this .tree.getNode(delegates[i]));
149: }
150: }
151: return (SiteNode[]) this .preOrder
152: .toArray(new SiteNode[this .preOrder.size()]);
153: }
154:
155: public SiteTreeNode[] getNextSiblings() {
156: SiteNode[] delegates = ((TreeNode) this .node).getNextSiblings();
157: SiteTreeNode[] nodes = new SiteTreeNode[delegates.length];
158: for (int i = 0; i < delegates.length; i++) {
159: nodes[i] = this .tree.getNode(delegates[i]);
160: }
161: return nodes;
162: }
163:
164: public SiteTreeNode[] getPrecedingSiblings() {
165: SiteNode[] delegates = ((TreeNode) this .node)
166: .getPrecedingSiblings();
167: SiteTreeNode[] nodes = new SiteTreeNode[delegates.length];
168: for (int i = 0; i < delegates.length; i++) {
169: nodes[i] = this.tree.getNode(delegates[i]);
170: }
171: return nodes;
172: }
173:
174: }
|