org.apache.sling.api.request.RequestParameter Java Examples
The following examples show how to use
org.apache.sling.api.request.RequestParameter.
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 |
@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 |
@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 |
@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 |
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"); } } } } }
Example #5
Source File: MultiFieldDropTargetPostProcessor.java From commerce-cif-connector with Apache License 2.0 | 4 votes |
@Override public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { RequestParameterMap requestParameterMap = request.getRequestParameterMap(); for (String key : requestParameterMap.keySet()) { if (key.startsWith(DROP_TARGET_PREFIX)) { RequestParameter requestParameter = requestParameterMap.getValue(key); if (requestParameter != null) { String target = key.replace(DROP_TARGET_PREFIX, StringUtils.EMPTY); String propertyValue = requestParameter.getString(); Resource resource = request.getResource(); // If it's actually a drag and drop, the POST contains a Sling './@CopyFrom' parameter // and the modifications map will already contain the COPY operation done by the D'n'D if (requestParameterMap.containsKey(SLING_COPY_FROM)) { Modification copyFrom = modifications .stream() .filter(m -> ModificationType.COPY.equals(m.getType())) .findFirst().orElseGet(null); if (copyFrom != null) { Resource dropComponent = resource.getResourceResolver().getResource(copyFrom.getDestination()); ModifiableValueMap properties = dropComponent.adaptTo(ModifiableValueMap.class); properties.remove(target); resource = dropComponent; // The property changes will be done on the D'n'D target resource } } RequestParameter selectionTypeParameter = requestParameterMap.getValue(SELECTION_ID); String selectionType = selectionTypeParameter != null ? selectionTypeParameter.getString() : null; RequestParameter multipleParameter = requestParameterMap.getValue(MULTIPLE); boolean multiple = true; if (multipleParameter != null) { multiple = Boolean.valueOf(multipleParameter.getString()); } processProperty(resource, target, propertyValue, key, selectionType, multiple); modifications.add(Modification.onModified(resource.getPath())); } } } }