Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2008, 05:01 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 780
Nicholas Jordan is on a distinguished road
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
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan : 10-13-2008 at 05:54 AM. Reason: URLDecode does not decode
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-13-2008, 08:16 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 475
fishtoprecords is on a distinguished road
Why define it yourself? just use the URLencode/decode functions in the libraries?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-15-2008, 05:49 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 780
Nicholas Jordan is on a distinguished road
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
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
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
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:
Quote:
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.
( 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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-15-2008, 07:05 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
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.

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) */
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-18-2008, 07:46 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 780
Nicholas Jordan is on a distinguished road
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
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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
characters from a string into an integer 2potatocakes New To Java 6 09-18-2008 01:08 PM
deleting characters from a String Hayzam New To Java 4 08-29-2008 02:14 PM
how to get the characters one by one from a String? Somitesh Chakraborty New To Java 3 08-20-2008 10:56 PM
How to split a string into multiple lines of x characters each JackJ New To Java 3 12-17-2007 04:35 AM
Getting all characters in a String Alayna New To Java 2 05-20-2007 01:49 PM


All times are GMT +3. The time now is 01:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org