01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.site.tree2;
19:
20: import org.apache.avalon.framework.container.ContainerUtil;
21: import org.apache.avalon.framework.logger.AbstractLogEnabled;
22: import org.apache.avalon.framework.logger.Logger;
23: import org.apache.avalon.framework.service.ServiceManager;
24: import org.apache.lenya.cms.publication.Area;
25: import org.apache.lenya.cms.publication.DocumentFactory;
26: import org.apache.lenya.cms.publication.DocumentUtil;
27: import org.apache.lenya.cms.publication.Publication;
28: import org.apache.lenya.cms.repository.RepositoryException;
29: import org.apache.lenya.cms.repository.RepositoryItem;
30: import org.apache.lenya.cms.repository.RepositoryItemFactory;
31: import org.apache.lenya.cms.repository.Session;
32: import org.apache.lenya.cms.repository.SharedItemStore;
33: import org.apache.lenya.cms.site.tree.SiteTree;
34:
35: /**
36: * Factory for sitetree objects.
37: *
38: * @version $Id: SiteTreeFactory.java 179568 2005-06-02 09:27:26Z jwkaltz $
39: */
40: public class SiteTreeFactory extends AbstractLogEnabled implements
41: RepositoryItemFactory {
42:
43: protected ServiceManager manager;
44:
45: /**
46: * Ctor.
47: * @param manager The service manager.
48: * @param logger The logger.
49: */
50: public SiteTreeFactory(ServiceManager manager, Logger logger) {
51: this .manager = manager;
52: ContainerUtil.enableLogging(this , logger);
53: }
54:
55: public RepositoryItem buildItem(Session session, String key)
56: throws RepositoryException {
57: String[] snippets = key.split(":");
58: String publicationId = snippets[0];
59: String areaName = snippets[1];
60: SiteTree tree;
61: try {
62: DocumentFactory factory = DocumentUtil
63: .createDocumentFactory(this .manager, session);
64: Publication publication = factory
65: .getPublication(publicationId);
66: Area area = publication.getArea(areaName);
67:
68: if (session.isModifiable()
69: || session instanceof SharedItemStore) {
70: tree = new SiteTreeImpl(this .manager, area, getLogger());
71: } else {
72: SharedItemStore store = null;
73: try {
74: store = (SharedItemStore) this .manager
75: .lookup(SharedItemStore.ROLE);
76: SiteTreeImpl sharedTree = (SiteTreeImpl) store
77: .getRepositoryItem(this , key);
78: tree = new DelegatingSiteTree(this .manager, area,
79: sharedTree);
80: } finally {
81: if (store != null) {
82: this .manager.release(store);
83: }
84: }
85: }
86: } catch (Exception e) {
87: throw new RepositoryException(e);
88: }
89: return tree;
90: }
91:
92: public String getItemType() {
93: return SiteTree.IDENTIFIABLE_TYPE;
94: }
95:
96: }
|