Search in sources :

Example 1 with UrlCreator

use of grails.web.mapping.UrlCreator in project grails-core by grails.

the class DefaultUrlMappingsHolder method getReverseMappingNoDefault.

@Override
public UrlCreator getReverseMappingNoDefault(String controller, String action, String namespace, String pluginName, String httpMethod, String version, Map params) {
    if (params == null)
        params = Collections.emptyMap();
    if (urlCreatorCache != null) {
        UrlCreatorCache.ReverseMappingKey key = urlCreatorCache.createKey(controller, action, namespace, pluginName, httpMethod, params);
        UrlCreator creator = urlCreatorCache.lookup(key);
        if (creator == null) {
            creator = resolveUrlCreator(controller, action, namespace, pluginName, httpMethod, version, params, false);
            if (creator != null) {
                creator = urlCreatorCache.putAndDecorate(key, creator);
            }
        }
        // preserve previous side-effect, remove mappingName from params
        params.remove("mappingName");
        return creator;
    }
    // cache is disabled
    return resolveUrlCreator(controller, action, namespace, pluginName, httpMethod, version, params, true);
}
Also used : UrlCreator(grails.web.mapping.UrlCreator)

Example 2 with UrlCreator

use of grails.web.mapping.UrlCreator in project grails-core by grails.

the class DefaultUrlMappingsHolder method resolveUrlCreator.

@SuppressWarnings("unchecked")
private UrlCreator resolveUrlCreator(final String controller, final String action, final String namespace, final String pluginName, String httpMethod, String version, Map params, boolean useDefault) {
    UrlMapping mapping = null;
    if (httpMethod == null) {
        httpMethod = UrlMapping.ANY_HTTP_METHOD;
    }
    mapping = namedMappings.get(params.remove("mappingName"));
    if (mapping == null) {
        mapping = lookupMapping(controller, action, namespace, pluginName, httpMethod, version, params);
        if (mapping == null) {
            lookupMapping(controller, action, namespace, pluginName, UrlMapping.ANY_HTTP_METHOD, version, params);
        }
    }
    if (mapping == null || (mapping instanceof ResponseCodeUrlMapping)) {
        UrlMappingKey lookupKey = new UrlMappingKey(controller, action, namespace, pluginName, httpMethod, version, Collections.<String>emptySet());
        mapping = mappingsLookup.get(lookupKey);
        if (mapping == null) {
            lookupKey.httpMethod = UrlMapping.ANY_HTTP_METHOD;
            mapping = mappingsLookup.get(lookupKey);
        }
    }
    if (mapping == null || (mapping instanceof ResponseCodeUrlMapping)) {
        Set<String> lookupParams = new HashSet<String>(DEFAULT_ACTION_PARAMS);
        Set<String> paramKeys = new HashSet<String>(params.keySet());
        paramKeys.removeAll(lookupParams);
        lookupParams.addAll(paramKeys);
        UrlMappingKey lookupKey = new UrlMappingKey(controller, null, namespace, pluginName, httpMethod, version, lookupParams);
        mapping = mappingsLookup.get(lookupKey);
        if (mapping == null) {
            lookupKey.httpMethod = UrlMapping.ANY_HTTP_METHOD;
            mapping = mappingsLookup.get(lookupKey);
        }
        if (mapping == null) {
            lookupParams.removeAll(paramKeys);
            UrlMappingKey lookupKeyModifiedParams = new UrlMappingKey(controller, null, namespace, pluginName, httpMethod, version, lookupParams);
            mapping = mappingsLookup.get(lookupKeyModifiedParams);
            if (mapping == null) {
                lookupKeyModifiedParams.httpMethod = UrlMapping.ANY_HTTP_METHOD;
                mapping = mappingsLookup.get(lookupKeyModifiedParams);
            }
        }
    }
    if (mapping == null || (mapping instanceof ResponseCodeUrlMapping)) {
        Set<String> lookupParams = new HashSet<String>(DEFAULT_CONTROLLER_PARAMS);
        Set<String> paramKeys = new HashSet<String>(params.keySet());
        paramKeys.removeAll(lookupParams);
        lookupParams.addAll(paramKeys);
        UrlMappingKey lookupKey = new UrlMappingKey(null, null, namespace, pluginName, httpMethod, version, lookupParams);
        mapping = mappingsLookup.get(lookupKey);
        if (mapping == null) {
            lookupKey.httpMethod = UrlMapping.ANY_HTTP_METHOD;
            mapping = mappingsLookup.get(lookupKey);
        }
        if (mapping == null) {
            lookupParams.removeAll(paramKeys);
            UrlMappingKey lookupKeyModifiedParams = new UrlMappingKey(null, null, namespace, pluginName, httpMethod, version, lookupParams);
            mapping = mappingsLookup.get(lookupKeyModifiedParams);
            if (mapping == null) {
                lookupKeyModifiedParams.httpMethod = UrlMapping.ANY_HTTP_METHOD;
                mapping = mappingsLookup.get(lookupKeyModifiedParams);
            }
        }
    }
    if (mapping == null || (mapping instanceof ResponseCodeUrlMapping)) {
        Set<String> lookupParams = new HashSet<>(DEFAULT_NAMESPACE_PARAMS);
        Set<String> paramKeys = new HashSet<String>(params.keySet());
        paramKeys.removeAll(lookupParams);
        lookupParams.addAll(paramKeys);
        UrlMappingKey lookupKey = new UrlMappingKey(null, null, null, pluginName, httpMethod, version, lookupParams);
        mapping = mappingsLookup.get(lookupKey);
        if (mapping == null) {
            lookupKey.httpMethod = UrlMapping.ANY_HTTP_METHOD;
            mapping = mappingsLookup.get(lookupKey);
        }
        if (mapping == null) {
            lookupParams.removeAll(paramKeys);
            UrlMappingKey lookupKeyModifiedParams = new UrlMappingKey(null, null, null, pluginName, httpMethod, version, lookupParams);
            mapping = mappingsLookup.get(lookupKeyModifiedParams);
            if (mapping == null) {
                lookupKeyModifiedParams.httpMethod = UrlMapping.ANY_HTTP_METHOD;
                mapping = mappingsLookup.get(lookupKeyModifiedParams);
            }
        }
    }
    UrlCreator creator = null;
    if (mapping == null || (mapping instanceof ResponseCodeUrlMapping)) {
        if (useDefault) {
            creator = new DefaultUrlCreator(controller, action);
        }
    } else {
        creator = mapping;
    }
    return creator;
}
Also used : UrlMapping(grails.web.mapping.UrlMapping) HashSet(java.util.HashSet) UrlCreator(grails.web.mapping.UrlCreator)

Example 3 with UrlCreator

use of grails.web.mapping.UrlCreator in project grails-core by grails.

the class DefaultUrlMappingsHolder method getReverseMapping.

@Override
public UrlCreator getReverseMapping(String controller, String action, String namespace, String pluginName, String httpMethod, String version, Map params) {
    if (params == null)
        params = Collections.emptyMap();
    if (urlCreatorCache != null) {
        UrlCreatorCache.ReverseMappingKey key = urlCreatorCache.createKey(controller, action, namespace, pluginName, httpMethod, params);
        UrlCreator creator = urlCreatorCache.lookup(key);
        if (creator == null) {
            creator = resolveUrlCreator(controller, action, namespace, pluginName, httpMethod, version, params, true);
            creator = urlCreatorCache.putAndDecorate(key, creator);
        }
        // preserve previous side-effect, remove mappingName from params
        params.remove("mappingName");
        return creator;
    }
    // cache is disabled
    return resolveUrlCreator(controller, action, namespace, pluginName, httpMethod, version, params, true);
}
Also used : UrlCreator(grails.web.mapping.UrlCreator)

Aggregations

UrlCreator (grails.web.mapping.UrlCreator)3 UrlMapping (grails.web.mapping.UrlMapping)1 HashSet (java.util.HashSet)1