FormChooserProfileProvider.java 2.67 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.commons.PathInfo
 *  com.day.cq.personalization.ProfileProvider
 *  com.day.cq.security.profile.Profile
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.foundation.forms.impl;

import com.day.cq.commons.PathInfo;
import com.day.cq.personalization.ProfileProvider;
import com.day.cq.security.profile.Profile;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0, label="CQ5 Foundation: Form Chooser Profile Provider", description="Resolves Profiles from form chooser resources.")
@Service
@Properties(value={@Property(name="service.description", value={"CQ5 Foundation: Form Chooser Profile Provider"}), @Property(name="service.ranking", intValue={5000}, propertyPrivate=1)})
public class FormChooserProfileProvider
implements ProfileProvider {
    private static final Logger log = LoggerFactory.getLogger(FormChooserProfileProvider.class);

    public Profile getProfile(SlingHttpServletRequest request) {
        ResourceResolver resourceResolver = request.getResourceResolver();
        Resource resource = request.getResource();
        try {
            PathInfo info = new PathInfo(new URI(request.getRequestURI()).getPath());
            if (!info.getResourcePath().equals(resource.getPath())) {
                log.debug("Found FormChooser request for {} to {}", (Object)resource.getPath(), (Object)info.getResourcePath());
                resource = resourceResolver.getResource(info.getResourcePath());
            }
            if (resource != null) {
                return (Profile)resource.adaptTo(Profile.class);
            }
        }
        catch (URISyntaxException e) {
            log.warn("Found request with invalid syntax fall back to request's resource {}", (Object)resource.getPath());
        }
        return null;
    }

    public Profile getProfile(ResourceResolver resolver) {
        return null;
    }
}