01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * @author www.gerdziegler.de
13: */
14: package org.ztemplates.actions.urlhandler.tree;
15:
16: import java.util.Set;
17:
18: import org.apache.log4j.Logger;
19: import org.ztemplates.actions.ZISecurityProvider;
20: import org.ztemplates.actions.urlhandler.ZIUrlHandler;
21: import org.ztemplates.classpath.ZClassPathRoots;
22: import org.ztemplates.classpath.ZClassPathRootsJavaClassPath;
23: import org.ztemplates.classpath.ZClassRepository;
24: import org.ztemplates.classpath.ZIClassRepository;
25:
26: /**
27: *
28: *
29: */
30: public class ZUrlHandlerFactory {
31: private static Logger log = Logger
32: .getLogger(ZUrlHandlerFactory.class);
33:
34: public static final ZISecurityProvider defaultSecurityService = new ZISecurityProvider() {
35:
36: public String addSecurityToUrl(String url, Set<String> roles) {
37: return url;
38: }
39:
40: public boolean isUserInRole(String role) {
41: return true;
42: }
43:
44: public String removeSecurityFromUrl(String url) {
45: return url;
46: }
47:
48: public String getUserName() {
49: return "defaultUser";
50: }
51: };
52:
53: public static ZIUrlHandler create(
54: ZIClassRepository classRepository,
55: ZISecurityProvider security, String prefix)
56: throws Exception {
57: // ZIUrlHandler ret = new ZUrlHandlerRepositoryRegex(classRepository);
58:
59: ZIUrlHandler ret = new ZTreeUrlHandler(classRepository,
60: security, prefix);
61: StringBuffer sb = new StringBuffer();
62: ret.printInfo(sb);
63: log.info(sb.toString());
64:
65: return ret;
66: }
67:
68: public static ZIUrlHandler create(String pojoPackage,
69: ZISecurityProvider security, String prefix)
70: throws Exception {
71: ZClassPathRoots roots = new ZClassPathRootsJavaClassPath();
72: ZIClassRepository classRepository = new ZClassRepository(roots,
73: pojoPackage);
74: ZIUrlHandler ret = create(classRepository, security, prefix);
75: return ret;
76: }
77:
78: public static ZIUrlHandler create(
79: ZIClassRepository classRepository,
80: ZISecurityProvider security) throws Exception {
81: return create(classRepository, security, null);
82: }
83:
84: public static ZIUrlHandler create(String pojoPackage,
85: ZISecurityProvider security) throws Exception {
86: return create(pojoPackage, security, null);
87: }
88: }
|