package jumpstart.web.services; import jumpstart.web.translators.YesNoTranslator; import jumpstart.web.validators.Letters; import org.apache.tapestry5.Translator; import org.apache.tapestry5.Validator; import org.apache.tapestry5.ioc.Configuration; import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.OrderedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.InjectService; import org.apache.tapestry5.services.BindingFactory; import org.apache.tapestry5.services.BindingSource; import org.apache.tapestry5.services.Dispatcher; /** * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to * configure and extend Tapestry, or to place your own service definitions. * See http://tapestry.apache.org/tapestry5/tapestry-ioc/module.html */ public class AppModule { // Add 3 services to those provided by Tapestry. // - IBusinessServicesLocator and CountryNames are used by pages which ask Tapestry to @Inject them. // - ProtectedPageGateKeeper is contributed, below, to Tapestry's MasterDispatcher. public static void bind(ServiceBinder binder) { binder.bind(IBusinessServicesLocator.class, BusinessServicesLocator.class); binder.bind(CountryNames.class); binder.bind(ProtectedPageGateKeeper.class).withId("ProtectedPageGateKeeper"); } // Tell Tapestry about our custom validators, translators, and their message files. // We do this by contributing to Tapestry's FieldValidatorSource service, TranslatorSource service, // and ValidationMessagesSource service. @SuppressWarnings("unchecked") public static void contributeFieldValidatorSource(MappedConfiguration configuration) { configuration.add("letters", new Letters()); } @SuppressWarnings("unchecked") public static void contributeTranslatorSource(Configuration configuration) { configuration.add(new YesNoTranslator()); } public void contributeValidationMessagesSource(Configuration configuration) { configuration.add("jumpstart/web/validators/ValidationMessages"); configuration.add("jumpstart/web/translators/TranslationMessages"); } // Tell Tapestry which locales we support. // We do this by contributing to Tapestry's ApplicationDefaults service. public static void contributeApplicationDefaults(MappedConfiguration configuration) { configuration.add("tapestry.supported-locales", "en_US,en_GB,fr"); } // Tell Tapestry how to handle a new binding prefix, "list:" (we use "list:" in at least one place, UserSearch.tml). // We do this by contributing to Tapestry's BindingSource service. // - Based on http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefix public static void contributeBindingSource(MappedConfiguration configuration, BindingSource bindingSource) { configuration.add("list", new ListBindingFactory(bindingSource)); } // Tell Tapestry where to slot our ProtectedPageGateKeeper into its chain of dispatchers // We do this by contributing to Tapestry's Master Dispatcher. // - ProtectedPageGateKeeper prevents access to pages marked as @ProtectedPage unless logged in. // - Dispatchers are described in http://tapestry.apache.org/tapestry5/guide/request.html . // - Based on http://wiki.apache.org/tapestry/Tapestry5HowToControlAccess public void contributeMasterDispatcher(OrderedConfiguration configuration, @InjectService("ProtectedPageGateKeeper") Dispatcher protectedPageGateKeeper) { configuration.add("ProtectedPageGateKeeper", protectedPageGateKeeper, "before:PageRender"); } }