Author: vgritsenko Date: Tue Apr 26 09:43:49 2005 New Revision: 164816 URL: http://svn.apache.org/viewcvs?rev=164816&view=rev Log: Use EMPTY_PROPERTIES
Modified: cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java Modified: cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java?rev=164816&r1=164815&r2=164816&view=diff ============================================================================== --- cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java (original) +++ cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java Tue Apr 26 09:43:49 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,16 +15,10 @@ */ package org.apache.cocoon.webapps.authentication.context; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - import org.apache.avalon.framework.CascadingRuntimeException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.parameters.Parameters; + import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.components.source.SourceUtil; @@ -36,7 +30,9 @@ import org.apache.cocoon.webapps.authentication.user.UserHandler; import org.apache.cocoon.webapps.session.context.SessionContext; import org.apache.cocoon.webapps.session.context.SimpleSessionContext; +import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMUtil; + import org.apache.excalibur.source.SourceParameters; import org.apache.excalibur.source.SourceResolver; import org.apache.excalibur.xml.xpath.XPathProcessor; @@ -47,16 +43,21 @@ import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.AttributesImpl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; /** * This is the implementation for the authentication context - * + * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id$ + * @version $Id$ */ -public class AuthenticationContext -implements SessionContext { +public class AuthenticationContext implements SessionContext { protected String name; protected UserHandler handler; @@ -68,14 +69,14 @@ protected SourceResolver resolver; /** A list of roles the user is in */ protected List roles; - + /** Constructor */ public AuthenticationContext(Context context, XPathProcessor processor, SourceResolver resolver) { this.context = context; this.xpathProcessor = processor; this.resolver = resolver; } - + /** * Initialize the context. This method has to be called right after * the constructor. @@ -91,25 +92,25 @@ throw new CascadingRuntimeException("Unable to create simple context.", pe); } } - + /** * Return the current authentication state */ protected RequestState getState() { return DefaultAuthenticationManager.getRequestState( this.context ); } - + /** * Initialize this context */ - public void init(Document doc) + public void init(Document doc) throws ProcessingException { if ( initialized ) { throw new ProcessingException("The context can only be initialized once."); } this.authContext.setNode("/", doc.getFirstChild()); } - + /* (non-Javadoc) * @see org.apache.cocoon.webapps.session.context.SessionContext#setup(java.lang.String, java.lang.String, java.lang.String) */ @@ -135,7 +136,7 @@ if (!path.startsWith("/")) path = '/' + path; final String applicationName = this.getState().getApplicationName(); - + DocumentFragment frag = null; if ( path.equals("/") ) { @@ -222,7 +223,7 @@ this.cleanParametersCache(); this.authContext.setXML(path, fragment); - } else if (path.equals("/application") + } else if (path.equals("/application") || path.startsWith("/application/") ) { if (applicationName == null) { @@ -302,7 +303,7 @@ this.cleanParametersCache(); this.authContext.removeXML(path); - } else if (path.equals("/application") + } else if (path.equals("/application") || path.startsWith("/application/") ) { if (applicationName == null) { throw new ProcessingException("removeXML: Application is required for path " + path); @@ -398,12 +399,12 @@ if (path.equals("/") ) { // get all: first authentication then application - contentHandler.startElement("", "authentication", "authentication", new AttributesImpl()); + contentHandler.startElement("", "authentication", "authentication", XMLUtils.EMPTY_ATTRIBUTES); this.authContext.streamXML("/authentication", contentHandler, lexicalHandler); contentHandler.endElement("", "authentication", "authentication"); if (applicationName != null) { - contentHandler.startElement("", "application", "application", new AttributesImpl()); + contentHandler.startElement("", "application", "application", XMLUtils.EMPTY_ATTRIBUTES); this.authContext.streamXML("/applications/" + applicationName, contentHandler, lexicalHandler); contentHandler.endElement("", "application", "application"); } @@ -561,7 +562,7 @@ throws ProcessingException { String authLoadResource = this.handler.getHandlerConfiguration().getLoadResource(); SourceParameters authLoadResourceParameters = this.handler.getHandlerConfiguration().getLoadResourceParameters(); - + if (authLoadResource == null) { throw new ProcessingException("The context " + this.name + " does not support loading."); } @@ -576,14 +577,14 @@ } parameters = this.createParameters(parameters, path, - false); + false); DocumentFragment frag; - - frag = SourceUtil.readDOM(authLoadResource, - null, - parameters, + + frag = SourceUtil.readDOM(authLoadResource, + null, + parameters, resolver); - + this.setXML(path, frag); } // end synchronized @@ -617,9 +618,9 @@ path, true); DocumentFragment fragment; - fragment = SourceUtil.readDOM(loadResource, - null, - parameters, + fragment = SourceUtil.readDOM(loadResource, + null, + parameters, resolver); this.authContext.setXML("/applications/" + applicationName + '/', fragment); @@ -745,7 +746,7 @@ } } - public Map getContextInfo() + public Map getContextInfo() throws ProcessingException { Map map = (Map)this.authContext.getAttribute( "cachedmap" ); if (map == null) { @@ -765,8 +766,8 @@ } return map; } - - public SourceParameters getContextInfoAsParameters() + + public SourceParameters getContextInfoAsParameters() throws ProcessingException { SourceParameters pars = (SourceParameters)this.authContext.getAttribute( "cachedpar" ); if (pars == null) { @@ -779,14 +780,14 @@ /** * Load XML of an application */ - public void loadApplicationXML(ApplicationConfiguration appConf, + public void loadApplicationXML(ApplicationConfiguration appConf, SourceResolver resolver) throws ProcessingException { String loadResource = appConf.getLoadResource(); SourceParameters loadResourceParameters = appConf.getLoadResourceParameters(); if ( !this.handler.isApplicationLoaded(appConf) && loadResource != null ) { synchronized (this.authContext) { - + SourceParameters parameters; if (loadResourceParameters != null) { parameters = (SourceParameters)loadResourceParameters.clone(); @@ -797,12 +798,12 @@ null, true); DocumentFragment fragment; - fragment = SourceUtil.readDOM(loadResource, - null, - parameters, + fragment = SourceUtil.readDOM(loadResource, + null, + parameters, resolver); this.authContext.setXML("/applications/" + appConf.getName() + '/', fragment); - + } // end synchronized } this.handler.setApplicationIsLoaded(appConf); Modified: cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java?rev=164816&r1=164815&r2=164816&view=diff ============================================================================== --- cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java (original) +++ cocoon/blocks/supported/authentication-fw/trunk/java/org/apache/cocoon/webapps/authentication/generation/ConfigurationGenerator.java Tue Apr 26 09:43:49 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,11 @@ */ package org.apache.cocoon.webapps.authentication.generation; - -import java.io.IOException; -import java.util.Enumeration; -import java.util.Map; - import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; + import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.environment.ObjectModelHelper; @@ -39,6 +35,7 @@ import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMUtil; + import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceParameters; @@ -48,17 +45,19 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Map; + /** * This is the authentication Configuration Generator. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: ConfigurationGenerator.java,v 1.10 2004/06/18 14:28:55 vgritsenko Exp $ + * @version $Id$ */ -public final class ConfigurationGenerator -extends ServiceableGenerator { +public final class ConfigurationGenerator extends ServiceableGenerator { /** Request parameter */ public static final String REQ_PARAMETER_STATE = "authstate"; @@ -151,28 +150,27 @@ boolean isAdmin = (src == null || src.equals("admin")); // now start producing xml: - AttributesImpl attr = new AttributesImpl(); - consumer.startElement("", "configuration", "configuration", attr); + consumer.startElement("", "configuration", "configuration", XMLUtils.EMPTY_ATTRIBUTES); // set the conf uri: // This is a bug in the servlet 2.2 API!!! // It does not contain the context: String uri = HttpUtils.getRequestURL(this.request).toString(); // So: ABSOLUTELY USELESS String uri = response.encodeURL(request.getRequestURI()); - consumer.startElement("", "uri", "uri", attr); + consumer.startElement("", "uri", "uri", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters(uri.toCharArray(), 0, uri.length()); consumer.endElement("", "uri", "uri"); if (isAdmin == true) { // build the menue - consumer.startElement("", "menue", "menue", attr); + consumer.startElement("", "menue", "menue", XMLUtils.EMPTY_ATTRIBUTES); if (handler.getNewRoleResource() != null) { - consumer.startElement("", "addrole", "addrole", attr); + consumer.startElement("", "addrole", "addrole", XMLUtils.EMPTY_ATTRIBUTES); consumer.endElement("", "addrole", "addrole"); } if (handler.getDeleteRoleResource() != null) { - consumer.startElement("", "delrole", "delrole", attr); + consumer.startElement("", "delrole", "delrole", XMLUtils.EMPTY_ATTRIBUTES); consumer.endElement("", "delrole", "delrole"); } @@ -256,7 +254,7 @@ } addingNewUserFailed = !this.addUser(role, id, pars, handler); if (addingNewUserFailed == false) { - consumer.startElement("", "addeduser", "addeduser", attr); + consumer.startElement("", "addeduser", "addeduser", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters(id.toCharArray(), 0, id.length()); consumer.endElement("", "addeduser", "addeduser"); } @@ -308,7 +306,7 @@ } catch (javax.xml.transform.TransformerException local) { throw new ProcessingException("TransformerException: " + local, local); } - consumer.startElement("", "uservalues", "uservalues", attr); + consumer.startElement("", "uservalues", "uservalues", XMLUtils.EMPTY_ATTRIBUTES); if (users != null && users.hasChildNodes() == true) { NodeList childs = users.getChildNodes(); for(int i = 0; i < childs.getLength(); i++) { @@ -318,11 +316,11 @@ } consumer.endElement("", "uservalues", "uservalues"); } - consumer.startElement("", "user", "user", attr); + consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters("old".toCharArray(), 0, 3); consumer.endElement("", "user", "user"); if (isAdmin == false) { - consumer.startElement("", "role", "role", attr); + consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters(role.toCharArray(), 0, role.length()); consumer.endElement("", "role", "role"); } @@ -351,7 +349,7 @@ } catch (javax.xml.transform.TransformerException local) { throw new ProcessingException("TransformerException: " + local, local); } - consumer.startElement("", "uservalues", "uservalues", attr); + consumer.startElement("", "uservalues", "uservalues", XMLUtils.EMPTY_ATTRIBUTES); if (users != null && users.hasChildNodes() == true) { NodeList childs = users.getChildNodes(); for(int i = 0; i < childs.getLength(); i++) { @@ -361,18 +359,18 @@ } consumer.endElement("", "uservalues", "uservalues"); } - consumer.startElement("", "user", "user", attr); + consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters("error".toCharArray(), 0, 5); consumer.endElement("", "user", "user"); if (isAdmin == false) { - consumer.startElement("", "role", "role", attr); + consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters(role.toCharArray(), 0, role.length()); consumer.endElement("", "role", "role"); } } if (state.equals("adduser") == true) { - consumer.startElement("", "user", "user", attr); + consumer.startElement("", "user", "user", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters("new".toCharArray(), 0, 3); consumer.endElement("", "user", "user"); } @@ -405,7 +403,7 @@ // include selected role String role = (String)session.getAttribute(SESSION_CONTEXT_ATTRIBUTE_ADMIN_ROLE); if (role != null) { - consumer.startElement("", "role", "role", attr); + consumer.startElement("", "role", "role", XMLUtils.EMPTY_ATTRIBUTES); consumer.characters(role.toCharArray(), 0, role.length()); consumer.endElement("", "role", "role"); }