Search in sources :

Example 1 with Core

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

the class MavenComponentLibraryInfoSource method parse.

private ComponentLibraryInfo parse(InputStream inputStream) {
    ComponentLibraryInfo info = null;
    if (inputStream != null) {
        Document document;
        try {
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            document = documentBuilder.parse(inputStream);
        } catch (Exception e) {
            logger.warn("Exception while parsing pom.xml", e);
            return null;
        }
        info = new ComponentLibraryInfo();
        info.setGroupId(extractText(document, "(/project/groupId | /project/parent/groupId)[1]"));
        info.setArtifactId(extractText(document, "/project/artifactId"));
        info.setVersion(extractText(document, "/project/version"));
        info.setName(extractText(document, "/project/name"));
        info.setDescription(extractText(document, "/project/description"));
        info.setDocumentationUrl(extractText(document, "/project/properties/documentationUrl"));
        info.setHomepageUrl(extractText(document, "/project/properties/homepageUrl"));
        info.setIssueTrackerUrl(extractText(document, "/project/issueManagement/url"));
        info.setJavadocUrl(extractText(document, "/project/properties/javadocUrl"));
        info.setSourceBrowseUrl(extractText(document, "/project/scm/url"));
        info.setSourceRootUrl(extractText(document, "/project/properties/sourceRootUrl"));
        info.setTapestryVersion(extractText(document, "(/project/dependencies/dependency[./groupId='org.apache.tapestry'][./artifactId='tapestry-core']/version | /project/properties/tapestryVersion)[1]"));
        String tags = extractText(document, "/project/properties/tags");
        if (tags != null && tags.length() > 0) {
            info.setTags(Arrays.asList(tags.split(",")));
        }
    }
    return info;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) ComponentLibraryInfo(org.apache.tapestry5.services.ComponentLibraryInfo) Document(org.w3c.dom.Document) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException)

Example 2 with Core

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

the class PropertyEditorTest method no_editor_block_available.

@Test
public void no_editor_block_available() {
    PropertyModel model = mockPropertyModel();
    PropertyOverrides overrides = mockPropertyOverrides();
    ComponentResources resources = mockComponentResources();
    BeanBlockSource source = newMock(BeanBlockSource.class);
    RuntimeException exception = new RuntimeException("Simulated failure.");
    Messages messages = mockMessages();
    Location l = mockLocation();
    String propertyId = "foo";
    String dataType = "unk";
    String propertyName = "fooProp";
    Object object = "[OBJECT]";
    String formattedMessage = "formatted-message";
    expect(model.getId()).andReturn(propertyId);
    train_getOverrideBlock(overrides, propertyId, null);
    expect(model.getDataType()).andReturn(dataType);
    expect(source.getEditBlock(dataType)).andThrow(exception);
    expect(model.getPropertyName()).andReturn(propertyName);
    train_getLocation(resources, l);
    expect(messages.format("core-block-error", propertyName, dataType, object, exception)).andReturn(formattedMessage);
    replay();
    PropertyEditor pe = new PropertyEditor();
    pe.inject(resources, overrides, model, source, messages, object);
    try {
        pe.beginRender();
        unreachable();
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), formattedMessage);
        assertSame(ex.getLocation(), l);
    }
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanBlockSource(org.apache.tapestry5.services.BeanBlockSource) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 3 with Core

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

the class AbstractServiceCreator method createInjectionResources.

/**
 * Returns a map (based on injectionResources) that includes (possibly) an additional mapping containing the
 * collected configuration data. This involves scanning the parameters and generic types.
 */
