Example usage for org.apache.commons.beanutils PropertyUtils PropertyUtils

List of usage examples for org.apache.commons.beanutils PropertyUtils PropertyUtils

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils PropertyUtils.

Prototype

PropertyUtils

Source Link

Usage

From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.SecureIconDisplay.java

private String getParamValue(Form form, String paramProperty) throws JspException {
    String paramValue = null;//from   w  w  w  .  j  a  v  a 2 s.c o  m
    try {
        PropertyUtils beanPropertyUtil = new PropertyUtils();
        paramValue = (String) beanPropertyUtil.getProperty(form, paramProperty);

    } catch (Exception ex) {
        throw new JspException(ex.toString());
    }
    return paramValue;
}

From source file:org.paxle.gui.impl.servlets.ParserTestServlet.java

protected void fillContext(Context context, HttpServletRequest request) {
    String cmdLocation = null;//from   w  ww  .  j a  va  2  s  . co m
    String cDocCharset = "UTF-8";
    File cDocContentFile = null;
    String cDocContentType = null;
    boolean mimeTypeDetection = false;
    boolean charsetDetection = false;

    try {
        context.put(CONTEXT_MIMETYPE_DETECTOR, this.mimeTypeDetector);
        context.put(CONTEXT_CHARSET_DETECTOR, this.charsetDetector);

        if (ServletFileUpload.isMultipartContent(request)) {
            // Create a factory for disk-based file items
            final FileItemFactory factory = new DiskFileItemFactory();

            // Create a new file upload handler
            final ServletFileUpload upload = new ServletFileUpload(factory);

            // Parse the request
            @SuppressWarnings("unchecked")
            final List<FileItem> items = upload.parseRequest(request);

            // Process the uploaded items
            final Iterator<FileItem> iter = items.iterator();
            while (iter.hasNext()) {
                final FileItem item = iter.next();
                final String fieldName = item.getFieldName();

                if (item.isFormField()) {
                    if (fieldName.equals(PARAM_COMMAND_URI)) {
                        cmdLocation = item.getString();
                        context.put(PARAM_COMMAND_URI, cmdLocation);
                    } else if (fieldName.equals(PARAM_ENABLE_MIMETYPE_DETECTION)) {
                        mimeTypeDetection = true;
                    } else if (fieldName.equals(PARAM_ENABLE_CHARSET_DETECTION)) {
                        charsetDetection = true;
                    }
                } else {
                    try {
                        // ignore unknown items
                        if (!fieldName.equals(PARAM_CRAWLERDOC_NAME))
                            continue;

                        // getting the content type
                        cDocContentType = item.getContentType();

                        // getting the file-Name
                        String fileName = item.getName();
                        if (fileName != null) {
                            context.put(PARAM_CRAWLERDOC_NAME, fileName);
                            fileName = FilenameUtils.getName(fileName);
                        } else {
                            String errorMsg = String.format("Fileupload field '%s' has no valid filename '%s'.",
                                    PARAM_CRAWLERDOC_NAME, item.getFieldName());
                            this.logger.warn(errorMsg);
                            context.put(CONTEXT_ERROR_MSG, errorMsg);
                            continue;
                        }

                        // creating a temp-file
                        cDocContentFile = this.tfm.createTempFile();

                        // getting the content
                        item.write(cDocContentFile);
                    } finally {
                        // delete uploaded item
                        item.delete();
                    }
                }
            }

            // detect the mime-type of the uploaded file
            if (this.mimeTypeDetector != null && mimeTypeDetection) {
                final String tempMimeType = this.mimeTypeDetector.getMimeType(cDocContentFile);
                if (tempMimeType != null)
                    cDocContentType = tempMimeType;
            }

            // determine the charset of the uploaded file
            if (this.charsetDetector != null && charsetDetection) {
                final String tempCharset = this.charsetDetector.detectCharset(cDocContentFile);
                if (tempCharset != null)
                    cDocCharset = tempCharset;
            }

            // creating a crawler-document
            final ICrawlerDocument cDoc = this.cDocFactory.createDocument(ICrawlerDocument.class);
            cDoc.setStatus(ICrawlerDocument.Status.OK);
            cDoc.setContent(cDocContentFile);
            cDoc.setMimeType(cDocContentType);
            cDoc.setCharset(cDocCharset);

            // creating a dummy command
            final ICommand cmd = this.cmdFactory.createDocument(ICommand.class);
            cmd.setLocation(URI.create(cmdLocation));
            cmd.setCrawlerDocument(cDoc);

            // parsing the command
            this.parser.process(cmd);
            if (cmd.getResult() != Result.Passed) {
                context.put(CONTEXT_ERROR_MSG,
                        String.format("Unable to parse the document: %s", cmd.getResultText()));
                return;
            }

            // trying to get the parsed content
            final IParserDocument pdoc = cmd.getParserDocument();
            if (pdoc == null) {
                context.put("errorMsg", "Unable to parse the document: parser-document is null.");
                return;
            } else if (pdoc.getStatus() != Status.OK) {
                context.put(CONTEXT_ERROR_MSG,
                        String.format("Unable to parse the document: %s", pdoc.getStatusText()));
                return;
            }

            /*
             * Remembering some object in the request-context
             * This is required for cleanup. See #requestCleanup(...)
             */
            request.setAttribute(CONTEXT_CMD, cmd);
            request.setAttribute(REQ_ATTR_LINEITERS, new ArrayList<Reader>());

            /*
             * Passing some properties to the rendering engine
             */
            context.put(CONTEXT_CMD, cmd);
            context.put(CONTEXT_PROP_UTIL, new PropertyUtils());
            context.put(CONTEXT_SERVLET, this);
            if (mimeTypeDetection && this.mimeTypeDetector != null) {
                context.put(PARAM_ENABLE_MIMETYPE_DETECTION, Boolean.TRUE);
            }
            if (charsetDetection && this.charsetDetector != null) {
                context.put(PARAM_ENABLE_CHARSET_DETECTION, Boolean.TRUE);
            }
        }
    } catch (Throwable e) {
        this.logger.error(e);

        // delete temp-file
        if (cDocContentFile != null) {
            try {
                this.tfm.releaseTempFile(cDocContentFile);
            } catch (IOException e2) {
                /* ignore this */}
        }
    }
}