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