• 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

Instantiating URL from Html Content Stored in a String

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anyway to instantiate a URL object based on html that is in a String? What I want to be able to do is something like the following:


where htmlContent is a string that holds the actual html content such as

This should easily be doable, but I don't seem to find any ways.

Thanks for taking time to read my question,
Cyrus
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, as should be clear from the documentation of java.net.URL, a URL is a Uniform Resource Locator, in other words it points to content.

Exactly what are you trying to accomplish?

Bill
 
Cyrus Taz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

Thanks for the reply. I'm trying to feed my own content to a URL object for testing purposes. Basically, I want to load my own Html code to a URL, and then run testing on that URL. I know there are libraries such as Jtidy, or HtmlCleaner which can do parsing of the html and loading it, but I really want to be able to load Html to a URL object, rather than use these third party libraries.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you're saying still doesn't make sense--you don't "load content into a URL"--a URL is used to *retrieve* content.

What, *precisely*, are you trying to do?
 
Cyrus Taz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does make sense. I have thousands of pages of Html which are saved into database rather than on the file system, and this is not uncommon practice at all. Now, I want to read these html pages, process them, and then save them back to the database; and we have third party classes and methods which require URL objects to be passed to them. So, one solution is to save them to a temporary file, and create URL based on the path of that temporary file. In this situation (and there are many similar situations), it is of no material where the content comes from; and the process of saving the files of course is very slow compared to the rest of the tests. So, I'm doing the extra step of saving the html content to a file just cause the API of these third party libraries are asking for URL.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it *doesn't* make sense.

URLs don't have content. They *read* content. I'd probably just write a URLStreamHandler, or subclass and override URL.openStream, depending on your requirements. Or just expose them with an internal server and pass a normal URL.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic