Search in sources :

Example 1 with DocumentLinker

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

the class TapestryModule method contributeMarkupRenderer.

/**
 * Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental}
 * service. Filters
 * often provide {@link org.apache.tapestry5.annotations.Environmental} services needed by
 * components as they render.
 * <dl>
 * <dt>DocumentLinker</dt>
 * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}</dd>
 * <dt>ClientBehaviorSupport (deprecated in 5.4)</dt>
 * <dd>Provides {@link ClientBehaviorSupport}</dd>
 * <dt>Heartbeat</dt>
 * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
 * <dt>ValidationDecorator (deprecated in 5.4)</dt>
 * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
 * <dt>PageNameMeta (since 5.4)</dt>
 * <dd>Renders a {@code <meta/>} tag describing the active page name (development mode only)</dd>
 * <dt>ImportCoreStack (since 5.4) </dt>
 * <dd>Imports the "core" stack (necessary to get the Bootstrap CSS, if nothing else).</dd>
 * </dl>
 *
 * @see org.apache.tapestry5.SymbolConstants#OMIT_GENERATOR_META
 * @see org.apache.tapestry5.http.TapestryHttpSymbolConstants#PRODUCTION_MODE
 * @see org.apache.tapestry5.SymbolConstants#INCLUDE_CORE_STACK
 * @see org.apache.tapestry5.SymbolConstants#ENABLE_PAGELOADING_MASK
 */
public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration, final ModuleManager moduleManager, @Symbol(SymbolConstants.OMIT_GENERATOR_META) final boolean omitGeneratorMeta, @Symbol(TapestryHttpConstants.TAPESTRY_VERSION) final String tapestryVersion, @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE) boolean productionMode, @Symbol(SymbolConstants.INCLUDE_CORE_STACK) final boolean includeCoreStack, @Symbol(SymbolConstants.ENABLE_PAGELOADING_MASK) final boolean enablePageloadingMask, final ValidationDecoratorFactory validationDecoratorFactory) {
    MarkupRendererFilter documentLinker = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            DocumentLinkerImpl linker = new DocumentLinkerImpl(moduleManager, omitGeneratorMeta, enablePageloadingMask, tapestryVersion);
            environment.push(DocumentLinker.class, linker);
            renderer.renderMarkup(writer);
            environment.pop(DocumentLinker.class);
            linker.updateDocument(writer.getDocument());
        }
    };
    MarkupRendererFilter clientBehaviorSupport = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            ClientBehaviorSupportImpl clientBehaviorSupport = new ClientBehaviorSupportImpl();
            environment.push(ClientBehaviorSupport.class, clientBehaviorSupport);
            renderer.renderMarkup(writer);
            environment.pop(ClientBehaviorSupport.class);
        }
    };
    MarkupRendererFilter heartbeat = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            Heartbeat heartbeat = new HeartbeatImpl();
            heartbeat.begin();
            environment.push(Heartbeat.class, heartbeat);
            renderer.renderMarkup(writer);
            environment.pop(Heartbeat.class);
            heartbeat.end();
        }
    };
    MarkupRendererFilter defaultValidationDecorator = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
            environment.push(ValidationDecorator.class, decorator);
            renderer.renderMarkup(writer);
            environment.pop(ValidationDecorator.class);
        }
    };
    MarkupRendererFilter importCoreStack = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            renderer.renderMarkup(writer);
            environment.peekRequired(JavaScriptSupport.class).importStack(InternalConstants.CORE_STACK_NAME);
        }
    };
    configuration.add("DocumentLinker", documentLinker);
    configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
    configuration.add("Heartbeat", heartbeat);
    configuration.add("ValidationDecorator", defaultValidationDecorator);
    if (includeCoreStack) {
        configuration.add("ImportCoreStack", importCoreStack);
    }
    if (productionMode) {
        configuration.add("PageNameMeta", null);
    } else {
        configuration.addInstance("PageNameMeta", PageNameMetaInjector.class);
    }
}
Also used : MarkupRenderer(org.apache.tapestry5.services.MarkupRenderer) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) MarkupRendererFilter(org.apache.tapestry5.services.MarkupRendererFilter) JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) Heartbeat(org.apache.tapestry5.services.Heartbeat) MarkupWriter(org.apache.tapestry5.MarkupWriter) ValidationDecorator(org.apache.tapestry5.ValidationDecorator)

Example 2 with DocumentLinker

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

the class TapestryModule method contributePartialMarkupRenderer.

/**
 * Contributes {@link PartialMarkupRendererFilter}s used when rendering a
 * partial Ajax response.
 * <dl>
 * <dt>DocumentLinker
 * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}
 * <dt>ClientBehaviorSupport</dt>
 * <dd>Provides {@link ClientBehaviorSupport}</dd>
 * <dt>Heartbeat</dt>
 * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
 * <dt>DefaultValidationDecorator</dt>
 * <dt>ValidationDecorator</dt>
 * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
 * </dl>
 */
