Package org.apache.sling.api.request

Examples of org.apache.sling.api.request.RequestParameter


        }
        final String contentRootName = targetName + "." + contentType;

        try {
            InputStream contentStream = null;
          RequestParameter contentParameter = request.getRequestParameter(SlingPostConstants.RP_CONTENT);
            if (contentParameter != null) {
                contentStream = contentParameter.getInputStream();
            } else {
                RequestParameter contentFile = request.getRequestParameter(SlingPostConstants.RP_CONTENT_FILE);
                if (contentFile != null) {
                    contentStream = contentFile.getInputStream();
                }
            }

            if (contentStream == null) {
                response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED,
View Full Code Here


    // SLING-1091: If a :name parameter is supplied, the (first) value of this parameter is used unmodified as the name
    //    for the new node. If the name is illegally formed with respect to JCR name requirements, an exception will be
    //    thrown when trying to create the node. The assumption with the :name parameter is, that the caller knows what
    //    he (or she) is supplying and should get the exact result if possible.
    RequestParameterMap parameters = request.getRequestParameterMap();
    RequestParameter specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME);
    if ( specialParam != null ) {
        if ( specialParam.getString() != null && specialParam.getString().length() > 0 ) {
            // If the path ends with a *, create a node under its parent, with
            // a generated node name
            basePath = basePath += "/" + specialParam.getString();

            // if the resulting path already exists then report an error
            Session session = request.getResourceResolver().adaptTo(Session.class);
              String jcrPath = removeAndValidateWorkspace(basePath, session);
              if (request.getResourceResolver().getResource(jcrPath) != null) {
View Full Code Here

     * @param request
     * @param key
     * @return
     */
    public static boolean hasMany(SlingHttpServletRequest request, String key) {
        final RequestParameter rp = request.getRequestParameter(key);
        if (rp == null) {
            return false;
        }
        return getAll(request, key).length > 1;
    }
View Full Code Here

     * @param request
     * @param key
     * @return
     */
    public static String[] getAll(SlingHttpServletRequest request, String key) {
        final RequestParameter rp = request.getRequestParameter(key);
        if (rp == null) {
            return new String[0];
        }
        return StringUtils.split(rp.getString(), DELIMITER);
    }
View Full Code Here

    public boolean requestDataUsed() {
        return this.requestDataUsed;
    }

    public String getParameter(String name) {
        RequestParameter param = this.getRequestParameter(name);
        return (param != null) ? param.getString() : null;
    }
View Full Code Here

        // Parse the request
        try {
            List<?> /* FileItem */items = upload.parseRequest(rc);
            for (Iterator<?> ii = items.iterator(); ii.hasNext();) {
                FileItem fileItem = (FileItem) ii.next();
                RequestParameter pp = new MultipartRequestParameter(fileItem);
                parameters.addParameter(fileItem.getFieldName(), pp);
            }
        } catch (FileUploadException fue) {
            // TODO: log
        }
View Full Code Here

    @Override
    public void destroy() {
    }

    private String getParameter(SlingHttpServletRequest slingRequest, String param) {
        final RequestParameter requestParameter =
                slingRequest.getRequestParameter(param);
        if (requestParameter == null) {
            return null;
        }
        return StringUtils.stripToNull(requestParameter.getString());
    }
View Full Code Here

     * @param prop the assembled property info
     * @throws RepositoryException if an error occurs
     */
    public void setFile(Node parent, RequestProperty prop, HtmlResponse response)
            throws RepositoryException {
        RequestParameter value = prop.getValues()[0];
        assert !value.isFormField();

        // ignore if empty
        if (value.getSize() <= 0) {
            return;
        }

        // get node name
        String name = prop.getName();
        if (name.equals("*")) {
            name = value.getFileName();
            // strip of possible path (some browsers include the entire path)
            name = name.substring(name.lastIndexOf('/') + 1);
            name = name.substring(name.lastIndexOf('\\') + 1);
        }
        name = Text.escapeIllegalJcrChars(name);

        // check type hint. if the type is ok and extends from nt:file,
        // create an nt:file with that type. if it's invalid, drop it and let
        // the parent node type decide.
        boolean createNtFile = parent.isNodeType(NT_FOLDER);
        String typeHint = prop.getTypeHint();
        if (typeHint != null) {
            try {
                NodeTypeManager ntMgr = parent.getSession().getWorkspace().getNodeTypeManager();
                NodeType nt = ntMgr.getNodeType(typeHint);
                createNtFile = nt.isNodeType(NT_FILE);
            } catch (RepositoryException e) {
                // assuming type not valid.
                typeHint = null;
            }
        }

        // also create an nt:file if the name contains an extension
        // the rationale is that if the file name is "important" we want
        // an nt:file, and an image name with an extension is probably "important"
        if(!createNtFile && name.indexOf('.') > 0) {
            createNtFile = true;
        }

        // set empty type
        if (typeHint == null) {
            typeHint = createNtFile ? NT_FILE : NT_RESOURCE;
        }

        // remove node
        if (parent.hasNode(name)) {
            parent.getNode(name).remove();
        }

        // create nt:file node if needed
        if (createNtFile) {
            // create nt:file
            parent = parent.addNode(name, typeHint);
            response.onCreated(parent.getPath());
            name = JCR_CONTENT;
            typeHint = NT_RESOURCE;
        }

        // create resource node
        Node res = parent.addNode(name, typeHint);
        response.onCreated(res.getPath());

        // get content type
        String contentType = value.getContentType();
        if (contentType != null) {
            int idx = contentType.indexOf(';');
            if (idx > 0) {
                contentType = contentType.substring(0, idx);
            }
        }
        if (contentType == null || contentType.equals("application/octet-stream")) {
            // try to find a better content type
            contentType = this.servletContext.getMimeType(value.getFileName());
            if (contentType == null || contentType.equals("application/octet-stream")) {
                contentType = "application/octet-stream";
            }
        }

        // set properties
        response.onModified(
            res.setProperty(JCR_LASTMODIFIED, Calendar.getInstance()).getPath()
        );
        response.onModified(
            res.setProperty(JCR_MIMETYPE, contentType).getPath()
        );
        try {
            response.onModified(
                res.setProperty(JCR_DATA, value.getInputStream()).getPath()
            );
        } catch (IOException e) {
            throw new RepositoryException("Error while retrieving inputstream from parameter value.", e);
        }
    }
View Full Code Here

    public boolean requestDataUsed() {
        return this.requestDataUsed;
    }

    public String getParameter(String name) {
        RequestParameter param = this.getRequestParameter(name);
        return (param != null) ? param.getString() : null;
    }
View Full Code Here

        // Parse the request
        try {
            List<?> /* FileItem */items = upload.parseRequest(rc);
            for (Iterator<?> ii = items.iterator(); ii.hasNext();) {
                FileItem fileItem = (FileItem) ii.next();
                RequestParameter pp = new MultipartRequestParameter(fileItem);
                parameters.addParameter(fileItem.getFieldName(), pp);
            }
        } catch (FileUploadException fue) {
            // TODO: log
        }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.request.RequestParameter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.