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.tree;
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.DocumentFactory;
25: import org.apache.lenya.cms.publication.DocumentUtil;
26: import org.apache.lenya.cms.publication.Publication;
27: import org.apache.lenya.cms.repository.RepositoryException;
28: import org.apache.lenya.cms.repository.RepositoryItem;
29: import org.apache.lenya.cms.repository.RepositoryItemFactory;
30: import org.apache.lenya.cms.repository.Session;
31:
32: /**
33: * Factory for sitetree objects.
34: *
35: * @version $Id: SiteTreeFactory.java 179568 2005-06-02 09:27:26Z jwkaltz $
36: */
37: public class SiteTreeFactory extends AbstractLogEnabled implements
38: RepositoryItemFactory {
39:
40: protected ServiceManager manager;
41:
42: /**
43: * Ctor.
44: * @param manager The service manager.
45: * @param logger The logger.
46: */
47: public SiteTreeFactory(ServiceManager manager, Logger logger) {
48: this .manager = manager;
49: ContainerUtil.enableLogging(this , logger);
50: }
51:
52: public RepositoryItem buildItem(Session session, String key)
53: throws RepositoryException {
54: String[] snippets = key.split(":");
55: String publicationId = snippets[0];
56: String area = snippets[1];
57: DefaultSiteTree tree;
58: try {
59: DocumentFactory factory = DocumentUtil
60: .createDocumentFactory(this .manager, session);
61: Publication publication = factory
62: .getPublication(publicationId);
63: tree = new DefaultSiteTree(factory, publication, area,
64: this .manager, getLogger());
65: } catch (Exception e) {
66: throw new RepositoryException(e);
67: }
68: return tree;
69: }
70:
71: public String getItemType() {
72: return SiteTree.IDENTIFIABLE_TYPE;
73: }
74:
75: public boolean isSharable() {
76: return true;
77: }
78:
79: }
|