When writing a internet browser in java - java

I came across the problem of not having an editor kit that could not handle some parts of a webpage. Examples include javascript and css. Does anyone know where I can find an editor kit that is suitable for that?
Also I'm curious as to what programming language browsers like Google Chrome and IE use.

Try Aptana Studio

There are already miscellaneous browser projects using java. The java Scripting API supporting undermore JavaScript (JS sometime named ECMAScript) will be worth looking into. You should on reading the HTML, construct a DOM tree and interprete <script> blocks, which may operate on the DOM or write HTML you have to read from.
The EditorKit in swing builds a too simple non.tree StyledDocument, which you have to bridge.
The way to proceed would be to first not use swing output but immediately generate a DOM/generated HTML.

Related

Can you make JEditorPanes understand advanced HTML and CSS?

Is it possible to make a JEditorPane understand more advanced HTML and CSS?
I mean, when you enter HTML or CSS such as <button>, <progress>, or most other tags, it does not understand them. Is there any way to make it understand and display more complex and advanced coding? If it is, how would I do it?
Thanks!
Yes. Java 7 EE has HTML5 functionality although I'm not sure about specific tags. Also, there are external packages, like one from Intel freely available and you can always extend the functionality yourself in some way or another.
Edit: addendum to my 2nd suggestion (implementing the topic in the linked question)
The Intel JWebEngine (which might be what you are already looking for) documentation says:
What are the advantages versus the built-in Java HTML editor?
The built-in Java HTML editor of Java is very limited. It only
supports HTML 3.2 with some features of HTML 4 and CSS. The support of
CSS is wrong in many cases, especially when it comes to cascading
selectors. The text is often too small and on many web sites Java only
shows an error instead of a incorrectly formatted page.
Here are some further differences:
JWebEngine can display the ACID 1 test correctly - Java does not
JWebEngine can display the ACID 2 test partly - Java only displays a
blank page because an error occurs
JWebEngine basically shows HTML pages like a browser with JavaScript disabled
In cases where the CSS
and HTML specifications are not explicit about implementation
JWebEngine is designed to mirror Mozilla FireFox's behavior.
No it just understands basic HTML 4.
You could use a JavaFx WebView inside a JFXPanel

Is there any Eclipse API to parse CSS and HTML?

Eclipse provide very nice aproach to build AST tree from PHP, JavaScript and JAVA code. You can go over every each element of language recieving positions of that elements + it validate code and you have positions of syntax errors.
I tried to find similiar API for HTML and CSS but without successes. I'm sure that it exist, because Eclipse support highlighting and code assist for that languages. Will be happy to receive any advice!
Have you looked at the WebTools source editing project?
http://projects.eclipse.org/projects/webtools.sourceediting
They offer editors for CSS and HTML. The Validators are alo part of this prpject I think.
As HTML and CSS is different from programming languages, you may not get an AST similar to Java, adn the derived PHP and Javascript plugins.
Your question maybe easier to answer when you state why you need access to the AST: erro checking, automated code refactoring, ...
If you cannot find it in those projects, you can have a look at ANTLR, where you create you own language definitions, compile them to Java. These are then quite easy to put into an Eclipse Builder, so you can have access to the AST you created for the files you're editing.
I believe Eclipse for Java EE is what you want. It validates HTML code, I'm not sure about CSS
I use eclipse for php. This distribuition does edit html, css, javascript files : http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr
JSOUP is a simple HTML/CSS parser
For CSS alone you could try the GWT CSS abstraction

Replacement for Jaxer for parsing/crawling websites

I have an old tool an (ex-)colleague wrote a few years back with Jaxer, that I'd like to replace/rewrite.
Jaxer is an (abandoned) server-side framework based on a headless Mozilla/Gecko-Browser allowing you to use JavaScript and the DOM server-side.
Since Jaxer is abandoned and because I have big problems installing and running Aptana Studio 1.5 with Jaxer on a new computer, I'm looking for a library/framework/something on which I can base a new version.
This tool is only run locally inside Aptana Studio (the IDE for Jaxer) and was never intended to be an actual web app. It crawls our customers websites by loading them page by page into the server-side Mozilla. In order to do that it uses jQuery and predefined CSS selectors to find the links in the menus and parse other information out of the pages. The final result is basically a glorified sitemap.
I'd like to keep this modus operandi if possible and continue using jQuery/JavaScript/the DOM to load and parse/access the pages, but it can be wrapped in a framework based on another language such as Java. I considered writing something based on Gecko myself, but that seems a bit over the top, so I'm open for an other suggestions.
As far as HTML crawling/parsing goes:
http://ccil.org/~cowan/XML/tagsoup/
or
http://jsoup.org/

When JEditorPane will not do. JRex, JRex wherefore are thou JRex?

IDEA: Implement a recent web browser into a java application (for saved offline, non server content).
The question is this: can I have a java application implement a webbrowser with jquery / html / css support within a java program?
So I am asking anyone who has played with JRex for advice: I want to know how complicated will it be to integrate an open source webbrowser into java. I am not all that keen on the idea of compiling Mozilla from source build. Is there a ready made compiled version?
Is there a simplified method to have latest compiled version (most current in terms of support for HTML css & javascript), and integrate that into an application?
Also: I appreciate the amount of work required to support for HTML4 nevermind 5, and CSS2 compliance. How close is JRex to that?
Application: My intention with the webbrowser is to render a webpage from offline content. It will not need to be online content, and will simply be for file based displays = e.g. file:///C:...
Does the webbrowser have to be wrapped into a server to function, e.g. to pass files to the browser to render is how complicated? I am not keen to have to implement Jetty or another server type application just for this.
If JRex is not the solution... what then? Is it possible to start a browser implementation within Java and can Java interact with the information and traverse the Dom?
Or alternatively is there .hta equivalent in recent browsers like firefox?
If you need to have the embedded browser interact with your application code, you could try the SWT Browser control, it's actually maintained as opposed to JRex. Browser uses either WebKit or Gecko or embedded IE as appropriate, or lets you choose which one you want, so it should run jQuery and familiar Javascript. And since SWT is a JNI library to begin with they probably already have guidance on how to deploy an app that uses JNI.
You can feed HTML into the control from a string (example) or a java Url - which can point to local files or resource files in your JAR, which I assume will let you split your app into different files.
To call Java code, you need to expose it as Javascript functions. example
To manipulate the HTML from Java code, you need to call Javascript functions from Java. example
To make the previous two tasks easier, you might want to look into a JSON library to simplify passing around complex data.
Does it have to be implemented within a Java program? Could you let the user use the default browser on their machine (ie does it matter what browser)?
If not would use the Java Desktop API.
if (desktop.isSupported(Desktop.Action.BROWSE)) {
txtBrowserURI.setEnabled(true);
btnLaunchBrowser.setEnabled(true);
}
If you are using Java 1.5 try http://javadesktop.org/articles/jdic/

browser plug-ins in java based browser

I have a Java Browser and want it to use plugins like a flash-plugin within it (similar to the plugin functions in Firefox).
How can I do so?
You cannot write browser plugins in Java. Don't try.
Provided that your browser supports plugins, whether it's written in Java, HeadFuck or plain old Haskell, you should be able to tell it how to recognize flash content, and give it the necessary wrapper functions to your plugged-in renderer.
So you'll need to carefully read two pieces of documentation: that of your browser, and that of the target renderer.
Unless we get more info on exactly what browser you're talking about, and about what plugin your talking about, there's not much more to say...
The purpose of the JEditorPane is to process "text/html" which is the default, "text/plain", and "text/rtf". JEditorPane is mostly used for displaying HTML. The RTF support is not too complete.
Many people expect a self made browser based on JEditorPane to be able to execute JavaScript, which is not the case. You could do that with the Lobo Project though. Lobo browser allows you to use plug-ins too. I reckon that a Flash plug-in would be fairly complicated to create.
Take also a look at the Mozilla Widget for Java Swing MozSwing.

Categories

Resources