Search in sources :

Example 1 with RequestParameter

use of org.apache.sling.api.request.RequestParameter in project sling by apache.

the class UtilTest method test_decode_query.

public void test_decode_query() throws IllegalArgumentException, UnsupportedEncodingException, IOException {
    final ParameterMap map = new ParameterMap();
    final String query = "a=1&b=2&c=3&a=1&b=2&c=3";
    Util.parseQueryString(new ByteArrayInputStream(query.getBytes(Util.ENCODING_DIRECT)), Util.ENCODING_DIRECT, map, false);
    assertEquals(3, map.size());
    List<RequestParameter> pars = map.getRequestParameterList();
    assertEquals(6, pars.size());
    assertEquals("a", pars.get(0).getName());
    assertEquals("1", pars.get(0).getString());
    assertEquals("b", pars.get(1).getName());
    assertEquals("2", pars.get(1).getString());
    assertEquals("c", pars.get(2).getName());
    assertEquals("3", pars.get(2).getString());
    assertEquals("a", pars.get(3).getName());
    assertEquals("1", pars.get(3).getString());
    assertEquals("b", pars.get(4).getName());
    assertEquals("2", pars.get(4).getString());
    assertEquals("c", pars.get(5).getName());
    assertEquals("3", pars.get(5).getString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RequestParameter(org.apache.sling.api.request.RequestParameter)

Example 2 with RequestParameter

use of org.apache.sling.api.request.RequestParameter in project APM by Cognifide.

the class ScriptUploadServlet method doPost.

@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());
    }
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script) InputStream(java.io.InputStream) RequestParameter(org.apache.sling.api.request.RequestParameter) RepositoryException(javax.jcr.RepositoryException)

Example 3 with RequestParameter

use of org.apache.sling.api.request.RequestParameter in project sling by apache.

the class LinkProcessor method process.

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");
                }
            }
        }
    }
}
Also used : Item(javax.jcr.Item) RequestParameter(org.apache.sling.api.request.RequestParameter) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 4 with RequestParameter

use of org.apache.sling.api.request.RequestParameter in project sling by apache.

the class ImportMboxServlet method doPost.

@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.");
    }
}
Also used : RequestParameter(org.apache.sling.api.request.RequestParameter) InputStream(java.io.InputStream)

Example 5 with RequestParameter

use of org.apache.sling.api.request.RequestParameter in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractFormHelperImpl method getPostForm.

/**
 * Gets the Form from POST requests.
 *
 * @param formName
 * @param request
 * @return
 */
protected final Form getPostForm(final String formName, final SlingHttpServletRequest request) {
    final Map<String, String> map = new HashMap<String, String>();
    final RequestParameterMap requestMap = request.getRequestParameterMap();
    for (final String key : requestMap.keySet()) {
        // POST LookupKey formName param does not matter
        if (StringUtils.equals(key, this.getPostLookupKey(null))) {
            continue;
        }
        final RequestParameter[] values = requestMap.getValues(key);
        if (values == null || values.length == 0) {
            log.debug("Value did not exist for key: {}", key);
        } else if (values.length == 1) {
            log.debug("Adding to form data: {} ~> {}", key, values[0].toString());
            map.put(key, values[0].getString());
        } else {
            // Requires support for transporting them and re-writing them back into HTML Form on error
            for (final RequestParameter value : values) {
                // Use the first non-blank value, or use the last value (which will be blank or not-blank)
                final String tmp = value.toString();
                map.put(key, tmp);
                if (StringUtils.isNotBlank(tmp)) {
                    break;
                }
            }
        }
    }
    return this.clean(new FormImpl(formName, request.getResource().getPath(), map));
}
Also used : RequestParameterMap(org.apache.sling.api.request.RequestParameterMap) HashMap(java.util.HashMap) FormImpl(com.adobe.acs.commons.forms.impl.FormImpl) RequestParameter(org.apache.sling.api.request.RequestParameter)

Aggregations

RequestParameter (org.apache.sling.api.request.RequestParameter)25 RequestParameterMap (org.apache.sling.api.request.RequestParameterMap)8 Map (java.util.Map)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Resource (org.apache.sling.api.resource.Resource)4 RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)4 ArrayList (java.util.ArrayList)3 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 PersistenceException (org.apache.sling.api.resource.PersistenceException)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 PageManager (com.day.cq.wcm.api.PageManager)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 PostConstruct (javax.annotation.PostConstruct)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 ValueMap (org.apache.sling.api.resource.ValueMap)2