Package org.apache.sling.api.request

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


        // find the first request parameter that matches one of
        // our parameterNames, in order, and has a value
        if (parameters!=null) {
            // we first check for the special sling parameters
            RequestParameter specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME);
            if ( specialParam != null ) {
                if ( specialParam.getString() != null && specialParam.getString().length() > 0 ) {
                    valueToUse = specialParam.getString();
                    doFilter = false;
                }
            }
            if ( valueToUse == null ) {
                specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME_HINT);
                if ( specialParam != null ) {
                    if ( specialParam.getString() != null && specialParam.getString().length() > 0 ) {
                        valueToUse = specialParam.getString();
                    }
                }
            }

            if (valueToUse == null) {
View Full Code Here


     */
    public void setFile(Node parent, RequestProperty prop, List<Modification> changes)
            throws RepositoryException {
      RequestParameter[] values = prop.getValues();
      for (RequestParameter requestParameter : values) {
          RequestParameter value = requestParameter;

          // ignore if a plain form field or empty
            if (value.isFormField() || value.getSize() <= 0) {
                continue;
            }

            // 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
            Node resParent;
            if (createNtFile) {
                // create nt:file
                resParent = parent.addNode(name, typeHint);
                changes.add(Modification.onCreated(resParent.getPath()));
                name = JCR_CONTENT;
                typeHint = NT_RESOURCE;
            } else {
              resParent = parent;
            }

            // create resource node
            Node res = resParent.addNode(name, typeHint);
            changes.add(Modification.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
            changes.add(Modification.onModified(
                res.setProperty(JCR_LASTMODIFIED, Calendar.getInstance()).getPath()
            ));
            changes.add(Modification.onModified(
                res.setProperty(JCR_MIMETYPE, contentType).getPath()
            ));
            try {
                changes.add(Modification.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

        }
    }

    private Set<String> getCategoriesParam(final SlingHttpServletRequest request) {
        final LinkedHashSet<String> categories = new LinkedHashSet<String>();
        final RequestParameter requestParameter = request.getRequestParameter(PARAM_CATEGORIES);

        if (requestParameter != null) {
            final String[] segments = StringUtils.split(requestParameter.getString(), ",");

            for (final String segment : segments) {
                if (StringUtils.isNotBlank(segment)) {
                    categories.add(StringUtils.stripToEmpty(segment));
                }
View Full Code Here

        }
        return categories;
    }

    private boolean hasLibraryTypeParam(final SlingHttpServletRequest request, final String paramLibraryType) {
        final RequestParameter requestParameter = request.getRequestParameter(paramLibraryType);

        if (requestParameter != null) {
            return Boolean.parseBoolean(requestParameter.getString());
        }
        return false;
    }
View Full Code Here

        return false;
    }

    private static boolean hasIncomingQueryParamData(SlingHttpServletRequest request) {
        RequestParameter param = request.getRequestParameter(ActiveForm.CQ_FORM);
        if (param == null) {
            return false;
        }
        return StringUtils.isNotBlank(param.getString());
    }
View Full Code Here

     *
     * @param request
     * @return
     */
    protected static boolean hasIncomingQueryParamData(SlingHttpServletRequest request) {
        RequestParameter param = request.getRequestParameter(CQ_ERRORS);
        if (param == null) {
            return false;
        }
        return StringUtils.isNotBlank(param.getString());
    }
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.