001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixcore.workflow.context;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.Properties;
024:
025: import de.schlund.pfixcore.auth.Role;
026: import de.schlund.pfixcore.auth.RoleNotFoundException;
027: import de.schlund.pfixcore.auth.RoleProvider;
028: import de.schlund.pfixcore.workflow.ContextInterceptor;
029: import de.schlund.pfixcore.workflow.ContextInterceptorFactory;
030: import de.schlund.pfixcore.workflow.ContextResource;
031: import de.schlund.pfixcore.workflow.PageMap;
032: import de.schlund.pfixcore.workflow.State;
033: import de.schlund.pfixcore.workflow.VariantManager;
034: import de.schlund.pfixxml.Variant;
035: import de.schlund.pfixxml.config.ContextConfig;
036:
037: /**
038: * Provides server-wide context information for the {@link de.schlund.pfixxml.ContextXMLServlet}.
039: * <b>Should not be used by other classes than ContextXMLServlet</b>
040: *
041: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
042: */
043: public class ServerContextImpl implements RoleProvider {
044:
045: private ContextConfig config;
046:
047: private String name;
048:
049: private PageFlowManager pageflowmanager;
050: private VariantManager variantmanager;
051: private PageMap pagemap;
052:
053: private ContextInterceptor[] startInterceptors;
054: private ContextInterceptor[] endInterceptors;
055:
056: public ServerContextImpl(ContextConfig config, String contextName)
057: throws Exception {
058: this .config = config;
059: this .name = contextName;
060:
061: variantmanager = (VariantManager) new VariantManager(config);
062: pageflowmanager = new PageFlowManager(config, variantmanager);
063: pagemap = new PageMap(config);
064:
065: createInterceptors();
066: }
067:
068: private void createInterceptors() throws Exception {
069: ArrayList<ContextInterceptor> list = new ArrayList<ContextInterceptor>();
070: for (Iterator<Class<? extends ContextInterceptor>> i = config
071: .getStartInterceptors().iterator(); i.hasNext();) {
072: String classname = i.next().getName();
073: list.add(ContextInterceptorFactory.getInstance()
074: .getInterceptor(classname));
075: }
076: startInterceptors = (ContextInterceptor[]) list
077: .toArray(new ContextInterceptor[] {});
078:
079: list.clear();
080: for (Iterator<Class<? extends ContextInterceptor>> i = config
081: .getEndInterceptors().iterator(); i.hasNext();) {
082: String classname = i.next().getName();
083: list.add(ContextInterceptorFactory.getInstance()
084: .getInterceptor(classname));
085: }
086: endInterceptors = (ContextInterceptor[]) list
087: .toArray(new ContextInterceptor[] {});
088: }
089:
090: public Properties getProperties() {
091: return config.getProperties();
092: }
093:
094: public Properties getPropertiesForContextResource(
095: ContextResource res) {
096: return config.getContextResourceConfig(res.getClass())
097: .getProperties();
098: }
099:
100: public State getAuthState() {
101: String authpage = config.getAuthPage();
102: if (authpage == null) {
103: return null;
104: }
105: return pagemap.getState(authpage);
106: }
107:
108: public ContextConfig getContextConfig() {
109: return config;
110: }
111:
112: public PageFlowManager getPageFlowManager() {
113: return pageflowmanager;
114: }
115:
116: public VariantManager getVariantManager() {
117: return variantmanager;
118: }
119:
120: public PageMap getPageMap() {
121: return pagemap;
122: }
123:
124: public ContextInterceptor[] getStartInterceptors() {
125: return startInterceptors;
126: }
127:
128: public ContextInterceptor[] getEndInterceptors() {
129: return endInterceptors;
130: }
131:
132: public String getName() {
133: return name;
134: }
135:
136: public String getPageMatchingVariant(String pagename,
137: Variant variant) {
138: if (variant != null & variant.getVariantFallbackArray() != null
139: && variantmanager != null) {
140: return variantmanager.getVariantMatchingPageRequestName(
141: pagename, variant);
142: } else {
143: return pagename;
144: }
145: }
146:
147: public Role getRole(String roleName) throws RoleNotFoundException {
148: Role role = getContextConfig().getRole(roleName);
149: if (role == null)
150: throw new RoleNotFoundException(roleName);
151: return role;
152: }
153:
154: }
|