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();
}
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();
}
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());
}
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);
}
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);
}
Aggregations