andrewducker: (overwhelming firepower)
andrewducker ([personal profile] andrewducker) wrote2011-11-24 08:07 am

Anyone here know much about Java?

I have user input for a URL field. I want them to be able to enter anything from "http://andrewducker.wordpress.com/xmlrpc.php" to "andrewducker.wordpress.com" and be able to end up at the same end point.

I've wasted a couple of hours messing around with the various constructors for URL and not got to anywhere satisfactory, should I just do string checking and construct it myself?

I should make it clear - I always want the /xmlrpc.php bit to be what's on the end of the URL, that's a Wordpress standard, so I don't need to do any complex discovery. I just need to append that if it's not there.

I was hoping that someone would have written a class that could append bits of URLs together, but the basic stuff in the built in URL class doesn't quite cut it.
pseudomonas: per bend sinister azure and or a chameleon counterchanged (Default)

[personal profile] pseudomonas 2011-11-24 01:16 pm (UTC)(link)
Can you do all the manipulations as Strings and then just convert it to URL at the end?

[identity profile] bugshaw.livejournal.com 2011-11-24 08:13 am (UTC)(link)
Would "Enter your Wordpress domain" work?
drplokta: (Default)

[personal profile] drplokta 2011-11-24 09:15 am (UTC)(link)
Regardless of programming language, that sounds to me like a job for a single regular expression -- something like (untested): s/(htttp\:)*(\/)*(.*)(/(xmlrpc(\.)*(php)*)*)*/\3/

[identity profile] strawberryfrog.livejournal.com 2011-11-24 09:39 am (UTC)(link)
If that was c#, I would not use a regex - I'd
1) construct a Uri from the string
2) read off some of the properties of the uri. Something like uri.Scheme + uri.Host + "/xmlrpc.php" should be what you want (unless port numbers are involved).
Edited 2011-11-24 09:39 (UTC)