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());
}
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());
}
}
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");
}
}
}
}
}
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.");
}
}
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));
}
Aggregations