当前位置: 首页>>代码示例>>Java>>正文


Java SlingHttpServletResponse类代码示例

本文整理汇总了Java中org.apache.sling.api.SlingHttpServletResponse的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletResponse类的具体用法?Java SlingHttpServletResponse怎么用?Java SlingHttpServletResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SlingHttpServletResponse类属于org.apache.sling.api包,在下文中一共展示了SlingHttpServletResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的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: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的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

示例3: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的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

示例4: getContentModel

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
/**
 * This method gets the Content Model of a resource.
 *
 * @param request This is a SlingHttpServletRequest
 * @param response This is a SlingHttpServletResponse
 * @return contentModel The Content Model of a resource
 */
@Override
public ContentModel getContentModel (final SlingHttpServletRequest request, final SlingHttpServletResponse response) {
    final ContentModel contentModel = new TemplateContentModelImpl(request, response);
    try {
        Resource resource = request.getResource();
        if (resource != null) {
            ExecutionContextImpl executionContext = new ExecutionContextImpl();
            executionContext.put(SLING_HTTP_REQUEST, request);
            executionContext.put(ENGINE_RESOURCE, resource.getResourceType());
            contextProcessorEngine.execute(executionContext, contentModel);
        }

    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    return contentModel;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:25,代码来源:ContentModelFactoryServiceImpl.java

示例5: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    String version = request.getParameter("version");
    String groupId = request.getParameter("groupId");
    String artifactId = request.getParameter("artifactId");

    boolean dependenciesOnly = "true".equals(request.getParameter("dependenciesOnly"));

    String responseContent;
    if(dependenciesOnly)
    {
        responseContent = pomGenerator.generateDependenciesPomFragment(bundleContext, "");
    }
    else
    {
        responseContent = pomGenerator.generatePOM(bundleContext, groupId, artifactId, version);
    }
    response.getWriter().write(responseContent);
}
 
开发者ID:sbrinkmann,项目名称:aem-maven-repository,代码行数:20,代码来源:MavenDependencyServlet.java

示例6: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) 
        throws ServletException, IOException 
{
    final Timer.Context t = metrics.timer(getClass().getSimpleName()).time();

    try {
        // Output the count of our child nodes
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/plain");
        final PrintWriter w = response.getWriter();
        w.print(request.getResource().getPath());
        w.print(" has ");
        w.print(countChildren(request.getResource(), ID));
        w.print(" descendant nodes with an '");
        w.print(ID);
        w.print("' property. Sling instance ID is ");
        w.print(settings.getSlingId());
        w.println(".");
        w.flush();
    } finally {
        t.stop();
    }
}
 
开发者ID:bdelacretaz,项目名称:sling-adaptto-2016,代码行数:25,代码来源:RootGetServlet.java

