You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/09/21 18:29:33 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/request/multipart MultipartParser.java

vgritsenko    2002/09/21 09:29:32

  Modified:    .        Tag: cocoon_2_0_3_branch changes.xml
               .        changes.xml
               src/java/org/apache/cocoon/components/request/multipart Tag:
                        cocoon_2_0_3_branch MultipartParser.java
  Log:
  fix cross-platform upload issues
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.138.2.54 +5 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.138.2.53
  retrieving revision 1.138.2.54
  diff -u -r1.138.2.53 -r1.138.2.54
  --- changes.xml	21 Sep 2002 15:06:43 -0000	1.138.2.53
  +++ changes.xml	21 Sep 2002 16:29:31 -0000	1.138.2.54
  @@ -39,6 +39,10 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="fix">
  +    Fix issue with cross-platform uploads. Uploaded file's name converted
  +    to match destination platform's path separator.
  +  </action>
     <action dev="VG" type="update" fixes-bug="12131">
       Absolute path now can be specified for work, cache, and upload directory.
       Read comments in web.xml, and verify your settings.
  
  
  
  1.255     +5 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.254
  retrieving revision 1.255
  diff -u -r1.254 -r1.255
  --- changes.xml	21 Sep 2002 15:07:56 -0000	1.254
  +++ changes.xml	21 Sep 2002 16:29:31 -0000	1.255
  @@ -40,6 +40,10 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="fix">
  +    Fix issue with cross-platform uploads. Uploaded file's name converted
  +    to match destination platform's path separator.
  +  </action>
     <action dev="VG" type="update" fixes-bug="12131">
       Absolute path now can be specified for work, cache, and upload directory.
       Read comments in web.xml, and verify your settings.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +20 -27    xml-cocoon2/src/java/org/apache/cocoon/components/request/multipart/MultipartParser.java
  
  Index: MultipartParser.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/request/multipart/MultipartParser.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- MultipartParser.java	23 May 2002 12:01:46 -0000	1.1.2.2
  +++ MultipartParser.java	21 Sep 2002 16:29:32 -0000	1.1.2.3
  @@ -179,20 +179,18 @@
               throws IOException, MultipartException {
   
           Hashtable headers = new Hashtable();
  -
           headers = readHeaders(ts);
  -
           try {
               if (headers.containsKey("filename")) {
  -		if (!"".equals(headers.get("filename"))) {
  -                	parseFilePart(ts, headers);
  -		} else {
  -			// IE6 sends an empty part with filename="" for
  -			// empty upload fields. Just parse away the part
  -			byte[] buf = new byte[32];
  -			while(ts.getState() == TokenStream.STATE_READING)
  -				ts.read(buf);  
  -		}
  +                if (!"".equals(headers.get("filename"))) {
  +                    parseFilePart(ts, headers);
  +                } else {
  +                    // IE6 sends an empty part with filename="" for
  +                    // empty upload fields. Just parse away the part
  +                    byte[] buf = new byte[32];
  +                    while(ts.getState() == TokenStream.STATE_READING)
  +                        ts.read(buf);  
  +                }
               } else if (((String) headers.get("content-disposition"))
                       .toLowerCase().equals("form-data")) {
                   parseInlinePart(ts, headers);
  @@ -233,11 +231,14 @@
           if (!saveUploadedFilesToDisk) {
               out = new ByteArrayOutputStream();
           } else {
  -            String filePath = uploadDirectory.getPath() + File.separator;
  -	
  -            String fileName =
  -                    new File((String) headers.get("filename")).getName();
  +            String fileName = (String) headers.get("filename");
  +            if(File.separatorChar == '\\')
  +                fileName = fileName.replace('/','\\');
  +            else
  +                fileName = fileName.replace('\\','/');
   
  +            String filePath = uploadDirectory.getPath() + File.separator;
  +            fileName = new File(fileName).getName();
               file = new File(filePath + fileName);
   
               if (file.exists()) {
  @@ -259,15 +260,12 @@
           }
   
           int read = 0;
  -
           while (in.getState() == TokenStream.STATE_READING) {    // read data
               read = in.read(buf);
  -
               out.write(buf, 0, read);
           }
   
           out.close();
  -
           if (file == null) {
               byte[] bytes = ((ByteArrayOutputStream) out).toByteArray();
   
  @@ -295,7 +293,6 @@
   
           while (in.getState() == TokenStream.STATE_READING) {
               int read = in.read(buf);
  -
               value.append(new String(buf, 0, read, this.characterEncoding));
           }
   
  @@ -304,7 +301,6 @@
   
           if (v == null) {
               v = new Vector();
  -
               put(field, v);
           }
   
  @@ -331,14 +327,13 @@
               headers.put(tokenizer.nextToken(" :").toLowerCase(),
                           tokenizer.nextToken(" :;"));
   
  -	        // The extra tokenizer.hasMoreTokens() in headers.put
  -	        // handles the filename="" case IE6 submits for an empty
  -	        // upload field.
  +            // The extra tokenizer.hasMoreTokens() in headers.put
  +            // handles the filename="" case IE6 submits for an empty
  +            // upload field.
               while (tokenizer.hasMoreTokens()) {
                   headers.put(tokenizer.nextToken(" ;=\""),
                               tokenizer.hasMoreTokens() ? tokenizer.nextToken("=\"") : "");
               }
  -
               hdrline = readln(in);
           }
   
  @@ -355,7 +350,6 @@
       private String getBoundary(String hdr) {
   
           int start = hdr.toLowerCase().indexOf("boundary=");
  -
           if (start > -1) {
               return "--" + hdr.substring(start + 9);
           } else {
  @@ -379,7 +373,6 @@
   
           while ((b != -1) && (b != '\r')) {
               out.append((char) b);
  -
               b = in.read();
           }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org