• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to break up url in java?

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i have to need two string from one url how can i do that suppose this is a url  http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-edit&clip_id=75.2017-08-22.9&target=wb2¬b=1&img=//192.168.2.18/pm8/data/pmin/2017/201708/20170822/cuts/3667.jpg
in this url i have to find img value & target value at same time  
       
with this codition im able to find img value but i also need target value
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Search for "&target=" (and possibly "?target=", since it might be the first parameter). Then copy everything until the next "&" or the end of the string, whatever comes first.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if im running another if inside this if its not running
like this if (trgurl.matches("target="){

                int n = trgurl.indexOf("target=");
                     //String str1 = Integer.toString(n);
                     System.out.println(n+7);
                     int len = trgurl.length();
                     System.out.println("string length is: "+trgurl.length());
                     System.out.println(trgurl.substring(n+7,97));
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you didn't say what this code does ("it is not running" is a very unhelpful error description), the first thing that springs to mind is the "97" - where does that come from, and what is it supposed to accomplish? The parameter only extends as far as the following "&", no?
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its working now its just for find target value in the url  
if (trgurl.matches("(.*)target=(.*)")){
                     int n1= trgurl.indexOf("target=");
                     //String str1 = Integer.toString(n);
                     System.out.println(n1+7);
                     System.out.println(trgurl.substring(n1+7,97));
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but the problem is that i want to stop the navigated url in one webview and open that in another webview? is there any method or way to stop navigation in webview
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to stop worker state in swing  when the state contain img in url .
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-headlines&do=subject&subject_uid=Z10 i want to stop the navigation or worker.state at this url so it cant open the next url on clicking the link in pervious url i.e http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-edit&clip_id=69.2017-08-23.42&target=wb2¬b=1&img=//192.168.2.18/pm8/data/pmin/2017/201708/20170823/cuts/3696.jpg
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
like in vb for cancel the navigation there is method called cancel = true
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i find worker.cancel(true); but it is stopping complete webvciew but i want to stop particular url.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the documentation for the cancel() method? What does it say? Please supply a link to it.
Do not think there is a relationship between something in Java® and something with a similar name in VB; the two are different languages and the two things probably mean something different. Are you sure it is safe to use cancel(true)?

What do the links in your previous post mean? Since they have 192 in, they are probably not accessible to us.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://pmms.ankiti.com/?module=mm-pm-edit&clip_id=37.2017-08-23.18&target=wb2¬b=1&img=//192.168.2.28/pm8/data/pmin/2017/201708/20170823/cuts/1541.jpg this is alternate url for access
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://docs.oracle.com/javafx/2/api/javafx/concurrent/Worker.State.html and this is a cancel method documentation
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
campbell you can access this url which i had mention above now but you need to login and id is -rajveersingh.kumar5@gmail.com password-rajveer405
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you That method would appear to be all right to use. Don't know any more about where you are making the Worker thread stop.
 
Rancher
Posts: 387
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To parse the URL, I advise looking at this StackOverflow topic:
 https://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection

I copy and pasted part of the StackOverflow answer here, but I'm sure I'd just lose some context when I did that, so best just to follow the link and study the question and answer there.

I think, in this case, it is best to follow the template of the StackOverflow answer, rather than to write your own routine for parsing URLs, as the format of URLs can be more complicated then you expect, so using an widely accepted answer as a base will help you achieve a more robust solution.

Similarly, for the other question revealed in the thread regarding How to prevent navigation in WebView and perform some other action instead?, see:
 https://stackoverflow.com/questions/15555510/javafx-stop-opening-url-in-webview-open-in-browser-instead
Note that the accepted answer advises DOM level intercepts, rather than the solution of monitoring the location property for changes and performing actions based upon that (as user testing showed that monitoring the location property and making changes to the location in the change listener to be unreliable in some cases).  The advised solution (again copied from StackOverflow) was:

The comment on the answer is also important:
"This is the best way. Add a listener on webView.getEngine().getLoadWorker().stateProperty(), check for State.SUCCEEDED, and then call the above, making sure to use the org.w3c classes where names conflict with the JavaFX namespace (as in the case of Node, Event etc.). "
Also note that the event filter calls evt.preventDefault() to stop the actioning of a default action (navigation).  That seems a superior solution (to me) to trying to monitor the WebView worker state and cancel it.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks john but i have to cancel the particular url in webview in application and worker state is cancelling complete site
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://pmms.ankiti.com/?module=mm-pm-edit&clip_id=37.2017-08-23.18&target=wb2¬b=1&img=//192.168.2.28/pm8/data/pmin/2017/201708/20170823/cuts/1541.jpg just check this url login id - rajveersingh.kumar5@gmail.com password- rajveer405 than after login set the workdate after that go to headline link in that go to any section and in that sections choose any e paper after that you will see edit page i dont want that edit page in same webview i want in another webview.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see exactly like this after finance page which is in 1st webview after that edit page come in same webview but i have to stop the navigation in first webview and open that edit page in second webview
exact1.png
[Thumbnail for exact1.png]
For refrence
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to disable selectable links within the webview
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to use a condition like if url contains target than it should stop the navigation and open that page in another webview
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my code just change the url for debugging
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> thanks john but i have to cancel the particular url in webview in application and worker state is cancelling complete site

The solution I posted cancels navigation from particular tags (the a anchors).  It does this via looking up elements in the document.  If you want to cancel a particular link to a url, then you could look up the DOM element for that url anchor by ID (if it has one) and cancel that using a variation of the solution I posted, it would not cancel the "complete site".

Another potential solution is to use a JavaScript call to prevent navigation (it's essentially the same thing, although it looks completely different, as it operates on the same underlying document model that the Java code I posted does).
 https://gist.github.com/jewelsea/3077942
If you did it with JavaScript though, you would still need to callback into Java to open the new WebView location, so it is probably simpler to do it in Java.

- John
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but in anchor tag we can pass a complete url but i have to pass if url contains target then it should stop navigation because there are many url with target
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know its silly john but i'm not able to apply your solution in my program
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain exactly what is going wrong. We can only help if we know the tull details.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 as im applying john solution im getting error event target cannot find symbol compile time error
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basically how can i target the url with target =wb2  so that i can stop navigation of each url.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  this is how i applied john solution but im getting error
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is error log run:
http://192.168.2.18/a3/host/pmms.ankiti.com/?
http://192.168.2.18/a3/host/pmms.ankiti.com/?
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-workdate
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-workdate
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-ini&noob=1&noshell=1&ini=rajveersingh&output_format=html
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=home&ini=rajveersingh
http://192.168.2.18/a3/host/pmms.ankiti.com/?win=IBB&module=mm-pm-headlines
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-headlines&do=subject&subject_uid=Z10
http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-edit&clip_id=45.2017-08-29.40&target=wb2¬b=1&img=//192.168.2.18/pm8/data/pmin/2017/201708/20170829/cuts/1819.jpg
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: document.getElementsByTagName
at verticalseperator.HV$1.changed(HV.java:102)
at verticalseperator.HV$1.changed(HV.java:91)
at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.web.WebEngine$LoadWorker.updateState(WebEngine.java:1287)
at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1398)
at javafx.scene.web.WebEngine$LoadWorker.access$1200(WebEngine.java:1280)
at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1267)
at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:2499)
at com.sun.webkit.WebPage.fwkFireLoadEvent(WebPage.java:2343)
at com.sun.webkit.Timer.twkFireTimerEvent(Native Method)
at com.sun.webkit.Timer.fireTimerEvent(Timer.java:83)
at com.sun.webkit.Timer.notifyTick(Timer.java:64)
at javafx.scene.web.WebEngine$PulseTimer.lambda$null$49(WebEngine.java:1228)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748)
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is running fine but the problem is to disable the particular link and its disable the particular link
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see the screenshot this is my problem in application the url is navigating above webview also and down webview also thats why i have to stop the above one from navigating away.
navigate.png
[Thumbnail for navigate.png]
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to admit I didn't read all your posts and follow all your links Niti.

But responding to one of the comments you made...
  "i have to use a condition like if url contains target than it should stop the navigation and open that page in another webview"

The following code will intercept clicks on a bing search engine link, cancel the navigation in the WebView in which the link was clicked and instead open the link in another WebView.  It uses the HTML DOM APIs that I referenced in an earlier post and stated was my preferred recommendation of how to solve this problem.  The lookup is done based upon a id defined for a href element, if you don't have an id and cannot control the source webpage to add one in, then you could still use the java HTML dom APIs to determine if the href string of the clicked element contains your target string, it would just be a bit more complicated to do so (and I haven't provided code for that).

Also, note that if you actually have a target attribute, like the following link:
 <a href="https://www.w3schools.com" target="_blank">Visit W3Schools</a>
The target attributes tells a html browser to open a URL in a new window or tab.
WebView has a handler for that:
 https://docs.oracle.com/javase/8/javafx/api/javafx/scene/web/WebEngine.html#setCreatePopupHandler-javafx.util.Callback-
Within the popuphandler you can open the url in a new WebEngine instance (or another existing WebEngine instance).
That may be a very clean way of accomplishing what you want if the scenario works for you.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks john great thing i dont know that we can use html like this but my problem is regarding the matches of url means there are many url in my application which have the target so how can i give so many url in href to stop navigation thats why im thinking to use if condition like                              if (trgurl.matches("(.*)target=wb2(.*)")){ navigation code } i hope now you will able to understand me properly
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-edit&clip_id=66.2017-08-30.60&target=wb2¬b=1&img=//192.168.2.18/pm8/data/pmin/2017/201708/20170830/cuts/3741.jpg

2.http://192.168.2.18/a3/host/pmms.ankiti.com/?module=mm-pm-edit&clip_id=65.2017-08-30.62&target=wb2¬b=1&img=//192.168.2.18/pm8/data/pmin/2017/201708/20170830/cuts/3601.jpg     like this there are hundred of url which contain target means the pattern match of url which the have similar in it so  thats why using that word if url == target
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suppose if url contains img its doesnt mean the target of webengine if you had seen screenshot ihad able to open the same page in down webview also so target is not needed just to stop navigation of particular urls which is having img or target keyword should stop navigating the page i hope its clear
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first webviewl loads and displays a page of links. I need to be able to click a link and have it open its page in the second webview, but not the first webview, which is its natural action.
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What your telling the nodelist and jquery its stops the click action i dont want to stop the click action i just want to stop that page to open in same webview and open in other webiew like target= blank does on click action its open in next window like that only i had to do on click target =webview2
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
means in one browser/webview link is clicked and open in another browser/webview
 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats why i told you to debug my code you will understand it correctly
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic