allowable characters from URLDecoder.decode(String
Think this this would find all the allowable: (..?..) 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: 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: }
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
should not have escapes in decoded string, no?
Quote:
Originally Posted by
Norm
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 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: 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:
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:
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:
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.