    001    // Copyright 2011, 2012 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    // http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.kaptcha.services;
    016
    017    import org.apache.tapestry5.internal.InternalConstants;
    018    import org.apache.tapestry5.ioc.*;
    019    import org.apache.tapestry5.ioc.annotations.Contribute;
    020    import org.apache.tapestry5.ioc.annotations.Value;
    021    import org.apache.tapestry5.ioc.services.FactoryDefaults;
    022    import org.apache.tapestry5.ioc.services.SymbolProvider;
    023    import org.apache.tapestry5.kaptcha.KaptchaSymbolConstants;
    024    import org.apache.tapestry5.kaptcha.internal.services.KaptchaDataTypeAnalyzer;
    025    import org.apache.tapestry5.kaptcha.internal.services.KaptchaProducerImpl;
    026    import org.apache.tapestry5.services.*;
    027    import org.apache.tapestry5.services.messages.ComponentMessagesSource;
    028
    029    /**
    030     * Defines core services for Kaptcha support.
    031     *
    032     * @since 5.3
    033     */
    034    public class KaptchaModule
    035    {
    036        public static void bind(ServiceBinder binder)
    037        {
    038            binder.bind(KaptchaProducer.class, KaptchaProducerImpl.class);
    039        }
    040
    041        @Contribute(SymbolProvider.class)
    042        @FactoryDefaults
    043        public static void factoryDefaults(MappedConfiguration<String, Object> configuration)
    044        {
    045            configuration.add(KaptchaSymbolConstants.KAPTCHA_DEFAULT_VISIBLE, false);
    046        }
    047
    048        @Contribute(ComponentClassResolver.class)
    049        public static void provideLibraryMapping(Configuration<LibraryMapping> configuration)
    050        {
    051            configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.kaptcha"));
    052        }
    053
    054        @Contribute(ComponentMessagesSource.class)
    055        public static void provideLibraryMessages(
    056                OrderedConfiguration<Resource> configuration,
    057                @Value("classpath:org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties")
    058                Resource coreCatalog)
    059        {
    060            configuration.add("TapestryKaptcha", coreCatalog, "before:AppCatalog");
    061        }
    062
    063        public static void contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer> configuration)
    064        {
    065            configuration.add("Kaptcha", new KaptchaDataTypeAnalyzer(), "after:Annotation");
    066        }
    067
    068        @Contribute(BeanBlockSource.class)
    069        public static void provideDefaultBeanBlocks(Configuration<BeanBlockContribution> configuration)
    070        {
    071            configuration.add(new EditBlockContribution("kaptcha", "KaptchaEditBlocks", "kaptcha"));
    072
    073        }
    074    }