示例7: removeSingleFile

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
private void removeSingleFile(ResourceResolver resolver, SlingHttpServletResponse response,
		String fileName) throws IOException {
	if (StringUtils.isEmpty(fileName)) {
		ServletUtils.writeMessage(response, "error", "File name to be removed cannot be empty");
	} else {
		final Script script = scriptFinder.find(fileName, resolver);
		if (script == null) {
			ServletUtils
					.writeMessage(response, "error", String.format("Script not found: '%s'", fileName));
		} else {
			final String scriptPath = script.getPath();

			try {
				scriptStorage.remove(script, resolver);

				ServletUtils.writeMessage(response, "success",
						String.format("Script removed successfully: %s", scriptPath));
			} catch (RepositoryException e) {
				response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
				ServletUtils.writeJson(response,
						String.format("Cannot remove script: '%s'." + " Repository error: %s", scriptPath,
								e.getMessage()));
			}
		}
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:27,代码来源:ScriptRemoveServlet.java

示例8: getParameters

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
private BackgroundJobParameters getParameters(final SlingHttpServletRequest request,
		final SlingHttpServletResponse response) throws IOException {
	final String searchPath = request.getParameter(FILE_REQUEST_PARAMETER);
	final String modeName = request.getParameter(MODE_REQUEST_PARAMETER);
	final String userName = request.getUserPrincipal().getName();

	if (StringUtils.isEmpty(searchPath)) {
		ServletUtils.writeMessage(response, ERROR_RESPONSE_TYPE,
				"Please set the script file name: -d \"file=[name]\"");
		return null;
	}

	if (StringUtils.isEmpty(modeName)) {
		ServletUtils.writeMessage(response, ERROR_RESPONSE_TYPE, "Running mode not specified.");
		return null;
	}

	return new BackgroundJobParameters(searchPath, modeName, userName);
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:20,代码来源:ScriptRunBackgroundServlet.java

示例9: resizeAndStreamLayer

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
/**
 * Given a {@link Layer}, this method will attempt to resize it proportionally given the supplied {@code resizeWidth}. If the resize
 * operation would result in up-scaling, then the layer is rendered without any resize operation applied.
 *
 * @param response    the response
 * @param layer       the layer
 * @param imageType   the mime type of the image represented by the {@code layer}
 * @param resizeWidth the resize width
 * @throws IOException if the streaming of the {@link Layer} into the response's output stream cannot be performed
 */
private void resizeAndStreamLayer(SlingHttpServletResponse response, Layer layer, String imageType, int resizeWidth)
        throws IOException {
    int width = layer.getWidth();
    int height = layer.getHeight();
    int resizeHeight = calculateResizeHeight(width, height, resizeWidth);
    if (resizeHeight > 0) {
        layer.resize(resizeWidth, resizeHeight);
        response.setContentType(imageType);
        LOGGER.debug("Resizing processed (cropped and/or rotated) layer from its current width of {}px to {}px.", width, resizeWidth);
        layer.write(imageType, 1.0, response.getOutputStream());
    } else {
        response.setContentType(imageType);
        LOGGER.debug("No need to resize processed (cropped and/or rotated) layer since it would lead to upscaling; rendering.");
        layer.write(imageType, 1.0, response.getOutputStream());
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:27,代码来源:AdaptiveImageServlet.java

示例10: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response)
        throws ServletException, IOException {
    try {
        WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class);
        ArrayList<Resource> resources = new ArrayList<>();
        if (workflowSession != null) {
            WorkflowModel[] models = workflowSession.getModels();
            for (WorkflowModel model : models) {
                resources.add(new WorkflowModelResource(model, request.getResourceResolver()));
            }
        }
        SimpleDataSource dataSource = new SimpleDataSource(resources.iterator());
        request.setAttribute(DataSource.class.getName(), dataSource);
    } catch (WorkflowException e) {
        throw new ServletException(e);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:19,代码来源:WorkflowModelDataSourceServlet.java

示例11: getCommerceService

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
public static CommerceService getCommerceService(Resource resource) {
    CommerceService commerceService = mock(CommerceService.class);
    try {
        when(commerceService.login(any(SlingHttpServletRequest.class), any(SlingHttpServletResponse.class))).then(invocationOnMock -> {
            CommerceSession commerceSession = mock(CommerceSession.class);
            when(commerceSession.getProductPriceInfo(any(Product.class), any(PriceFilter.class))).then(invocation -> {
                Product product = invocation.getArgumentAt(0, Product.class);
                if (product.getPath().equals(resource.getPath())) {
                    return new ArrayList<PriceInfo>() {{
                        add(new PriceInfo(UNIVERSAL_PRICE, new Locale("en", "US")));
                    }};
                }
                return null;
            });
            return commerceSession;
        });
    } catch (CommerceException e) {
        throw new RuntimeException("Unable to mock CommerceService.");
    }
    return commerceService;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:MockCommerceFactory.java

示例12: doModifyProduct

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
private void doModifyProduct(SlingHttpServletRequest request, SlingHttpServletResponse response, CommerceSession session) throws IOException {
    String qty = request.getParameter("quantity");
    int quantity = StringUtils.isNumeric(qty) ? xssAPI.getValidInteger(qty, 1) : -1;
    if (quantity < 0) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    String entryNumber = request.getParameter("entryNumber");
    int entry = xssAPI.getValidInteger(entryNumber, -1);
    try {
        if (entry < 0 || entry >= session.getCartEntries().size()) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        if (quantity > 0) {
            session.modifyCartEntry(entry, quantity);
        } else {
            session.deleteCartEntry(entry);
        }

    } catch (CommerceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:27,代码来源:CartEntryServlet.java

示例13: doAddProduct

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
private void doAddProduct(SlingHttpServletRequest request, SlingHttpServletResponse response, CommerceSession session)
        throws IOException {
    String productPath = request.getParameter("product-path");
    String qty = request.getParameter("product-quantity");

    Resource productResource = request.getResourceResolver().getResource(productPath);
    Product product = productResource.adaptTo(Product.class);

    int quantity = 1;
    if (qty != null && qty.length() > 0) {
        quantity = xssAPI.getValidInteger(qty, 1);
        if (quantity < 0) {
            quantity = 1;
        }
    }

    try {
        session.addCartEntry(product, quantity);
    } catch (CommerceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:23,代码来源:CartEntryServlet.java

示例14: renderContent

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
private String renderContent(SlingHttpServletRequest request, SlingHttpServletResponse response, String contentPath)
        throws ServletException, IOException {

    // We wrap the original POST request in a GET and wrap the response in a string buffer
    GetRequestWrapper requestWrapper = new GetRequestWrapper(request);
    BufferingResponseWrapper responseWrapper = new BufferingResponseWrapper(response);

    RequestDispatcherOptions options = new RequestDispatcherOptions();
    options.setReplaceSelectors("");

    Page currentPage = request.getResource().adaptTo(Page.class);
    Page root = WeRetailHelper.findRoot(currentPage);

    String path = CONTENT_WE_RETAIL_DEFAULT + contentPath; // Fallback if root is not found
    if (root != null) {
        path = root.getPath() + contentPath;
    }

    request.getRequestDispatcher(path, options).include(requestWrapper, responseWrapper);
    return responseWrapper.toStrippedOutput();
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:22,代码来源:CartEntryServlet.java

示例15: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入依赖的package包/类
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    try {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");

        Page currentPage = request.getResource().adaptTo(Page.class);
        JSONWriter w = new JSONWriter(response.getWriter());

        w.object();
        w.key("name").value(currentPage.getTitle());

        w.endObject();
    } catch (Exception ex) {
        log.error("Request failed", ex);
        throw new ServletException(ex);
    }
}
 
开发者ID:AdobeAtAdobe,项目名称:aaa-aem-boilerplate,代码行数:20,代码来源:ThingJsonServlet.java


注:本文中的org.apache.sling.api.SlingHttpServletResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。