Results 1 to 5 of 5
  1. #1
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Question allowable characters from URLDecoder.decode(String

    Think this this would find all the allowable: (..?..)
    Java Code:
    Pattern.compile("file:(\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
    (earlier post on the matter)

    RFC 2396
    RFC 1738
    RFC 1808
    RFC 1630

    And what is enc in:
    Java Code:
    static String decode(String s, String enc) 
              Decodes a application/x-www-form-urlencoded string using a specific encoding scheme.
    Are they talking about application/x-www-form-urlencoded...?...


    { message additional information from test build: }
    Java Code:
    // Okay, this should be our name.
    String string = this.getClass().getName();
    string.replaceAll("\\.", "/");
    // Normal sanity check.
    if(string != null)
    {
    //
    ce79a43b0673a1.append(FileDog.this.getClass().getResource("/" + string + ".class"));
    java.net.URL ab277d49021f= new java.net.URL(ce79a43b0673a1.toString());
    //
                    java.util.regex.Pattern pitterPatter = java.util.regex.Pattern.compile("file:(/|\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
    //
    String cc09566 = new String(java.nio.charset.Charset.defaultCharset().toString());
    String l1434be = new String(java.net.URLDecoder.decode(ab277d49021f.toExternalForm(),cc09566));
    /****** here we go...  ******/
    java.util.regex.Matcher d572b093064 = pitterPatter.matcher(l1434be);
    // If we captured state of where we are at ....
    while(d572b093064.find())
    {
    //
    ce79a43b0673a1.append(d572b093064.group());
    isValid=Boolean.valueOf(true);//
     }
     return ce79a43b0673a1.toString();//
    }
    
    // prints: file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    Last edited by Nicholas Jordan; 10-13-2008 at 04:54 AM. Reason: URLDecode does not decode
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Why define it yourself? just use the URLencode/decode functions in the libraries?

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Red face stops at web-inf

    Quote Originally Posted by fishtoprecords View Post
    Why define it yourself? just use the URLencode/decode functions in the libraries?
    I worked on this trying to achieve a way to manipulate or at least prove the string returned by lib method. That arrived at a string that prints a decoded string. Then to get all up to "/web-inf/" I attempted to write a regex - this time looking at the rfc to determine what characters to allow. I then did
    Java Code:
    /****** here we go...  ******/
    java.util.regex.Matcher d572b09 = pitterPatter.matcher(l1434be);
    // If we captured state of where we are at ....
    while(d572b09.find())
    {
      // StringBuffer.append(Matcher.group());//
      ce79a43b0673a1.append(d572b09.group());
    }
    isValid=Boolean.valueOf(true);//
    return ce79a43b0673a1.toString();//
    - the returned string prints with the %20's still in it. I would think
    Java Code:
    Pattern.compile("file:( /|\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
    would capture all up to the end of "WEB-INF/" on a decoded string - thus I could append a filename to that and achieve a file.open(StringBuffer.toString());

    Just trying to get the Charset issue to work on the lib decode was an achievement, could not discover why and where
    Java Code:
    StringBuffer.append(d572b09.group());
    would fail ( in the manner described ) .....

    At a loss for words, do not know what to ask. I looked into all the db stuff, I will continue to work on using a db but I wish to write a file behind WEB-INF that I determine the syntax of and can make decisions such as using:
    ASCII reserves the first 32 codes (numbers 031 decimal) for control characters: codes originally intended not to carry printable information, but rather to control devices (such as printers) that make use of ASCII, or to provide meta-information about data streams such as those stored on magnetic tape.
    ( source: Wiki ) or use some printable characters or just exactly what to do without being directed and determined by entities with ulterior interests.

    EG: I do not see where the regex captures "%20" Even if we allow for ("\\d)+ in the regex it should not pick up "%" ~ at least not by common sense.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    Can you explain what the objective of your code is?
    Here's simple code to replace the %20 with a blank.
    Your code already does it. I don't understand what the regex if for.

    Java Code:
    // Find path to class file (w/o %20)
    
    import java.net.URLDecoder;
    
    
    public class FindPathToFile {
    
       public static void main(String[] args) {
          try {
             new FindPathToFile();
          }catch(Exception x){x.printStackTrace();}
       }
    
        private final static String Percent = "%";
    
       public FindPathToFile() throws Exception {
          // Okay, this should be our name.
          String string = this.getClass().getName();
          string.replaceAll("\\.", "/");
          System.out.println("string=" + string + ", user.dir=" + System.getProperty("user.dir"));
          StringBuffer sb = new StringBuffer();
    
          // Normal sanity check.
          if(string != null)      {
             //
             sb.append(/*FileDog.*/this.getClass().getResource("/" + string + ".class"));
             java.net.URL url= new java.net.URL(sb.toString());
             System.out.println("url=" + url);
    
             String URLStr = url.toString();
             if(URLStr.indexOf(Percent) >= 0) {
                URLStr = URLDecoder.decode(URLStr, "UTF8");
                System.out.println("decode= " + URLStr);
             }
    
    
             //
             java.util.regex.Pattern pitterPatter 
               = java.util.regex.Pattern.compile("file:(/|\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
             //
             String dfltCS = new String(java.nio.charset.Charset.defaultCharset().toString());
             System.out.println("defaultCS="  + dfltCS); //1252
             String decodedURL = new String(java.net.URLDecoder.decode(url.toExternalForm(), dfltCS));
             System.out.println("decode2=" + decodedURL);
             /****** here we go...  ******/
             java.util.regex.Matcher mtchr = pitterPatter.matcher(decodedURL);
             // If we captured state of where we are at ....
             while(mtchr.find())       {
                //
                sb.append(mtchr.group());
    //            isValid=Boolean.valueOf(true);//
              }
           System.out.println( sb.toString());//
          }
          
         // prints: file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    
       } // end main
    } // end class
    
    /*   Output from above
    Running: D:\Java\jre6_10\bin\java.exe -classpath D:\JavaDevelopment;. -Xmx128M FindPathToFile
    
    string=FindPathToFile, user.dir=D:\JavaDevelopment\Testing\JavaForum\Folder with blanks
    url=file:/D:/JavaDevelopment/Testing/JavaForum/Folder%20with%20blanks/FindPathToFile.class
    decode= file:/D:/JavaDevelopment/Testing/JavaForum/Folder with blanks/FindPathToFile.class
    defaultCS=windows-1252
    decode2=file:/D:/JavaDevelopment/Testing/JavaForum/Folder with blanks/FindPathToFile.class
    file:/D:/JavaDevelopment/Testing/JavaForum/Folder%20with%20blanks/FindPathToFile.class
    
    0 error(s)
    */

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Question should not have escapes in decoded string, no?

    Quote Originally Posted by Norm View Post
    Can you explain what the objective of your code is?
    Here's simple code to replace the %20 with a blank.
    Your code already does it. I don't understand what the regex if for.
    The intent here is to obtain what amounts to File.toString() - or more correctly
    Java Code:
    /** C:\src_jdk1.5.0_12\java\io\File.java
     * An abstract representation of file and directory pathnames.
     */
     String locationOnRemoteServer = new String(File.getName());//
     String locationOnRemoteServer = new String(File.getAbsolutePath());//
     String locationOnRemoteServer = new String(File.getCanonicalPath());//
     String locationOnRemoteServer = new String(File.getAbsolutePath());//
     /**
     * Avoiding somehow:    /**
     *
     * "The exact form of the URI is system-dependent."
     */
    Running your code with as few changes as I could ( moved it to an instance method to use the this pointer as you did ), I get:
    Java Code:
    string=FileDog, user.dir=C:\Documents and Settings\All Users\Documents
    url=file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    decode= file:/C:/Documents and Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    defaultCharacterSet = windows-1252
    decode2=file:/C:/Documents and Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
    Which shows an equivilant last line:
    Java Code:
    file:/D:/JavaDevelopment/Testing/JavaForum/Folder%20with%20blanks/FindPathToFile.class
    Thus appears to me to be the same result of Matcher finding escape codes in a string that was supposed to be decoded, no?

    The inclusion of ", user.dir=" + System.getProperty("user.dir")); in your sample provides an appealing avenue of exploration. For the short version of what my code intends to do we can take Jason Weiss' ISBN:0-12-742751-1 contradistincted to the front pages of the news today and surmise that I should write code I understand.

    Thus, a simple replacement of %20 to find /WEB-INF/ in a File.getWhereIt'sAt() should yield to a lib method, URL.decode(), that is documented to return a string.

    Doing a regex work on the String should not in my opinion result in an optimized version that defeated the intent of:
    Java Code:
    String URLStr = url.toString();
    if(URLStr.indexOf(Percent) >= 0) {
    URLStr = URLDecoder.decode(URLStr, "UTF8");
    System.out.println("decode= " + URLStr);
    Which we would ( I would think ) do URLDecoder.decode(URLStr, "UTF8"); directly on the result of sb.append(/*FileDog.*/this.getClass().getResource("/" + string + ".class")); probably thus:
    Java Code:
    Matcher matcher = Pattern.matcher(URLDecoder.decode(this.getClass().getResource("/" + string + ".class", "UTF8")));//
    The intent of that being to find /WEB-INF/ or some descendent folder or dir such that a conventional File may be written and thus ftp'd or used in a Servlet such that the application works in a manner I understand.

    I sure do not understand what .class is doing in all this.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. characters from a string into an integer
    By 2potatocakes in forum New To Java
    Replies: 7
    Last Post: 05-08-2012, 01:31 PM
  2. deleting characters from a String
    By Hayzam in forum New To Java
    Replies: 4
    Last Post: 08-29-2008, 01:14 PM
  3. how to get the characters one by one from a String?
    By Somitesh Chakraborty in forum New To Java
    Replies: 3
    Last Post: 08-20-2008, 09:56 PM
  4. Replies: 3
    Last Post: 12-17-2007, 03:35 AM
  5. Getting all characters in a String
    By Alayna in forum New To Java
    Replies: 2
    Last Post: 05-20-2007, 12:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •