mrglavas    2004/07/14 12:24:23

  Modified:    java/src/org/apache/xml/serialize DOMSerializerImpl.java
  Log:
  In writeToURI, escapes in URIs such

  as: file:///D:/My%20Documents/file.xml were not being

  decoded. On Windows, we were writing to

  "D:\My%20Documents\file.xml" instead of

  "D:\My Documents\file.xml".

  

  Thanks to the patch by Ankit Pasricha, now decoding

  URI escape sequences.
  
  Revision  Changes    Path
  1.28      +21 -5     
xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java
  
  Index: DOMSerializerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DOMSerializerImpl.java    14 Jul 2004 14:23:37 -0000      1.27
  +++ DOMSerializerImpl.java    14 Jul 2004 19:24:23 -0000      1.28
  @@ -29,6 +29,7 @@
   import java.net.HttpURLConnection;
   import java.net.URL;
   import java.net.URLConnection;
  +import java.util.StringTokenizer;
   import java.util.Vector;
   
   import org.apache.xerces.dom.AttrImpl;
  @@ -928,10 +929,7 @@
               // Use FileOutputStream if this URI is for a local file.
               if (protocol.equals("file") 
                   && (host == null || host.length() == 0 || 
host.equals("localhost"))) {
  -                // REVISIT: We have to decode %nn sequences. For
  -                // now files containing spaces and other characters
  -                // which were escaped in the URI will fail. -- mrglavas
  -                out = new FileOutputStream(new File(url.getPath()));
  +                out = new FileOutputStream(getPathWithoutEscapes(url.getPath()));   
           
               }
               // Try to write to some other kind of URI. Some protocols
               // won't support this, though HTTP should work.
  @@ -1153,6 +1151,24 @@
           }        
           }
                  
  +    }
  +    
  +    private String getPathWithoutEscapes(String origPath) {
  +        if (origPath != null && origPath.length() != 0 && origPath.indexOf('%') != 
-1) {
  +            // Locate the escape characters
  +            StringTokenizer tokenizer = new StringTokenizer(origPath, "%");
  +            StringBuffer result = new StringBuffer(origPath.length());
  +            int size = tokenizer.countTokens();
  +            result.append(tokenizer.nextToken());
  +            for(int i = 1; i < size; ++i) {
  +                String token = tokenizer.nextToken();
  +                // Decode the 2 digit hexadecimal number following % in '%nn'
  +                result.append((char)Integer.valueOf(token.substring(0, 2), 
16).intValue());
  +                result.append(token.substring(2));
  +            }
  +            return result.toString();
  +        }
  +        return origPath;
       }
   
   }//DOMSerializerImpl
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to