use of org.apache.tapestry5.internal.plastic.asm.Handle in project tapestry-5 by apache.
the class TapestryModule method contributeComponentEventRequestHandler.
/**
* Contributes filters:
* <dl>
* <dt>Ajax</dt>
* <dd>Determines if the request is Ajax oriented, and redirects to an alternative handler if so</dd>
* <dt>Secure</dt>
* <dd>Sends a redirect if an non-secure request accesses a secure page</dd>
* </dl>
*/
public void contributeComponentEventRequestHandler(OrderedConfiguration<ComponentEventRequestFilter> configuration, final RequestSecurityManager requestSecurityManager, @Ajax ComponentEventRequestHandler ajaxHandler) {
ComponentEventRequestFilter secureFilter = new ComponentEventRequestFilter() {
public void handle(ComponentEventRequestParameters parameters, ComponentEventRequestHandler handler) throws IOException {
if (requestSecurityManager.checkForInsecureComponentEventRequest(parameters))
return;
handler.handle(parameters);
}
};
configuration.add("Secure", secureFilter);
configuration.add("Ajax", new AjaxFilter(request, ajaxHandler));
}
use of org.apache.tapestry5.internal.plastic.asm.Handle in project tapestry-5 by apache.
the class PageTester method pushFieldValuesIntoRequest.
private void pushFieldValuesIntoRequest(Element form) {
Visitor visitor = new Visitor() {
public void visit(Element element) {
if (InternalUtils.isNonBlank(element.getAttribute("disabled")))
return;
String name = element.getName();
if (name.equals("input")) {
String type = extractNonBlank(element, "type");
if (type.equals("radio") || type.equals("checkbox")) {
if (InternalUtils.isBlank(element.getAttribute("checked")))
return;
}
if (type.equals("button") || type.equals("submit"))
return;
// Handle radio, checkbox, text, radio, hidden
String value = element.getAttribute("value");
if (InternalUtils.isNonBlank(value))
request.loadParameter(extractNonBlank(element, "name"), value);
return;
}
if (name.equals("option")) {
String value = element.getAttribute("value");
if (InternalUtils.isNonBlank(element.getAttribute("selected"))) {
String selectName = extractNonBlank(findAncestor(element, "select"), "name");
request.loadParameter(selectName, value);
}
return;
}
if (name.equals("textarea")) {
String content = element.getChildMarkup();
if (InternalUtils.isNonBlank(content))
request.loadParameter(extractNonBlank(element, "name"), content);
return;
}
}
};
form.visit(visitor);
}
use of org.apache.tapestry5.internal.plastic.asm.Handle in project tapestry-5 by apache.
the class ActivationRequestParameterWorker method mapFieldToQueryParameter.
private void mapFieldToQueryParameter(PlasticField field, TransformationSupport support) {
ActivationRequestParameter annotation = field.getAnnotation(ActivationRequestParameter.class);
String parameterName = getParameterName(field, annotation);
// Assumption: the field type is not one that's loaded by the component class loader, so it's safe
// to convert to a hard type during class transformation.
Class fieldType = classCache.forName(field.getTypeName());
ValueEncoder encoder = valueEncoderSource.getValueEncoder(fieldType);
FieldHandle handle = field.getHandle();
String fieldName = String.format("%s.%s", field.getPlasticClass().getClassName(), field.getName());
setValueFromInitializeEventHandler(support, fieldName, annotation.required(), handle, parameterName, encoder, urlEncoder);
decorateLinks(support, fieldName, handle, parameterName, encoder, urlEncoder);
preallocateName(support, parameterName);
}
use of org.apache.tapestry5.internal.plastic.asm.Handle in project tapestry-5 by apache.
the class PageActivationContextWorker method createPassivateHandler.
private static ComponentEventHandler createPassivateHandler(final FieldHandle[] handles) {
return new ComponentEventHandler() {
public void handleEvent(Component instance, ComponentEvent event) {
Object result;
if (handles.length == 1) {
// simple / common case for a single @PageActivationContext
result = handles[0].get(instance);
} else {
LinkedList<Object> list = CollectionFactory.newLinkedList();
// iterate backwards
for (int i = handles.length - 1; i > -1; i--) {
FieldHandle handle = handles[i];
Object value = handle.get(instance);
// ignore trailing nulls
if (value != null || !list.isEmpty()) {
list.addFirst(value);
}
}
result = list.isEmpty() ? null : list;
}
event.storeResult(result);
}
};
}
use of org.apache.tapestry5.internal.plastic.asm.Handle in project tapestry-5 by apache.
the class XMLTokenStreamTests method testStreamEncoding.
/**
* This test sets the system's default encoding to cp1252 (as on german windows) and tries to parse a non-ascii xml file
* with XMLTokenStream. This is to test a critical section within XMLTokenStream.openStream() where the
* binary file is converted to charcters and back before it is parsed.
* @throws Exception
*/
@Test
public void testStreamEncoding() throws Exception {
String oldEncoding = System.getProperty("file.encoding");
System.setProperty("file.encoding", "cp1252");
resetDefaultCharset();
try {
MappedConfigurationStub<String, URL> parserUrlMap = new MappedConfigurationStub<String, URL>();
String unicodeString = "\u00FC";
String testDocument = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>" + unicodeString + "</root>\n";
XMLTokenStream xts = new XMLTokenStream(new ResourceStub(testDocument.getBytes("utf-8")), parserUrlMap);
// Ugly way to handle exceptions like java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
// when running tests
int attempts = 0;
int maxAttempts = 10;
boolean success = false;
while (!success && attempts < maxAttempts) {
try {
xts.parse();
} catch (IOException e) {
e.printStackTrace();
Thread.sleep(5000);
attempts++;
continue;
}
success = true;
}
if (attempts == maxAttempts) {
throw new RuntimeException("Maximum number of attempts reached");
}
Assert.assertEquals(xts.next(), XMLTokenType.START_ELEMENT);
Assert.assertEquals(xts.getLocalName(), "root");
Assert.assertEquals(xts.next(), XMLTokenType.CHARACTERS);
Assert.assertEquals(xts.getText(), unicodeString);
Assert.assertEquals(xts.next(), XMLTokenType.END_ELEMENT);
Assert.assertEquals(xts.next(), XMLTokenType.END_DOCUMENT);
} finally {
System.setProperty("file.encoding", oldEncoding);
resetDefaultCharset();
}
}
Aggregations