001// Copyright 2011-2013 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
015package org.apache.tapestry5.kaptcha.modules;
016
017import org.apache.tapestry5.internal.InternalConstants;
018import org.apache.tapestry5.ioc.*;
019import org.apache.tapestry5.ioc.annotations.Contribute;
020import org.apache.tapestry5.ioc.annotations.Value;
021import org.apache.tapestry5.ioc.services.FactoryDefaults;
022import org.apache.tapestry5.ioc.services.SymbolProvider;
023import org.apache.tapestry5.kaptcha.KaptchaSymbolConstants;
024import org.apache.tapestry5.kaptcha.internal.services.KaptchaDataTypeAnalyzer;
025import org.apache.tapestry5.kaptcha.internal.services.KaptchaProducerImpl;
026import org.apache.tapestry5.kaptcha.services.KaptchaProducer;
027import org.apache.tapestry5.services.*;
028import org.apache.tapestry5.services.messages.ComponentMessagesSource;
029
030/**
031 * Defines core services for Kaptcha support.
032 *
033 * @since 5.3
034 */
035public class KaptchaModule
036{
037    public static void bind(ServiceBinder binder)
038    {
039        binder.bind(KaptchaProducer.class, KaptchaProducerImpl.class);
040    }
041
042    @Contribute(SymbolProvider.class)
043    @FactoryDefaults
044    public static void factoryDefaults(MappedConfiguration<String, Object> configuration)
045    {
046        configuration.add(KaptchaSymbolConstants.KAPTCHA_DEFAULT_VISIBLE, true);
047    }
048
049    @Contribute(ComponentClassResolver.class)
050    public static void provideLibraryMapping(Configuration<LibraryMapping> configuration)
051    {
052        configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.kaptcha"));
053    }
054
055    @Contribute(ComponentMessagesSource.class)
056    public static void provideLibraryMessages(
057            OrderedConfiguration<Resource> configuration,
058            @Value("classpath:org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties")
059            Resource kaptchaCatalog)
060    {
061        configuration.add("TapestryKaptcha", kaptchaCatalog, "before:AppCatalog");
062    }
063
064    public static void contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer> configuration)
065    {
066        configuration.add("Kaptcha", new KaptchaDataTypeAnalyzer(), "after:Annotation");
067    }
068
069    @Contribute(BeanBlockSource.class)
070    public static void provideDefaultBeanBlocks(Configuration<BeanBlockContribution> configuration)
071    {
072        configuration.add(new EditBlockContribution("kaptcha", "KaptchaEditBlocks", "kaptcha"));
073
074    }
075}