Search in sources :

Example 21 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class DynamicTemplateSaxParser method createExpansionExtractor.

private static Mapper<DynamicDelegate, String> createExpansionExtractor(final String expression, final Location location, final BindingSource bindingSource) {
    return new Mapper<DynamicDelegate, String>() {

        public String map(DynamicDelegate delegate) {
            try {
                Binding binding = bindingSource.newBinding("dynamic template binding", delegate.getComponentResources().getContainerResources(), delegate.getComponentResources(), BindingConstants.PROP, expression, location);
                Object boundValue = binding.get();
                return boundValue == null ? null : boundValue.toString();
            } catch (Throwable t) {
                throw new TapestryException(ExceptionUtils.toMessage(t), location, t);
            }
        }
    };
}
Also used : Binding(org.apache.tapestry5.Binding) Mapper(org.apache.tapestry5.func.Mapper) DynamicDelegate(org.apache.tapestry5.services.dynamic.DynamicDelegate) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 22 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class DynamicTemplateSaxParser method createCompositeExtractorFromText.

private Mapper<DynamicDelegate, String> createCompositeExtractorFromText(String text, Location location) {
    Matcher matcher = EXPANSION_PATTERN.matcher(text);
    List<Mapper<DynamicDelegate, String>> extractors = CollectionFactory.newList();
    int startx = 0;
    while (matcher.find()) {
        int matchStart = matcher.start();
        if (matchStart != startx) {
            String prefix = text.substring(startx, matchStart);
            extractors.add(createTextExtractor(prefix));
        }
        // Group 1 includes the real text of the expansion, with whitespace
        // around the
        // expression (but inside the curly braces) excluded.
        String expression = matcher.group(1);
        extractors.add(createExpansionExtractor(expression, location, bindingSource));
        startx = matcher.end();
    }
    if (startx < text.length())
        extractors.add(createTextExtractor(text.substring(startx, text.length())));
    if (extractors.size() == 1)
        return extractors.get(0);
    return creatCompositeExtractor(extractors);
}
Also used : Mapper(org.apache.tapestry5.func.Mapper) Matcher(java.util.regex.Matcher)

Example 23 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PageLoaderImpl method addParameterBindingAction.

private void addParameterBindingAction(AssemblerContext context, final EmbeddedComponentAssembler embeddedAssembler, final String parameterName, final String parameterValue, final String metaDefaultBindingPrefix, final Location location, final boolean ignoreUnmatchedFormal) {
    if (embeddedAssembler.isBound(parameterName))
        return;
    embeddedAssembler.setBound(parameterName);
    if (parameterValue.startsWith(InternalConstants.INHERIT_BINDING_PREFIX)) {
        String containerParameterName = parameterValue.substring(InternalConstants.INHERIT_BINDING_PREFIX.length());
        addInheritedBindingAction(context, parameterName, containerParameterName);
        return;
    }
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            // Because of published parameters, we have to wait until page assembly time to throw out
            // informal parameters bound to components that don't support informal parameters ...
            // otherwise we'd throw out (sometimes!) published parameters.
            final ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                if (ignoreUnmatchedFormal) {
                    return;
                }
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", pageAssembly.createdElement.peek().getCompleteId(), parameterName), null, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            final String defaultBindingPrefix = binder.getDefaultBindingPrefix(metaDefaultBindingPrefix);
            InternalComponentResources containerResources = pageAssembly.activeElement.peek().getComponentResources();
            ComponentPageElement embeddedElement = pageAssembly.createdElement.peek();
            InternalComponentResources embeddedResources = embeddedElement.getComponentResources();
            Binding binding = elementFactory.newBinding(parameterName, containerResources, embeddedResources, defaultBindingPrefix, parameterValue, location);
            binder.bind(embeddedElement, binding);
        }
    });
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 24 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PageLoaderImpl method parameter.

private void parameter(AssemblerContext context) {
    final ParameterToken token = context.next(ParameterToken.class);
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            String parameterName = token.name;
            ComponentPageElement element = pageAssembly.createdElement.peek();
            Location location = token.getLocation();
            BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
            Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
            EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
            ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            binder.bind(pageAssembly.createdElement.peek(), binding);
            pageAssembly.bodyElement.push(block);
        }
    });
    consumeToEndElementAndPopBodyElement(context);
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues) Location(org.apache.tapestry5.commons.Location)

Example 25 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class ComponentResourcesRenderer method render.

public void render(ComponentResources object, MarkupWriter writer) {
    writer.writef("%s (class %s)", object.getCompleteId(), object.getComponentModel().getComponentClassName());
    Location location = object.getLocation();
    if (location != null) {
        writer.element("br");
        writer.end();
        masterRenderer.render(location, writer);
    }
}
Also used : Location(org.apache.tapestry5.commons.Location)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2