4

This is my first question on Stack Overflow , so if it is bad form please excuse and correct me !

As the Title implies I am trying to implement a light-weight web browser in Java , however I am running into a problem but before I go into details I will provide a brief description of my implementation :

The program consists of the following classes:
GUI (Extends JFrame implements HyperlinkListener) : The graphical user interface
Engine : Does all the actual work
BlackListPolicy (implements CookiePolicy)

I am using a JEditorPane with its content set to "text/html" to display the webpages Whenever the "GO" button or a link is clicked the Engine gets a URL and then JEditorPane.setPage(URL)

So this brings me to the first part of my question :
The browser is working , however only simple html pages are being displayed if I go to Google for example If I click a link it works , it remembers my settings (Cookies) but if a press "Google search" button for example nothing happens , no embedded objects (Flash , applets , etc.) are displayed and other pages are not being encoded properly

My theory is either that JEditorPane can't display such objects and is not a good choice for a web browser , or that I Set the wrong content type for it.

As for part two of my question :
As a cookieHandler I am doing the following:

BlackListPolicy blackListPolicy = new BlackListPolicy();
CookieManager cookieManager = new CookieManager(null, blackListPolicy);

Thus I am using the default CookieStore , which to my limited understanding uses an internal implementation to store Cookies (they are not persistent) which is what I want However if someone would go on what I would call "an extreme browsing session" storing an excessive amount of cookies would that cause any performance or memory issues or does the default CookieStore handle such cases?

Before you ask , yes I am a student but this is not a homework assignment or even something that is related to my current programing Courses , this is something that I want to implement because I noticed that the best way to learn programing is to write programs
I only need Abstract answers maybe with a link that would send me towards the right direction , if you would like me to post my code I would gladly do so

~Thanks

Lucas Zamboulis
  • 2,494
  • 5
  • 24
  • 27
Batreekh
  • 43
  • 6
  • Maybe this would help: web browser embedded into Java http://stackoverflow.com/questions/5199190/web-browser-embedded-into-java – Costis Aivalis Mar 07 '11 at 19:27
  • 1
    For future reference: in this post you have two questions that are orthogonal - so you should have made two different posts (and if you wanted, you could have linked from one post to the other if required, but I don't think it would be required in this case). – Lucas Zamboulis Mar 07 '11 at 19:55

2 Answers2

4

Your settings are not wrong on your JEditorPane as it only supports a small subset of HTML. If you want something better you are going to have to build an entire browser yourself which definitely is not a small project.

jzd
  • 23,473
  • 9
  • 54
  • 76
  • thanks for the quick answer , however if I want something better is there any material that can help me with that ? also what do you think of the second part of my question regarding CookieStore ~thanks – Batreekh Mar 07 '11 at 19:27
  • @Batreekh, I don't have any experience with CookieStore, but I imagine the user would have to do some massive amount of web surfing before you ran into memory or performance issues. – jzd Mar 07 '11 at 19:30
  • I think that some of the stored cookies will be removed if you get close to memory limit. – Alexey Ivanov Sep 11 '11 at 07:12
1

I know this is an old post, but, have you considered using HTMLUnit?

It's a bit complex but I think it's what you're looking for - a fully java based browser library with full JS support.

http://htmlunit.sourceforge.net/

Kijewski
  • 25,517
  • 12
  • 101
  • 143