Search in sources :

Example 16 with Context

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

the class ServletContextSymbolProviderTest method access_of_keys_is_case_insensitive.

@Test
public void access_of_keys_is_case_insensitive() {
    ServletContext context = newMock(ServletContext.class);
    String key1 = "fred";
    String value1 = "Fred Flintstone";
    String key2 = "barney";
    String value2 = "Barney Rubble";
    expect(context.getInitParameterNames()).andReturn(toEnumeration(key1, key2));
    expect(context.getInitParameter(key1)).andReturn(value1);
    expect(context.getInitParameter(key2)).andReturn(value2);
    replay();
    SymbolProvider p = new ServletContextSymbolProvider(context);
    assertEquals(p.valueForSymbol(key1), value1);
    assertEquals(p.valueForSymbol(key2), value2);
    // Not in config is null
    assertNull(p.valueForSymbol("wilma"));
    // Check for case insensitivity
    assertEquals(p.valueForSymbol("FRED"), value1);
    verify();
}
Also used : ServletContextSymbolProvider(org.apache.tapestry5.http.internal.ServletContextSymbolProvider) SymbolProvider(org.apache.tapestry5.ioc.services.SymbolProvider) ServletContext(javax.servlet.ServletContext) ServletContextSymbolProvider(org.apache.tapestry5.http.internal.ServletContextSymbolProvider) Test(org.testng.annotations.Test)

Example 17 with Context

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

the class ContextResourceSymbolProviderTest method access.

@Test
public void access() throws Exception {
    File f = File.createTempFile("foo", ".properties");
    setupFile(f);
    Context context = mockContext();
    expect(context.getRealFile("/bar/" + f.getName())).andReturn(f);
    replay();
    ContextResourceSymbolProvider provider = new ContextResourceSymbolProvider(context, "bar/" + f.getName());
    /* test general access */
    assertEquals(provider.valueForSymbol("homer"), "simpson");
    assertEquals(provider.valueForSymbol("monty"), "burns");
    /* check for case-insensitivity */
    assertEquals(provider.valueForSymbol("HOMER"), "simpson");
    /* non-existent keys should return null */
    assertNull(provider.valueForSymbol("marge"));
    verify();
    f.delete();
}
Also used : Context(org.apache.tapestry5.http.services.Context) File(java.io.File) Test(org.testng.annotations.Test)

Example 18 with Context

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

the class AppPageRenderLinkTransformer method transformPageRenderLink.

public Link transformPageRenderLink(Link defaultLink, PageRenderRequestParameters parameters) {
    if (!parameters.getLogicalPageName().equals("View"))
        return null;
    StringBuilder path = new StringBuilder();
    Locale locale = persistentLocale.get();
    if (locale != null)
        path.append('/').append(locale.toString());
    path.append('/');
    // Cheating: we know there's exactly one value in the context.
    path.append(parameters.getActivationContext().get(String.class, 0));
    return defaultLink.copyWithBasePath(path.toString());
}
Also used : PersistentLocale(org.apache.tapestry5.services.PersistentLocale) Locale(java.util.Locale)

Example 19 with Context

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

the class AppPageRenderLinkTransformer method decodePageRenderRequest.

public PageRenderRequestParameters decodePageRenderRequest(Request request) {
    String path = request.getPath();
    String[] split = path.substring(1).split("/");
    if (split.length == 1 && split[0].equals(""))
        return null;
    int pacx = 0;
    String possibleLocaleName = split[0];
    // Might be just the page activation context, or it might be locale then page
    // activation context
    boolean localeSpecified = localizationSetter.isSupportedLocaleName(possibleLocaleName);
    if (localeSpecified) {
        pacx++;
    }
    if (pacx >= split.length)
        return null;
    if (localeSpecified)
        localizationSetter.setLocaleFromLocaleName(possibleLocaleName);
    boolean isLoopback = request.getParameter(TapestryConstants.PAGE_LOOPBACK_PARAMETER_NAME) != null;
    return new PageRenderRequestParameters("View", new ArrayEventContext(typeCoercer, split[pacx]), isLoopback);
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ArrayEventContext(org.apache.tapestry5.internal.services.ArrayEventContext)

Example 20 with Context

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

the class PlasticFieldImpl method replaceFieldReadAccess.

private void replaceFieldReadAccess(String conduitFieldName) {
    ensureNotPublic();
    boolean writeBehindEnabled = isWriteBehindEnabled();
    String getAccessName = plasticClass.makeUnique(plasticClass.methodNames, "conduit_get_" + node.name);
    getAccess = new MethodNode(accessForMethod(), getAccessName, "()" + node.desc, null, null);
    InstructionBuilder builder = plasticClass.newBuilder(getAccess);
    // Get the correct FieldConduit object on the stack
    pushFieldConduitOntoStack(conduitFieldName, builder);
    builder.loadThis();
    // Now push the instance context on the stack
    plasticClass.pushInstanceContextFieldOntoStack(builder);
    builder.invoke(FieldConduit.class, Object.class, "get", Object.class, InstanceContext.class).castOrUnbox(typeName);
    if (writeBehindEnabled) {
        if (isWide()) {
            // Dupe this under the wide value, then pop the wide value
            builder.dupeWide().loadThis().dupe(2).pop();
        } else {
            builder.dupe().loadThis().swap();
        }
        // At which point the stack is the result value, this, the result value
        builder.putField(plasticClass.className, node.name, typeName);
    // And now it is just the result value
    }
    builder.returnResult();
    plasticClass.addMethod(getAccess);
    plasticClass.redirectFieldRead(node.name, isPrivate(), getAccess);
}
Also used : MethodNode(org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)

Aggregations

Test (org.testng.annotations.Test)29 Context (org.apache.tapestry5.http.services.Context)18 Link (org.apache.tapestry5.http.Link)16 EventContext (org.apache.tapestry5.EventContext)12 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)9 Request (org.apache.tapestry5.http.services.Request)9 Response (org.apache.tapestry5.http.services.Response)9 ComponentModel (org.apache.tapestry5.model.ComponentModel)9 Logger (org.slf4j.Logger)9 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)8 ServletContext (javax.servlet.ServletContext)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)7 ComponentResources (org.apache.tapestry5.ComponentResources)6 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)6 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)6 JSONObject (org.apache.tapestry5.json.JSONObject)6 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)5