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
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.
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/
Related
As I train myself on Selenium, I'm using Page Object Model as my design. My practice site is https://www.beeradvocate.com (I like beer and it's presenting some testing challenges I was looking for).
Once such instance is a page overlay or modal window.
I know in POM each page has it's own Class where the page objects are located and the corresponding methods/actions to be taken upon them. Furthermore, if I click a link that navigates to another page, that would return a new page object in the function such as:
return new HomePage();
When the Login link is clicked it generates an overlay modal window. It seems that Frames aren't treated as their own Page Class. It takes a switchToFrame() action. Would the same apply for this overlay? Perhaps just a getWindowHandles() action to navigate to it?
I'm working on this too, and the main problem is that you need to find a way to login to the website. If you are not logged in, you can get only actually receive the first 25 reviews..
I would suggest creating a separate class to represent your modal, especially if it's shared by other pages or may be moved out of that page one day.
But if the modal is super-simple and only included on one page and really specific to that page, then it could be represented by a group of functions within that POM. However you'd need to recognise those methods as a "region" or a sub-group in some way, like namespacing the methods, or using decorators, which I always think in OO terms smells like there's a sub-object here which needs dividing out!
Dividing and composing is pretty cheap in Java so there's not much penalty. But having a big page object with tons of "sub components" can get messy. It probably depends on how well sub-structured the site itself is which will guide your decision. Like if the selector for the modal is relatively clean and separate from the host page itself, it's less "owned" by the page.
This similar answer points out that a "POM" is more of a module reprentation than an entire "page" (whatever that means these days!).
https://stackoverflow.com/a/47141290/209288
This answer also asks the same question.
https://stackoverflow.com/a/49002231/209288
I came looking for a similar answer, and have just made my mind up to decompose my modals, while reading these discussions. (So my answer is based on 15 minutes of thought, not experience!)
How can i get the page URL in single-approver-definition.xml in the e-mail template that is used to send an e-mail to the content creator once the reviewer approves or rejects the submission. The existing xml is as follows:
<template>
Your submission has been reviewed and the reviewer has applied the following:
${taskComments}.
</template>
I tried ${serviceContext.getAttribute("contentURL")} and it didn't work.
I want to be able to do - Your submission for ${pageURL} has been reviewed and the reviewier has applied the following: \n ${taskComments}.\n
Any suggestions will be appreciated.
I don't get what variable exactly you want to process in your notification. As I can only assume, you are using it for Web Contents and all interesting variables are stored in two places.
Workflow context variables - they are available directly. Few examples like:
${taskComments}
${entryType}
${userId}
${userName}
...
ServiceContext variables - they are available using $serviceContext. Few examples:
$serviceContext.getAttributes().get("version")
$serviceContext.getAttributes().get("articleId")
${serviceContext.getPortalURL()}
...
For all interesting variables check this url https://www.liferay.com/web/igor.beslic/blog/-/blogs/workflow-in-action-kaleo-workflow-context-variables Some could change already, however most of them is working fine for current version.
Content changes might be made on a page, they can also be triggered through Control Panel (or the API for that matter). When you're in a workflow, you typically don't have this context any more - if you find it somehow I'd not rely on it to be there. A workflow is unrelated to the UI and pages.
Also, an article might be submitted on one page, where it might be replaced/removed before it's even approved. In that case the link wouldn't help.
What might work is to check the concept behind "Web Content Display Pages" (if your article has them configured and you deal with web content). But the mechanics will vary depending on the actual content type you're dealing with. And content that goes through workflow might not be displayed on any page at all (e.g. when submitted through Control Panel) or on many different pages (either explicitly - Web Content Display - or implicitly - Asset Publisher).
#tomic basically provides pointers to what you have, I'm only reasoning why your initial problem is problematic to solve at best - it's not fully specifiable.
I have been developing an AJAX web application using GWT. I've read several blogs and forums about this question and left with no clear idea. I understand that GWT is an AJAX application, that supports only stand-alone web application. By stand-alone, I meant GWT to be a single web page that would suffice the user requirements. However the use case I have is pretty complex and I'm stuck in this use case that doesn't let me proceed.
My usecase(s) goes like this:
Usecase #1: There is an order entry form where user will enter a search string to search for a particular item. With GWT, I could display the result in a table (say celltable). However, when I click a column in the cellTable, I want the value of the column to be sent to the server and display another page that will display only the details of the selected column. I'm not sure how to accomplish this.
Usecase #2: Let's say the web application I develop is called "InventoryControl" and I have different requirements such as:
display Available stock
display Order stock
display Manufactured unit
and Using Java servlets, I could just type http://localhost/availableStock?stockId=1234 on my browser to get the "Display available stock" for the given stockId and then http://localhost:orderStock?stockId=1234 to get the "display order stock" and similarly "display manufactured unit". Is the same possible using GWT? i.e. when I type http://localhost/availableStock?stockId=1234, is it possible to read the parameter being passed and then display the corresponding page?
If these are not meant to be guaranteed by GWT, should I stick with Plain old JAVA servlets/JSP?
Thanks in advance.
Ashok - Please note, what filip suggests above does not require multiple "pages" in the sense of additional html host pages. You can build a panel holding your display of the details, and swap it into the rootpanel of your host in the onSuccess() of your rpc call. The GWT history mechanism allows you to assign anchors to these "places" and provide a mechanism to map these anchors to specific display classes in your code.
GWT already has a mechanism for handling multiple page applications. Have a look at Activities and Places. You can define each page as a place in your application, and use the GWT mechanism to go from place to place at any time. Using places also allows you to easily add tokens/query parameters to each "page", in an OO manner, without having to worry about populating/querying the URL directly. Have a good read of the link!
I have a page called Orders and a page called OrderDetails. As described in the excellent MVP tutorial I'm working with History (with a central ValueChangeListener) and an "event bus" HandlerManager.
I have a handler registered for the event that someone clicks on an order, which basically creates the OrderDetailPresenter, passes in the order ID (which is contained in the ShowOrderDetailEvent), and then calls History.newItem("orderDetails").
This has a couple major disadvantages: This newly created History step does NOT know which order ID was passed in. So for example, if someone bookmarks the order details page (or goes back then forward in their browser), they'll get an empty page with no order details.
So my question is: Should I instead do something like History.newItem("orderDetails?id="+id), and then parse the history token in my value change listener? If so, is there a best practice, an API, or library for parsing and formatting arguments into a string in this way?
Yes, that's what you should do. There is, so far as I know, no library for making this easier.
A bit of advice, though: if at all possible, you should avoid using a scheme that requires you to use percent escapes in your history item string. The reason is that what location.hash returns when location.href ends in, say #%3C#%40 varies from browser to browser. For example, Chrome returns #%3C#%40; Firefox returns #<##. Setting location.hash can have similar browser-specific effects.
GWT's History token mechanism relies on location.hash and doesn't normalize this difference in browser behavior. The end result is that if you use something that requires percent escapes, you will get urls that can't be shared across browsers - this is an issue if on some other page you want to generate links that jump to a particular spot within your GWT app, or if you expect users to share URLs that link to within your GWT app. (or when your user installs Chrome, imports their bookmarks from Firefox that pointed to particular spots inside your webapp, and suddenly the bookmarks don't work as they did before)
For paranoia, I'd avoid putting any ?, #, &, %, <, or > characters in your history token string. However, strings like orderDetails/oid=12313378 should be fine, and cross-browser.
(Edited to clarify that the issue I'm talking about is dealing with having identical URLs work in multiple different browsers, not of having the history token method work at all in each of the various browsers)
I am trying to clear everything on my HTML form when I visit it from a hyperlink entry.
Any ideas? My development language is java.
are you using session-scoped data? if so, close your browser and open it again.
I'm not sure the application is, but one way to accomplish this would be to use JavaScript. For example, if it is acceptable to clear the form every time that page is visited you could write a quick function that clears the form when the page is loaded (i.e., using the onload event).
If you only want to clear the form when the page is hit from that link you could add a param to the URL (e.g., clearForm=true) and use JavaScript to pick up the query string and clear the form when that parameter is present.
This is, of course, a purely client-side solution. For a server-side solution it would be helpful to know what framework you are using.