How can I decompose a URL in Wicket? I've got the following URL:
http://www.example.com[:8080]/context/wicket/[bookmarkable/]WICKET-RELATED-URL
|---------------------------|-------|----------------------------------------|
A B C
I found a way to get the full URL (A,B,C):
RequestCycle.get().getUrlRenderer().renderFullUrl(
RequestCycle.get().getRequest().getUrl())
and a way to get just the context (B):
RequestCycle.get().getRequest().getContextPath()
Is there a similar way to get part (A) of the URL? Or do I have to work with substrings?
Don't use regular expressions! ;)
There is java.net.URL object which parses an url and allows access to any part of it separately. Also, you could combine a new url from the parts and compose back a string form of the url.
Depends what exactly you want in wicket, maybe there is a ready to use method to do it with the wicket. You haven't told about your problem, but about a probable solution only.
You could use wickets RequestUtil.toAbsolutePath(String relativePagePath).
According to JavaDoc, it "Calculates absolute path to url relative to another absolute url."
I've been using it with 'urlFor()' to generate links to put into mails but as long as you can define a relative path to your target, this should be your solution.
RequestCycle.get().getRequest().getUrl().get(Protocol|Host|Port)()
Regular expressions can fit your requirements
Related
I want to extract url of a facebook page by giving a keyword. Eg if I specify a keyword like "gulab jamun" on facebook can I get the url of that page.I tried different ways but I don't even know that is it possible. So can anyone help me for resolving this issue.I tried that using existing API's too restfb and facebook4j but I think it's not possible through that. can any one help me
I think you'll have no success with how you tried it... The RegEx should be passed where?
A solution might be to use the Search API for Pages (https://developers.facebook.com/docs/reference/api/search/#types), for example like this:
https://graph.facebook.com/search?q=gulab+jamun&type=page&access_token={YOUR_APP_ACCESS_TOKEN}
Then you can filter the results for the Page names of interest. To get the URL, you need to request the Page details per Page as follows:
https://graph.facebook.com/{PAGE_ID_FROM_RESULT}?fields=id,name,link
A one-step solution is as far as I know not possible.
My team's lead developer is trying to figure out a way to pass session information in some other way than via the URL when using WebObjects.
Our site was built using web objects, but the problem we're now having is that when bloggers blog about us and post links from our site in their blog posts, the URL typically includes session information it and isn't valid for anyone other than the person who copied the link in the first place, Bloggers trying to point people to www.example-dot-com are instead blogging links such as
www.example-dot-com/cgi-bin/WebObjects/example.woa/wo/0.11.3.8
Anyone have any suggestions? Thanks!
There are a couple of issues here. Firstly, if you want to remove the session ID from the URL (which is the default), you override WOSession.setStoresIDsInCookies() to return true and WOSession.setStoresIDsInURLs() to return false.
However, your example URL doesn't have a session ID, so presumably you've figured that out. There are then a number of ways to get friendlier URLs, the easiest of which is probably to use direct actions. You could then have a URL more like www.example-dot-com/cgi-bin/WebObjects/example.woa/wa/someTarget.
Finally, Project Wonder provides full support for URL re-writing, to the extent that you could have something more like www.example-dot-com/someTarget.
I'm building an Android application which allows people scan QR code and open its content if that is a URL. But before opening, I want to check it's a safe URL. I check Google Safe Browsing API, and it turns out I need to download and save malware and infected URL list, which's impossible for Android client.
There's another way with http://www.google.com/safebrowsing/diagnostic?site= but this have two disadvantages:
1.It doesn't work with full URL or URL paramater:
Work: http://www.google.com/safebrowsing/diagnostic?site=http://example.com
Don't work: http://www.google.com/safebrowsing/diagnostic?site=http://example.com/abc/def?ghi=opq
2.It opens a web page which tell us URL is safe or not, but I'd rather want it return a HTTP status code: like 201 -> safe, 202 -> isn't safe (which is easier to process).
The first disadvantage's not much a problem, but the second's really annoying. Can anyone show me another way around? Really thank.
There is an API that maybe solves all of your problems: http://code.google.com/apis/safebrowsing/
And here is an Java client implementation for it: http://code.google.com/p/jgooglesafebrowsing/
One thing I would suggest is to have a server side implementation and have an Rest api exposed. Your android app can act as a client for the same
You need to urlencode your URL as you cannot have two ? characters in the URL at the same time.
So your URL should looks like:
https://transparencyreport.google.com/safe-browsing/search?url=http:%2F%2Fexample.com%2Fabc%2Fdef%3Fghi%3Dopq
In Java, you can use URLEncoder.encode().
See: Java URL encoding of query string parameters
Is there a Actionscript/Flash equivalent to Java's GetDocumentBase() Method?
I'm trying to figure out if I can create events depending on what url the flash object was loaded from.
If the object is loaded at www.Happywifi.com show a happy face animation. If it is loaded at
www.Happywifi.com/question/ Show a question mark face.
I'm interested in flash, it seems like more detailed animations are possible with flash that what we are using in Java.
For the love of God please don't respond with "Why are you doing it that way!". The platform we are working with has a few constraints.
Have a look at the LoaderInfo class (check out the docs)
You could use either the url property or the loaderURL property. Like this:
trace(root.loaderInfo.loaderURL)
You should be able to use the LoaderInfo class which has the loaderURL property.
Something like:
stage.loaderInfo.loaderURL
Which will give you a string of the URL from where the file was loaded. Then you can do your additional processing.
Note that this is not the URL from which the page that was contains this object, but rather the actual URL of where the .swf file resides.
Using flash vars might be another solution to your problem if you can embed different objects on the page depending on what you want.
Is there a way of getting the websites absolute URL (http://www.domain.com/) using Java? because I've googled a bit but I only come across with having to make 2 or 3 classes to create that function =/
Update:
The thing is I am trying to create a crawler that will give me some information and among that I'd like to get the URL of the webpage it's getting the information from. I'm developing this in JAVA and what I meant to say was that I was wondering if there was some getUrl(); or any method like that to get me the Url, because I know it can be done but I've only done it writing a whole other class to retrieve the url and then inherit it and use it further...hope it made it clearer
I'm assuming you just want the domain from a JSP, however you may find you need the entire URL including the prefix, domain, path and parameters. The easiest way to get this quickly is to use the Request object and build it. Have a look here for more info:
http://www.exforsys.com/tutorials/jsp/jsp-request-object.html
Here is Sun's API on the HttpServletRequest interface:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html
The question is not really clear, but I'll make the assumption that you are trying to get the path from within a Servlet.
String realPath = getServletConfig().getServletContext().getRealPath(relativePath);
Could you be more specific? Your question states:
Is there a way of getting the websites
absolute URL (http://www.domain.com/)
using Java?
By "the website" which website are you asking for? I can see multiple ways of interpreting your question:
Given a URL, if there a way to get the hostname portion of it?
Given a relative path, how do you get the full path?
Within the context of a Servlet, is there a way to get the name of the deployed server?
etc...