• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiating URL from Html Content Stored in a String

 
Cyrus Taz
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic