Using embedded CSS in Mail - java

I am Generating and sending Mailer using Servlet by replacing placeholders in Mail Template.Can I Use embedded style in Email for Styling as Below instead of inline styling
I am using a Newsletter email which has three place holder for Header Image, Email Body and Email Footer.Now the problem is since the Header Image is with in a anchor tag I am getting a border around the Image.
Is it Possible to get rid of the border by using embedded css
Is there any alternate solution for this problem since the whole ###HEADER_IMAGE### is replaced by Image tag rather than Just image source.
The HTML code is as below.
<html>
<style>
a img
{
border-style : none;
}
</style>
<table width="590">
<tr>
<td colspan="2">
<a href="#" target="_blank">
###HEADER_IMAGE###
</a>
</td>
</tr>
</table>
<div>
###EMAIL_BODY###
</div>
<div>
###EMAIL_FOOTER###
</div>
</html>
Thanks for Reply

Related

Wrong rendering while generating pdf from html in Java

I'm trying to convert simple html to pdf but the styling in my browser is different than the one in pdf. I'm using flying-saucer-pdf v9.1.18. Do you have any idea why?
here is how it looks on web browser and how it looks in the generated pdf:
https://i.stack.imgur.com/MB7DB.jpg
Here is my simple html template:
<html>
<head>
<style>
.aligned {
vertical-align: bottom;
}
.colored {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<table border="1" width="300px" height="300px">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td class="colored">4</td>
</tr>
<tr>
<td>5</td>
<td class="aligned">6</td>
</tr>
</table>
</body>
</html>
From docs:
No support for legacy or "street" HTML, although there are several
open source Java HTML cleaners of varying quality available. We render
well-formed XML; XHTML is a well-formed XML document which uses a
special set of tags. We can't render most HTML "in the wild". At best,
you can "clean up" old HTML with TagSoup or JTidy or similar library
and hope for the best. But without a bunch of work, you won't be able
to use Flying Saucer for a real web browser component. However, note
that's not a technical limitation, just a lack of time and resources.
The "height" attribute of TABLE tag is standard at all, I guess flying-saucer is ignoring it.
See e.g. Setting the height of a table in HTML has no effect

HTML output not being displayed correctly in JEditorPane

I have two tables that are supposed to be side by side on the same line.
One table ("stableTable") is always on the right side of the viewable area, and the other table ("movingTable") can be modified to have its align be left, center or right.
Here's the HTML Code
<html>
<head>
<!--Test Header-->
<style>
body {display: inline; width: auto;}
table {width: auto;}
table, th, tr, td {border: 1px solid;}
</style>
</head>
<body>
<table class="stableTable" align="right">
<tr>
<td>
WORLD
</td>
</tr>
</table>
<table class="movingTable" align="right">
<tr>
<td>
HELLO
</td>
</tr>
</table>
</body>
</html>
When I put this in an HTML file and open the browser it shows up correctly as seen below (both side by side):
But here's the output when I put this same HTML code in a JEditorPane (one is on top of the other):
I'm stumped on this one as I have tried different things in an HTML file that appears correct when I open it up on a browser, but it doesn't in the Java JEditorPane.
Any thoughts?
EDIT:
After looking online a little, it appears that Java has a poor track record for rendering HTML and CSS correctly. I found an article that mentioned downloading flyingsaucer jar file (I ended up downloading the flying-saucer-core-9.0.4.jar version) and it appears to render the HTML side by side as I wanted.
Now my only task is to get it to work within the existing maven project I'm working in with the actual tables.
I believe the issue here is with the JEditorPane itself and that it (and Java itself) has a poor track record of rendering HTML/CSS.
I have found that using flying saucer 3rd party app is the way to go. I have tested with that and it does render the HTML as I want.
Here's the link to the specific flying saucer version that I used https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-core/9.0.4

Header, Footer, Left and Right side Template in JSP

Developing a WebPage with Footer, Header and Left column.
Below is main.jsp code
<table>
<tr valign='top'><td><%#include file='leftside.jsp'%></td>
<td><table>
<tr><td><%#include file='header.jsp'%></td></tr>
<tr><td>Content</td></tr>
<tr><td><%#include file='footer.jsp'%></td></tr>
</table>
</td>
</tr>
</table>
The leftside.jsp code is below
<body bgcolor=blue>
Leftside
</body>
On running main.jsp, I only get the text as Leftside. The background color of blue is not displayed. Am i missing anything? Thanks.
Try to use this:
<body style="background-color:blue;">
Or with adding the apostrophes "blue":
<body bgcolor="blue">
Instead this:
<body bgcolor=blue>
Please use the apostrophes "" and it will work fine
<body bgcolor="blue">
Leftside
</body>

Convert Html String content to java Map

I have the following html string content and i want to convert it into java map using java.
<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div><div dir="ltr"><div><p style="font-family:arial,sans-serif;font-size:13px">Notification for shipment event group "Picked up" for 13 May 14.<u></u><u></u></p>
<div class="MsoNormal" align="center" style="font-family:arial,sans-serif;font-size:13px;text-align:center">
<hr size="2" width="100%" align="center"></div><table border="0" cellpadding="0" style="font-family:arial,sans-serif;font-size:13px">
<tbody><tr><td style="padding:0.75pt">
<p class="MsoNormal">
AWB Number: 8841965182<br>
Pickup Date: 2014-05-13 20:11:00<br>
Service: P<br>
Pieces: 1<br>
enter code here`
I have used jsoup but did not worked.
Take a look at Boilerpipe
A similar question is asked here at SO

Jsoup parsing for nested html

I have an HTML to parse with Jsoup and I lose track after the HTML's weird structure. I can summarize HTML like this(Every line is one level inside of the above):
<html>
<body class="page3078">
<div id="mainCapsule">
<div id="contentCapsule" class="capsule">
<div id="content">
<div id="subCapsule" class="clearFix" xmlns="">
<div id="contentLeft">
<iframe width="635" height="1000" frameborder="0" src="apps/Results.aspx">
#document
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background:none;">
<form id="form1" action="Results.aspx" method="post" name="form1">
<div class="pressContent">
<div class="tableCapsule details">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="even">
Basically I want to get text inside of the tag with class "even". I tried directly calling class even like this:
doc.getElementsByClass("even")
It didn't work. I tried parent > child relationship with selector method. It didn't work either. I tried this inside of second html tag:
doc.select("body.page3078 > html > body > #form1 > th");
Didn't work either. Where am I wrong?
One comment summarizes the start of a solution here:
As mentioned here you need to get the page from the iframe in a separate jsoup parser. This page isn't weird at all - it's just a separate page is shown in the iframe. – Boris the Spider

Categories