editing html/webpages in java - java

I want to create a java application that allows users to import a web page and be able to edit it within the program.
Importing a web page will render it and the components of the page (images, text, etc) will be editable or draggable, allowing the user to re-layout the components.
For example, the user can load a web page that has an image header, but decides to have it at the bottom of the page. They can simply click and drag the image down and the html will be reformatted appropriately. It is basically a WYSIWYG html editor...
Will this be a difficult task? I am stuck at how to parse the web page into draggable components and being able to export the html after all the edits.
From what I can see, I'd need wrapper classes for html components and a way to keep track of all the changing positions and objects, but I could be wrong. Are there any helpful tools for this task?

I think creating something from sctratch will be difficult. But you can use Eclipse Web Tools Platform (either just by installing it or by developing your own plugin/distribution based on that). It has a fairly good HTML Editor/Web Page Editor which has WYSIWYG features.
EDIT: Also this question has some tips: Java WYSIWYG HTML editor

Related

Easiest way to render HTML from String in Java

I need to render HTML page from a Java String. The String contains a full HTML page which may include CSS and Javascript. I know that some CSS/script reference may missing because I only has the html, so it's not a problem.
I have tried using JEditorPane, but it only works for very simple HTML. If it can't render, it will display nothing.
Is there any library I can use?
You can use the Desktop class. It will open the default browser of your platform.
Read the section from the Swing tutorial on How to Integrate With the Desktop Class for more information and working examples.

Use all word functionalities in jsp

I want to create my jsp page which contains word like functionality where user can add text, save them, do track change function. change fonts and color. Is there any plugin or java script plugin available to implement this kind of functionality in project.?
you can use CKEditor for the same.
CKEditor will give you all the functionality like word file.
CKEditor.com
use tinyMCE (http://www.tinymce.com/)
to display word-like editor.
sample: http://www.tinymce.com/tryit/basic.php
Use tinymce which is a javascript plugin that does text wysiwyg editing

how to take print out of JSP page rendered on browser from code behind

I want to take print out of the rendered JSP page using serverside Java code.
I am also using JSF tags in my JSP page.
Currently I am using JavaScript code, but want to get rid of using client side scripting because it won't work if user disables JavaScript in browser. I am using
window.print();
Is there any way to do without JavaScript? If yes, I also would like to set the default printer and not to display print dialog box and take print using the default printer.
There (fortunately) is no provision that an HTML page can trigger a print dialog or so.
You could provide a link to popup window with a print-friendly copy of the page. Or a link to a PDF copy of the page. With JSF both are (with due effort) possible. (Don't ask me specifics though.)

Framework to facilitate editable, dynamic, SEO friendly product pages on open source enterprise Java stack?

Let me outline the problem space. I want to create a SEO friendly page that contains dynamic information, but also has areas of information that are easily editable by HTML content editors (NOT programmers) outside of the normal development lifecycle (I'll call this content 'static' content). For example think of a product page that has fluffy content about a product and some pictures on top (the static content) , and then at the bottom real-time dynamic search results from our site for that product (the dynamic content).
Some constraints:
AJAX is not an option for the dynamic portion (spiders will not get the dynamic content)
an IFrame is not an option for the dynamic portion (dilutes benefit of SEO)
the static content should be easily editable at any time by someone outside of development, and the changes should take effect in a timely manner (real time is not necessary, but they should not need to wait until we restart the webapp servers, for example).
these pages will be hit hard so performance and system impact is a factor (for example going to the database or file system for content on every page hit is not reasonable).
What I am thinking is that the entire page needs to be a standard dynamic servlet, with customized areas of HTML that the content editors can somehow edit. It is this editing aspect that I am looking for suggestions on. I could solve the problem with text files that are available on our NAS in a shared location to both the content editors and the webapp server cluster, and are read in by the webapp servers and cached at page access and pushed to portions of the view layer, but I'm hoping there is something out there that makes this a bit less hackish or at least does some of the plumbing for me that could plug into our view or controller layer.
Of course if there is a way to keep the entire page static, but pull in some dynamic data in a way that spiders will see it as part of the same page, that would be ideal.
Notes on technologies:
- we use an open source java stack with Velocity as the view layer to serve our dynamic servlet content
- Apache serves all static html pages
you may want to look at clickframes, or at drupal- the first is a way to write up pages in xml, that then get generated into a site;
the second is a portal toolkit.

Viewing HTML inside Applet without using JEditorPane

I have a small (500kb) swing applet that displays very simple/limited set of small HTML page(s) inside it with JEditorPane, however this does not seem to work 100% fluently, some customers get a blank page displayed without any java exceptions. The page works OK from my machine. I need a more reliable way to show HTML page to all our users.
Any ideas if there is a small + free class to use instead of JEditorPane
OR is there an easy fix to make it more reliable (non blank)
private JEditorPane m_editorPane = new JTextPane();
m_editorPane.setEditable( false);
m_editorPane.setBackground(new Color(239 ,255, 215));
m_editorPane.setBounds(30,42,520,478 );
m_editorPane.setDoubleBuffered(true);
m_editorPane.setBorder(null);
m_editorPane.registerEditorKitForContentType("text/html", "com.xxxxx.SynchronousHTMLEditorKit");
m_editorPane.setPage(ResourceLoader.getURLforDataFile(param.trim()));
Although I haven't used it before, Lobo is an open source web browser for Java with support for HTML 4, Javascript and CSS 2.
Compared to the JEditorPane which only has support of HTML 3.2, it seems like Lobo may be a better bet for loading modern web pages.
AFAIK, JEditorPane is a very primitive HTML component: it is confused by CSS and knows nothing about JS.
I doubt you will find a "small + free" class doing better, HTML parsing and displaying isn't a simple business, even less today.
Perhaps it is better to let the big names in the business to take care of this task, ie. using Internet Explorer or Mozilla components (depending on what is available, etc.): JDIC: Embedding a Web browser in Java.
I've recently POC-ed several java HTML rendering solutions. We decided on JEditorPane because we really need to minimize the size of our jar and it's built into Swing. However, the best library I came across was Flying Saucer. It doesn't have any js support but it's rendering quality and api is top notch, and it's "free" (LGLP), 100% Java, and only about 1mb (still too big for us, but small compared to other options). However, it only renders strict XHTML (all attribute values have to be quoted, all tags properly formed), but that may be OK depending on your needs (and HtmlCleaner or some other such utility may help towards that end).

Categories