Package com.oreilly.servlet.multipart

Examples of com.oreilly.servlet.multipart.Part


        }
        parameters.put(paramName, newValues);
      }
    }

    Part part;
    while ((part = parser.readNextPart()) != null) {
      String name = part.getName();
      if (part.isParam()) {
        // It's a parameter part, add it to the vector of values
        ParamPart paramPart = (ParamPart) part;
        String value = paramPart.getStringValue();
        Vector existingValues = (Vector)parameters.get(name);
        if (existingValues == null) {
          existingValues = new Vector();
          parameters.put(name, existingValues);
        }
        existingValues.addElement(value);
      }
      else if (part.isFile()) {
        // It's a file part
        FilePart filePart = (FilePart) part;
        String fileName = filePart.getFileName();
        if (fileName != null) {
          filePart.setRenamePolicy(policy)// null policy is OK
View Full Code Here


                    && req.getContentType().toUpperCase().
                    startsWith("MULTIPART/FORM-DATA")) {
                final int size = Integer.parseInt(WebMailServer.
                        getStorage().getConfig("max attach size"));
                final MultipartParser mparser = new MultipartParser(req, size);
                Part p;
                while ((p = mparser.readNextPart()) != null) {
                    if (p.isFile()) {
                        final ByteStore bs = ByteStore.getBinaryFromIS(
                                ((FilePart) p).getInputStream(), size);
                        bs.setName(((FilePart) p).getFileName());
                        bs.setContentType(getStorage().getMimeType(
                                    ((FilePart) p).getFileName()));
                        http_header.setContent(p.getName(), bs);
                        log.info("File name " + bs.getName());
                        log.info("Type      " + bs.getContentType());

                    } else if (p.isParam()) {
                        http_header.setContent(p.getName(),
                                ((ParamPart) p).getStringValue());
                    }

                    // log.info("Parameter "+p.getName());
                }
View Full Code Here

    try {
      // don't worry about NullPointerExceptions.
      // we'll catch exceptions if any operation fails.
      MultipartParser mpp = new MultipartParser(ureq.getHttpReq(), (int) fileUploadLimit * 1024);
      mpp.setEncoding("UTF-8");
      Part part;
      boolean fileWritten = false;
      while ((part = mpp.readNextPart()) != null) {
        if (part.isFile() && !fileWritten) {
          FilePart fPart = (FilePart) part;
          String type = fPart.getContentType();
          // get file contents
          Tracing.logWarn(type + fPart.getFileName(), this.getClass());
          if (fPart != null && fPart.getFileName() != null && type.startsWith("text") && (type.toLowerCase().endsWith("calendar"))) {
           
            // store the uploaded file by a temporary name
            CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager();
            String calID = ImportCalendarManager.getTempCalendarIDForUpload(ureq);
            File tmpFile = calManager.getCalendarFile(CalendarManager.TYPE_USER, calID);
            fPart.writeTo(tmpFile);
           
            // try to parse the tmp file
            Object calendar = calManager.readCalendar(CalendarManager.TYPE_USER, calID);
            if (calendar != null) {
              fileWritten = true;
            }
           
            //the uploaded calendar file is ok.
            fireEvent(ureq, Event.DONE_EVENT);
          }
        } else if (part.isParam()) {
          ParamPart pPart = (ParamPart) part;
          if (pPart.getName().equals("cancel")) {
            // action cancelled
            fireEvent(ureq, Event.CANCELLED_EVENT);
          }
View Full Code Here

      // Max file size = 1GB
      MultipartParser mp = new MultipartParser(request,
          1024 * 1024 * 1024, false, false, "gbk");
      System.out
          .println("The file is uploaded by httpclient multiple part method.");
      Part part;
      while ((part = mp.readNextPart()) != null) {
        String name = part.getName();
        if (part.isParam()) {
          ParamPart paramPart = (ParamPart) part;
          String value = paramPart.getStringValue();
          // System.out.println("param: name=" + name + "; value=" +
          // value);
          params.put(name, value);
        } else if (part.isFile()) {
          // it's a file part
          FilePart filePart = (FilePart) part;
          String fileName = filePart.getFileName();
          String filePath = filePart.getFilePath();
          if (fileName != null) {
View Full Code Here

    protected void receiveMultipart(HttpServletRequest request, HttpServletResponse response, HashMap<String, Object> params) throws IOException {
        ArrayList<FileApi.FileInfo> files = new ArrayList<FileApi.FileInfo>();
       
    MultipartParser parser = new MultipartParser(request, Integer.MAX_VALUE, true, true, null);
    FileApi api = getFileApi();
    Part part;
    while ((part = parser.readNextPart()) != null) {
      String name = part.getName();
     
      if (part.isParam()) {
        ParamPart paramPart = (ParamPart) part;
        Object value = paramPart.getStringValue();
       
        /*
         * TODO/HACK
 
View Full Code Here

    private void processMultiPart(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/plain");
        MultipartParser mp = new MultipartParser(req, 2048);
        Part part = null;
        while ((part = mp.readNextPart()) != null) {
            String name = part.getName().trim();
            if (part.isParam()) {
                // it's a parameter part
                ParamPart paramPart = (ParamPart) part;
                String value = paramPart.getStringValue().trim();
                LOG.info("param; name=" + name + ", value=" + value);
                out.print("param; name=" + name + ", value=" + value);
            } else if (part.isFile()) {
                // it's a file part
                FilePart filePart = (FilePart) part;
                String fileName = filePart.getFileName();
                if (fileName != null) {
                    // the part actually contained a file
View Full Code Here

TOP

Related Classes of com.oreilly.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.