Search in sources :

Example 11 with LocalizationSetter

use of org.apache.tapestry5.services.LocalizationSetter in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method no_extra_context.

private void no_extra_context(boolean finalSlash) throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(false);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    String path = "/foo/Bar" + (finalSlash ? "/" : "");
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertEquals(parameters.getActivationContext().getCount(), 0);
    assertFalse(parameters.isLoopback());
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 12 with LocalizationSetter

use of org.apache.tapestry5.services.LocalizationSetter in project tapestry-5 by apache.

the class LocalizationSetterImplTest method get_locale_model.

@Test
public void get_locale_model() {
    LocalizationSetter setter = new LocalizationSetterImpl(null, null, null, "en,fr");
    SelectModel model = setter.getSupportedLocalesModel();
    assertNull(model.getOptionGroups());
    List<OptionModel> options = model.getOptions();
    assertEquals(options.size(), 2);
    assertEquals(options.get(0).getLabel(), "English");
    // Note that the label is localized to the underlying locale, not the default locale.
    // That's why its "français" (i.e., as a French speaker would say it), not "French"
    // (like an English speaker).
    assertEquals(options.get(1).getLabel(), "fran\u00e7ais");
    assertEquals(options.get(0).getValue(), Locale.ENGLISH);
    assertEquals(options.get(1).getValue(), Locale.FRENCH);
}
Also used : OptionModel(org.apache.tapestry5.OptionModel) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) SelectModel(org.apache.tapestry5.SelectModel) Test(org.testng.annotations.Test)

Example 13 with LocalizationSetter

use of org.apache.tapestry5.services.LocalizationSetter in project tapestry-5 by apache.

the class JavaScriptModule method setupApplicationCatalogModules.

@Contribute(ModuleManager.class)
public static void setupApplicationCatalogModules(MappedConfiguration<String, Object> configuration, LocalizationSetter localizationSetter, ComponentMessagesSource messagesSource, ResourceChangeTracker resourceChangeTracker, @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON) {
    for (Locale locale : localizationSetter.getSupportedLocales()) {
        MessageCatalogResource resource = new MessageCatalogResource(locale, messagesSource, resourceChangeTracker, compactJSON);
        configuration.add("t5/core/messages/" + locale.toString(), new JavaScriptModuleConfiguration(resource));
    }
}
Also used : Locale(java.util.Locale) MessageCatalogResource(org.apache.tapestry5.internal.util.MessageCatalogResource) JavaScriptModuleConfiguration(org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 14 with LocalizationSetter

use of org.apache.tapestry5.services.LocalizationSetter in project tapestry-5 by apache.

the class JavaScriptModule method setupModuleDispatchers.

@Contribute(Dispatcher.class)
@Primary
public static void setupModuleDispatchers(OrderedConfiguration<Dispatcher> configuration, ModuleManager moduleManager, OperationTracker tracker, ResourceStreamer resourceStreamer, PathConstructor pathConstructor, JavaScriptStackSource javaScriptStackSource, JavaScriptStackPathConstructor javaScriptStackPathConstructor, LocalizationSetter localizationSetter, @Symbol(SymbolConstants.MODULE_PATH_PREFIX) String modulePathPrefix, @Symbol(SymbolConstants.ASSET_PATH_PREFIX) String assetPathPrefix) {
    configuration.add("Modules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, false), "after:Asset", "before:ComponentEvent");
    configuration.add("ComnpressedModules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, true), "after:Modules", "before:ComponentEvent");
}
Also used : ModuleDispatcher(org.apache.tapestry5.internal.services.javascript.ModuleDispatcher) Primary(org.apache.tapestry5.ioc.annotations.Primary) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 15 with LocalizationSetter

use of org.apache.tapestry5.services.LocalizationSetter in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method just_the_locale_name.

@Test
public void just_the_locale_name() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    train_getPath(request, "/en");
    train_setLocaleFromLocaleName(ls, "en", true);
    train_isPageName(resolver, "", false);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Test(org.testng.annotations.Test)

Aggregations

LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)24 Test (org.testng.annotations.Test)21 Request (org.apache.tapestry5.http.services.Request)19 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)13 Response (org.apache.tapestry5.http.services.Response)12 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)8 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 Locale (java.util.Locale)2 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)2 PersistentLocale (org.apache.tapestry5.services.PersistentLocale)2 OptionModel (org.apache.tapestry5.OptionModel)1 SelectModel (org.apache.tapestry5.SelectModel)1 ModuleDispatcher (org.apache.tapestry5.internal.services.javascript.ModuleDispatcher)1