Results 1 to 5 of 5
- 10-13-2008, 03:01 AM #1
allowable characters from URLDecoder.decode(String
Think this this would find all the allowable: (..?..)
(earlier post on the matter)Java Code:Pattern.compile("file:(\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
RFC 2396
RFC 1738
RFC 1808
RFC 1630
And what is enc in:Are they talking about application/x-www-form-urlencoded...?...Java Code:static String decode(String s, String enc) Decodes a application/x-www-form-urlencoded string using a specific encoding scheme.
{ 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.classLast edited by Nicholas Jordan; 10-13-2008 at 03:54 AM. Reason: URLDecode does not decode
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 10-13-2008, 06:16 AM #2
Why define it yourself? just use the URLencode/decode functions in the libraries?
- 10-15-2008, 03:49 PM #3
stops at web-inf
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
- the returned string prints with the %20's still in it. I would thinkJava 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();//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());Java Code:Pattern.compile("file:( /|\\w|\\d|-|_|\\.|!|~|\\*|\'|\\(|\\))+WEB-INF/");//
Just trying to get the Charset issue to work on the lib decode was an achievement, could not discover why and wherewould fail ( in the manner described ) .....Java Code:StringBuffer.append(d572b09.group());
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:( source: Wiki ) or use some printable characters or just exactly what to do without being directed and determined by entities with ulterior interests.ASCII reserves the first 32 codes (numbers 0–31 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.
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
- 10-15-2008, 05:05 PM #4
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) */
- 10-18-2008, 05:46 PM #5
should not have escapes in decoded string, no?
The intent here is to obtain what amounts to File.toString() - or more correctly
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:/** 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." */
Which shows an equivilant last line: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
Thus appears to me to be the same result of Matcher finding escape codes in a string that was supposed to be decoded, no?Java Code:file:/D:/JavaDevelopment/Testing/JavaForum/Folder%20with%20blanks/FindPathToFile.class
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:
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:String URLStr = url.toString(); if(URLStr.indexOf(Percent) >= 0) { URLStr = URLDecoder.decode(URLStr, "UTF8"); System.out.println("decode= " + URLStr);
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.Java Code:Matcher matcher = Pattern.matcher(URLDecoder.decode(this.getClass().getResource("/" + string + ".class", "UTF8")));//
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
-
characters from a string into an integer
By 2potatocakes in forum New To JavaReplies: 7Last Post: 05-08-2012, 12:31 PM -
deleting characters from a String
By Hayzam in forum New To JavaReplies: 4Last Post: 08-29-2008, 12:14 PM -
how to get the characters one by one from a String?
By Somitesh Chakraborty in forum New To JavaReplies: 3Last Post: 08-20-2008, 08:56 PM -
How to split a string into multiple lines of x characters each
By JackJ in forum New To JavaReplies: 3Last Post: 12-17-2007, 02:35 AM -
Getting all characters in a String
By Alayna in forum New To JavaReplies: 2Last Post: 05-20-2007, 11:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks