FormChooserProfileProvider.java
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* 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;
}
}