Search in sources :

Example 6 with AvailableValues

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()));
}
Also used : AssetAlias(org.apache.tapestry5.services.AssetAlias) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 7 with AvailableValues

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));
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 8 with AvailableValues

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());
}
Also used : AvailableValuesRenderer(org.apache.tapestry5.internal.renderers.AvailableValuesRenderer) ObjectRenderer(org.apache.tapestry5.services.ObjectRenderer) DefaultObjectRenderer(org.apache.tapestry5.services.DefaultObjectRenderer) DefaultObjectRenderer(org.apache.tapestry5.services.DefaultObjectRenderer) JSONObject(org.apache.tapestry5.json.JSONObject) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Example 9 with AvailableValues

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;
}
Also used : UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 10 with AvailableValues

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));
}
Also used : Mapper(org.apache.tapestry5.func.Mapper) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Aggregations

UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)10 AvailableValues (org.apache.tapestry5.commons.util.AvailableValues)9 Binding (org.apache.tapestry5.Binding)2 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)2 List (java.util.List)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 Location (org.apache.tapestry5.commons.Location)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Mapper (org.apache.tapestry5.func.Mapper)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 AvailableValuesRenderer (org.apache.tapestry5.internal.renderers.AvailableValuesRenderer)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 ComponentModel (org.apache.tapestry5.model.ComponentModel)1 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)1 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)1 AssetAlias (org.apache.tapestry5.services.AssetAlias)1 DefaultObjectRenderer (org.apache.tapestry5.services.DefaultObjectRenderer)1 ObjectRenderer (org.apache.tapestry5.services.ObjectRenderer)1 Test (org.testng.annotations.Test)1