Search in sources :

Example 51 with Path

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

the class JavaScriptModule method setupBaseModules.

@Contribute(ModuleManager.class)
public static void setupBaseModules(MappedConfiguration<String, Object> configuration, @Path("${tapestry.asset.root}/underscore-shim.js") Resource underscoreShim, @Path("${tapestry.asset.root}/jquery-shim.js") Resource jqueryShim, @Path("${tapestry.asset.root}/typeahead.js") Resource typeahead, @Path("${tapestry.asset.root}/moment-2.15.1.js") Resource moment, @Path("${tapestry.asset.root}/bootstrap/js/transition.js") Resource transition, @Path("${tapestry.asset.root}/bootstrap4/js/bootstrap-util.js") Resource bootstrapUtil, Compatibility compatibility) {
    // The underscore shim module allows Underscore to be injected
    configuration.add("underscore", new JavaScriptModuleConfiguration(underscoreShim));
    configuration.add("jquery", new JavaScriptModuleConfiguration(jqueryShim));
    if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
        final String[] modules = new String[] { "affix", "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" };
        addBootstrap3Modules(configuration, transition, modules);
        Resource popover = transition.forFile("popover.js");
        configuration.add("bootstrap/popover", new AMDWrapper(popover).require("bootstrap/tooltip").asJavaScriptModuleConfiguration());
    }
    if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
        configuration.add("bootstrap/bootstrap-util", new JavaScriptModuleConfiguration(bootstrapUtil));
        configuration.add("bootstrap/popper", new JavaScriptModuleConfiguration(bootstrapUtil.forFile("popper.js")));
        for (String name : new String[] { "alert", "button", "carousel", "collapse", "dropdown", "modal", "scrollspy", "tab", "tooltip" }) {
            Resource lib = bootstrapUtil.forFile(name + ".js");
            if (lib.exists()) {
                configuration.add("bootstrap/" + name, new JavaScriptModuleConfiguration(lib).dependsOn("bootstrap/bootstrap-util").dependsOn("bootstrap/popper"));
            }
        }
    }
    // is completely disabled
    if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
        final String[] modules = new String[] { "alert", "dropdown", "collapse" };
        addBootstrap3Modules(configuration, transition, modules);
    }
    configuration.add("t5/core/typeahead", new JavaScriptModuleConfiguration(typeahead).dependsOn("jquery"));
    configuration.add("moment", new JavaScriptModuleConfiguration(moment));
}
Also used : JavaScriptModuleConfiguration(org.apache.tapestry5.services.javascript.JavaScriptModuleConfiguration) AMDWrapper(org.apache.tapestry5.services.javascript.AMDWrapper) MessageCatalogResource(org.apache.tapestry5.internal.util.MessageCatalogResource) Resource(org.apache.tapestry5.commons.Resource) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 52 with Path

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

the class AssetsModule method provideBuiltinAssetDispatchers.

/**
 * Contributes an handler for each mapped classpath alias, as well handlers for context assets
 * and stack assets (combined {@link org.apache.tapestry5.services.javascript.JavaScriptStack} files).
 */
@Contribute(Dispatcher.class)
@AssetRequestDispatcher
public static void provideBuiltinAssetDispatchers(MappedConfiguration<String, AssetRequestHandler> configuration, @ContextProvider AssetFactory contextAssetFactory, @Autobuild StackAssetRequestHandler stackAssetRequestHandler, ClasspathAssetAliasManager classpathAssetAliasManager, ResourceStreamer streamer, AssetSource assetSource, ClasspathAssetProtectionRule classpathAssetProtectionRule) {
    Map<String, String> mappings = classpathAssetAliasManager.getMappings();
    for (String folder : mappings.keySet()) {
        String path = mappings.get(folder);
        configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetSource, path, classpathAssetProtectionRule));
    }
    configuration.add(RequestConstants.CONTEXT_FOLDER, new ContextAssetRequestHandler(streamer, contextAssetFactory.getRootResource()));
    configuration.add(RequestConstants.STACK_FOLDER, stackAssetRequestHandler);
}
Also used : ContextAssetRequestHandler(org.apache.tapestry5.internal.services.assets.ContextAssetRequestHandler) ClasspathAssetRequestHandler(org.apache.tapestry5.internal.services.assets.ClasspathAssetRequestHandler) Contribute(org.apache.tapestry5.ioc.annotations.Contribute) AssetRequestDispatcher(org.apache.tapestry5.services.AssetRequestDispatcher)

