Author: vgritsenko Date: Mon Jan 10 06:34:31 2005 New Revision: 124800 URL: http://svn.apache.org/viewcvs?view=rev&rev=124800 Log: svn:eol-style native
Modified: cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java (contents, props changed) cocoon/trunk/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzDriverDelegate.java (props changed) cocoon/trunk/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobStoreCMT.java (props changed) cocoon/trunk/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobStoreTX.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBindingBuilder.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java (contents, props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java (contents, props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinition.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/DateTestJavaSelectionList.java (props changed) cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java (contents, props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java (contents, props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/PageLabelEventAspect.java (props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/PageLabelEventConverter.java (props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java (contents, props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelLinkService.java (props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java (props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java (contents, props changed) cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java (contents, props changed) cocoon/trunk/src/blocks/querybean/java/org/apache/cocoon/bean/query/ContextAccess.java (props changed) cocoon/trunk/src/blocks/querybean/java/org/apache/cocoon/bean/query/SimpleLuceneCriterion.java (props changed) cocoon/trunk/src/blocks/querybean/java/org/apache/cocoon/bean/query/SimpleLuceneCriterionBean.java (props changed) cocoon/trunk/src/blocks/querybean/java/org/apache/cocoon/bean/query/SimpleLuceneQuery.java (props changed) cocoon/trunk/src/blocks/querybean/java/org/apache/cocoon/bean/query/SimpleLuceneQueryBean.java (props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/ClientBindingGenerator.java (props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java (contents, props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/InvalidServiceException.java (props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/LoadException.java (props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java (props changed) cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/generation/CSVGenerator.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionException.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java (contents, props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/AbstractExpression.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/Context.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/DefaultContext.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/Expression.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/ExpressionCompiler.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/GenericExpressionCompiler.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/jexl/JexlContext.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/jexl/JexlExpression.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/jexl/JexlExpressionCompiler.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/util/ELUtils.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/el/util/ParseHandler.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/util/ContextStackMap.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/util/IncludingConfiguration.java (props changed) cocoon/trunk/src/blocks/template/java/org/apache/cocoon/util/TypeUtils.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/ExtendedSitemapComponentTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java (contents, props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java (contents, props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java (contents, props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/el/jexl/JexlExpressionTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/el/util/ELUtilsTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/generation/TemplateGeneratorTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/script/ScriptCompilerTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/script/ScriptInvokerTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/util/ContextStackMapTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/util/IncludingConfigurationTestCase.java (props changed) cocoon/trunk/src/blocks/template/test/org/apache/cocoon/util/TypeUtilsTestCase.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java (contents, props changed) cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (contents, props changed) cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/StoreJanitorImpl.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/BoundedQueue.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/ChannelWrapper.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadFactory.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadPool.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/LinkedQueue.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/Queue.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/RunnableManager.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/SynchronousChannel.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadFactory.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadPool.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/selection/RegexpHeaderSelector.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/util/ReflectionUtils.java (props changed) cocoon/trunk/src/java/org/apache/cocoon/xml/StringXMLizable.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java (contents, props changed) cocoon/trunk/src/test/org/apache/cocoon/MockLogger.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java (contents, props changed) cocoon/trunk/src/test/org/apache/cocoon/components/thread/AbstractTestCase.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/components/thread/DefaultRunnableManagerTestCase.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/components/thread/DefaultThreadFactoryTestCase.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java (props changed) cocoon/trunk/src/test/org/apache/cocoon/selection/RegexpHeaderSelectorTestCase.java (props changed) cocoon/trunk/src/webapp/WEB-INF/src/org/apache/cocoon/components/flow/java/AbstractContinuable.java (props changed) cocoon/trunk/src/webapp/WEB-INF/src/org/apache/cocoon/forms/flow/java/FormInstance.java (props changed) cocoon/trunk/src/webapp/WEB-INF/src/org/apache/cocoon/samples/flow/java/CalculatorFlow.java (props changed) cocoon/trunk/src/webapp/WEB-INF/src/org/apache/cocoon/samples/flow/java/FormFlow.java (props changed) cocoon/trunk/src/webapp/WEB-INF/src/org/apache/cocoon/samples/flow/java/PersistenceFlow.java (props changed) Modified: cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java&r1=124799&p2=cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java (original) +++ cocoon/trunk/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/generation/JaasSecurityGenerator.java Mon Jan 10 06:34:31 2005 @@ -1,170 +1,170 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.webapps.authentication.generation; - -import java.security.Principal; -import java.security.acl.Group; -import java.util.*; - -import javax.security.auth.Subject; -import javax.security.auth.callback.*; -import javax.security.auth.login.LoginContext; - -import org.apache.avalon.framework.parameters.Parameters; -import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.generation.ServiceableGenerator; -import org.apache.cocoon.webapps.session.ContextManager; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -/** - * This Generator provides a possibility to use the Authentication Framework - * of Cocoon against a JAAS-Realm of an Application Server.<br> - * You must provide following Parameters to get it running: - * <ul><li><b>jaasRealm</b> - The JNDI name of the JAAS Realm</li> - * <li><b>username</b> - The username of the user</li> - * <li><b>password</b> - The password of the user</li></ul> - * - * @version $Id: PortalJaasSecurityGenerator.java 96 2004-08-28 21:30:23Z kulawik $ - */ -public class JaasSecurityGenerator extends ServiceableGenerator { - - private String userid; - private String password; - private String jaasRealm = "jaas-cms-security-domain"; - - /* (non-Javadoc) - * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters) - */ - public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) { - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("begin setup"); - } - try { - super.setup(resolver, objectModel, src, par); - ContextManager cm = (ContextManager) this.manager.lookup(ContextManager.ROLE); - try { - if (cm.hasSessionContext()) { - cm.deleteContext("authentication"); - } - } catch (Exception exe) { - } - userid = par.getParameter("username"); - password = par.getParameter("password"); - try { - String jaasRealmTmp = par.getParameter("jaasRealm", null); - if (jaasRealmTmp != null && !jaasRealmTmp.equalsIgnoreCase("")) { - jaasRealm = jaasRealmTmp; - } - } catch (Exception se) { - } - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("trying to login as " + userid + " on the webpage"); - } - } catch (Exception ex) { - new ProcessingException(ex.getMessage()); - } - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("end setup"); - } - } - - public void addTextNode(String nodeName, String text) throws SAXException { - contentHandler.startElement("", nodeName, nodeName, new AttributesImpl()); - contentHandler.characters(text.toCharArray(), 0, text.length()); - contentHandler.endElement("", nodeName, nodeName); - } - - /* (non-Javadoc) - * @see org.apache.cocoon.generation.Generator#generate() - */ - public void generate() throws SAXException, ProcessingException { - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("begin generate"); - } - contentHandler.startDocument(); - contentHandler.startElement("", "authentication", "authentication", new AttributesImpl()); - - try { - LoginContext lc = new LoginContext(jaasRealm, new InternalCallbackHandler()); - lc.login(); - Subject s = lc.getSubject(); - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("Subject is: " + s.getPrincipals().toString()); - } - String principal = ""; - ArrayList roles = new ArrayList(); - - Iterator it = s.getPrincipals(java.security.Principal.class).iterator(); - while (it.hasNext()) { - Principal prp = (Principal) it.next(); - if (prp.getName().equalsIgnoreCase("Roles")) { - Group grp = (Group) prp; - Enumeration enumm = grp.members(); - while (enumm.hasMoreElements()) { - Principal sg = (Principal) enumm.nextElement(); - roles.add(sg.getName()); - } - } else { - principal = prp.getName(); - } - } - lc.logout(); - - addTextNode("ID", principal); - it = roles.iterator(); - while (it.hasNext()) { - String role = (String) it.next(); - addTextNode("role", role); - } - contentHandler.startElement("", "data", "data", new AttributesImpl()); - addTextNode("user", principal); - contentHandler.endElement("", "data", "data"); - } catch (Exception exe) { - this.getLogger().warn("Could not login user \"" + userid + "\""); - } finally { - contentHandler.endElement("", "authentication", "authentication"); - contentHandler.endDocument(); - if (this.getLogger().isDebugEnabled()) { - this.getLogger().debug("end generate"); - } - } - } - - /** - * Callback Handler - */ - private class InternalCallbackHandler implements CallbackHandler { - - /* (non-Javadoc) - * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[]) - */ - public void handle(Callback[] callbacks) throws UnsupportedCallbackException { - - for (int i = 0; i < callbacks.length; i++) { - if (callbacks[i] instanceof NameCallback) { - // prompt the user for a username - NameCallback nc = (NameCallback) callbacks[i]; - nc.setName(userid); - } else if (callbacks[i] instanceof PasswordCallback) { - PasswordCallback pc = (PasswordCallback) callbacks[i]; - pc.setPassword(password.toCharArray()); - } - } - } - } +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.webapps.authentication.generation; + +import java.security.Principal; +import java.security.acl.Group; +import java.util.*; + +import javax.security.auth.Subject; +import javax.security.auth.callback.*; +import javax.security.auth.login.LoginContext; + +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.environment.SourceResolver; +import org.apache.cocoon.generation.ServiceableGenerator; +import org.apache.cocoon.webapps.session.ContextManager; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * This Generator provides a possibility to use the Authentication Framework + * of Cocoon against a JAAS-Realm of an Application Server.<br> + * You must provide following Parameters to get it running: + * <ul><li><b>jaasRealm</b> - The JNDI name of the JAAS Realm</li> + * <li><b>username</b> - The username of the user</li> + * <li><b>password</b> - The password of the user</li></ul> + * + * @version $Id: PortalJaasSecurityGenerator.java 96 2004-08-28 21:30:23Z kulawik $ + */ +public class JaasSecurityGenerator extends ServiceableGenerator { + + private String userid; + private String password; + private String jaasRealm = "jaas-cms-security-domain"; + + /* (non-Javadoc) + * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters) + */ + public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) { + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("begin setup"); + } + try { + super.setup(resolver, objectModel, src, par); + ContextManager cm = (ContextManager) this.manager.lookup(ContextManager.ROLE); + try { + if (cm.hasSessionContext()) { + cm.deleteContext("authentication"); + } + } catch (Exception exe) { + } + userid = par.getParameter("username"); + password = par.getParameter("password"); + try { + String jaasRealmTmp = par.getParameter("jaasRealm", null); + if (jaasRealmTmp != null && !jaasRealmTmp.equalsIgnoreCase("")) { + jaasRealm = jaasRealmTmp; + } + } catch (Exception se) { + } + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("trying to login as " + userid + " on the webpage"); + } + } catch (Exception ex) { + new ProcessingException(ex.getMessage()); + } + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("end setup"); + } + } + + public void addTextNode(String nodeName, String text) throws SAXException { + contentHandler.startElement("", nodeName, nodeName, new AttributesImpl()); + contentHandler.characters(text.toCharArray(), 0, text.length()); + contentHandler.endElement("", nodeName, nodeName); + } + + /* (non-Javadoc) + * @see org.apache.cocoon.generation.Generator#generate() + */ + public void generate() throws SAXException, ProcessingException { + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("begin generate"); + } + contentHandler.startDocument(); + contentHandler.startElement("", "authentication", "authentication", new AttributesImpl()); + + try { + LoginContext lc = new LoginContext(jaasRealm, new InternalCallbackHandler()); + lc.login(); + Subject s = lc.getSubject(); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("Subject is: " + s.getPrincipals().toString()); + } + String principal = ""; + ArrayList roles = new ArrayList(); + + Iterator it = s.getPrincipals(java.security.Principal.class).iterator(); + while (it.hasNext()) { + Principal prp = (Principal) it.next(); + if (prp.getName().equalsIgnoreCase("Roles")) { + Group grp = (Group) prp; + Enumeration enumm = grp.members(); + while (enumm.hasMoreElements()) { + Principal sg = (Principal) enumm.nextElement(); + roles.add(sg.getName()); + } + } else { + principal = prp.getName(); + } + } + lc.logout(); + + addTextNode("ID", principal); + it = roles.iterator(); + while (it.hasNext()) { + String role = (String) it.next(); + addTextNode("role", role); + } + contentHandler.startElement("", "data", "data", new AttributesImpl()); + addTextNode("user", principal); + contentHandler.endElement("", "data", "data"); + } catch (Exception exe) { + this.getLogger().warn("Could not login user \"" + userid + "\""); + } finally { + contentHandler.endElement("", "authentication", "authentication"); + contentHandler.endDocument(); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug("end generate"); + } + } + } + + /** + * Callback Handler + */ + private class InternalCallbackHandler implements CallbackHandler { + + /* (non-Javadoc) + * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[]) + */ + public void handle(Callback[] callbacks) throws UnsupportedCallbackException { + + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof NameCallback) { + // prompt the user for a username + NameCallback nc = (NameCallback) callbacks[i]; + nc.setName(userid); + } else if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback) callbacks[i]; + pc.setPassword(password.toCharArray()); + } + } + } + } } Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java&r1=124799&p2=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java (original) +++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertor.java Mon Jan 10 06:34:31 2005 @@ -1,68 +1,68 @@ -/* - * Copyright 2004 Outerthought bvba and Schaubroeck nv - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.forms.datatype.convertor; - -import org.apache.cocoon.forms.datatype.convertor.Convertor; -import org.apache.cocoon.forms.datatype.convertor.ConversionResult; -import org.apache.cocoon.forms.validation.ValidationError; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.outerj.daisy.htmlcleaner.HtmlCleanerTemplate; -import org.outerj.daisy.htmlcleaner.HtmlCleaner; - -import java.util.Locale; - -/** - * A CForms convertor doing string-to-string conversion by utilizing - * the Daisy HtmlCleaner component. - */ -public class HtmlCleaningConvertor implements Convertor { - HtmlCleanerTemplate template; - - public HtmlCleaningConvertor(HtmlCleanerTemplate template) { - this.template = template; - } - - public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) { - HtmlCleaner cleaner = template.newHtmlCleaner(); - try { - String result = cleaner.cleanToString(value); - return new ConversionResult(result); - } catch (Exception e) { - Throwable t = ExceptionUtils.getRootCause(e); - if (t == null) - t = e; - String message = t.getMessage(); - if (message == null) - message = t.toString(); - ValidationError validationError = new ValidationError(message, false); - return new ConversionResult(validationError); - } - } - - public String convertToString(Object object, Locale locale, Convertor.FormatCache formatCache) { - return (String)object; - } - - public Class getTypeClass() { - return java.lang.String.class; - } - - public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { - // nothing to say about me - } -} +/* + * Copyright 2004 Outerthought bvba and Schaubroeck nv + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import org.apache.cocoon.forms.datatype.convertor.Convertor; +import org.apache.cocoon.forms.datatype.convertor.ConversionResult; +import org.apache.cocoon.forms.validation.ValidationError; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.outerj.daisy.htmlcleaner.HtmlCleanerTemplate; +import org.outerj.daisy.htmlcleaner.HtmlCleaner; + +import java.util.Locale; + +/** + * A CForms convertor doing string-to-string conversion by utilizing + * the Daisy HtmlCleaner component. + */ +public class HtmlCleaningConvertor implements Convertor { + HtmlCleanerTemplate template; + + public HtmlCleaningConvertor(HtmlCleanerTemplate template) { + this.template = template; + } + + public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) { + HtmlCleaner cleaner = template.newHtmlCleaner(); + try { + String result = cleaner.cleanToString(value); + return new ConversionResult(result); + } catch (Exception e) { + Throwable t = ExceptionUtils.getRootCause(e); + if (t == null) + t = e; + String message = t.getMessage(); + if (message == null) + message = t.toString(); + ValidationError validationError = new ValidationError(message, false); + return new ConversionResult(validationError); + } + } + + public String convertToString(Object object, Locale locale, Convertor.FormatCache formatCache) { + return (String)object; + } + + public Class getTypeClass() { + return java.lang.String.class; + } + + public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { + // nothing to say about me + } +} Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java&r1=124799&p2=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java (original) +++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/HtmlCleaningConvertorBuilder.java Mon Jan 10 06:34:31 2005 @@ -1,73 +1,73 @@ -/* - * Copyright 2004 Outerthought bvba and Schaubroeck nv - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.forms.datatype.convertor; - -import org.apache.cocoon.forms.datatype.convertor.ConvertorBuilder; -import org.apache.cocoon.forms.datatype.convertor.Convertor; -import org.apache.cocoon.forms.util.DomHelper; -import org.apache.cocoon.forms.CacheManager; -import org.apache.cocoon.components.source.SourceUtil; -import org.apache.avalon.framework.service.Serviceable; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.Source; -import org.w3c.dom.Element; -import org.outerj.daisy.htmlcleaner.HtmlCleanerTemplate; -import org.outerj.daisy.htmlcleaner.HtmlCleanerFactory; -import org.xml.sax.InputSource; - -/** - * Builds [EMAIL PROTECTED] HtmlCleaningConvertor}s. - */ -public class HtmlCleaningConvertorBuilder implements ConvertorBuilder, Serviceable { - private ServiceManager serviceManager; - - public void service(ServiceManager serviceManager) throws ServiceException { - this.serviceManager = serviceManager; - } - - public Convertor build(Element element) throws Exception { - String config = DomHelper.getAttribute(element, "config"); - - Source source = null; - SourceResolver sourceResolver = null; - CacheManager cacheManager = null; - try { - cacheManager = (CacheManager)serviceManager.lookup(CacheManager.ROLE); - sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE); - source = sourceResolver.resolveURI(config); - - String prefix = HtmlCleanerTemplate.class.getName(); - HtmlCleanerTemplate template = (HtmlCleanerTemplate)cacheManager.get(source, prefix); - if (template == null) { - HtmlCleanerFactory factory = new HtmlCleanerFactory(); - InputSource is = SourceUtil.getInputSource(source); - template = factory.buildTemplate(is); - cacheManager.set(template, source, prefix); - } - - return new HtmlCleaningConvertor(template); - } finally { - if (source != null) - sourceResolver.release(source); - if (sourceResolver != null) - serviceManager.release(sourceResolver); - if (cacheManager != null) - serviceManager.release(cacheManager); - } - } -} +/* + * Copyright 2004 Outerthought bvba and Schaubroeck nv + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import org.apache.cocoon.forms.datatype.convertor.ConvertorBuilder; +import org.apache.cocoon.forms.datatype.convertor.Convertor; +import org.apache.cocoon.forms.util.DomHelper; +import org.apache.cocoon.forms.CacheManager; +import org.apache.cocoon.components.source.SourceUtil; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.excalibur.source.SourceResolver; +import org.apache.excalibur.source.Source; +import org.w3c.dom.Element; +import org.outerj.daisy.htmlcleaner.HtmlCleanerTemplate; +import org.outerj.daisy.htmlcleaner.HtmlCleanerFactory; +import org.xml.sax.InputSource; + +/** + * Builds [EMAIL PROTECTED] HtmlCleaningConvertor}s. + */ +public class HtmlCleaningConvertorBuilder implements ConvertorBuilder, Serviceable { + private ServiceManager serviceManager; + + public void service(ServiceManager serviceManager) throws ServiceException { + this.serviceManager = serviceManager; + } + + public Convertor build(Element element) throws Exception { + String config = DomHelper.getAttribute(element, "config"); + + Source source = null; + SourceResolver sourceResolver = null; + CacheManager cacheManager = null; + try { + cacheManager = (CacheManager)serviceManager.lookup(CacheManager.ROLE); + sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE); + source = sourceResolver.resolveURI(config); + + String prefix = HtmlCleanerTemplate.class.getName(); + HtmlCleanerTemplate template = (HtmlCleanerTemplate)cacheManager.get(source, prefix); + if (template == null) { + HtmlCleanerFactory factory = new HtmlCleanerFactory(); + InputSource is = SourceUtil.getInputSource(source); + template = factory.buildTemplate(is); + cacheManager.set(template, source, prefix); + } + + return new HtmlCleaningConvertor(template); + } finally { + if (source != null) + sourceResolver.release(source); + if (sourceResolver != null) + serviceManager.release(sourceResolver); + if (cacheManager != null) + serviceManager.release(cacheManager); + } + } +} Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java&r1=124799&p2=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java (original) +++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java Mon Jan 10 06:34:31 2005 @@ -1,136 +1,136 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.forms.samples.dreamteam; - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - -/** - * Manager - */ -public class Manager { - private static Manager manager = new Manager(); - private List allPersons = null; - private Team dreamTeam = null; - - private Manager() { - super(); - } - - public static Manager getManager() { - if (manager == null) { - manager = new Manager(); - } - return manager; - } - public Hashtable getAllPersonsByPosition() { - Hashtable list = new Hashtable(); - Team team = null; - TeamMember teamMember = null; - String position = null; - for (int i = 0; i < allPersons.size(); i++) { - teamMember = (TeamMember)allPersons.get(i); - position = teamMember.getPosition(); - if (list.containsKey(position)) { - team = (Team)list.get(position); - } - else { - team = new Team(); - list.put(position, team); - } - team.addMember(teamMember); - } - return list; - - } - public TeamMember getPerson(String memberID) { - TeamMember member = null; - if (allPersons == null) { - return null; - } - for (Iterator iter = allPersons.iterator(); iter.hasNext();) { - member = (TeamMember) iter.next(); - if (member.getMemberId().equals(memberID)) { - return member; - } - } - return null; - } - - public void buildDreamTeam(Team dreamlist) { - if (dreamTeam != null) { - dreamTeam.getTeam().clear(); - } - dreamTeam = new Team(); - TeamMember listMember = null; - TeamMember dreamMember = null; - for (Iterator iter = dreamlist.getTeam().iterator(); iter.hasNext();) { - listMember = (TeamMember) iter.next(); - dreamMember = getPerson(listMember.getMemberId()); - dreamTeam.addMember(dreamMember); - } - } - - public Team getDreamTeam() { - if (dreamTeam == null) { - dreamTeam = new Team(); - dreamTeam.setTeam(allPersons); - } - return dreamTeam; - } - - public void readPlayers(Document doc) { - NodeList players = doc.getElementsByTagName("player"); - Node player = null; - int size = players.getLength(); - for (int i = 0; i < size; i++) { - player = players.item(i); - addPlayer((Element)player); - } - } - - private void addPlayer(Element player) { - // convert the XML node to a TeamMember - if (allPersons == null) { - allPersons = new ArrayList(); - } - TeamMember member = null; - member = new TeamMember(); - member.setMemberId("" + (allPersons.size() + 1)); - member.setName(getElementValue(player, "name")); - member.setPosition(getElementValue(player, "position")); - member.setCountry(getElementValue(player, "country")); -// System.out.println(member.toString()); - allPersons.add(member); - } - - private String getElementValue(Element element, String tag) { - String result = null; - NodeList nodes = element.getElementsByTagName(tag); - result = nodes.item(0).getFirstChild().getNodeValue(); -// System.out.println("element: " + tag + "=" + result); - return result; - } - -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.samples.dreamteam; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * Manager + */ +public class Manager { + private static Manager manager = new Manager(); + private List allPersons = null; + private Team dreamTeam = null; + + private Manager() { + super(); + } + + public static Manager getManager() { + if (manager == null) { + manager = new Manager(); + } + return manager; + } + public Hashtable getAllPersonsByPosition() { + Hashtable list = new Hashtable(); + Team team = null; + TeamMember teamMember = null; + String position = null; + for (int i = 0; i < allPersons.size(); i++) { + teamMember = (TeamMember)allPersons.get(i); + position = teamMember.getPosition(); + if (list.containsKey(position)) { + team = (Team)list.get(position); + } + else { + team = new Team(); + list.put(position, team); + } + team.addMember(teamMember); + } + return list; + + } + public TeamMember getPerson(String memberID) { + TeamMember member = null; + if (allPersons == null) { + return null; + } + for (Iterator iter = allPersons.iterator(); iter.hasNext();) { + member = (TeamMember) iter.next(); + if (member.getMemberId().equals(memberID)) { + return member; + } + } + return null; + } + + public void buildDreamTeam(Team dreamlist) { + if (dreamTeam != null) { + dreamTeam.getTeam().clear(); + } + dreamTeam = new Team(); + TeamMember listMember = null; + TeamMember dreamMember = null; + for (Iterator iter = dreamlist.getTeam().iterator(); iter.hasNext();) { + listMember = (TeamMember) iter.next(); + dreamMember = getPerson(listMember.getMemberId()); + dreamTeam.addMember(dreamMember); + } + } + + public Team getDreamTeam() { + if (dreamTeam == null) { + dreamTeam = new Team(); + dreamTeam.setTeam(allPersons); + } + return dreamTeam; + } + + public void readPlayers(Document doc) { + NodeList players = doc.getElementsByTagName("player"); + Node player = null; + int size = players.getLength(); + for (int i = 0; i < size; i++) { + player = players.item(i); + addPlayer((Element)player); + } + } + + private void addPlayer(Element player) { + // convert the XML node to a TeamMember + if (allPersons == null) { + allPersons = new ArrayList(); + } + TeamMember member = null; + member = new TeamMember(); + member.setMemberId("" + (allPersons.size() + 1)); + member.setName(getElementValue(player, "name")); + member.setPosition(getElementValue(player, "position")); + member.setCountry(getElementValue(player, "country")); +// System.out.println(member.toString()); + allPersons.add(member); + } + + private String getElementValue(Element element, String tag) { + String result = null; + NodeList nodes = element.getElementsByTagName(tag); + result = nodes.item(0).getFirstChild().getNodeValue(); +// System.out.println("element: " + tag + "=" + result); + return result; + } + +} Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java&r1=124799&p2=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java (original) +++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/helpers/FullScreenMapping.java Mon Jan 10 06:34:31 2005 @@ -1,44 +1,44 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.portal.acting.helpers; - -import org.apache.cocoon.portal.PortalService; -import org.apache.cocoon.portal.coplet.CopletInstanceData; -import org.apache.cocoon.portal.event.Event; -import org.apache.cocoon.portal.event.impl.FullScreenCopletEvent; -import org.apache.cocoon.portal.layout.Layout; -import org.apache.cocoon.portal.profile.ProfileManager; - -/** - * Helper class for a full screen event - * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CopletMapping.java 30941 2004-07-29 19:56:58Z vgritsenko $ -*/ -public class FullScreenMapping extends Mapping { - public String copletId; - public String layoutId; - - public Event getEvent(PortalService service, Object data) { - final ProfileManager manager = service.getComponentManager().getProfileManager(); - final CopletInstanceData cid = manager.getCopletInstanceData(this.copletId); - final Layout layout = manager.getPortalLayout(null, layoutId) ; - - Event e = new FullScreenCopletEvent(cid, layout); - return e; - } - -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.portal.acting.helpers; + +import org.apache.cocoon.portal.PortalService; +import org.apache.cocoon.portal.coplet.CopletInstanceData; +import org.apache.cocoon.portal.event.Event; +import org.apache.cocoon.portal.event.impl.FullScreenCopletEvent; +import org.apache.cocoon.portal.layout.Layout; +import org.apache.cocoon.portal.profile.ProfileManager; + +/** + * Helper class for a full screen event + * + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Id: CopletMapping.java 30941 2004-07-29 19:56:58Z vgritsenko $ +*/ +public class FullScreenMapping extends Mapping { + public String copletId; + public String layoutId; + + public Event getEvent(PortalService service, Object data) { + final ProfileManager manager = service.getComponentManager().getProfileManager(); + final CopletInstanceData cid = manager.getCopletInstanceData(this.copletId); + final Layout layout = manager.getPortalLayout(null, layoutId) ; + + Event e = new FullScreenCopletEvent(cid, layout); + return e; + } + +} Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java&r1=124799&p2=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java (original) +++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java Mon Jan 10 06:34:31 2005 @@ -1,139 +1,139 @@ -/* - * Copyright 1999-2002,2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.portal.generation; - -import java.util.Map; - -import org.apache.avalon.framework.parameters.ParameterException; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.cocoon.environment.ObjectModelHelper; -import org.apache.cocoon.generation.ServiceableGenerator; -import org.apache.cocoon.portal.Constants; -import org.apache.cocoon.portal.PortalService; -import org.apache.cocoon.portal.coplet.CopletInstanceData; -import org.xml.sax.SAXException; - -/** - * Abstract generator implementation that provides a method getCopletInstanceData(). - * There are two possibilities how the generator obtains the information required for - * getting the coplet instance data:<br><br> - * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol, - * all required information are passed automatically.<br> - * 2) Otherwise the portal name and the coplet id must be passed to the generator - * as paremeters in the following way: - * - * <pre><map:generator type="coplet"> - * <map:parameter name="portalName" type="exampleportal"/> - * <map:parameter name="copletId" type="examplecoplet"/> - * </map:generator></pre> - * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: AbstractCopletTransformer.java 30941 2004-07-29 19:56:58Z vgritsenko $ - */ -public abstract class AbstractCopletGenerator -extends ServiceableGenerator { - - /** - * Parameter name. - */ - public static final String COPLET_ID_PARAM = "copletId"; - - /** - * Parameter name. - */ - public static final String PORTAL_NAME_PARAM = "portalName"; - - /** The portal service */ - private PortalService _portalService; - - /** - * Try to get the coplet instance data belonging to the current request - * @return The coplet instance data - * @throws SAXException If an errors occurs or the instance data is not available - */ - protected CopletInstanceData getCopletInstanceData() - throws SAXException { - CopletInstanceData cid = this.getCopletInstanceData(null); - if ( cid == null ) { - throw new SAXException("Could not find coplet instance data for the current pipeline."); - } - return cid; - } - - - /** - * Get the portal service - */ - protected PortalService getPortalService() - throws SAXException { - if ( this._portalService == null ) { - try { - this._portalService = (PortalService)this.manager.lookup(PortalService.ROLE); - } catch (ServiceException se) { - throw new SAXException("Unable to get portal service.", se); - } - } - return this._portalService; - } - - - /** - * Try to get the coplet instance data with the given id - * @param copletId The id of the coplet instance or null if this transformer - * is used inside a coplet pipeline - * @return The coplet instance data or null - * @throws SAXException If an error occurs - */ - protected CopletInstanceData getCopletInstanceData(String copletId) - throws SAXException { - final Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT); - - if ( copletId == null ) { - // determine coplet id - if (context != null) { - copletId = (String)context.get(Constants.COPLET_ID_KEY); - } else { - copletId = (String)objectModel.get(Constants.COPLET_ID_KEY); - if ( copletId == null ) { - try { - copletId = this.parameters.getParameter(COPLET_ID_PARAM); - - } catch (ParameterException e) { - throw new SAXException("copletId must be passed as parameter or in the object model within the parent context."); - } - } - } - } - if (copletId == null) { - throw new SAXException("copletId must be passed as parameter or in the object model within the parent context."); - } - - CopletInstanceData object = this.getPortalService().getComponentManager().getProfileManager().getCopletInstanceData( copletId ); - - return object; - } - - /* (non-Javadoc) - * @see org.apache.avalon.excalibur.pool.Recyclable#recycle() - */ - public void recycle() { - if ( this._portalService != null ) { - this.manager.release( this._portalService ); - this._portalService = null; - } - super.recycle(); - } -} +/* + * Copyright 1999-2002,2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.portal.generation; + +import java.util.Map; + +import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.generation.ServiceableGenerator; +import org.apache.cocoon.portal.Constants; +import org.apache.cocoon.portal.PortalService; +import org.apache.cocoon.portal.coplet.CopletInstanceData; +import org.xml.sax.SAXException; + +/** + * Abstract generator implementation that provides a method getCopletInstanceData(). + * There are two possibilities how the generator obtains the information required for + * getting the coplet instance data:<br><br> + * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol, + * all required information are passed automatically.<br> + * 2) Otherwise the portal name and the coplet id must be passed to the generator + * as paremeters in the following way: + * + * <pre><map:generator type="coplet"> + * <map:parameter name="portalName" type="exampleportal"/> + * <map:parameter name="copletId" type="examplecoplet"/> + * </map:generator></pre> + * + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Id: AbstractCopletTransformer.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public abstract class AbstractCopletGenerator +extends ServiceableGenerator { + + /** + * Parameter name. + */ + public static final String COPLET_ID_PARAM = "copletId"; + + /** + * Parameter name. + */ + public static final String PORTAL_NAME_PARAM = "portalName"; + + /** The portal service */ + private PortalService _portalService; + + /** + * Try to get the coplet instance data belonging to the current request + * @return The coplet instance data + * @throws SAXException If an errors occurs or the instance data is not available + */ + protected CopletInstanceData getCopletInstanceData() + throws SAXException { + CopletInstanceData cid = this.getCopletInstanceData(null); + if ( cid == null ) { + throw new SAXException("Could not find coplet instance data for the current pipeline."); + } + return cid; + } + + + /** + * Get the portal service + */ + protected PortalService getPortalService() + throws SAXException { + if ( this._portalService == null ) { + try { + this._portalService = (PortalService)this.manager.lookup(PortalService.ROLE); + } catch (ServiceException se) { + throw new SAXException("Unable to get portal service.", se); + } + } + return this._portalService; + } + + + /** + * Try to get the coplet instance data with the given id + * @param copletId The id of the coplet instance or null if this transformer + * is used inside a coplet pipeline + * @return The coplet instance data or null + * @throws SAXException If an error occurs + */ + protected CopletInstanceData getCopletInstanceData(String copletId) + throws SAXException { + final Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT); + + if ( copletId == null ) { + // determine coplet id + if (context != null) { + copletId = (String)context.get(Constants.COPLET_ID_KEY); + } else { + copletId = (String)objectModel.get(Constants.COPLET_ID_KEY); + if ( copletId == null ) { + try { + copletId = this.parameters.getParameter(COPLET_ID_PARAM); + + } catch (ParameterException e) { + throw new SAXException("copletId must be passed as parameter or in the object model within the parent context."); + } + } + } + } + if (copletId == null) { + throw new SAXException("copletId must be passed as parameter or in the object model within the parent context."); + } + + CopletInstanceData object = this.getPortalService().getComponentManager().getProfileManager().getCopletInstanceData( copletId ); + + return object; + } + + /* (non-Javadoc) + * @see org.apache.avalon.excalibur.pool.Recyclable#recycle() + */ + public void recycle() { + if ( this._portalService != null ) { + this.manager.release( this._portalService ); + this._portalService = null; + } + super.recycle(); + } +} Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java&r1=124799&p2=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java (original) +++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationFWUserInfoProvider.java Mon Jan 10 06:34:31 2005 @@ -1,93 +1,93 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.portal.profile.impl; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; -import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.webapps.authentication.AuthenticationManager; -import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; -import org.apache.cocoon.webapps.authentication.user.RequestState; -import org.apache.cocoon.webapps.authentication.user.UserHandler; - -/** - * Get the information about the current user. - * This implementation uses the authentication-fw block - * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $ - */ -public class AuthenticationFWUserInfoProvider -implements UserInfoProvider, Serviceable { - - protected ServiceManager manager; - - - /* (non-Javadoc) - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager manager) throws ServiceException { - this.manager = manager; - } - - /* (non-Javadoc) - * @see org.apache.cocoon.portal.profile.impl.UserInfoProvider#getUserInfo(java.lang.String, java.lang.String) - */ - public UserInfo getUserInfo(String portalName, String layoutKey) - throws Exception { - AuthenticationManager authManager = null; - try { - authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); - final UserInfo info = new UserInfo(portalName, layoutKey); - - final RequestState state = authManager.getState(); - final UserHandler handler = state.getHandler(); - - info.setUserName(handler.getUserId()); - try { - info.setGroup((String)handler.getContext().getContextInfo().get("group")); - } catch (ProcessingException pe) { - // ignore this - } - - final ApplicationConfiguration ac = state.getApplicationConfiguration(); - if ( ac == null ) { - throw new ProcessingException("Configuration for portal not found in application configuration."); - } - final Configuration appConf = ac.getConfiguration("portal"); - if ( appConf == null ) { - throw new ProcessingException("Configuration for portal not found in application configuration."); - } - final Configuration config = appConf.getChild("profiles"); - final Configuration[] children = config.getChildren(); - final Map configs = new HashMap(); - if ( children != null ) { - for(int i=0; i < children.length; i++) { - configs.put(children[i].getName(), children[i].getAttribute("uri")); - } - } - info.setConfigurations(configs); - return info; - } finally { - this.manager.release( authManager ); - } - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.portal.profile.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.webapps.authentication.AuthenticationManager; +import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration; +import org.apache.cocoon.webapps.authentication.user.RequestState; +import org.apache.cocoon.webapps.authentication.user.UserHandler; + +/** + * Get the information about the current user. + * This implementation uses the authentication-fw block + * + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public class AuthenticationFWUserInfoProvider +implements UserInfoProvider, Serviceable { + + protected ServiceManager manager; + + + /* (non-Javadoc) + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) + */ + public void service(ServiceManager manager) throws ServiceException { + this.manager = manager; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.portal.profile.impl.UserInfoProvider#getUserInfo(java.lang.String, java.lang.String) + */ + public UserInfo getUserInfo(String portalName, String layoutKey) + throws Exception { + AuthenticationManager authManager = null; + try { + authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); + final UserInfo info = new UserInfo(portalName, layoutKey); + + final RequestState state = authManager.getState(); + final UserHandler handler = state.getHandler(); + + info.setUserName(handler.getUserId()); + try { + info.setGroup((String)handler.getContext().getContextInfo().get("group")); + } catch (ProcessingException pe) { + // ignore this + } + + final ApplicationConfiguration ac = state.getApplicationConfiguration(); + if ( ac == null ) { + throw new ProcessingException("Configuration for portal not found in application configuration."); + } + final Configuration appConf = ac.getConfiguration("portal"); + if ( appConf == null ) { + throw new ProcessingException("Configuration for portal not found in application configuration."); + } + final Configuration config = appConf.getChild("profiles"); + final Configuration[] children = config.getChildren(); + final Map configs = new HashMap(); + if ( children != null ) { + for(int i=0; i < children.length; i++) { + configs.put(children[i].getName(), children[i].getAttribute("uri")); + } + } + info.setConfigurations(configs); + return info; + } finally { + this.manager.release( authManager ); + } + } +} Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java&r1=124799&p2=cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java (original) +++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/UserInfoProvider.java Mon Jan 10 06:34:31 2005 @@ -1,33 +1,33 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.portal.profile.impl; - -/** - * Get the information about the current user. - * This data object is used for loading the profile. It decouples the - * portal from the used authentication method. - * - * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $ - */ -public interface UserInfoProvider { - - /** - * Return the user info about the current user. - */ - UserInfo getUserInfo(String portalName, String layoutKey) - throws Exception; -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.portal.profile.impl; + +/** + * Get the information about the current user. + * This data object is used for loading the profile. It decouples the + * portal from the used authentication method. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public interface UserInfoProvider { + + /** + * Return the user info about the current user. + */ + UserInfo getUserInfo(String portalName, String layoutKey) + throws Exception; +} Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java&r1=124799&p2=cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java (original) +++ cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/ws/EndpointDefinition.java Mon Jan 10 06:34:31 2005 @@ -1,227 +1,227 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.flow.ws; - -import java.util.Iterator; -import java.util.Map; - -import javax.wsdl.Binding; -import javax.wsdl.Definition; -import javax.wsdl.Port; -import javax.wsdl.Service; -import javax.wsdl.WSDLException; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; - -/** - * Represents a service endpoint in a WSDL document. - */ -public class EndpointDefinition { - - private Definition wsdlDef; - private String namespaceURI; - private Service service; - private Port port; - - /** - * Creates a new EndpointDefinition. If a particular service is not - * identified the endpoint is created using the first service definition - * occurring in the WSDL with a port with a SOAP binding. - * - * @param wsdlURL - * @param serviceName - * @param portName - * @throws WSDLException - * @throws InvalidServiceException - */ - public EndpointDefinition(String wsdlURL, String serviceName, - String portName) throws WSDLException, InvalidServiceException { - wsdlDef = loadWSDLDefinition(wsdlURL); - namespaceURI = wsdlDef.getTargetNamespace(); - initialize(serviceName, portName); - } - - /** - * Returns the target namespace of the WSDL document in which this endpoint - * is defined. - * - * @return - */ - public String getNamespaceURI() { - return namespaceURI; - } - - /** - * Returns the name of the service that this endpoint belongs to. - * - * @return - */ - public String getServiceName() { - return service.getQName().getLocalPart(); - } - - /** - * Returns the name of the port that concretely defines the endpoint. - * - * @return - */ - public String getPortName() { - return port.getName(); - } - - /** - * Sets the service and port for this endpoint using the named entities if - * provided. - * - * @param serviceName - * @param portName - * @throws InvalidServiceException - */ - private void initialize(String serviceName, String portName) - throws InvalidServiceException { - if (serviceName != null) { - service = getServiceNamed(serviceName); - } else { - service = getDefaultService(); - } - // if using default service a port was already created in validating the - // service. - if (port == null) { - if (portName != null) { - port = getPortNamed(portName); - } else { - // returns 1st port with a soap binding for the given service or - // throws an exception if none found - port = getDefaultPort(service); - } - } - } - - /** - * Loads the WSDL document containing the definition of this endpoint. - * - * @param wsdlURL - * @return @throws - * WSDLException - */ - private Definition loadWSDLDefinition(String wsdlURL) throws WSDLException { - WSDLFactory factory = WSDLFactory.newInstance(); - WSDLReader reader = factory.newWSDLReader(); - reader.setFeature("javax.wsdl.verbose", false); - reader.setFeature("javax.wsdl.importDocuments", true); - Definition wsdlDef = reader.readWSDL(wsdlURL); - return wsdlDef; - } - - /** - * Returns an object representation of the named service. - * - * @param serviceName - * @return - */ - private Service getServiceNamed(String serviceName) { - return wsdlDef.getService(new QName(namespaceURI, serviceName)); - } - - /** - * Returns an object representing the default service if none is specified - * when this endpoint is created. The default service is determined by - * selecting the 1st service that has a port with a SOAP binding. - * - * @return @throws - * InvalidServiceException - */ - private Service getDefaultService() throws InvalidServiceException { - Map services = wsdlDef.getServices(); - Iterator it = services.values().iterator(); - while (it.hasNext()) { - Service service = (Service) it.next(); - Port port = getDefaultPort(service); - if (port != null) { - this.port = port; - return service; - } - } - String msg = "No services defined in WSDL document named: " - + wsdlDef.getQName().getLocalPart(); - throw new InvalidServiceException(msg); - } - - /** - * Returns an object representation of the named port. - * - * @param portName - * @return - */ - private Port getPortNamed(String portName) { - Map serviceMap = wsdlDef.getServices(); - Iterator services = serviceMap.values().iterator(); - while (services.hasNext()) { - Service service = (Service) services.next(); - Map portMap = service.getPorts(); - Iterator ports = portMap.values().iterator(); - while (ports.hasNext()) { - Port port = (Port) ports.next(); - if (port.getName().equals(portName)) { - return port; - } - } - } - return null; - } - - /** - * Returns an object representing the default port if none is specified at - * the time this endpoint is created. The default port is determined by - * selecting the 1st port, for the given service, that has a SOAP binding. - * - * @param service - * @throws InvalidServiceException - */ - private Port getDefaultPort(Service service) throws InvalidServiceException { - Map ports = service.getPorts(); - Iterator it = ports.values().iterator(); - while (it.hasNext()) { - Port port = (Port) it.next(); - if (hasSoapBinding(port)) { - return port; - } - } - String msg = "No ports with SOAP binding for service named: " - + service.getQName().getLocalPart(); - throw new InvalidServiceException(msg); - } - - /** - * Tests if a port has a SOAP binding. - * - * @param port - * @return - */ - private boolean hasSoapBinding(Port port) { - Binding binding = port.getBinding(); - Iterator it = port.getExtensibilityElements().iterator(); - while (it.hasNext()) { - Object element = it.next(); - if (element instanceof SOAPAddress) { - return true; - } - } - return false; - } +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.flow.ws; + +import java.util.Iterator; +import java.util.Map; + +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +/** + * Represents a service endpoint in a WSDL document. + */ +public class EndpointDefinition { + + private Definition wsdlDef; + private String namespaceURI; + private Service service; + private Port port; + + /** + * Creates a new EndpointDefinition. If a particular service is not + * identified the endpoint is created using the first service definition + * occurring in the WSDL with a port with a SOAP binding. + * + * @param wsdlURL + * @param serviceName + * @param portName + * @throws WSDLException + * @throws InvalidServiceException + */ + public EndpointDefinition(String wsdlURL, String serviceName, + String portName) throws WSDLException, InvalidServiceException { + wsdlDef = loadWSDLDefinition(wsdlURL); + namespaceURI = wsdlDef.getTargetNamespace(); + initialize(serviceName, portName); + } + + /** + * Returns the target namespace of the WSDL document in which this endpoint + * is defined. + * + * @return + */ + public String getNamespaceURI() { + return namespaceURI; + } + + /** + * Returns the name of the service that this endpoint belongs to. + * + * @return + */ + public String getServiceName() { + return service.getQName().getLocalPart(); + } + + /** + * Returns the name of the port that concretely defines the endpoint. + * + * @return + */ + public String getPortName() { + return port.getName(); + } + + /** + * Sets the service and port for this endpoint using the named entities if + * provided. + * + * @param serviceName + * @param portName + * @throws InvalidServiceException + */ + private void initialize(String serviceName, String portName) + throws InvalidServiceException { + if (serviceName != null) { + service = getServiceNamed(serviceName); + } else { + service = getDefaultService(); + } + // if using default service a port was already created in validating the + // service. + if (port == null) { + if (portName != null) { + port = getPortNamed(portName); + } else { + // returns 1st port with a soap binding for the given service or + // throws an exception if none found + port = getDefaultPort(service); + } + } + } + + /** + * Loads the WSDL document containing the definition of this endpoint. + * + * @param wsdlURL + * @return @throws + * WSDLException + */ + private Definition loadWSDLDefinition(String wsdlURL) throws WSDLException { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setFeature("javax.wsdl.importDocuments", true); + Definition wsdlDef = reader.readWSDL(wsdlURL); + return wsdlDef; + } + + /** + * Returns an object representation of the named service. + * + * @param serviceName + * @return + */ + private Service getServiceNamed(String serviceName) { + return wsdlDef.getService(new QName(namespaceURI, serviceName)); + } + + /** + * Returns an object representing the default service if none is specified + * when this endpoint is created. The default service is determined by + * selecting the 1st service that has a port with a SOAP binding. + * + * @return @throws + * InvalidServiceException + */ + private Service getDefaultService() throws InvalidServiceException { + Map services = wsdlDef.getServices(); + Iterator it = services.values().iterator(); + while (it.hasNext()) { + Service service = (Service) it.next(); + Port port = getDefaultPort(service); + if (port != null) { + this.port = port; + return service; + } + } + String msg = "No services defined in WSDL document named: " + + wsdlDef.getQName().getLocalPart(); + throw new InvalidServiceException(msg); + } + + /** + * Returns an object representation of the named port. + * + * @param portName + * @return + */ + private Port getPortNamed(String portName) { + Map serviceMap = wsdlDef.getServices(); + Iterator services = serviceMap.values().iterator(); + while (services.hasNext()) { + Service service = (Service) services.next(); + Map portMap = service.getPorts(); + Iterator ports = portMap.values().iterator(); + while (ports.hasNext()) { + Port port = (Port) ports.next(); + if (port.getName().equals(portName)) { + return port; + } + } + } + return null; + } + + /** + * Returns an object representing the default port if none is specified at + * the time this endpoint is created. The default port is determined by + * selecting the 1st port, for the given service, that has a SOAP binding. + * + * @param service + * @throws InvalidServiceException + */ + private Port getDefaultPort(Service service) throws InvalidServiceException { + Map ports = service.getPorts(); + Iterator it = ports.values().iterator(); + while (it.hasNext()) { + Port port = (Port) it.next(); + if (hasSoapBinding(port)) { + return port; + } + } + String msg = "No ports with SOAP binding for service named: " + + service.getQName().getLocalPart(); + throw new InvalidServiceException(msg); + } + + /** + * Tests if a port has a SOAP binding. + * + * @param port + * @return + */ + private boolean hasSoapBinding(Port port) { + Binding binding = port.getBinding(); + Iterator it = port.getExtensibilityElements().iterator(); + while (it.hasNext()) { + Object element = it.next(); + if (element instanceof SOAPAddress) { + return true; + } + } + return false; + } } Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/Expression.java Mon Jan 10 06:34:31 2005 @@ -1,30 +1,30 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression; - -import java.util.Iterator; - -public interface Expression { - public Object evaluate(ExpressionContext context) throws ExpressionException; - - public Iterator iterate(ExpressionContext context) throws ExpressionException; - - public void assign(ExpressionContext context, Object value) throws ExpressionException; - - public String getExpression(); - - public String getLanguage(); -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression; + +import java.util.Iterator; + +public interface Expression { + public Object evaluate(ExpressionContext context) throws ExpressionException; + + public Iterator iterate(ExpressionContext context) throws ExpressionException; + + public void assign(ExpressionContext context, Object value) throws ExpressionException; + + public String getExpression(); + + public String getLanguage(); +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionCompiler.java Mon Jan 10 06:34:31 2005 @@ -1,23 +1,23 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression; - -public interface ExpressionCompiler { - public String ROLE = ExpressionCompiler.class.getName(); - - public Expression compile(String language, String expression) - throws ExpressionException; -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression; + +public interface ExpressionCompiler { + public String ROLE = ExpressionCompiler.class.getName(); + + public Expression compile(String language, String expression) + throws ExpressionException; +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionContext.java Mon Jan 10 06:34:31 2005 @@ -1,69 +1,69 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression; - -import java.util.HashMap; -import java.util.Map; - -public class ExpressionContext extends HashMap { - private ExpressionContext closure; - private Object contextBean = null; - - public ExpressionContext() { - this(null); - } - - public ExpressionContext(ExpressionContext closure) { - this.closure = closure; - } - - public Object getContextBean() { - if (contextBean != null) - return contextBean; - else if (closure != null) - return closure.getContextBean(); - else - return null; - } - - public void setContextBean(Object contextBean) { - this.contextBean = contextBean; - } - - public Map getVars() { - return this; - } - - public void setVars(Map map) { - clear(); - putAll(map); - } - - public boolean containsKey(Object key) { - return this.get(key) != null; - } - - public Object get(Object key) { - if (key.equals("this")) { - return this; - } - Object result = super.get(key); - if (result == null && closure != null) { - result = closure.get(key); - } - return result; - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression; + +import java.util.HashMap; +import java.util.Map; + +public class ExpressionContext extends HashMap { + private ExpressionContext closure; + private Object contextBean = null; + + public ExpressionContext() { + this(null); + } + + public ExpressionContext(ExpressionContext closure) { + this.closure = closure; + } + + public Object getContextBean() { + if (contextBean != null) + return contextBean; + else if (closure != null) + return closure.getContextBean(); + else + return null; + } + + public void setContextBean(Object contextBean) { + this.contextBean = contextBean; + } + + public Map getVars() { + return this; + } + + public void setVars(Map map) { + clear(); + putAll(map); + } + + public boolean containsKey(Object key) { + return this.get(key) != null; + } + + public Object get(Object key) { + if (key.equals("this")) { + return this; + } + Object result = super.get(key); + if (result == null && closure != null) { + result = closure.get(key); + } + return result; + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/ExpressionFactory.java Mon Jan 10 06:34:31 2005 @@ -1,68 +1,68 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression; - -import org.apache.avalon.framework.CascadingRuntimeException; -import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.ServiceSelector; -import org.apache.avalon.framework.service.Serviceable; -import org.apache.avalon.framework.thread.ThreadSafe; - -public class ExpressionFactory - extends AbstractLogEnabled - implements Disposable, Serviceable, ThreadSafe { - public static String ROLE = ExpressionFactory.class.getName(); - - /** The component manager */ - protected ServiceManager manager; - - /** The Expression compiler selector */ - protected ServiceSelector compilerSelector; - - public void service(final ServiceManager manager) - throws ServiceException { - this.manager = manager; - - this.compilerSelector = - (ServiceSelector)this.manager.lookup(ExpressionCompiler.ROLE + "Selector"); - } - - public void dispose() { - if(null != this.manager) { - this.manager.release(this.compilerSelector); - this.compilerSelector = null; - } - } - - public Expression getExpression(String language, String expression) - throws ExpressionException { - - Expression expressionImpl = null; - ExpressionCompiler compiler = null; - try { - compiler = (ExpressionCompiler)this.compilerSelector.select(language); - expressionImpl = compiler.compile(language, expression); - } catch(final ServiceException ce) { - throw new ExpressionException("Can't find a compiler for " + language); - } finally { - this.compilerSelector.release(compiler); - } - return expressionImpl; - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression; + +import org.apache.avalon.framework.CascadingRuntimeException; +import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.ServiceSelector; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.thread.ThreadSafe; + +public class ExpressionFactory + extends AbstractLogEnabled + implements Disposable, Serviceable, ThreadSafe { + public static String ROLE = ExpressionFactory.class.getName(); + + /** The component manager */ + protected ServiceManager manager; + + /** The Expression compiler selector */ + protected ServiceSelector compilerSelector; + + public void service(final ServiceManager manager) + throws ServiceException { + this.manager = manager; + + this.compilerSelector = + (ServiceSelector)this.manager.lookup(ExpressionCompiler.ROLE + "Selector"); + } + + public void dispose() { + if(null != this.manager) { + this.manager.release(this.compilerSelector); + this.compilerSelector = null; + } + } + + public Expression getExpression(String language, String expression) + throws ExpressionException { + + Expression expressionImpl = null; + ExpressionCompiler compiler = null; + try { + compiler = (ExpressionCompiler)this.compilerSelector.select(language); + expressionImpl = compiler.compile(language, expression); + } catch(final ServiceException ce) { + throw new ExpressionException("Can't find a compiler for " + language); + } finally { + this.compilerSelector.release(compiler); + } + return expressionImpl; + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java Mon Jan 10 06:34:31 2005 @@ -1,325 +1,325 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jexl; - -import java.util.Enumeration; -import java.util.Iterator; - -import org.apache.commons.jexl.util.introspection.Info; -import org.apache.commons.jexl.util.introspection.UberspectImpl; -import org.apache.commons.jexl.util.introspection.VelMethod; -import org.apache.commons.jexl.util.introspection.VelPropertyGet; -import org.apache.commons.jexl.util.introspection.VelPropertySet; -import org.apache.commons.lang.StringUtils; -import org.mozilla.javascript.*; - - -/** - * Jexl Introspector that supports Rhino JavaScript objects - * as well as Java Objects - */ -public class JSIntrospector extends UberspectImpl { - - static class JSMethod implements VelMethod { - - Scriptable scope; - String name; - - public JSMethod(Scriptable scope, String name) { - this.scope = scope; - this.name = name; - } - - public Object invoke(Object thisArg, Object[] args) throws Exception { - Context cx = Context.enter(); - try { - Object result; - Scriptable thisObj = !(thisArg instanceof Scriptable) ? - Context.toObject(thisArg, scope) : (Scriptable)thisArg; - result = ScriptableObject.getProperty(thisObj, name); - Object[] newArgs = null; - if (args != null) { - newArgs = new Object[args.length]; - int len = args.length; - for (int i = 0; i < len; i++) { - newArgs[i] = args[i]; - if (args[i] != null && - !(args[i] instanceof Number) && - !(args[i] instanceof Boolean) && - !(args[i] instanceof String) && - !(args[i] instanceof Scriptable)) { - newArgs[i] = Context.toObject(args[i], scope); - } - } - } - result = ScriptRuntime.call(cx, result, thisObj, newArgs, scope); - if (result == Undefined.instance || result == Scriptable.NOT_FOUND) { - result = null; - } else if (!(result instanceof NativeJavaClass)) { - while (result instanceof Wrapper) { - result = ((Wrapper)result).unwrap(); - } - } - return result; - } catch (JavaScriptException e) { - throw new java.lang.reflect.InvocationTargetException(e); - } finally { - Context.exit(); - } - } - - public boolean isCacheable() { - return false; - } - - public String getMethodName() { - return name; - } - - public Class getReturnType() { - return Object.class; - } - - } - - static class JSPropertyGet implements VelPropertyGet { - - Scriptable scope; - String name; - - public JSPropertyGet(Scriptable scope, String name) { - this.scope = scope; - this.name = name; - } - - public Object invoke(Object thisArg) throws Exception { - Context cx = Context.enter(); - try { - Scriptable thisObj = !(thisArg instanceof Scriptable) ? - Context.toObject(thisArg, scope) : (Scriptable)thisArg; - Object result = ScriptableObject.getProperty(thisObj, name); - if (result == Scriptable.NOT_FOUND) { - result = ScriptableObject.getProperty(thisObj, "get" + StringUtils.capitalize(name)); - if (result != Scriptable.NOT_FOUND && result instanceof Function) { - try { - result = ((Function)result).call( - cx, ScriptableObject.getTopLevelScope(thisObj), thisObj, new Object[] {}); - } catch (JavaScriptException exc) { - exc.printStackTrace(); - result = null; - } - } - } - if (result == Scriptable.NOT_FOUND || result == Undefined.instance) { - result = null; - } else if (result instanceof Wrapper && !(result instanceof NativeJavaClass)) { - result = ((Wrapper)result).unwrap(); - } - return result; - } finally { - Context.exit(); - } - } - - public boolean isCacheable() { - return false; - } - - public String getMethodName() { - return name; - } - } - - static class JSPropertySet implements VelPropertySet { - - Scriptable scope; - String name; - - public JSPropertySet(Scriptable scope, String name) { - this.scope = scope; - this.name = name; - } - - public Object invoke(Object thisArg, Object rhs) throws Exception { - Context.enter(); - try { - Scriptable thisObj; - Object arg = rhs; - if (!(thisArg instanceof Scriptable)) { - thisObj = Context.toObject(thisArg, scope); - } else { - thisObj = (Scriptable)thisArg; - } - if (arg != null && - !(arg instanceof Number) && - !(arg instanceof Boolean) && - !(arg instanceof String) && - !(arg instanceof Scriptable)) { - arg = Context.toObject(arg, scope); - } - ScriptableObject.putProperty(thisObj, name, arg); - return rhs; - } finally { - Context.exit(); - } - } - - public boolean isCacheable() { - return false; - } - - public String getMethodName() { - return name; - } - } - - public static class NativeArrayIterator implements Iterator { - - NativeArray arr; - int index; - - public NativeArrayIterator(NativeArray arr) { - this.arr = arr; - this.index = 0; - } - - public boolean hasNext() { - return index < (int)arr.jsGet_length(); - } - - public Object next() { - Context.enter(); - try { - Object result = arr.get(index++, arr); - if (result == Undefined.instance || - result == Scriptable.NOT_FOUND) { - result = null; - } else { - if (!(result instanceof NativeJavaClass)) { - while (result instanceof Wrapper) { - result = ((Wrapper)result).unwrap(); - } - } - } - return result; - } finally { - Context.exit(); - } - } - - public void remove() { - arr.delete(index); - } - } - - static class ScriptableIterator implements Iterator { - - Scriptable scope; - Object[] ids; - int index; - - public ScriptableIterator(Scriptable scope) { - this.scope = scope; - this.ids = scope.getIds(); - this.index = 0; - } - - public boolean hasNext() { - return index < ids.length; - } - - public Object next() { - Context.enter(); - try { - Object result = ScriptableObject.getProperty(scope, ids[index++].toString()); - if (result == Undefined.instance || result == Scriptable.NOT_FOUND) { - result = null; - } else if (!(result instanceof NativeJavaClass)) { - while (result instanceof Wrapper) { - result = ((Wrapper)result).unwrap(); - } - } - return result; - } finally { - Context.exit(); - } - } - - public void remove() { - Context.enter(); - try { - scope.delete(ids[index].toString()); - } finally { - Context.exit(); - } - } - } - - public Iterator getIterator(Object obj, Info i) throws Exception { - if (!(obj instanceof Scriptable)) { - // support Enumeration - /* - Booth Enumeration and Iterator are supported in - Uberspect. The only difference is that they emit a - rather long warning message to commons logging, telling - that Enumerations and Iterator not are resettable and - cannot be reused. - */ - if (obj instanceof Enumeration) { - final Enumeration e = (Enumeration)obj; - return new Iterator() { - - public boolean hasNext() { - return e.hasMoreElements(); - } - - public Object next() { - return e.nextElement(); - } - - public void remove() { - // no action - } - - }; - } - if (obj instanceof Iterator) { - // support Iterator - return (Iterator)obj; - } - return super.getIterator(obj, i); - } - if (obj instanceof NativeArray) { - return new NativeArrayIterator((NativeArray)obj); - } - return new ScriptableIterator((Scriptable)obj); - } - - public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception { - return !(obj instanceof Scriptable) ? - super.getMethod(obj, methodName, args, i) : new JSMethod((Scriptable)obj, methodName); - } - - public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception { - return !(obj instanceof Scriptable) ? - super.getPropertyGet(obj, identifier, i) : new JSPropertyGet((Scriptable)obj, identifier); - } - - public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception { - return !(obj instanceof Scriptable) ? - super.getPropertySet(obj, identifier, arg, i) : new JSPropertySet((Scriptable)obj, identifier); - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jexl; + +import java.util.Enumeration; +import java.util.Iterator; + +import org.apache.commons.jexl.util.introspection.Info; +import org.apache.commons.jexl.util.introspection.UberspectImpl; +import org.apache.commons.jexl.util.introspection.VelMethod; +import org.apache.commons.jexl.util.introspection.VelPropertyGet; +import org.apache.commons.jexl.util.introspection.VelPropertySet; +import org.apache.commons.lang.StringUtils; +import org.mozilla.javascript.*; + + +/** + * Jexl Introspector that supports Rhino JavaScript objects + * as well as Java Objects + */ +public class JSIntrospector extends UberspectImpl { + + static class JSMethod implements VelMethod { + + Scriptable scope; + String name; + + public JSMethod(Scriptable scope, String name) { + this.scope = scope; + this.name = name; + } + + public Object invoke(Object thisArg, Object[] args) throws Exception { + Context cx = Context.enter(); + try { + Object result; + Scriptable thisObj = !(thisArg instanceof Scriptable) ? + Context.toObject(thisArg, scope) : (Scriptable)thisArg; + result = ScriptableObject.getProperty(thisObj, name); + Object[] newArgs = null; + if (args != null) { + newArgs = new Object[args.length]; + int len = args.length; + for (int i = 0; i < len; i++) { + newArgs[i] = args[i]; + if (args[i] != null && + !(args[i] instanceof Number) && + !(args[i] instanceof Boolean) && + !(args[i] instanceof String) && + !(args[i] instanceof Scriptable)) { + newArgs[i] = Context.toObject(args[i], scope); + } + } + } + result = ScriptRuntime.call(cx, result, thisObj, newArgs, scope); + if (result == Undefined.instance || result == Scriptable.NOT_FOUND) { + result = null; + } else if (!(result instanceof NativeJavaClass)) { + while (result instanceof Wrapper) { + result = ((Wrapper)result).unwrap(); + } + } + return result; + } catch (JavaScriptException e) { + throw new java.lang.reflect.InvocationTargetException(e); + } finally { + Context.exit(); + } + } + + public boolean isCacheable() { + return false; + } + + public String getMethodName() { + return name; + } + + public Class getReturnType() { + return Object.class; + } + + } + + static class JSPropertyGet implements VelPropertyGet { + + Scriptable scope; + String name; + + public JSPropertyGet(Scriptable scope, String name) { + this.scope = scope; + this.name = name; + } + + public Object invoke(Object thisArg) throws Exception { + Context cx = Context.enter(); + try { + Scriptable thisObj = !(thisArg instanceof Scriptable) ? + Context.toObject(thisArg, scope) : (Scriptable)thisArg; + Object result = ScriptableObject.getProperty(thisObj, name); + if (result == Scriptable.NOT_FOUND) { + result = ScriptableObject.getProperty(thisObj, "get" + StringUtils.capitalize(name)); + if (result != Scriptable.NOT_FOUND && result instanceof Function) { + try { + result = ((Function)result).call( + cx, ScriptableObject.getTopLevelScope(thisObj), thisObj, new Object[] {}); + } catch (JavaScriptException exc) { + exc.printStackTrace(); + result = null; + } + } + } + if (result == Scriptable.NOT_FOUND || result == Undefined.instance) { + result = null; + } else if (result instanceof Wrapper && !(result instanceof NativeJavaClass)) { + result = ((Wrapper)result).unwrap(); + } + return result; + } finally { + Context.exit(); + } + } + + public boolean isCacheable() { + return false; + } + + public String getMethodName() { + return name; + } + } + + static class JSPropertySet implements VelPropertySet { + + Scriptable scope; + String name; + + public JSPropertySet(Scriptable scope, String name) { + this.scope = scope; + this.name = name; + } + + public Object invoke(Object thisArg, Object rhs) throws Exception { + Context.enter(); + try { + Scriptable thisObj; + Object arg = rhs; + if (!(thisArg instanceof Scriptable)) { + thisObj = Context.toObject(thisArg, scope); + } else { + thisObj = (Scriptable)thisArg; + } + if (arg != null && + !(arg instanceof Number) && + !(arg instanceof Boolean) && + !(arg instanceof String) && + !(arg instanceof Scriptable)) { + arg = Context.toObject(arg, scope); + } + ScriptableObject.putProperty(thisObj, name, arg); + return rhs; + } finally { + Context.exit(); + } + } + + public boolean isCacheable() { + return false; + } + + public String getMethodName() { + return name; + } + } + + public static class NativeArrayIterator implements Iterator { + + NativeArray arr; + int index; + + public NativeArrayIterator(NativeArray arr) { + this.arr = arr; + this.index = 0; + } + + public boolean hasNext() { + return index < (int)arr.jsGet_length(); + } + + public Object next() { + Context.enter(); + try { + Object result = arr.get(index++, arr); + if (result == Undefined.instance || + result == Scriptable.NOT_FOUND) { + result = null; + } else { + if (!(result instanceof NativeJavaClass)) { + while (result instanceof Wrapper) { + result = ((Wrapper)result).unwrap(); + } + } + } + return result; + } finally { + Context.exit(); + } + } + + public void remove() { + arr.delete(index); + } + } + + static class ScriptableIterator implements Iterator { + + Scriptable scope; + Object[] ids; + int index; + + public ScriptableIterator(Scriptable scope) { + this.scope = scope; + this.ids = scope.getIds(); + this.index = 0; + } + + public boolean hasNext() { + return index < ids.length; + } + + public Object next() { + Context.enter(); + try { + Object result = ScriptableObject.getProperty(scope, ids[index++].toString()); + if (result == Undefined.instance || result == Scriptable.NOT_FOUND) { + result = null; + } else if (!(result instanceof NativeJavaClass)) { + while (result instanceof Wrapper) { + result = ((Wrapper)result).unwrap(); + } + } + return result; + } finally { + Context.exit(); + } + } + + public void remove() { + Context.enter(); + try { + scope.delete(ids[index].toString()); + } finally { + Context.exit(); + } + } + } + + public Iterator getIterator(Object obj, Info i) throws Exception { + if (!(obj instanceof Scriptable)) { + // support Enumeration + /* + Booth Enumeration and Iterator are supported in + Uberspect. The only difference is that they emit a + rather long warning message to commons logging, telling + that Enumerations and Iterator not are resettable and + cannot be reused. + */ + if (obj instanceof Enumeration) { + final Enumeration e = (Enumeration)obj; + return new Iterator() { + + public boolean hasNext() { + return e.hasMoreElements(); + } + + public Object next() { + return e.nextElement(); + } + + public void remove() { + // no action + } + + }; + } + if (obj instanceof Iterator) { + // support Iterator + return (Iterator)obj; + } + return super.getIterator(obj, i); + } + if (obj instanceof NativeArray) { + return new NativeArrayIterator((NativeArray)obj); + } + return new ScriptableIterator((Scriptable)obj); + } + + public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception { + return !(obj instanceof Scriptable) ? + super.getMethod(obj, methodName, args, i) : new JSMethod((Scriptable)obj, methodName); + } + + public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception { + return !(obj instanceof Scriptable) ? + super.getPropertyGet(obj, identifier, i) : new JSPropertyGet((Scriptable)obj, identifier); + } + + public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception { + return !(obj instanceof Scriptable) ? + super.getPropertySet(obj, identifier, arg, i) : new JSPropertySet((Scriptable)obj, identifier); + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlCompiler.java Mon Jan 10 06:34:31 2005 @@ -1,28 +1,28 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jexl; - -import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionException; - -public class JexlCompiler implements ExpressionCompiler, ThreadSafe { - public Expression compile(String language, String expression) - throws ExpressionException{ - return new JexlExpression(language, expression); - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jexl; + +import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionException; + +public class JexlCompiler implements ExpressionCompiler, ThreadSafe { + public Expression compile(String language, String expression) + throws ExpressionException{ + return new JexlExpression(language, expression); + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java Mon Jan 10 06:34:31 2005 @@ -1,133 +1,133 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jexl; - -import java.lang.reflect.Field; -import java.util.Iterator; -import java.util.Map; - -import org.apache.commons.jexl.JexlContext; -import org.apache.commons.jexl.util.Introspector; -import org.apache.commons.jexl.util.introspection.Info; -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionContext; -import org.apache.cocoon.components.expression.ExpressionException; - -public class JexlExpression implements Expression { - - private final String language; - private final org.apache.commons.jexl.Expression compiledExpression; - - public JexlExpression(String language, String expression) - throws ExpressionException { - this.language = language; - try { - this.compiledExpression = - org.apache.commons.jexl.ExpressionFactory.createExpression(expression); - } catch (Exception e) { - throw new ExpressionException("Couldn't create expression " + expression, e); - } - } - - public Object evaluate(ExpressionContext context) - throws ExpressionException{ - try { - return this.compiledExpression.evaluate(new ContextAdapter(context)); - } catch (Exception e) { - throw new ExpressionException("Couldn't evaluate expression " + - getExpression(), e); - } - } - - public Iterator iterate(ExpressionContext context) - throws ExpressionException { - Iterator iter = null; - Object result = evaluate(context); - if (result != null) { - /* The Info object is supposed to contain the script - location where the expression is invoked and use that - in a warning log message if no iterator can be - generated. This info is not available in the expression - object and might not be relevant either as it can be - used from a non script situation. - */ - try { - iter = Introspector.getUberspect().getIterator(result, new Info("Unknown", 0, 0)); - } catch (Exception e) { - throw new ExpressionException("Couldn't get an iterator from expression " + - getExpression(), e); - } - } - if (iter == null) { - iter = EMPTY_ITER; - } - return iter; - } - - public void assign(ExpressionContext context, Object value) - throws ExpressionException { - throw new UnsupportedOperationException("Assign is not yet implemented for Jexl"); - } - - public String getExpression() { - return this.compiledExpression.getExpression(); - } - - public String getLanguage() { - return this.language; - } - - private static class ContextAdapter implements JexlContext { - private final ExpressionContext context; - public ContextAdapter(ExpressionContext context) { - this.context = context; - } - - public Map getVars() { - return this.context.getVars(); - } - - public void setVars(Map map) { - this.context.setVars(map); - } - } - - private static final Iterator EMPTY_ITER = new Iterator() { - public boolean hasNext() { - return false; - } - - public Object next() { - return null; - } - - public void remove() { - // EMPTY - } - }; - - static { - // Hack: there's no _nice_ way to add my introspector to Jexl right now - try { - Field field = Introspector.class.getDeclaredField("uberSpect"); - field.setAccessible(true); - field.set(null, new JSIntrospector()); - } catch (Exception e) { - e.printStackTrace(); - } - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jexl; + +import java.lang.reflect.Field; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.jexl.JexlContext; +import org.apache.commons.jexl.util.Introspector; +import org.apache.commons.jexl.util.introspection.Info; +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionContext; +import org.apache.cocoon.components.expression.ExpressionException; + +public class JexlExpression implements Expression { + + private final String language; + private final org.apache.commons.jexl.Expression compiledExpression; + + public JexlExpression(String language, String expression) + throws ExpressionException { + this.language = language; + try { + this.compiledExpression = + org.apache.commons.jexl.ExpressionFactory.createExpression(expression); + } catch (Exception e) { + throw new ExpressionException("Couldn't create expression " + expression, e); + } + } + + public Object evaluate(ExpressionContext context) + throws ExpressionException{ + try { + return this.compiledExpression.evaluate(new ContextAdapter(context)); + } catch (Exception e) { + throw new ExpressionException("Couldn't evaluate expression " + + getExpression(), e); + } + } + + public Iterator iterate(ExpressionContext context) + throws ExpressionException { + Iterator iter = null; + Object result = evaluate(context); + if (result != null) { + /* The Info object is supposed to contain the script + location where the expression is invoked and use that + in a warning log message if no iterator can be + generated. This info is not available in the expression + object and might not be relevant either as it can be + used from a non script situation. + */ + try { + iter = Introspector.getUberspect().getIterator(result, new Info("Unknown", 0, 0)); + } catch (Exception e) { + throw new ExpressionException("Couldn't get an iterator from expression " + + getExpression(), e); + } + } + if (iter == null) { + iter = EMPTY_ITER; + } + return iter; + } + + public void assign(ExpressionContext context, Object value) + throws ExpressionException { + throw new UnsupportedOperationException("Assign is not yet implemented for Jexl"); + } + + public String getExpression() { + return this.compiledExpression.getExpression(); + } + + public String getLanguage() { + return this.language; + } + + private static class ContextAdapter implements JexlContext { + private final ExpressionContext context; + public ContextAdapter(ExpressionContext context) { + this.context = context; + } + + public Map getVars() { + return this.context.getVars(); + } + + public void setVars(Map map) { + this.context.setVars(map); + } + } + + private static final Iterator EMPTY_ITER = new Iterator() { + public boolean hasNext() { + return false; + } + + public Object next() { + return null; + } + + public void remove() { + // EMPTY + } + }; + + static { + // Hack: there's no _nice_ way to add my introspector to Jexl right now + try { + Field field = Introspector.class.getDeclaredField("uberSpect"); + field.setAccessible(true); + field.set(null, new JSIntrospector()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathCompiler.java Mon Jan 10 06:34:31 2005 @@ -1,28 +1,28 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jxpath; - -import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionException; - -public class JXPathCompiler implements ExpressionCompiler, ThreadSafe { - public Expression compile(String language, String expression) - throws ExpressionException{ - return new JXPathExpression(language, expression); - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jxpath; + +import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionException; + +public class JXPathCompiler implements ExpressionCompiler, ThreadSafe { + public Expression compile(String language, String expression) + throws ExpressionException{ + return new JXPathExpression(language, expression); + } +} Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java&r1=124799&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java (original) +++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java Mon Jan 10 06:34:31 2005 @@ -1,96 +1,96 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jxpath; - -import java.util.Iterator; -import java.util.Map; - -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionContext; -import org.apache.cocoon.components.expression.ExpressionException; -import org.apache.commons.jxpath.CompiledExpression; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.jxpath.Variables; - -public class JXPathExpression implements Expression { - - private final String language; - private final String expression; - private final CompiledExpression compiledExpression; - - public JXPathExpression(String language, String expression) - throws ExpressionException { - this.language = language; - this.expression = expression; - this.compiledExpression = JXPathContext.compile(expression); - } - - public Object evaluate(ExpressionContext context) - throws ExpressionException{ - return this.compiledExpression.getValue(getContext(context)); - } - - public Iterator iterate(ExpressionContext context) - throws ExpressionException { - return this.compiledExpression.iterate(getContext(context)); - } - - public void assign(ExpressionContext context, Object value) - throws ExpressionException { - this.compiledExpression.setValue(getContext(context), value); - } - - public String getExpression() { - return this.expression; - } - - public String getLanguage() { - return this.language; - } - - private JXPathContext getContext(ExpressionContext context) { - // This could be made more efficient by caching the - // JXPathContext within the Context object. - JXPathContext jxcontext = JXPathContext.newContext(null, context.getContextBean()); - jxcontext.setVariables(new VariableAdapter(context)); - return jxcontext; - } - - private static class VariableAdapter implements Variables { - private ExpressionContext context; - - public VariableAdapter(ExpressionContext context) { - this.context = context; - } - - public void declareVariable(String name, Object value) { - this.context.put(name, value); - } - - public Object getVariable(String name) { - return this.context.get(name); - } - - public boolean isDeclaredVariable(String name) { - return this.context.containsKey(name); - } - - public void undeclareVariable(String name) { - throw new UnsupportedOperationException("Operation undeclareVariable is not supported"); - } - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jxpath; + +import java.util.Iterator; +import java.util.Map; + +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionContext; +import org.apache.cocoon.components.expression.ExpressionException; +import org.apache.commons.jxpath.CompiledExpression; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.jxpath.Variables; + +public class JXPathExpression implements Expression { + + private final String language; + private final String expression; + private final CompiledExpression compiledExpression; + + public JXPathExpression(String language, String expression) + throws ExpressionException { + this.language = language; + this.expression = expression; + this.compiledExpression = JXPathContext.compile(expression); + } + + public Object evaluate(ExpressionContext context) + throws ExpressionException{ + return this.compiledExpression.getValue(getContext(context)); + } + + public Iterator iterate(ExpressionContext context) + throws ExpressionException { + return this.compiledExpression.iterate(getContext(context)); + } + + public void assign(ExpressionContext context, Object value) + throws ExpressionException { + this.compiledExpression.setValue(getContext(context), value); + } + + public String getExpression() { + return this.expression; + } + + public String getLanguage() { + return this.language; + } + + private JXPathContext getContext(ExpressionContext context) { + // This could be made more efficient by caching the + // JXPathContext within the Context object. + JXPathContext jxcontext = JXPathContext.newContext(null, context.getContextBean()); + jxcontext.setVariables(new VariableAdapter(context)); + return jxcontext; + } + + private static class VariableAdapter implements Variables { + private ExpressionContext context; + + public VariableAdapter(ExpressionContext context) { + this.context = context; + } + + public void declareVariable(String name, Object value) { + this.context.put(name, value); + } + + public Object getVariable(String name) { + return this.context.get(name); + } + + public boolean isDeclaredVariable(String name) { + return this.context.containsKey(name); + } + + public void undeclareVariable(String name) { + throw new UnsupportedOperationException("Operation undeclareVariable is not supported"); + } + } +} Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java&r1=124799&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java (original) +++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java Mon Jan 10 06:34:31 2005 @@ -1,68 +1,68 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression; - -import org.apache.avalon.framework.service.ServiceException; -import org.apache.cocoon.CocoonTestCase; - -public class ExpressionTestCase extends CocoonTestCase { - - public void testContext() { - ExpressionContext parentContext = new ExpressionContext(); - parentContext.put("var1", "foo"); - parentContext.put("var2", "bar"); - - ExpressionContext context = new ExpressionContext(parentContext); - context.put("var1", "zonk"); - - assertEquals("foo", parentContext.get("var1")); - assertEquals("bar", parentContext.get("var2")); - assertEquals("zonk", context.get("var1")); - assertEquals("bar", context.get("var2")); - } - - public void testContextBean() { - ExpressionContext parentContext = new ExpressionContext(); - parentContext.setContextBean("foo"); - - ExpressionContext context = new ExpressionContext(parentContext); - context.setContextBean("bar"); - - assertEquals("foo", parentContext.getContextBean()); - assertEquals("bar", context.getContextBean()); - } - - public void testFactoryJexl() throws ExpressionException, ServiceException { - ExpressionFactory factory = (ExpressionFactory)this.lookup(ExpressionFactory.ROLE); - assertNotNull("Test lookup of expression factory", factory); - - Expression expression = factory.getExpression("jexl", "1+2"); - assertNotNull("Test expression compilation", expression); - - assertEquals(new Long(3), expression.evaluate(new ExpressionContext())); - } - - public void testFactoryJXPath() throws ExpressionException, ServiceException { - ExpressionFactory factory = (ExpressionFactory)this.lookup(ExpressionFactory.ROLE); - assertNotNull("Test lookup of expression factory", factory); - - Expression expression = factory.getExpression("jxpath", "1+2"); - assertNotNull("Test expression compilation", expression); - - assertEquals(new Double(3), expression.evaluate(new ExpressionContext())); - } -} - +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression; + +import org.apache.avalon.framework.service.ServiceException; +import org.apache.cocoon.CocoonTestCase; + +public class ExpressionTestCase extends CocoonTestCase { + + public void testContext() { + ExpressionContext parentContext = new ExpressionContext(); + parentContext.put("var1", "foo"); + parentContext.put("var2", "bar"); + + ExpressionContext context = new ExpressionContext(parentContext); + context.put("var1", "zonk"); + + assertEquals("foo", parentContext.get("var1")); + assertEquals("bar", parentContext.get("var2")); + assertEquals("zonk", context.get("var1")); + assertEquals("bar", context.get("var2")); + } + + public void testContextBean() { + ExpressionContext parentContext = new ExpressionContext(); + parentContext.setContextBean("foo"); + + ExpressionContext context = new ExpressionContext(parentContext); + context.setContextBean("bar"); + + assertEquals("foo", parentContext.getContextBean()); + assertEquals("bar", context.getContextBean()); + } + + public void testFactoryJexl() throws ExpressionException, ServiceException { + ExpressionFactory factory = (ExpressionFactory)this.lookup(ExpressionFactory.ROLE); + assertNotNull("Test lookup of expression factory", factory); + + Expression expression = factory.getExpression("jexl", "1+2"); + assertNotNull("Test expression compilation", expression); + + assertEquals(new Long(3), expression.evaluate(new ExpressionContext())); + } + + public void testFactoryJXPath() throws ExpressionException, ServiceException { + ExpressionFactory factory = (ExpressionFactory)this.lookup(ExpressionFactory.ROLE); + assertNotNull("Test lookup of expression factory", factory); + + Expression expression = factory.getExpression("jxpath", "1+2"); + assertNotNull("Test expression compilation", expression); + + assertEquals(new Double(3), expression.evaluate(new ExpressionContext())); + } +} + Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java&r1=124799&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java (original) +++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jexl/JexlTestCase.java Mon Jan 10 06:34:31 2005 @@ -1,54 +1,54 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jexl; - -import java.util.Iterator; - -import junit.framework.TestCase; -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionContext; -import org.apache.cocoon.components.expression.ExpressionException; - -public class JexlTestCase extends TestCase { - - public void testExpression() throws ExpressionException { - ExpressionCompiler compiler = new JexlCompiler(); - Expression expression = compiler.compile("jexl", "1+2"); - assertEquals(new Long(3), expression.evaluate(new ExpressionContext())); - } - - public void testContextExpression() throws ExpressionException { - ExpressionCompiler compiler = new JexlCompiler(); - ExpressionContext context = new ExpressionContext(); - context.put("a", new Long(1)); - context.put("b", new Long(2)); - Expression expression = compiler.compile("jexl", "a+b"); - assertEquals(new Long(3), expression.evaluate(context)); - } - - public void testIterator() throws ExpressionException { - ExpressionCompiler compiler = new JexlCompiler(); - ExpressionContext context = new ExpressionContext(); - String[] arr = {"foo"}; - context.put("arr", arr); - Expression expression = compiler.compile("jexl", "arr"); - Iterator iter = expression.iterate(context); - assertTrue("hasNext", iter.hasNext()); - assertEquals("foo", iter.next()); - assertFalse("hasNext", iter.hasNext()); - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jexl; + +import java.util.Iterator; + +import junit.framework.TestCase; +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionContext; +import org.apache.cocoon.components.expression.ExpressionException; + +public class JexlTestCase extends TestCase { + + public void testExpression() throws ExpressionException { + ExpressionCompiler compiler = new JexlCompiler(); + Expression expression = compiler.compile("jexl", "1+2"); + assertEquals(new Long(3), expression.evaluate(new ExpressionContext())); + } + + public void testContextExpression() throws ExpressionException { + ExpressionCompiler compiler = new JexlCompiler(); + ExpressionContext context = new ExpressionContext(); + context.put("a", new Long(1)); + context.put("b", new Long(2)); + Expression expression = compiler.compile("jexl", "a+b"); + assertEquals(new Long(3), expression.evaluate(context)); + } + + public void testIterator() throws ExpressionException { + ExpressionCompiler compiler = new JexlCompiler(); + ExpressionContext context = new ExpressionContext(); + String[] arr = {"foo"}; + context.put("arr", arr); + Expression expression = compiler.compile("jexl", "arr"); + Iterator iter = expression.iterate(context); + assertTrue("hasNext", iter.hasNext()); + assertEquals("foo", iter.next()); + assertFalse("hasNext", iter.hasNext()); + } +} Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java?view=diff&rev=124800&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java&r1=124799&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java&r2=124800 ============================================================================== --- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java (original) +++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java Mon Jan 10 06:34:31 2005 @@ -1,54 +1,54 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.expression.jxpath; - -import java.util.Iterator; - -import junit.framework.TestCase; -import org.apache.cocoon.components.expression.Expression; -import org.apache.cocoon.components.expression.ExpressionCompiler; -import org.apache.cocoon.components.expression.ExpressionContext; -import org.apache.cocoon.components.expression.ExpressionException; - -public class JXPathTestCase extends TestCase { - - public void testExpression() throws ExpressionException { - ExpressionCompiler compiler = new JXPathCompiler(); - Expression expression = compiler.compile("jxpath", "1+2"); - assertEquals(new Double(3), expression.evaluate(new ExpressionContext())); - } - - public void testContextExpression() throws ExpressionException { - ExpressionCompiler compiler = new JXPathCompiler(); - ExpressionContext context = new ExpressionContext(); - context.put("a", new Long(1)); - context.put("b", new Long(2)); - Expression expression = compiler.compile("jxpath", "$a+$b"); - assertEquals(new Double(3), expression.evaluate(context)); - } - - public void testIterator() throws ExpressionException { - ExpressionCompiler compiler = new JXPathCompiler(); - ExpressionContext context = new ExpressionContext(); - String[] arr = {"foo"}; - context.setContextBean(arr); - Expression expression = compiler.compile("jxpath", "."); - Iterator iter = expression.iterate(context); - assertTrue("hasNext", iter.hasNext()); - assertEquals("foo", iter.next()); - assertFalse("!hasNext", iter.hasNext()); - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.expression.jxpath; + +import java.util.Iterator; + +import junit.framework.TestCase; +import org.apache.cocoon.components.expression.Expression; +import org.apache.cocoon.components.expression.ExpressionCompiler; +import org.apache.cocoon.components.expression.ExpressionContext; +import org.apache.cocoon.components.expression.ExpressionException; + +public class JXPathTestCase extends TestCase { + + public void testExpression() throws ExpressionException { + ExpressionCompiler compiler = new JXPathCompiler(); + Expression expression = compiler.compile("jxpath", "1+2"); + assertEquals(new Double(3), expression.evaluate(new ExpressionContext())); + } + + public void testContextExpression() throws ExpressionException { + ExpressionCompiler compiler = new JXPathCompiler(); + ExpressionContext context = new ExpressionContext(); + context.put("a", new Long(1)); + context.put("b", new Long(2)); + Expression expression = compiler.compile("jxpath", "$a+$b"); + assertEquals(new Double(3), expression.evaluate(context)); + } + + public void testIterator() throws ExpressionException { + ExpressionCompiler compiler = new JXPathCompiler(); + ExpressionContext context = new ExpressionContext(); + String[] arr = {"foo"}; + context.setContextBean(arr); + Expression expression = compiler.compile("jxpath", "."); + Iterator iter = expression.iterate(context); + assertTrue("hasNext", iter.hasNext()); + assertEquals("foo", iter.next()); + assertFalse("!hasNext", iter.hasNext()); + } +} Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java?view=diff&rev=124800&p1=cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java&r1=124799&p2=cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java&r2=124800 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java Mon Jan 10 06:34:31 2005 @@ -1,100 +1,100 @@ -/* - * Copyright 2002-2004 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. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.container; - -import java.util.HashMap; -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.components.SitemapConfigurable; -import org.apache.cocoon.components.SitemapConfigurationHolder; -import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo; -import org.apache.cocoon.core.container.CoreServiceManager; - -/** - * Default service manager for Cocoon's components. - * - * @version CVS $Revision: 1.6 $Id: CocoonServiceManager.java 55165 2004-10-20 16:51:50Z cziegeler $ - */ -public class CocoonServiceManager extends CoreServiceManager { - - /** The [EMAIL PROTECTED] SitemapConfigurationHolder}s */ - private Map sitemapConfigurationHolders = new HashMap(15); - - private ProcessorComponentInfo info; - - /** Create the ServiceManager with a parent ServiceManager */ - public CocoonServiceManager( final ServiceManager parent) { - super( parent ); - ProcessorComponentInfo parentInfo = null; - if (parent != null) { - try { - parentInfo = (ProcessorComponentInfo) parent.lookup(ProcessorComponentInfo.ROLE); - } catch (ServiceException e) { - // no parent - } - } - this.info = new ProcessorComponentInfo(parentInfo); - } - - public void addComponent(String role, String clazz, Configuration config) throws ConfigurationException { - super.addComponent(role, clazz, config); - // Let's ProcessorComponentInfo do its stuff. - // Note: if more behaviours of this kind are needed, we may setup an - // event listener mechanism on the core service manager - this.info.componentAdded(role, clazz, config); - } - - public void addRoleAlias(String existingRole, String newRole) throws ServiceException { - super.addRoleAlias(existingRole, newRole); - this.info.roleAliased(existingRole, newRole); - } - - public void initialize() throws Exception { - this.info.lock(); - this.addInstance(ProcessorComponentInfo.ROLE, this.info); - super.initialize(); - } - - /* (non-Javadoc) - * @see org.apache.cocoon.core.container.CocoonServiceManager#initialize(java.lang.String, java.lang.Object) - */ - protected void initialize(String role, Object component) throws ServiceException { - super.initialize(role, component); - if ( null != component && component instanceof SitemapConfigurable) { - - // FIXME: how can we prevent that this is called over and over again? - SitemapConfigurationHolder holder; - - holder = (SitemapConfigurationHolder)this.sitemapConfigurationHolders.get( role ); - if ( null == holder ) { - // create new holder - holder = new DefaultSitemapConfigurationHolder( role, this.roleManager ); - this.sitemapConfigurationHolders.put( role, holder ); - } - - try { - ((SitemapConfigurable)component).configure(holder); - } catch (ConfigurationException ce) { - throw new ServiceException(role, "Exception during setup of SitemapConfigurable.", ce); - } - } - } -} +/* + * Copyright 2002-2004 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. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.container; + +import java.util.HashMap; +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.components.SitemapConfigurable; +import org.apache.cocoon.components.SitemapConfigurationHolder; +import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo; +import org.apache.cocoon.core.container.CoreServiceManager; + +/** + * Default service manager for Cocoon's components. + * + * @version CVS $Revision: 1.6 $Id: CocoonServiceManager.java 55165 2004-10-20 16:51:50Z cziegeler $ + */ +public class CocoonServiceManager extends CoreServiceManager { + + /** The [EMAIL PROTECTED] SitemapConfigurationHolder}s */ + private Map sitemapConfigurationHolders = new HashMap(15); + + private ProcessorComponentInfo info; + + /** Create the ServiceManager with a parent ServiceManager */ + public CocoonServiceManager( final ServiceManager parent) { + super( parent ); + ProcessorComponentInfo parentInfo = null; + if (parent != null) { + try { + parentInfo = (ProcessorComponentInfo) parent.lookup(ProcessorComponentInfo.ROLE); + } catch (ServiceException e) { + // no parent + } + } + this.info = new ProcessorComponentInfo(parentInfo); + } + + public void addComponent(String role, String clazz, Configuration config) throws ConfigurationException { + super.addComponent(role, clazz, config); + // Let's ProcessorComponentInfo do its stuff. + // Note: if more behaviours of this kind are needed, we may setup an + // event listener mechanism on the core service manager + this.info.componentAdded(role, clazz, config); + } + + public void addRoleAlias(String existingRole, String newRole) throws ServiceException { + super.addRoleAlias(existingRole, newRole); + this.info.roleAliased(existingRole, newRole); + } + + public void initialize() throws Exception { + this.info.lock(); + this.addInstance(ProcessorComponentInfo.ROLE, this.info); + super.initialize(); + } + + /* (non-Javadoc) + * @see org.apache.cocoon.core.container.CocoonServiceManager#initialize(java.lang.String, java.lang.Object) + */ + protected void initialize(String role, Object component) throws ServiceException { + super.initialize(role, component); + if ( null != component && component instanceof SitemapConfigurable) { + + // FIXME: how can we prevent that this is called over and over again? + SitemapConfigurationHolder holder; + + holder = (SitemapConfigurationHolder)this.sitemapConfigurationHolders.get( role ); + if ( null == holder ) { + // create new holder + holder = new DefaultSitemapConfigurationHolder( role, this.roleManager ); + this.sitemapConfigurationHolders.put( role, holder ); + } + + try { + ((SitemapConfigurable)component).configure(holder); + } catch (ConfigurationException ce) { + throw new ServiceException(role, "Exception during setup of SitemapConfigurable.", ce); + } + } + } +} Modified: cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java?view=diff&rev=124800&p1=cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java&r1=124799&p2=cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java&r2=124800 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Mon Jan 10 06:34:31 2005 @@ -1,370 +1,370 @@ -/* - * Copyright 2004,2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon.components.store.impl; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.CacheException; -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.Element; - -import org.apache.cocoon.Constants; -import org.apache.cocoon.util.IOUtils; - -import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.activity.Initializable; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.parameters.ParameterException; -import org.apache.avalon.framework.parameters.Parameterizable; -import org.apache.avalon.framework.parameters.Parameters; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; -import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.excalibur.store.Store; -import org.apache.excalibur.store.StoreJanitor; - -/** - * Store implementation based on EHCache. - * (http://ehcache.sourceforge.net/) - */ -public class EHDefaultStore extends AbstractLogEnabled -implements Store, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable, ThreadSafe { - - // ---------------------------------------------------- Constants - - private static final String CONFIG_FILE = "org/apache/cocoon/components/store/impl/ehcache.xml"; - - private static int instanceCount = 0; - - // ---------------------------------------------------- Instance variables - - private Cache cache; - private CacheManager cacheManager; - - private final String cacheName; - - // configuration options - private int maxObjects; - private boolean overflowToDisk; - - /** The service manager */ - private ServiceManager manager; - - /** The store janitor */ - private StoreJanitor storeJanitor; - - private File workDir; - private File cacheDir; - - // ---------------------------------------------------- Lifecycle - - public EHDefaultStore() { - instanceCount++; - this.cacheName = "cocoon-ehcache-" + instanceCount; - } - - /* (non-Javadoc) - * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) - */ - public void contextualize(Context context) throws ContextException { - this.workDir = (File)context.get(Constants.CONTEXT_WORK_DIR); - this.cacheDir = (File)context.get(Constants.CONTEXT_CACHE_DIR); - } - - /* (non-Javadoc) - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager aManager) throws ServiceException { - this.manager = aManager; - this.storeJanitor = (StoreJanitor) this.manager.lookup(StoreJanitor.ROLE); - } - - /** - * Configure the store. The following options can be used: - * <ul> - * <li><code>maxobjects</code> (10000) - The maximum number of in-memory objects.</li> - * <li><code>overflow-to-disk</code> (true) - Whether to spool elements to disk after - * maxobjects has been exceeded.</li> - * <li><code>use-cache-directory</code> (false) - If true the <i>cache-directory</i> - * context entry will be used as the location of the disk store. - * Within the servlet environment this is set in web.xml.</li> - * <li><code>use-work-directory</code> (false) - If true the <i>work-directory</i> - * context entry will be used as the location of the disk store. - * Within the servlet environment this is set in web.xml.</li> - * <li><code>directory</code> - Specify an alternative location of the disk store. - * </ul> - */ - public void parameterize(Parameters parameters) throws ParameterException { - - this.maxObjects = parameters.getParameterAsInteger("maxobjects", 10000); - this.overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk", true); - - try { - if (parameters.getParameterAsBoolean("use-cache-directory", false)) { - if (this.getLogger().isDebugEnabled()) { - getLogger().debug("Using cache directory: " + cacheDir); - } - setDirectory(cacheDir); - } - else if (parameters.getParameterAsBoolean("use-work-directory", false)) { - if (this.getLogger().isDebugEnabled()) { - getLogger().debug("Using work directory: " + workDir); - } - setDirectory(workDir); - } - else if (parameters.getParameter("directory", null) != null) { - String dir = parameters.getParameter("directory"); - dir = IOUtils.getContextFilePath(workDir.getPath(), dir); - if (this.getLogger().isDebugEnabled()) { - getLogger().debug("Using directory: " + dir); - } - setDirectory(new File(dir)); - } - else { - try { - // Legacy: use working directory by default - setDirectory(workDir); - } catch (IOException e) { - } - } - } catch (IOException e) { - throw new ParameterException("Unable to set directory", e); - } - - } - - /** - * Sets the cache directory - */ - private void setDirectory(final File directory) throws IOException { - - /* Save directory path prefix */ - String directoryPath = getFullFilename(directory); - directoryPath += File.separator; - - /* If directory doesn't exist, create it anew */ - if (!directory.exists()) { - if (!directory.mkdir()) { - throw new IOException("Error creating store directory '" + directoryPath + "': "); - } - } - - /* Is given file actually a directory? */ - if (!directory.isDirectory()) { - throw new IOException("'" + directoryPath + "' is not a directory"); - } - - /* Is directory readable and writable? */ - if (!(directory.canRead() && directory.canWrite())) { - throw new IOException("Directory '" + directoryPath + "' is not readable/writable"); - } - - System.setProperty("java.io.tmpdir", directoryPath); - } - - /** - * Get the complete filename corresponding to a (typically relative) - * <code>File</code>. - * This method accounts for the possibility of an error in getting - * the filename's <i>canonical</i> path, returning the io/error-safe - * <i>absolute</i> form instead - * - * @param file The file - * @return The file's absolute filename - */ - private static String getFullFilename(File file) { - try { - return file.getCanonicalPath(); - } - catch (Exception e) { - return file.getAbsolutePath(); - } - } - - /** - * Initialize the CacheManager and created the Cache. - */ - public void initialize() throws Exception { - URL configFileURL = Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE); - this.cacheManager = CacheManager.create(configFileURL); - this.cache = new Cache(this.cacheName, this.maxObjects, this.overflowToDisk, true, 0, 0, true, 120); - this.cacheManager.addCache(this.cache); - this.storeJanitor.register(this); - } - - /** - * Shutdown the CacheManager. - */ - public void dispose() { - if (this.storeJanitor != null) { - this.storeJanitor.unregister(this); - this.manager.release(this.storeJanitor); - this.storeJanitor = null; - } - this.manager = null; - this.cacheManager.shutdown(); - this.cacheManager = null; - this.cache = null; - } - - // ---------------------------------------------------- Store implementation - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#free() - */ - public Object get(Object key) { - Object value = null; - try { - final Element element = this.cache.get((Serializable) key); - if (element != null) { - value = element.getValue(); - } - } - catch (CacheException e) { - getLogger().error("Failure retrieving object from store", e); - } - if (getLogger().isDebugEnabled()) { - if (value != null) { - getLogger().debug("Found key: " + key); - } - else { - getLogger().debug("NOT Found key: " + key); - } - } - return value; - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#free() - */ - public void store(Object key, Object value) throws IOException { - if (getLogger().isDebugEnabled()) { - getLogger().debug("Store object " + value + " with key "+ key); - } - final Element element = new Element((Serializable) key, (Serializable) value); - this.cache.put(element); - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#free() - */ - public void free() { - try { - final List keys = this.cache.getKeysNoDuplicateCheck(); - if (!keys.isEmpty()) { - // TODO find a way to get to the LRU one. - final Serializable key = (Serializable) keys.get(0); - if (getLogger().isDebugEnabled()) { - getLogger().debug("Freeing cache"); - getLogger().debug("key: " + key); - getLogger().debug("value: " + this.cache.get(key)); - } - if (!this.cache.remove(key)) { - if (getLogger().isInfoEnabled()) { - getLogger().info("Concurrency condition in free()"); - } - } - } - } - catch (CacheException e) { - if (getLogger().isWarnEnabled()) { - getLogger().warn("Error in free()", e); - } - } - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#remove(java.lang.Object) - */ - public void remove(Object key) { - if (getLogger().isDebugEnabled()) { - getLogger().debug("Removing item " + key); - } - this.cache.remove((Serializable) key); - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#clear() - */ - public void clear() { - if (getLogger().isDebugEnabled()) { - getLogger().debug("Clearing the store"); - } - try { - this.cache.removeAll(); - } - catch (IOException e) { - getLogger().error("Failure to clearing store", e); - } - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#containsKey(java.lang.Object) - */ - public boolean containsKey(Object key) { - try { - return this.cache.get((Serializable) key) != null; - } - catch (CacheException e) { - getLogger().error("Failure retrieving object from store",e); - } - return false; - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#keys() - */ - public Enumeration keys() { - List keys = null; - try { - keys = this.cache.getKeys(); - } - catch (CacheException e) { - if (getLogger().isWarnEnabled()) { - getLogger().warn("Error while getting cache keys", e); - } - keys = Collections.EMPTY_LIST; - } - return Collections.enumeration(keys); - } - - /* (non-Javadoc) - * @see org.apache.excalibur.store.Store#size() - */ - public int size() { - try { - return this.cache.getSize(); - } - catch (CacheException e) { - if (getLogger().isWarnEnabled()) { - getLogger().warn("Error while getting cache size", e); - } - return 0; - } - } - -} +/* + * Copyright 2004,2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.components.store.impl; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheException; +import net.sf.ehcache.CacheManager; +import net.sf.ehcache.Element; + +import org.apache.cocoon.Constants; +import org.apache.cocoon.util.IOUtils; + +import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.context.ContextException; +import org.apache.avalon.framework.context.Contextualizable; +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.excalibur.store.Store; +import org.apache.excalibur.store.StoreJanitor; + +/** + * Store implementation based on EHCache. + * (http://ehcache.sourceforge.net/) + */ +public class EHDefaultStore extends AbstractLogEnabled +implements Store, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable, ThreadSafe { + + // ---------------------------------------------------- Constants + + private static final String CONFIG_FILE = "org/apache/cocoon/components/store/impl/ehcache.xml"; + + private static int instanceCount = 0; + + // ---------------------------------------------------- Instance variables + + private Cache cache; + private CacheManager cacheManager; + + private final String cacheName; + + // configuration options + private int maxObjects; + private boolean overflowToDisk; + + /** The service manager */ + private ServiceManager manager; + + /** The store janitor */ + private StoreJanitor storeJanitor; + + private File workDir; + private File cacheDir; + + // ---------------------------------------------------- Lifecycle + + public EHDefaultStore() { + instanceCount++; + this.cacheName = "cocoon-ehcache-" + instanceCount; + } + + /* (non-Javadoc) + * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) + */ + public void contextualize(Context context) throws ContextException { + this.workDir = (File)context.get(Constants.CONTEXT_WORK_DIR); + this.cacheDir = (File)context.get(Constants.CONTEXT_CACHE_DIR); + } + + /* (non-Javadoc) + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) + */ + public void service(ServiceManager aManager) throws ServiceException { + this.manager = aManager; + this.storeJanitor = (StoreJanitor) this.manager.lookup(StoreJanitor.ROLE); + } + + /** + * Configure the store. The following options can be used: + * <ul> + * <li><code>maxobjects</code> (10000) - The maximum number of in-memory objects.</li> + * <li><code>overflow-to-disk</code> (true) - Whether to spool elements to disk after + * maxobjects has been exceeded.</li> + * <li><code>use-cache-directory</code> (false) - If true the <i>cache-directory</i> + * context entry will be used as the location of the disk store. + * Within the servlet environment this is set in web.xml.</li> + * <li><code>use-work-directory</code> (false) - If true the <i>work-directory</i> + * context entry will be used as the location of the disk store. + * Within the servlet environment this is set in web.xml.</li> + * <li><code>directory</code> - Specify an alternative location of the disk store. + * </ul> + */ + public void parameterize(Parameters parameters) throws ParameterException { + + this.maxObjects = parameters.getParameterAsInteger("maxobjects", 10000); + this.overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk", true); + + try { + if (parameters.getParameterAsBoolean("use-cache-directory", false)) { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Using cache directory: " + cacheDir); + } + setDirectory(cacheDir); + } + else if (parameters.getParameterAsBoolean("use-work-directory", false)) { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Using work directory: " + workDir); + } + setDirectory(workDir); + } + else if (parameters.getParameter("directory", null) != null) { + String dir = parameters.getParameter("directory"); + dir = IOUtils.getContextFilePath(workDir.getPath(), dir); + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Using directory: " + dir); + } + setDirectory(new File(dir)); + } + else { + try { + // Legacy: use working directory by default + setDirectory(workDir); + } catch (IOException e) { + } + } + } catch (IOException e) { + throw new ParameterException("Unable to set directory", e); + } + + } + + /** + * Sets the cache directory + */ + private void setDirectory(final File directory) throws IOException { + + /* Save directory path prefix */ + String directoryPath = getFullFilename(directory); + directoryPath += File.separator; + + /* If directory doesn't exist, create it anew */ + if (!directory.exists()) { + if (!directory.mkdir()) { + throw new IOException("Error creating store directory '" + directoryPath + "': "); + } + } + + /* Is given file actually a directory? */ + if (!directory.isDirectory()) { + throw new IOException("'" + directoryPath + "' is not a directory"); + } + + /* Is directory readable and writable? */ + if (!(directory.canRead() && directory.canWrite())) { + throw new IOException("Directory '" + directoryPath + "' is not readable/writable"); + } + + System.setProperty("java.io.tmpdir", directoryPath); + } + + /** + * Get the complete filename corresponding to a (typically relative) + * <code>File</code>. + * This method accounts for the possibility of an error in getting + * the filename's <i>canonical</i> path, returning the io/error-safe + * <i>absolute</i> form instead + * + * @param file The file + * @return The file's absolute filename + */ + private static String getFullFilename(File file) { + try { + return file.getCanonicalPath(); + } + catch (Exception e) { + return file.getAbsolutePath(); + } + } + + /** + * Initialize the CacheManager and created the Cache. + */ + public void initialize() throws Exception { + URL configFileURL = Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE); + this.cacheManager = CacheManager.create(configFileURL); + this.cache = new Cache(this.cacheName, this.maxObjects, this.overflowToDisk, true, 0, 0, true, 120); + this.cacheManager.addCache(this.cache); + this.storeJanitor.register(this); + } + + /** + * Shutdown the CacheManager. + */ + public void dispose() { + if (this.storeJanitor != null) { + this.storeJanitor.unregister(this); + this.manager.release(this.storeJanitor); + this.storeJanitor = null; + } + this.manager = null; + this.cacheManager.shutdown(); + this.cacheManager = null; + this.cache = null; + } + + // ---------------------------------------------------- Store implementation + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#free() + */ + public Object get(Object key) { + Object value = null; + try { + final Element element = this.cache.get((Serializable) key); + if (element != null) { + value = element.getValue(); + } + } + catch (CacheException e) { + getLogger().error("Failure retrieving object from store", e); + } + if (getLogger().isDebugEnabled()) { + if (value != null) { + getLogger().debug("Found key: " + key); + } + else { + getLogger().debug("NOT Found key: " + key); + } + } + return value; + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#free() + */ + public void store(Object key, Object value) throws IOException { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Store object " + value + " with key "+ key); + } + final Element element = new Element((Serializable) key, (Serializable) value); + this.cache.put(element); + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#free() + */ + public void free() { + try { + final List keys = this.cache.getKeysNoDuplicateCheck(); + if (!keys.isEmpty()) { + // TODO find a way to get to the LRU one. + final Serializable key = (Serializable) keys.get(0); + if (getLogger().isDebugEnabled()) { + getLogger().debug("Freeing cache"); + getLogger().debug("key: " + key); + getLogger().debug("value: " + this.cache.get(key)); + } + if (!this.cache.remove(key)) { + if (getLogger().isInfoEnabled()) { + getLogger().info("Concurrency condition in free()"); + } + } + } + } + catch (CacheException e) { + if (getLogger().isWarnEnabled()) { + getLogger().warn("Error in free()", e); + } + } + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#remove(java.lang.Object) + */ + public void remove(Object key) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Removing item " + key); + } + this.cache.remove((Serializable) key); + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#clear() + */ + public void clear() { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Clearing the store"); + } + try { + this.cache.removeAll(); + } + catch (IOException e) { + getLogger().error("Failure to clearing store", e); + } + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#containsKey(java.lang.Object) + */ + public boolean containsKey(Object key) { + try { + return this.cache.get((Serializable) key) != null; + } + catch (CacheException e) { + getLogger().error("Failure retrieving object from store",e); + } + return false; + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#keys() + */ + public Enumeration keys() { + List keys = null; + try { + keys = this.cache.getKeys(); + } + catch (CacheException e) { + if (getLogger().isWarnEnabled()) { + getLogger().warn("Error while getting cache keys", e); + } + keys = Collections.EMPTY_LIST; + } + return Collections.enumeration(keys); + } + + /* (non-Javadoc) + * @see org.apache.excalibur.store.Store#size() + */ + public int size() { + try { + return this.cache.getSize(); + } + catch (CacheException e) { + if (getLogger().isWarnEnabled()) { + getLogger().warn("Error while getting cache size", e); + } + return 0; + } + } + +} Modified: cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java?view=diff&rev=124800&p1=cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java&r1=124799&p2=cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java&r2=124800 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/CocoonTestCase.java Mon Jan 10 06:34:31 2005 @@ -1,82 +1,82 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.cocoon; - -import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.avalon.framework.configuration.DefaultConfiguration; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.cocoon.core.container.CoreServiceManager; -import org.apache.cocoon.core.container.CocoonServiceSelector; -import org.apache.cocoon.core.container.ContainerTestCase; -import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.impl.ResourceSourceFactory; -import org.apache.excalibur.source.impl.SourceResolverImpl; -import org.apache.excalibur.source.impl.URLSourceFactory; - -/** - * Testcase for Cocoon. - * - * @version CVS $Id: SitemapComponentTestCase.java 55427 2004-10-24 11:38:37Z cziegeler $ - */ -public abstract class CocoonTestCase extends ContainerTestCase { - - /* (non-Javadoc) - * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager) - */ - protected void addComponents(CoreServiceManager manager) - throws ServiceException, ConfigurationException { - super.addComponents(manager); - if ( this.addSourceFactories() ) { - // Create configuration for source-factories - final DefaultConfiguration df = new DefaultConfiguration("source-factories"); - DefaultConfiguration factory = new DefaultConfiguration("component-instance"); - factory.setAttribute("class", ResourceSourceFactory.class.getName()); - factory.setAttribute("name", "resource"); - df.addChild(factory); - factory = new DefaultConfiguration("component-instance"); - factory.setAttribute("class", URLSourceFactory.class.getName()); - factory.setAttribute("name", "*"); - df.addChild(factory); - manager.addComponent("org.apache.excalibur.source.SourceFactorySelector", - CocoonServiceSelector.class.getName(), - df); - } - if ( this.addSourceResolver() ) { - manager.addComponent(SourceResolver.ROLE, - SourceResolverImpl.class.getName(), - new DefaultConfiguration("", "-")); - } - } - - /** - * This method should return true if the source factories should - * be added automatically. Can be overwritten by subclasses. The - * default is true. - */ - protected boolean addSourceFactories() { - return true; - } - - /** - * This method should return true if the source resolver should - * be added automatically. Can be overwritten by subclasses. The - * default is true. - */ - protected boolean addSourceResolver() { - return true; - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon; + +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.configuration.DefaultConfiguration; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.cocoon.core.container.CoreServiceManager; +import org.apache.cocoon.core.container.CocoonServiceSelector; +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.excalibur.source.SourceResolver; +import org.apache.excalibur.source.impl.ResourceSourceFactory; +import org.apache.excalibur.source.impl.SourceResolverImpl; +import org.apache.excalibur.source.impl.URLSourceFactory; + +/** + * Testcase for Cocoon. + * + * @version CVS $Id: SitemapComponentTestCase.java 55427 2004-10-24 11:38:37Z cziegeler $ + */ +public abstract class CocoonTestCase extends ContainerTestCase { + + /* (non-Javadoc) + * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager) + */ + protected void addComponents(CoreServiceManager manager) + throws ServiceException, ConfigurationException { + super.addComponents(manager); + if ( this.addSourceFactories() ) { + // Create configuration for source-factories + final DefaultConfiguration df = new DefaultConfiguration("source-factories"); + DefaultConfiguration factory = new DefaultConfiguration("component-instance"); + factory.setAttribute("class", ResourceSourceFactory.class.getName()); + factory.setAttribute("name", "resource"); + df.addChild(factory); + factory = new DefaultConfiguration("component-instance"); + factory.setAttribute("class", URLSourceFactory.class.getName()); + factory.setAttribute("name", "*"); + df.addChild(factory); + manager.addComponent("org.apache.excalibur.source.SourceFactorySelector", + CocoonServiceSelector.class.getName(), + df); + } + if ( this.addSourceResolver() ) { + manager.addComponent(SourceResolver.ROLE, + SourceResolverImpl.class.getName(), + new DefaultConfiguration("", "-")); + } + } + + /** + * This method should return true if the source factories should + * be added automatically. Can be overwritten by subclasses. The + * default is true. + */ + protected boolean addSourceFactories() { + return true; + } + + /** + * This method should return true if the source resolver should + * be added automatically. Can be overwritten by subclasses. The + * default is true. + */ + protected boolean addSourceResolver() { + return true; + } +} Modified: cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java?view=diff&rev=124800&p1=cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java&r1=124799&p2=cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java&r2=124800 ============================================================================== --- cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java (original) +++ cocoon/trunk/src/test/org/apache/cocoon/MockProcessor.java Mon Jan 10 06:34:31 2005 @@ -1,70 +1,70 @@ -/* - * Copyright 1999-2004 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cocoon; - -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.cocoon.environment.Environment; -import org.apache.cocoon.environment.SourceResolver; - -/** - * Mock processor - * - * @version CVS $Id$ - */ -public class MockProcessor implements Processor { - - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#buildPipeline(org.apache.cocoon.environment.Environment) - */ - public InternalPipelineDescription buildPipeline(Environment environment) - throws Exception { - return null; - } - - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#getComponentConfigurations() - */ - public Configuration[] getComponentConfigurations() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#getContext() - */ - public String getContext() { - return null; - } - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#getRootProcessor() - */ - public Processor getRootProcessor() { - return this; - } - - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#getSourceResolver() - */ - public SourceResolver getSourceResolver() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.cocoon.Processor#process(org.apache.cocoon.environment.Environment) - */ - public boolean process(Environment environment) throws Exception { - return false; - } -} +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon; + +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.cocoon.environment.Environment; +import org.apache.cocoon.environment.SourceResolver; + +/** + * Mock processor + * + * @version CVS $Id$ + */ +public class MockProcessor implements Processor { + + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#buildPipeline(org.apache.cocoon.environment.Environment) + */ + public InternalPipelineDescription buildPipeline(Environment environment) + throws Exception { + return null; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#getComponentConfigurations() + */ + public Configuration[] getComponentConfigurations() { + return null; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#getContext() + */ + public String getContext() { + return null; + } + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#getRootProcessor() + */ + public Processor getRootProcessor() { + return this; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#getSourceResolver() + */ + public SourceResolver getSourceResolver() { + return null; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.Processor#process(org.apache.cocoon.environment.Environment) + */ + public boolean process(Environment environment) throws Exception { + return false; + } +}