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