Example 53 with Path

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

the class JpaGridDataSource method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(final int startIndex, final int endIndex, final List<SortConstraint> sortConstraints) {
    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<E> criteria = builder.createQuery(entityType);
    final Root<E> root = criteria.from(entityType);
    applyAdditionalConstraints(criteria.select(root), root, builder);
    for (final SortConstraint constraint : sortConstraints) {
        final String propertyName = constraint.getPropertyModel().getPropertyName();
        final Path<Object> propertyPath = root.get(propertyName);
        switch(constraint.getColumnSort()) {
            case ASCENDING:
                criteria.orderBy(builder.asc(propertyPath));
                break;
            case DESCENDING:
                criteria.orderBy(builder.desc(propertyPath));
                break;
            default:
        }
    }
    final TypedQuery<E> query = entityManager.createQuery(criteria);
    query.setFirstResult(startIndex);
    query.setMaxResults(endIndex - startIndex + 1);
    this.startIndex = startIndex;
    preparedResults = query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SortConstraint(org.apache.tapestry5.grid.SortConstraint)

Example 54 with Path

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

the class JavaScriptStackPathConstructorImpl method combinedStackURL.

private List<String> combinedStackURL(String stackName, JavaScriptStack stack) {
    try {
        StreamableResource assembled = assembler.assembleJavaScriptResourceForStack(stackName, compressionAnalyzer.isGZipSupported(), stack.getJavaScriptAggregationStrategy());
        String path = threadLocale.getLocale().toString() + '/' + stackName + ".js";
        String stackURL = assetPathConstructor.constructAssetPath(RequestConstants.STACK_FOLDER, path, assembled);
        return CollectionFactory.newList(stackURL);
    } catch (IOException ex) {
        throw new RuntimeException(String.format("Unable to construct path for '%s' JavaScript stack: %s", stackName, ExceptionUtils.toMessage(ex)), ex);
    }
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) IOException(java.io.IOException)

Example 55 with Path

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

the class DefaultOpenApiDescriptionGenerator method getPath.

private String getPath(Method method, Class<?> pageClass) {
    final StringBuilder builder = new StringBuilder();
    builder.append(pageRenderLinkSource.createPageRenderLink(pageClass).toString());
    for (Parameter parameter : method.getParameters()) {
        if (!isIgnored(parameter)) {
            builder.append("/");
            final StaticActivationContextValue staticValue = parameter.getAnnotation(StaticActivationContextValue.class);
            if (staticValue != null) {
                builder.append(staticValue.value());
            } else {
                builder.append("{");
                builder.append(getParameterName(parameter));
                builder.append("}");
            }
        }
    }
    String path = builder.toString();
    if (!path.startsWith(basePath)) {
        throw new RuntimeException(String.format("Method %s has path %s, which " + "doesn't start with base path %s. It's likely you need to adjust the " + "base path and/or the endpoint paths", method, path, basePath));
    } else {
        // keep the slash
        path = path.substring(basePath.length() - 1);
        // remove possible double slashes
        path = path.replace("//", "/");
    }
    return path;
}
Also used : StaticActivationContextValue(org.apache.tapestry5.annotations.StaticActivationContextValue) ActivationContextParameter(org.apache.tapestry5.annotations.ActivationContextParameter) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) Parameter(java.lang.reflect.Parameter)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4