Search in sources :

Example 11 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImpl method decodeComponentEventRequest.

public ComponentEventRequestParameters decodeComponentEventRequest(Request request) {
    String explicitLocale = null;
    // Split the path around slashes into a mutable list of terms, which will be consumed term by term.
    String requestPath = request.getPath();
    if (applicationFolderPrefix != null) {
        requestPath = removeApplicationPrefix(requestPath);
    }
    List<String> path = splitPath(requestPath);
    if (path.isEmpty()) {
        return null;
    }
    // Next up: the locale (which is optional)
    String potentialLocale = path.get(0);
    if (localizationSetter.isSupportedLocaleName(potentialLocale)) {
        explicitLocale = potentialLocale;
        path.remove(0);
    }
    StringBuilder pageName = new StringBuilder(100);
    String sep = "";
    while (!path.isEmpty()) {
        String name = path.remove(0);
        String eventType = EventConstants.ACTION;
        String nestedComponentId = "";
        boolean found = false;
        // First, look for an explicit action name.
        int colonx = name.lastIndexOf(':');
        if (colonx > 0) {
            found = true;
            eventType = name.substring(colonx + 1);
            name = name.substring(0, colonx);
        }
        int dotx = name.indexOf('.');
        if (dotx > 0) {
            found = true;
            nestedComponentId = name.substring(dotx + 1);
            name = name.substring(0, dotx);
        }
        pageName.append(sep).append(name);
        if (found) {
            ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path);
            if (result == null) {
                return result;
            }
            if (explicitLocale == null) {
                setLocaleFromRequest(request);
            } else {
                localizationSetter.setLocaleFromLocaleName(explicitLocale);
            }
            return result;
        }
        // Continue on to the next name in the path
        sep = "/";
    }
    return null;
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters)

Example 12 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class ClasspathAssetAliasManagerImpl method extractAssetAlias.

public AssetAlias extractAssetAlias(Resource resource) {
    String resourcePath = resource.getPath();
    for (String pathPrefix : sortedPathPrefixes) {
        if (resourcePath.startsWith(pathPrefix)) {
            if (pathPrefix.length() == resourcePath.length()) {
                throw new IllegalArgumentException(String.format("Resource path '%s' is not valid as it is mapped as virtual folder '%s'.", resourcePath, pathPrefixToAlias.get(pathPrefix)));
            }
            // Prevent matching path prefix "foo" against "foobar" ... it must match against "foo/".
            if (resourcePath.charAt(pathPrefix.length()) != '/') {
                continue;
            }
            String virtualFolder = pathPrefixToAlias.get(pathPrefix);
            // Don't want that slash seperating the folder from the rest of the path.
            String path = resourcePath.substring(pathPrefix.length() + 1);
            return new AssetAlias(virtualFolder, path);
        }
    }
    throw new UnknownValueException(String.format("Unable to create a client URL for classpath resource %s: The resource path was not within an aliased path.", resourcePath), new AvailableValues("Aliased paths", aliasToPathPrefix.values()));
}
Also used : AssetAlias(org.apache.tapestry5.services.AssetAlias) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 13 with Path

use of org.apache.tapestry5.annotations.Path 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 14 with Path

use of org.apache.tapestry5.annotations.Path 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 15 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class DefaultOpenApiDescriptionGenerator method processParameters.

private void processParameters(Method method, final String uri, final String httpMethod, final JSONObject methodDescription) {
    JSONArray parametersAsJsonArray = new JSONArray();
    for (Parameter parameter : method.getParameters()) {
        final JSONObject parameterDescription = new JSONObject();
        if (!isIgnored(parameter) && !parameter.isAnnotationPresent(StaticActivationContextValue.class)) {
            parameterDescription.put("in", "path");
        } else if (parameter.isAnnotationPresent(RequestParameter.class)) {
            parameterDescription.put("in", "query");
        } else if (parameter.isAnnotationPresent(RequestBody.class)) {
            processRequestBody(method, uri, httpMethod, methodDescription, parametersAsJsonArray, parameter);
        }
        if (!parameterDescription.isEmpty()) {
            // Optional<String> parameterName = getValue(method, uri, httpMethod, parameter, "name");
            // parameterDescription.put("name", parameterName.orElse(parameter.getName()));
            parameterDescription.put("name", getParameterName(parameter));
            getValue(method, uri, httpMethod, parameter, "description").ifPresent((v) -> parameterDescription.put("description", v));
            typeDescriber.describe(parameterDescription, parameter);
            parametersAsJsonArray.add(parameterDescription);
        }
    }
    if (!parametersAsJsonArray.isEmpty()) {
        methodDescription.put("parameters", parametersAsJsonArray);
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) JSONArray(org.apache.tapestry5.json.JSONArray) ActivationContextParameter(org.apache.tapestry5.annotations.ActivationContextParameter) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) Parameter(java.lang.reflect.Parameter)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4