Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse_url equivalent in grails / groovy?

Is there a groovy/grails equivalent to PHP's parse_url ( http://php.net/manual/en/function.parse-url.php ) or python's urlparse ( http://docs.python.org/library/urlparse.html ) that turns a URL string into a struct containing host,protocol, querystring, fragment, URI, etc?

I thought it might be in the grails.org/doc/latest/api/org/codehaus/groovy/grails/web/util/WebUtils.html , but didnt see anything. I dont think HTTPBuilder or assorted URLMapping utilities are what I need.

I really just want to pull a map out of the path and queryString and handle the edge cases (array of params /blah/fuzz?foo=bar&foo=baz, fragments /blah/fuzz?foo=bar#baz, encoded URLs for redirects) correctly.

I know I can handle the PATH component via clever use of URLMapping eg: /blah/$code, but im left with decoding the param block...

Thanks

like image 924
Tak Avatar asked Jul 13 '11 21:07

Tak


1 Answers

If I understand correctly, what you really need is plain old URI class:

new URI('http://google.com/?q=URL').query
like image 192
Artur Nowak Avatar answered Oct 19 '22 23:10

Artur Nowak