How to get internal content of jsf component? - java

I have a component's library and this library has Chart component. Chart is actually a jpg image.
I need to access this image. I need some basic tips where to search that image, maybe with examples based on some wellknown libraries like Tomahawk.

You could try using something like jQuery to help you acess the html page's dom structure after the page is rendered via javascript. Getting the image will be as simple as looking up a component by Id

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.

Parsing dynamically growing web pages with jsoup

I'm writing an Android app that parses a web page, filters the image links from it and load them in a WebView.
It works fine for static pages, but i have no idea how to handle pages that dynamically add content as i scroll down, such as 9gag, imgur, Facebook etc.
Is there a solution for this? I guess the dynamic content is handled by JavaScript. Maybe there's a way to call this JavaScript code before parsing the page?
I'd appreciate any advice.
Thanks in advance.
You should try looking at the requests that dynamic pages make.
All of them use a pattern of dynamic pagination, or a cursor.
Imgur for example issues requests with an url like this.
https://imgur.com/gallery/hot/viral/page/4/hit?set=0
Where you specify the page and the set is the portion of the page (Normaly they go up to 3)

iText inline svg not locate by coordinates

I've been trying to use batik and iText to create a PDF in my application containing an SVG graph, however I only seem to be able to find examples where the svg is located at some coordinates. I don't want to have the image located at some coordinates however, I'm wanting it to be put into the page, preferably fit to the width of the page depending on whether it is landscape or portrait and be inline with any other content that I might add, have everything wrap around it.
Is this possible? I'm beginning to suspect my wish that somewhere it will start behaving like HTML is going to be in vain.
Many thanks,
Andrew
p.s.I have a working JAVA class to place the SVG on the page as a template, as per this tutorial:
http://itextpdf.com/examples/iia.php?id=263
p.p.s.For people looking for this issue in relation to Vaadin Charts I've tagged the question as Vaadin related also, as that's what has generated my SVG.

Best way to embed exact output from an URL into a JSP

I am working with Liferay and I need to show a preview of HTML output of an URL as an embeded window in a JSP view. I am assessing different possibilities.
Store somewhat the interface to preview as a screenshot image and show it as an embeded image. Good thing is that formatting would be totally the same.
Parse URL output stream with a BufferedReader and clean all html, scripting, body tags with indexOf. Embed images as cid:
Some kind of include, jsp:include or liferay-util:include form direct URL of downloaded temporal HTML output
Any JQuery AJAX $().html() kind of solution
Any HTML-level solution in iframe, applet, frame, appletwindow or whatever if it exists
What do you think is the best or recommended way: simplest, reliable and exact looking? Any code or reference?
And in case I had to send it as a JavaMail Message content into an email direction?
Thank you!!
This should probably be done client-side, in Javascript, or even via iframes. Either put the iframes in the page directly, or have javascript code that generates the iframes, and point the iframes at the URL to be previewed. Keep it simple.

Play Framework: Generate PDF from template that uses Javascript for graphing

I have a template that has some Javascript used to generate graphs in the browser. I would like to use that same template to create a PDF and send as an attachment in an e-mail. In this scenario, there would be no browser/client interaction.
I am using the PDF module that is available from the Play website and I have managed to get the PDF rendering to work. The only issue is that the graphs don't show up in the PDF but all other static text does. I'm assuming the graphs aren't appearing in the PDF due to the Javascript not being executed prior to the PDF generation.
Does anyone have any ideas on how to get around this problem?
Since you are using the Play framework, the easiest way is likely to be using Rhino. http://www.mozilla.org/rhino/ That is Mozilla's implementation of Javascript to run on the JVM, which is what the Play framework runs on. You may have to make some changes to the Javascript, for instance if it uses the browser Canvas API you would have to make a facade object that sends those drawing commands to the PDF drawing object instead of the screen. Or to both places if that is what you want.
You might get a more detailed answer if you give some more information about the Javascript graphing code.
If you won't find better options consider using itext directly. It's a pdf rendering library that is used in pdf-plugin. You'll have to manually rewrite template in terms of pdf generation but you'll have full control of the result.
I donĀ“t know if this helps you, but this is what worked really fast for me.
I transformed the canvas into a PNG with:
var datastring = document.getElementById('myCanvas').toDataURL("image/png");
Then I sent that datastring to the server so that Play generates a PDF and I passed the variable to the PDF Generator
public static void reportPDF(String graphData){
PDF.renderPDF(graphData);
}
My pdf code looks like this:
<body>
<img width="100%" src="${graphData}"/>
</body>

Categories