Search in sources :

Example 1 with ComponentResources

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

the class PageContentTypeAnalyzerImpl method findContentType.

public ContentType findContentType(Page page) {
    ComponentResources pageResources = page.getRootComponent().getComponentResources();
    String contentTypeString = metaDataLocator.findMeta(MetaDataConstants.RESPONSE_CONTENT_TYPE, pageResources, String.class);
    return new ContentType(contentTypeString).withCharset(outputCharset);
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 2 with ComponentResources

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

the class PageElementFactoryImpl method parseAttributeExpansionExpression.

private StringProvider parseAttributeExpansionExpression(String expression, ComponentResources resources, final Location location) {
    final List<StringProvider> providers = newList();
    int startx = 0;
    while (true) {
        int expansionx = expression.indexOf(InternalConstants.EXPANSION_START, startx);
        if (expansionx < 0) {
            if (startx < expression.length())
                providers.add(new LiteralStringProvider(expression.substring(startx)));
            break;
        }
        if (startx != expansionx)
            providers.add(new LiteralStringProvider(expression.substring(startx, expansionx)));
        int endx = expression.indexOf("}", expansionx);
        if (endx < 0)
            throw new TapestryException(String.format("Attribute expression '%s' is missing a closing brace.", expression), location, null);
        String expansion = expression.substring(expansionx + 2, endx);
        final Binding binding = bindingSource.newBinding("attribute expansion", resources, resources, BindingConstants.PROP, expansion, location);
        final StringProvider provider = new StringProvider() {

            public String provideString() {
                try {
                    Object raw = binding.get();
                    return typeCoercer.coerce(raw, String.class);
                } catch (Exception ex) {
                    throw new TapestryException(ex.getMessage(), location, ex);
                }
            }
        };
        providers.add(provider);
        // Restart the search after '}'
        startx = endx + 1;
    }
    if (providers.size() == 1)
        return providers.get(0);
    return new StringProvider() {

        public String provideString() {
            StringBuilder builder = new StringBuilder();
            for (StringProvider provider : providers) builder.append(provider.provideString());
            return builder.toString();
        }
    };
}
Also used : Binding(org.apache.tapestry5.Binding) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 3 with ComponentResources

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

the class PersistentFieldManagerImpl method postChange.

public void postChange(String pageName, ComponentResources resources, String fieldName, Object newValue) {
    String strategyName = findStrategy(resources, fieldName);
    PersistentFieldStrategy strategy = getStrategy(strategyName);
    strategy.postChange(pageName, resources.getNestedId(), fieldName, newValue);
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy)

Example 4 with ComponentResources

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

the class ComponentDefaultProviderImplTest method default_translator.

@Test
public void default_translator() {
    ComponentResources resources = mockComponentResources();
    FieldTranslator translator = mockFieldTranslator();
    FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
    train_createDefaultTranslator(source, resources, "object", translator);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
    assertSame(provider.defaultTranslator("object", resources), translator);
    verify();
}
Also used : FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) FieldTranslator(org.apache.tapestry5.FieldTranslator) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 5 with ComponentResources

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

the class ComponentDefaultProviderImplTest method default_label_key_missing.

@Test
public void default_label_key_missing() {
    ComponentResources resources = mockComponentResources();
    ComponentResources container = mockComponentResources();
    Messages messages = mockMessages();
    String componentId = "myField";
    String key = componentId + "-label";
    train_getId(resources, componentId);
    train_getContainerResources(resources, container);
    train_getMessages(container, messages);
    train_contains(messages, key, false);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null);
    assertEquals(provider.defaultLabel(resources), "My Field");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Aggregations

ComponentResources (org.apache.tapestry5.ComponentResources)110 Test (org.testng.annotations.Test)99 Location (org.apache.tapestry5.commons.Location)34 Binding (org.apache.tapestry5.Binding)24 Messages (org.apache.tapestry5.commons.Messages)24 ComponentModel (org.apache.tapestry5.model.ComponentModel)17 FormSupport (org.apache.tapestry5.services.FormSupport)17 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)16 Component (org.apache.tapestry5.runtime.Component)15 MarkupWriter (org.apache.tapestry5.MarkupWriter)14 FieldValidator (org.apache.tapestry5.FieldValidator)13 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)13 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)13 Validator (org.apache.tapestry5.Validator)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)10 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)9 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)9 Request (org.apache.tapestry5.http.services.Request)7