protected final InjectionResources createInjectionResources() {
    InjectionResources core = new MapInjectionResources(injectionResources);
    InjectionResources configurations = new InjectionResources() {

        private boolean seenOne;

        @Override
        public <T> T findResource(Class<T> resourceType, Type genericType) {
            ConfigurationType thisType = PARAMETER_TYPE_TO_CONFIGURATION_TYPE.get(resourceType);
            if (thisType == null)
                return null;
            if (seenOne)
                throw new RuntimeException(IOCMessages.tooManyConfigurationParameters(creatorDescription));
            seenOne = true;
            switch(thisType) {
                case UNORDERED:
                    return resourceType.cast(getUnorderedConfiguration(genericType));
                case ORDERED:
                    return resourceType.cast(getOrderedConfiguration(genericType));
                case MAPPED:
                    return resourceType.cast(getMappedConfiguration(genericType));
            }
            return null;
        }
    };
    return new DelegatingInjectionResources(core, configurations);
}
Also used : ConfigurationType(org.apache.tapestry5.ioc.internal.ConfigurationType) ConfigurationType(org.apache.tapestry5.ioc.internal.ConfigurationType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InjectionResources(org.apache.tapestry5.ioc.internal.util.InjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources)

Example 4 with Core

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

the class Form method beginRender.

void beginRender(MarkupWriter writer) {
    Link link = resources.createFormEventLink(EventConstants.ACTION, context);
    String actionURL = secure && secureEnabled ? link.toAbsoluteURI(true) : link.toURI();
    actionSink = new ComponentActionSink(logger, clientDataEncoder);
    clientId = javascriptSupport.allocateClientId(resources);
    // Pre-register some names, to prevent client-side collisions with function names
    // attached to the JS Form object.
    IdAllocator allocator = new IdAllocator();
    preallocateNames(allocator);
    formSupport = createRenderTimeFormSupport(clientId, actionSink, allocator);
    environment.push(FormSupport.class, formSupport);
    environment.push(ValidationTracker.class, tracker);
    if (autofocus) {
        ValidationDecorator autofocusDecorator = new AutofocusValidationDecorator(environment.peek(ValidationDecorator.class), tracker, javascriptSupport);
        environment.push(ValidationDecorator.class, autofocusDecorator);
    }
    // Now that the environment is setup, inform the component or other
    // listeners that the form
    // is about to render.
    resources.triggerEvent(EventConstants.PREPARE_FOR_RENDER, context, null);
    resources.triggerEvent(EventConstants.PREPARE, context, null);
    // Push BeanValidationContext only after the container had a chance to prepare
    environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
    // Save the form element for later, in case we want to write an encoding
    // type attribute.
    form = writer.element("form", "id", clientId, "method", "post", "action", actionURL, "data-update-zone", zone, DATA_ATTRIBUTE, DATA_ATTRIBUTE_VALUE);
    if (clientValidation != ClientValidation.NONE) {
        writer.attributes("data-validate", "submit");
    }
    if (async) {
        javascriptSupport.require("t5/core/zone");
        writer.attributes("data-async-trigger", true);
    }
    resources.renderInformalParameters(writer);
    div = writer.element("div");
    for (String parameterName : link.getParameterNames()) {
        String[] values = link.getParameterValues(parameterName);
        for (String value : values) {
            // but the input value shouldn't be encoded.
            try {
                value = URLDecoder.decode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("Enable to decode parameter value for parameter {} in form {}", parameterName, form.getName(), e);
            }
            writer.element("input", "type", "hidden", "name", parameterName, "value", value);
            writer.end();
        }
    }
    // div
    writer.end();
    environment.peek(Heartbeat.class).begin();
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) IdAllocator(org.apache.tapestry5.ioc.util.IdAllocator) AutofocusValidationDecorator(org.apache.tapestry5.internal.util.AutofocusValidationDecorator) Heartbeat(org.apache.tapestry5.services.Heartbeat) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AutofocusValidationDecorator(org.apache.tapestry5.internal.util.AutofocusValidationDecorator) Link(org.apache.tapestry5.http.Link) BeanValidationContextImpl(org.apache.tapestry5.internal.BeanValidationContextImpl)

Example 5 with Core

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

the class FormFragment method beginRender.

/**
 * Renders a &lt;div&gt; tag and provides an override of the {@link org.apache.tapestry5.services.FormSupport}
 * environmental.
 */
void beginRender(MarkupWriter writer) {
    FormSupport formSupport = environment.peekRequired(FormSupport.class);
    String clientId = getClientId();
    hiddenFieldPositioner = new HiddenFieldPositioner(writer, rules);
    Element element = writer.element(this.element, "id", clientId, "data-component-type", "core/FormFragment");
    if (alwaysSubmit) {
        element.attribute("data-always-submit", "true");
    }
    resources.renderInformalParameters(writer);
    if (!visible) {
        element.attribute("style", "display: none;");
        if (!alwaysSubmit) {
            javascriptSupport.require("t5/core/form-fragment").invoke("hide").with(clientId);
        }
    }
    componentActions = new ComponentActionSink(logger, clientDataEncoder);
    // Here's the magic of environmentals ... we can create a wrapper around
    // the normal FormSupport environmental that intercepts some of the behavior.
    // Here we're setting aside all the actions inside the FormFragment so that we
    // can control whether those actions occur when the form is submitted.
    FormSupport override = new FormSupportAdapter(formSupport) {

        @Override
        public <T> void store(T component, ComponentAction<T> action) {
            componentActions.store(component, action);
        }

        @Override
        public <T> void storeCancel(T component, ComponentAction<T> action) {
            componentActions.storeCancel(component, action);
        }

        @Override
        public <T> void storeAndExecute(T component, ComponentAction<T> action) {
            componentActions.store(component, action);
            action.execute(component);
        }
    };
    // Tada! Now all the enclosed components will use our override of FormSupport,
    // until we pop it off.
    environment.push(FormSupport.class, override);
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) HiddenFieldPositioner(org.apache.tapestry5.corelib.internal.HiddenFieldPositioner) Element(org.apache.tapestry5.dom.Element) FormSupportAdapter(org.apache.tapestry5.corelib.internal.FormSupportAdapter) FormSupport(org.apache.tapestry5.services.FormSupport)

Aggregations

Link (org.apache.tapestry5.http.Link)8 Element (org.apache.tapestry5.dom.Element)5 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)5 Resource (org.apache.tapestry5.commons.Resource)3 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 ComponentResources (org.apache.tapestry5.ComponentResources)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 HeartbeatDeferred (org.apache.tapestry5.annotations.HeartbeatDeferred)2 Location (org.apache.tapestry5.commons.Location)2 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)2 MessageCatalogResource (org.apache.tapestry5.internal.util.MessageCatalogResource)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 Heartbeat (org.apache.tapestry5.services.Heartbeat)2 EOFException (java.io.EOFException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectStreamException (java.io.ObjectStreamException)1