use of org.apache.tapestry5.commons.util.AvailableValues 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.commons.util.AvailableValues in project tapestry-5 by apache.
the class BindParameterWorker method identifyParameterName.
private String identifyParameterName(ComponentResources resources, String firstGuess, String... otherGuesses) {
ComponentModel model = resources.getContainerResources().getComponentModel();
List<String> guesses = CollectionFactory.newList();
guesses.add(firstGuess);
for (String name : otherGuesses) {
guesses.add(name);
}
for (String name : guesses) {
if (model.isFormalParameter(name))
return name;
if (isPublishedParameter(model, name))
return name;
}
String message = String.format("Containing component %s does not contain a formal parameter or a published parameter %s %s.", model.getComponentClassName(), guesses.size() == 1 ? "matching" : "matching any of", InternalUtils.joinSorted(guesses));
List<String> formalAndPublishedParameters = CollectionFactory.newList(model.getParameterNames());
formalAndPublishedParameters.addAll(getPublishedParameters(model));
throw new UnknownValueException(message, new AvailableValues("Formal and published parameters", formalAndPublishedParameters));
}
use of org.apache.tapestry5.commons.util.AvailableValues in project tapestry-5 by apache.
the class TapestryModule method contributeObjectRenderer.
/**
* Contributes a default object renderer for type Object, plus specialized
* renderers for {@link org.apache.tapestry5.http.services.Request}, {@link org.apache.tapestry5.commons.Location},
* {@link org.apache.tapestry5.ComponentResources}, {@link org.apache.tapestry5.EventContext},
* {@link AvailableValues},
* List, and Object[].
*/
@SuppressWarnings("unchecked")
public void contributeObjectRenderer(MappedConfiguration<Class, ObjectRenderer> configuration, @InjectService("LocationRenderer") ObjectRenderer locationRenderer, final TypeCoercer typeCoercer) {
configuration.add(Object.class, new DefaultObjectRenderer());
configuration.addInstance(Request.class, RequestRenderer.class);
configuration.add(Location.class, locationRenderer);
ObjectRenderer preformatted = new ObjectRenderer<Object>() {
public void render(Object object, MarkupWriter writer) {
writer.element("pre");
writer.write(typeCoercer.coerce(object, String.class));
writer.end();
}
};
configuration.addInstance(List.class, ListRenderer.class);
configuration.addInstance(Object[].class, ObjectArrayRenderer.class);
configuration.addInstance(ComponentResources.class, ComponentResourcesRenderer.class);
configuration.addInstance(EventContext.class, EventContextRenderer.class);
configuration.add(AvailableValues.class, new AvailableValuesRenderer());
}
use of org.apache.tapestry5.commons.util.AvailableValues in project tapestry-5 by apache.
the class ComponentClassResolverImpl method resolvePageNameToClassName.
public String resolvePageNameToClassName(final String pageName) {
Data data = getData();
String result = locate(pageName, data.pageToClassName);
if (result == null) {
throw new UnknownValueException(String.format("Unable to resolve '%s' to a page class name.", pageName), new AvailableValues("Page names", presentableNames(data.pageToClassName)));
}
return result;
}
use of org.apache.tapestry5.commons.util.AvailableValues in project tapestry-5 by apache.
the class ObjectComponentEventResultProcessor method processResultValue.
public void processResultValue(Object value) throws IOException {
List<String> names = F.flow(configuredClasses).map(new Mapper<Class, String>() {
public String map(Class input) {
return PlasticUtils.toTypeName(input);
}
}).toList();
String message = String.format("A component event handler method returned the value %s. Return type %s can not be handled.", value, PlasticUtils.toTypeName(value.getClass()));
throw new UnknownValueException(message, new AvailableValues("Configured return types", names));
}
Aggregations