當前位置: 首頁>>代碼示例>>Java>>正文


Java SlingHttpServletRequest類代碼示例

本文整理匯總了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());
	}
}
 
開發者ID:Cognifide,項目名稱:APM,代碼行數:23,代碼來源:ScriptUploadServlet.java

示例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);
	}
}
 
開發者ID:PerficientDigital,項目名稱:AEM-DataLayer,代碼行數:21,代碼來源:AEMDataLayerInterceptorFilter.java

示例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();
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:21,代碼來源:AbstractExtJSONServlet.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:26,代碼來源:AddTransformedImagePathFromGlobalContextProcessor.java

示例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);
}
 
開發者ID:PerficientDigital,項目名稱:AEM-DataLayer,代碼行數:19,代碼來源:AEMDataLayerInterceptorFilter.java

示例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();
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:24,代碼來源:AbstractSelectHTMLServlet.java

示例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;
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:31,代碼來源:AssetProviderServlet.java

示例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);
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:21,代碼來源:AssetProviderServlet.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:21,代碼來源:AddDesignPropertiesContextProcessor.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:22,代碼來源:DeserializeJSONPropertyValuesContextProcessor.java

示例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);
    }

}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:23,代碼來源:AddGlobalPropertiesContextProcessor.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:19,代碼來源:AddTransformedImagePathFromDesignContextProcessor.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:19,代碼來源:AddTransformedMultipleImagePathsContextProcessor.java

示例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);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:17,代碼來源:AddTransformedImagePathsContextProcessor.java


注:本文中的org.apache.sling.api.SlingHttpServletRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。