public void contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter> configuration, final ValidationDecoratorFactory validationDecoratorFactory) {
    PartialMarkupRendererFilter documentLinker = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            PartialMarkupDocumentLinker linker = new PartialMarkupDocumentLinker();
            environment.push(DocumentLinker.class, linker);
            renderer.renderMarkup(writer, reply);
            environment.pop(DocumentLinker.class);
            linker.commit(reply);
        }
    };
    PartialMarkupRendererFilter clientBehaviorSupport = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ClientBehaviorSupportImpl support = new ClientBehaviorSupportImpl();
            environment.push(ClientBehaviorSupport.class, support);
            renderer.renderMarkup(writer, reply);
            environment.pop(ClientBehaviorSupport.class);
        }
    };
    PartialMarkupRendererFilter heartbeat = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            Heartbeat heartbeat = new HeartbeatImpl();
            heartbeat.begin();
            environment.push(Heartbeat.class, heartbeat);
            renderer.renderMarkup(writer, reply);
            environment.pop(Heartbeat.class);
            heartbeat.end();
        }
    };
    PartialMarkupRendererFilter defaultValidationDecorator = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
            environment.push(ValidationDecorator.class, decorator);
            renderer.renderMarkup(writer, reply);
            environment.pop(ValidationDecorator.class);
        }
    };
    configuration.add("DocumentLinker", documentLinker);
    configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
    configuration.add("Heartbeat", heartbeat);
    configuration.add("ValidationDecorator", defaultValidationDecorator);
}
Also used : PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) JSONObject(org.apache.tapestry5.json.JSONObject) Heartbeat(org.apache.tapestry5.services.Heartbeat) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) MarkupWriter(org.apache.tapestry5.MarkupWriter) ValidationDecorator(org.apache.tapestry5.ValidationDecorator)

Example 3 with DocumentLinker

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

the class JavaScriptModule method exposeJavaScriptSupportForFullPageRenders.

/**
 * Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental}
 * service. Filters
 * often provide {@link org.apache.tapestry5.annotations.Environmental} services needed by
 * components as they render.
 * <dl>
 * <dt>JavascriptSupport</dt>
 * <dd>Provides {@link JavaScriptSupport}</dd>
 * </dl>
 */
@Contribute(MarkupRenderer.class)
public void exposeJavaScriptSupportForFullPageRenders(OrderedConfiguration<MarkupRendererFilter> configuration, final JavaScriptStackSource javascriptStackSource, final JavaScriptStackPathConstructor javascriptStackPathConstructor, final Request request) {
    final BooleanHook suppressCoreStylesheetsHook = createSuppressCoreStylesheetHook(request);
    MarkupRendererFilter javaScriptSupport = new MarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
            DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
            JavaScriptSupportImpl support = new JavaScriptSupportImpl(linker, javascriptStackSource, javascriptStackPathConstructor, suppressCoreStylesheetsHook);
            environment.push(JavaScriptSupport.class, support);
            renderer.renderMarkup(writer);
            environment.pop(JavaScriptSupport.class);
            support.commit();
        }
    };
    configuration.add("JavaScriptSupport", javaScriptSupport, "after:DocumentLinker");
}
Also used : MarkupRenderer(org.apache.tapestry5.services.MarkupRenderer) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) MarkupRendererFilter(org.apache.tapestry5.services.MarkupRendererFilter) DocumentLinker(org.apache.tapestry5.internal.services.DocumentLinker) MarkupWriter(org.apache.tapestry5.MarkupWriter) JavaScriptSupportImpl(org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl) BooleanHook(org.apache.tapestry5.BooleanHook) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 4 with DocumentLinker

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

the class JavaScriptModule method exposeJavaScriptSupportForPartialPageRender.

/**
 * Contributes {@link PartialMarkupRendererFilter}s used when rendering a
 * partial Ajax response.
 * <dl>
 * <dt>JavaScriptSupport
 * <dd>Provides {@link JavaScriptSupport}</dd>
 * </dl>
 */
@Contribute(PartialMarkupRenderer.class)
public void exposeJavaScriptSupportForPartialPageRender(OrderedConfiguration<PartialMarkupRendererFilter> configuration, final JavaScriptStackSource javascriptStackSource, final JavaScriptStackPathConstructor javascriptStackPathConstructor, final Request request) {
    final BooleanHook suppressCoreStylesheetsHook = createSuppressCoreStylesheetHook(request);
    PartialMarkupRendererFilter javascriptSupport = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            IdAllocator idAllocator;
            if (request.getParameter(InternalConstants.SUPPRESS_NAMESPACED_IDS) == null) {
                String uid = Long.toHexString(System.nanoTime());
                String namespace = "_" + uid;
                idAllocator = new IdAllocator(namespace);
            } else {
                // When suppressed, work just like normal rendering.
                idAllocator = new IdAllocator();
            }
            DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
            JavaScriptSupportImpl support = new JavaScriptSupportImpl(linker, javascriptStackSource, javascriptStackPathConstructor, idAllocator, true, suppressCoreStylesheetsHook);
            environment.push(JavaScriptSupport.class, support);
            renderer.renderMarkup(writer, reply);
            environment.pop(JavaScriptSupport.class);
            support.commit();
        }
    };
    configuration.add("JavaScriptSupport", javascriptSupport, "after:DocumentLinker");
}
Also used : IdAllocator(org.apache.tapestry5.ioc.util.IdAllocator) PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) JSONObject(org.apache.tapestry5.json.JSONObject) DocumentLinker(org.apache.tapestry5.internal.services.DocumentLinker) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) MarkupWriter(org.apache.tapestry5.MarkupWriter) JavaScriptSupportImpl(org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl) BooleanHook(org.apache.tapestry5.BooleanHook) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

MarkupWriter (org.apache.tapestry5.MarkupWriter)4 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)4 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)4 BooleanHook (org.apache.tapestry5.BooleanHook)2 ValidationDecorator (org.apache.tapestry5.ValidationDecorator)2 DocumentLinker (org.apache.tapestry5.internal.services.DocumentLinker)2 JavaScriptSupportImpl (org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 Heartbeat (org.apache.tapestry5.services.Heartbeat)2 MarkupRenderer (org.apache.tapestry5.services.MarkupRenderer)2 MarkupRendererFilter (org.apache.tapestry5.services.MarkupRendererFilter)2 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)1 JavaScriptSupport (org.apache.tapestry5.services.javascript.JavaScriptSupport)1