本文整理汇总了Java中org.apache.sling.api.SlingHttpServletRequest类的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletRequest类的具体用法?Java SlingHttpServletRequest怎么用?Java SlingHttpServletRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SlingHttpServletRequest类属于org.apache.sling.api包,在下文中一共展示了SlingHttpServletRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws ServletException, IOException {
try {
final Map<String, InputStream> files = Maps.newHashMap();
for (RequestParameter file : request.getRequestParameters("file")) {
files.put(file.getFileName(), file.getInputStream());
}
final List<Script> scripts = scriptStorage
.saveAll(files, isOverwrite(request), request.getResourceResolver());
if (shouldRedirect(request)) {
response.sendRedirect(getRedirectTo(request));
} else {
ServletUtils.writeJson(response, ScriptUtils.toJson(scripts));
}
} catch (RepositoryException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ServletUtils.writeJson(response, "Cannot save script in repository: " + e.getMessage());
}
}
示例2: isApplicable
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
private boolean isApplicable(SlingHttpServletRequest request) {
Object appliable = request.getAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE);
if (appliable == null) {
Resource resource = request.getResource();
PageManager pMgr = resource.getResourceResolver().adaptTo(PageManager.class);
Page page = pMgr.getContainingPage(resource);
AEMDataLayerConfig config = AEMDataLayerConfig.getDataLayerConfig(page);
if (config != null) {
DataLayer dataLayer = new DataLayer(config, page);
request.setAttribute(DataLayerConstants.REQUEST_PROPERTY_AEM_DATALAYER, dataLayer);
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(true));
return true;
} else {
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(false));
return false;
}
} else {
return new Boolean(true).equals(appliable);
}
}
示例3: doGet
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<JSONArray>() {
@Override
protected JSONArray initialValue() {
return new JSONArray();
}
};
loadElements(request);
out.write(threadLocal.get().toString());
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例4: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
if (contentModel.has(CONFIG_GLOBAL_IMAGE_KEY)) {
String globalImageName = contentModel.getAsString(CONFIG_GLOBAL_IMAGE_KEY);
if (contentModel.has(COMPONENT_GLOBAL_DIALOG_PATH) && StringUtils.isNotEmpty(globalImageName)) {
String imageResourcePath = contentModel.getAsString(COMPONENT_GLOBAL_DIALOG_PATH) + SLASH + globalImageName;
Resource imageResource = request.getResourceResolver().getResource(request.getResource(),
imageResourcePath);
if (null != imageResource) {
String imagePath = assetPathService.getComponentImagePath(imageResource);
String globalImagePathPropertyName = globalImageName + StringUtils.capitalize(IMAGE_PATH);
contentModel.set(GLOBAL_PROPERTIES_KEY + DOT + globalImagePathPropertyName, imagePath);
}
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例5: doFilter
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (request instanceof SlingHttpServletRequest && isApplicable((SlingHttpServletRequest) request)) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
DataLayer dataLayer = DataLayerUtil.getDataLayer(slingRequest);
try {
updateDataLayer(slingRequest, dataLayer);
} catch (Exception e) {
log.warn("Exception updating DataLayer for resource " + slingRequest.getResource().getPath(), e);
}
}
chain.doFilter(request, response);
}
示例6: doGet
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<Map<String, String>>() {
@Override
protected Map<String, String> initialValue() {
return new HashMap<String, String>();
}
};
loadElements(request);
Set<String> keys = threadLocal.get().keySet();
for (String key : keys) {
String value = threadLocal.get().get(key);
out.write("<option value='" + value + "'>" + key + "</option>");
}
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例7: accepts
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
/**
* Only accept requests that.
* - Are not null
* - Have a suffix
* - if the suffix has 3 segments, the first suffix segment is a registered transform name
*
* @param request SlingRequest object
* @return true if the Servlet should handle the request
*/
@Override
public final boolean accepts(SlingHttpServletRequest request) {
if (request == null) {
return false;
}
final String suffix = request.getRequestPathInfo().getSuffix();
if (StringUtils.isBlank(suffix)) {
return false;
}
String[] selectors = request.getRequestPathInfo().getSelectors();
if (selectors.length == 2) {
int imageNumber = NumberUtils.toInt(selectors[1], -1);
if (imageNumber < 0) {
return false;
}
}
return true;
}
示例8: getAssetResource
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
private Resource getAssetResource(SlingHttpServletRequest request) {
Resource componentResource = request.getResource();
String damAssetPath = BLANK;
String[] selectors = request.getRequestPathInfo().getSelectors();
int assetIndex = -1;
if(selectors.length == 2) {
assetIndex = Integer.parseInt(selectors[1]);
}
if (assetIndex == -1) {
damAssetPath = ResourceUtils.getPropertyAsString(componentResource, FILE_REFERENCE);
} else {
List<String> fileReferences = ResourceUtils.getPropertyAsStrings(componentResource, FILE_REFERENCES);
if(fileReferences.size() > assetIndex) {
damAssetPath = fileReferences.get(assetIndex);
}
}
return request.getResourceResolver().getResource(damAssetPath);
}
示例9: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
ResourceResolver resourceResolver = request.getResourceResolver();
final Designer designer = resourceResolver.adaptTo(Designer.class);
Style style = designer.getStyle(resource);
if (style.getPath() != null) {
Resource designResource = resourceResolver.getResource(style.getPath());
Map<String, Object> designMap = (designResource != null) ? PropertyUtils.propsToMap(designResource) : new HashMap<String, Object>();
contentModel.set(DESIGN_PROPERTIES_KEY, designMap);
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例10: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Configuration config = configurationProvider.getFor(request.getResource().getResourceType());
Collection<String> propsWithJSONValues = config.asStrings(XK_DESERIALIZE_JSON_PROPS_CP, Mode.MERGE);
for(String propName : propsWithJSONValues) {
if(contentModel.has(propName)) {
String jsonString = contentModel.getAsString(propName);
if(JSONValue.isValidJson(jsonString)) {
Object value = JSONValue.parse(jsonString);
contentModel.set(propName, value);
}
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例11: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
log.debug("for {}", resource.getPath());
if (resource != null) {
ResourceResolver resourceResolver = request.getResourceResolver();
String globalPropertiesPath = ResourceUtils.getGlobalPropertiesPath(resource, resourceResolver);
if (globalPropertiesPath != null) {
Resource globalPropertiesResource = resourceResolver.getResource(globalPropertiesPath);
Map<String, Object> globalProperties = (globalPropertiesResource != null) ? PropertyUtils.propsToMap(globalPropertiesResource) : new HashMap<String, Object>();
contentModel.set(GLOBAL_PROPERTIES_KEY, globalProperties);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例12: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
ResourceResolver resourceResolver = request.getResourceResolver();
Style style = GeneralRequestObjects.getCurrentStyle(request);
if (style != null) {
Resource designResource = resourceResolver.getResource(style.getPath()); //get design resource
if (designResource != null) {
String imagePath = assetPathService.getComponentImagePath(designResource);
contentModel.set(DESIGN_PROPERTIES_KEY + DOT + IMAGE_PATH, imagePath);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例13: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Collection<String> fileReferences = ResourceUtils.getPropertyAsStrings(resource, FILE_REFERENCES);
Collection<String> imagePathList = new ArrayList<>();
for(int i = 0; i < fileReferences.size(); i++) {
imagePathList.add(assetPathService.getComponentAssetPath(resource, i));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例14: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
List<Resource> imageResources = $(resource).searchStrategy(SearchStrategy.QUERY).find(NT_UNSTRUCTURED).filter(IMAGE_RESOURCES_PREDICATE).asList();
Collection<String> imagePathList = new ArrayList<>();
for (Resource imageResource : imageResources) {
imagePathList.add(assetPathService.getComponentImagePath(imageResource));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS_FROM_RESOURCES, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
开发者ID:DantaFramework,项目名称:AEM,代码行数:17,代码来源:AddMultipleTransformedImagePathsFromResourcesContextProcessor.java
示例15: process
import org.apache.sling.api.SlingHttpServletRequest; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
List<Resource> imageResources = $(resource).searchStrategy(SearchStrategy.QUERY).find(NT_UNSTRUCTURED).filter(IMAGE_RESOURCES_PREDICATE).asList();
Map<String, String> imagePathList = new HashMap<>();
for (Resource imageResource : imageResources) {
imagePathList.put(imageResource.getName(), assetPathService.getComponentImagePath(imageResource));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS_FROM_RESOURCES, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}