Search in sources :

Example 81 with Link

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

the class LinkImplTest method retrieve_parameter_values.

@Test
public void retrieve_parameter_values() {
    Response response = mockResponse();
    replay();
    Link link = new LinkImpl("/foo/bar", false, null, response, null, null);
    link.addParameter("fred", "flintstone");
    assertEquals(link.getParameterValue("fred"), "flintstone");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 82 with Link

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

the class LinkImplTest method to_string_same_as_to_uri.

@Test
public void to_string_same_as_to_uri() {
    Response response = mockResponse();
    String url = "/bar/" + RAW_PATH;
    train_encodeURL(response, url, ENCODED);
    replay();
    Link link = new LinkImpl(url, false, LinkSecurity.INSECURE, response, null, null);
    assertEquals(link.toString(), ENCODED);
    assertEquals(link.getBasePath(), url);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 83 with Link

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

the class LinkImplTest method force_insecure_URI_from_secure_link.

@Test
public void force_insecure_URI_from_secure_link() {
    Response response = mockResponse();
    BaseURLSource baseURLSource = mockBaseURLSource();
    train_getBaseURL(baseURLSource, false, INSECURE_BASE_URL);
    train_encodeURL(response, INSECURE_BASE_URL + BASE_PATH, ENCODED);
    replay();
    Link link = new LinkImpl(BASE_PATH, false, LinkSecurity.SECURE, response, null, baseURLSource);
    assertEquals(link.toAbsoluteURI(false), ENCODED);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 84 with Link

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

the class ExceptionUtils method findCause.

/**
 * Locates a particular type of exception, working its way down via any property that returns some type of Exception.
 * This is more expensive, but more accurate, than {@link #findCause(Throwable, Class)} as it works with older exceptions
 * that do not properly implement the (relatively new) {@linkplain Throwable#getCause() cause property}.
 *
 * @param t      the outermost exception
 * @param type   the type of exception to search for
 * @param access used to access properties
 * @return the first exception of the given type, if found, or null
 */
public static <T extends Throwable> T findCause(Throwable t, Class<T> type, PropertyAccess access) {
    Throwable current = t;
    while (current != null) {
        if (type.isInstance(current)) {
            return type.cast(current);
        }
        Throwable next = null;
        ClassPropertyAdapter adapter = access.getAdapter(current);
        for (String name : adapter.getPropertyNames()) {
            Object value = adapter.getPropertyAdapter(name).get(current);
            if (value != null && value != current && value instanceof Throwable) {
                next = (Throwable) value;
                break;
            }
        }
        current = next;
    }
    return null;
}
Also used : ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter)

Example 85 with Link

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

the class ZoneRefresh method addJavaScript.

@AfterRender
void addJavaScript() {
    Link link = resources.createEventLink("zoneRefresh", context);
    javaScriptSupport.require("t5/core/zone-refresh").with(zone.getClientId(), period, link.toString());
}
Also used : Link(org.apache.tapestry5.http.Link) AfterRender(org.apache.tapestry5.annotations.AfterRender)

Aggregations

Link (org.apache.tapestry5.http.Link)66 Test (org.testng.annotations.Test)37 Response (org.apache.tapestry5.http.services.Response)19 MarkupWriter (org.apache.tapestry5.MarkupWriter)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)10 Request (org.apache.tapestry5.http.services.Request)8 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)8 Element (org.apache.tapestry5.dom.Element)7 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)7 Link (org.apache.tapestry5.Link)6 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)6 EventContext (org.apache.tapestry5.EventContext)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 IOException (java.io.IOException)4 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)4 BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)4 Page (org.apache.tapestry5.internal.structure.Page)4 List (java.util.List)3 ComponentResources (org.apache.tapestry5.ComponentResources)3