Package org.apache.cocoon.servlet.multipart

Examples of org.apache.cocoon.servlet.multipart.Part


            }
        }
    }
   
    public static void save(Request request, String param, String file) throws Exception {
        Part part = (Part) request.get(param);
        save(part,new File(file));
    }
View Full Code Here


     * @return The saved file or <code>null</code> if the upload was not successful.
     * @throws Exception when something went wrong.
     */
    public File save(Request request, String requestParameter) throws Exception {

        Part part = (Part) request.get(requestParameter);

        File file = null;

        boolean success = save(part);
        if (success) {
            file = new File(directory, part.getFileName());
        }

        return file;
    }
View Full Code Here

        final Iterator i = paramNames.iterator();
        while ( i.hasNext() ) {
            final String name = (String)i.next();
            final Object o = req.get(name);
            if ( o != null && o instanceof Part) {
                final Part file = (Part)o;
                try {
                    byte[] c = IOUtils.toByteArray(file.getInputStream());
                    ContentItem ci = new ContentItem(file.getFileName(), true);
                    ci.setContent(c);
                    store.addItem(ci);
                } catch (Exception ignore) {
                    // ignore the exception
                }
View Full Code Here

        }


        // If the request object is a Part, keep it
        if (obj instanceof Part) {
            Part requestPart = (Part)obj;
            if (this.part != null) {
                // Replace the current part
                this.part.dispose();
            }

            // Keep the request part
            requestPart.setDisposeWithRequest(false);
            this.part = requestPart;
            if (validateOversize()) {
                // Clear any validation error
                setValidationError(null);
            }
View Full Code Here

                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds =
                                new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }
View Full Code Here

                File asciiFile = (File) value;
                asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
                length = (int) asciiFile.length();
                clob = new ClobHelper(asciiStream, length);
            } else if (value instanceof Part) {
                Part anyFile = (Part) value;
                asciiStream = new BufferedInputStream(anyFile.getInputStream());
                length = anyFile.getSize();
                clob = new ClobHelper(asciiStream, length);
            } else if (value instanceof JDBCxlobHelper) {
                asciiStream = ((JDBCxlobHelper) value).inputStream;
                length = ((JDBCxlobHelper) value).length;
                clob = new ClobHelper(asciiStream, length);
            } else if (value instanceof Source) {
                asciiStream = ((Source) value).getInputStream();
                length = (int)((Source) value).getContentLength();
                clob = new ClobHelper(asciiStream, length);
            } else {
                String asciiText = value.toString();
                asciiStream = new ByteArrayInputStream(asciiText.getBytes());
                length = asciiText.length();
                clob = new ClobHelper(asciiStream, length);
            }

            statement.setClob(position, clob);
            break;
        case Types.CHAR:
            // simple large object, e.g. Informix's TEXT
            //System.out.println("CHAR");

            if (value instanceof File) {
                File asciiFile = (File) value;
                asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
                length = (int) asciiFile.length();
            } else if (value instanceof JDBCxlobHelper) {
                asciiStream = ((JDBCxlobHelper) value).inputStream;
                length = ((JDBCxlobHelper) value).length;
            } else if (value instanceof Source) {
                asciiStream = ((Source) value).getInputStream();
                length = (int)((Source) value).getContentLength();
            } else if (value instanceof Part) {
                Part anyFile = (Part) value;
                asciiStream = new BufferedInputStream(anyFile.getInputStream());
                length = anyFile.getSize();
                clob = new ClobHelper(asciiStream, length);
            } else {
                String asciiText = value.toString();
                asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes()));
                length = asciiText.length();
            }

            statement.setAsciiStream(position, asciiStream, length);
            break;
        case Types.BIGINT:
            //System.out.println("BIGINT");
            BigDecimal bd;

            if (value instanceof BigDecimal) {
                bd = (BigDecimal) value;
            } else if (value instanceof Number) {
                bd = BigDecimal.valueOf(((Number)value).longValue());
            } else {
                bd = new BigDecimal(value.toString());
            }

            statement.setBigDecimal(position, bd);
            break;
        case Types.TINYINT:
            //System.out.println("TINYINT");
            Byte b;
            if (value instanceof Byte) {
                b = (Byte) value;
            } else if (value instanceof Number) {
                b = new Byte(((Number) value).byteValue());
            } else {
                b = new Byte(value.toString());
            }

            statement.setByte(position, b.byteValue());
            break;
        case Types.DATE:
            //System.out.println("DATE");
            Date d;
            if (value instanceof Date) {
                d = (Date) value;
            } else if (value instanceof java.util.Date) {
                d = new Date(((java.util.Date) value).getTime());
            } else if (value instanceof Calendar) {
                d = new Date(((Calendar) value).getTime().getTime());
            } else {
                d = Date.valueOf(value.toString());
            }

            statement.setDate(position, d);
            break;
        case Types.DOUBLE:
            //System.out.println("DOUBLE");
            double db;

            if (value instanceof Number) {
                db = (((Number) value).doubleValue());
            } else {
                db = Double.parseDouble(value.toString());
            }
            statement.setDouble(position, db);
            break;
        case Types.FLOAT:
            //System.out.println("FLOAT");
            float f;

            if (value instanceof Number) {
                f = (((Number) value).floatValue());
            } else {
                f = Float.parseFloat(value.toString());
            }
            statement.setFloat(position, f);
            break;
        case Types.NUMERIC:
            //System.out.println("NUMERIC");
            long l;

            if (value instanceof Number) {
                l = (((Number) value).longValue());
            } else {
                l = Long.parseLong(value.toString());
            }

            statement.setLong(position, l);
            break;
        case Types.SMALLINT:
            //System.out.println("SMALLINT");
            Short s;
            if (value instanceof Short) {
                s = (Short) value;
            } else if (value instanceof Number) {
                s = new Short(((Number) value).shortValue());
            } else {
                s = new Short(value.toString());
            }

            statement.setShort(position, s.shortValue());
            break;
        case Types.TIME:
            //System.out.println("TIME");
            Time t;
            if (value instanceof Time) {
                t = (Time) value;
            } else if (value instanceof java.util.Date){
                t = new Time(((java.util.Date) value).getTime());
            } else {
                t = Time.valueOf(value.toString());
            }

            statement.setTime(position, t);
            break;
        case Types.TIMESTAMP:
            //System.out.println("TIMESTAMP");
            Timestamp ts;
            if (value instanceof Time) {
                ts = (Timestamp) value;
            } else if (value instanceof java.util.Date) {
                ts = new Timestamp(((java.util.Date) value).getTime());
            } else {
                ts = Timestamp.valueOf(value.toString());
            }

            statement.setTimestamp(position, ts);
            break;
        case Types.ARRAY:
            //System.out.println("ARRAY");
            statement.setArray(position, (Array) value); // no way to convert string to array
            break;
        case Types.STRUCT:
            //System.out.println("STRUCT");
        case Types.OTHER:
            //System.out.println("OTHER");
            statement.setObject(position, value);
            break;
        case Types.LONGVARBINARY:
            //System.out.println("LONGVARBINARY");
            statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));
            break;
        case Types.VARCHAR:
            //System.out.println("VARCHAR");
            statement.setString(position, value.toString());
            break;
        case Types.BLOB:
            //System.out.println("BLOB");
            if (value instanceof JDBCxlobHelper) {
                statement.setBinaryStream(position, ((JDBCxlobHelper)value).inputStream, ((JDBCxlobHelper)value).length);
            } else if (value instanceof Source){
                statement.setBinaryStream(position, ((Source)value).getInputStream(), (int)((Source)value).getContentLength());
            } else {
                Blob blob;
                if (value instanceof Blob) {
                    blob = (Blob) value;
                } else if( value instanceof File) {
                    file = (File)value;
                    blob = new BlobHelper(new FileInputStream(file), (int) file.length());
                } else if (value instanceof String) {
                    file = new File((String)value);
                    blob = new BlobHelper(new FileInputStream(file), (int) file.length());
                } else if (value instanceof Part) {
                    Part anyFile = (Part) value;
                    blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize());
                } else {
                    throw new SQLException("Invalid type for blob: "+value.getClass().getName());
                }
                //InputStream input = new BufferedInputStream(new FileInputStream(file));
                statement.setBlob(position, blob);
View Full Code Here

                if(request.get("file") != null) {
                    object = request.get("file");
                }

                Part filePart = null;
                File file = null;

                if (object instanceof Part)
                {
                        filePart = (Part) object;
                        file = ((PartOnDisk)filePart).getFile();
                }

                if (filePart != null && filePart.getSize() > 0)
                {
                        String name = filePart.getUploadName();

                        while (name.indexOf('/') > -1)
                        {
                                name = name.substring(name.indexOf('/') + 1);
                        }
View Full Code Here

    // Upload a new file
    Item item = Item.find(context, itemID);
   
   
    Object object = request.get("file");
    Part filePart = null;
    if (object instanceof Part)
      filePart = (Part) object;

    if (filePart != null && filePart.getSize() > 0)
    {
      InputStream is = filePart.getInputStream();

      String bundleName = request.getParameter("bundle");
     
      Bitstream bitstream;
      Bundle[] bundles = item.getBundles(bundleName);
      if (bundles.length < 1)
      {
        // set bundle's name to ORIGINAL
        bitstream = item.createSingleBitstream(is, bundleName);
       
        // set the permission as defined in the owning collection
        Collection owningCollection = item.getOwningCollection();
        if (owningCollection != null)
        {
            Bundle bnd = bitstream.getBundles()[0];
            bnd.inheritCollectionDefaultPolicies(owningCollection);
        }
      }
      else
      {
        // we have a bundle already, just add bitstream
        bitstream = bundles[0].createBitstream(is);
      }

      // Strip all but the last filename. It would be nice
      // to know which OS the file came from.
      String name = filePart.getUploadName();

      while (name.indexOf('/') > -1)
      {
        name = name.substring(name.indexOf('/') + 1);
      }

      while (name.indexOf('\\') > -1)
      {
        name = name.substring(name.indexOf('\\') + 1);
      }

      bitstream.setName(name);
      bitstream.setSource(filePart.getUploadName());
      bitstream.setDescription(request.getParameter("description"));

      // Identify the format
      BitstreamFormat format = FormatIdentifier.guessFormat(context, bitstream);
      bitstream.setFormat(format);
View Full Code Here

        }
        else
        {
          // Update the logo
        Object object = request.get("logo");
        Part filePart = null;
        if (object instanceof Part)
          filePart = (Part) object;

        if (filePart != null && filePart.getSize() > 0)
        {
          InputStream is = filePart.getInputStream();
         
          collection.setLogo(is);
        }
        }
       
View Full Code Here

    newCollection.setMetadata("provenance_description", provenanceDescription);
   
       
        // Set the logo
      Object object = request.get("logo");
      Part filePart = null;
    if (object instanceof Part)
      filePart = (Part) object;

    if (filePart != null && filePart.getSize() > 0)
    {
      InputStream is = filePart.getInputStream();
     
      newCollection.setLogo(is);
    }
       
        // Save everything
View Full Code Here

TOP

Related Classes of org.apache.cocoon.servlet.multipart.Part

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.