Java Code Examples for org.apache.sling.api.SlingHttpServletRequest#getRequestParameter()

The following examples show how to use org.apache.sling.api.SlingHttpServletRequest#getRequestParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkOperation.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRun(SlingHttpServletRequest request,
        HtmlResponse response, List<Modification> changes)
        throws RepositoryException {

    Session session = request.getResourceResolver().adaptTo(Session.class);
    String resourcePath = request.getResource().getPath();
    if (session.itemExists(resourcePath)) {
        Node source = (Node) session.getItem(resourcePath);

        // create a symetric link
        RequestParameter linkParam = request.getRequestParameter("target");
        if (linkParam != null) {
            String linkPath = linkParam.getString();
            if (session.itemExists(linkPath)) {
                Item targetItem = session.getItem(linkPath);
                if (targetItem.isNode()) {
                    linkHelper.createSymetricLink(source,
                        (Node) targetItem, "link");
                }
            }
        }
    }

}
 
Example 2
Source File: ImportMboxServlet.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) 
		throws ServletException, IOException {
	RequestParameter param = request.getRequestParameter(IMPORT_FILE_ATTRIB_NAME);
	if (param != null) {
		logger.info("Processing attachment: " + param.toString());

		InputStream mboxIS = param.getInputStream();
		store.saveAll(parser.parse(mboxIS));

		response.sendRedirect(MailArchiveServerConstants.ARCHIVE_PATH + ".html");
	} else {
		logger.info("No attachment to process.");
	}
}
 
Example 3
Source File: StatsTestServlet.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) 
        throws ServletException, IOException {
    final RequestParameter param = request.getRequestParameter(IMPORT_FILE_ATTRIB_NAME);
    if(param == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required parameter " + IMPORT_FILE_ATTRIB_NAME);
        return;
    }
    
    InputStream is = null;
    final PrintWriter pw = response.getWriter();
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    
    try {
        is = param.getInputStream();
        pw.println("Creating stats from supplied mbox file...");
        int counter=0;
        final Iterator<Message> it = parser.parse(is);
        while(it.hasNext()) {
            final Message m = it.next();
            final String [] to = MailStatsProcessorImpl.toArray(m.getTo());
            final String [] cc = MailStatsProcessorImpl.toArray(m.getCc());
            for(String from : MailStatsProcessorImpl.toArray(m.getFrom())) {
                processor.computeStats(m.getDate(), from.toString(), to, cc);
            }
            counter++;
        }
        pw.println(counter + " messages parsed");
    } finally {
        processor.flush();
        pw.flush();
        if(is != null) {
            is.close();
        }
    }
}
 
Example 4
Source File: LinkProcessor.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
public void process(SlingHttpServletRequest request,
		List<Modification> changes) throws Exception {

	Session session = request.getResourceResolver().adaptTo(Session.class);

	RequestParameter linkParam = request.getRequestParameter(":link");
	if (linkParam != null){
		String linkPath = linkParam.getString();
		// check if a new node have been created
		if (changes.size() > 0 && changes.get(0).getType() == ModificationType.CREATE) {
			// hack to get the resource path
			// is it possible to add the response to the method header ?
			String resourcePath = changes.get(0).getSource();
			Node source = (Node) session.getItem(resourcePath);

			// create a symetric link
			if (session.itemExists(linkPath)) {
				Item targetItem = session.getItem(linkPath);
				if (targetItem.isNode()) {
					linkHelper.createSymetricLink(source, (Node) targetItem, "link");
				}
			}
		}
	}


}