Posts

Showing posts from 2016

XMPP chat Java client with smack

XMPP Chatting

1. Connection
2. Register User
3. Login
4. Display user list
5. Send message
6. Change password
7. disconnect


import java.io.IOException; import java.util.Collection;
import org.jivesoftware.smack.AccountManager; import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.RosterEntry; import org.jivesoftware.smack.SASLAuthentication; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message;
publicclass ChatClient implements {
XMPPConnection connection;
publicvoid login(String userName, String password) throws XMPPException { ConnectionConfiguration cc = new ConnectionConfiguration("127.0.0.1", 5222, "127.0.0.1");
connection = new XMPPConnection(cc); try { connection.connect(); SASLAuthentication.supportSASLMechanism("PLAIN", 0); connection.l…

How to convert Html to Pdf using itextpdf

In Below code you can can convert pure html to PDF using Itextpdf.
You can specify custom header ,footer and page end content with page no.
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.0.6</version> </dependency>


import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.List;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zkoss.zul.Filedownload;
import com.itextpdf.text.BadElementException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfContentByte; import com…

How to show java web project version using Maven

Image
1. Pom.xml


<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<plugin> <artifactId>maven-war-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId> <version>2.1.1</version> <configuration> <archive> <manifestEntries> <SCM-Revision>${maven.build.timestamp}</SCM-Revision> </manifestEntries> </archive> </configuration>
</plugin>
2. Java code.
publicstatic String getProjectVersion() { ServletContext application = Sessions.getCurrent().getWebApp().getServletContext(); InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF"); Manifest manifest; try { manifest = new Manifest(inputStream); Attributes attr = manifest.getMainAttributes(); returnattr.getValue("SCM-Revision"); } catch (IOException e) { e.printStackTrace(); } return""; }

How to Print in Zk

Image
1. Print full page.

<buttonlabel="Print"onClick="Clients.print()"/>

jQuery export PDF with jspdf api in Zk

1. Download jspdf api https://mrrio.github.io/jsPDF/examples/basic.html

2. Download  html2canvas api. https://html2canvas.hertzen.com/

3. If you need multiple page PDF then download canvas2image api. https://github.com/hongru/canvas2image

Javascript code.


var form; function initPDF(target) { form = $('.' + target), cache_width = form.width(), a4 = [ 595.28, 841.89 ]; // for a4 size paper width and height
} // create pdf function createPDF(fileName) { $('body').scrollTop(0); getCanvas().then(function(canvas) { var img = canvas.toDataURL("image/png"), doc = new jsPDF({ unit : 'px', format : 'a4' }); doc.addImage(img, 'JPEG', 20, 20); var image = new Image(); image = Canvas2Image.convertToJPEG(canvas);
var croppingYPosition = 1095; count = (image.height) / 1095;
for (var i = 1; i < count; i++) { doc.addPage(); var sourceX = 0; var sourceY = croppingYPosition; var sourceWidth = image.width; var sourceHeight = 1095; var destWidth = sourceWidth; var destHeight …

jQuery Full calendar implemented in ZK

Image
Full calendar

1. Download http://fullcalendar.io/download/

2. Document http://fullcalendar.io/docs/

3.  Javascript code.

function initCalendar(data, date) { var decodedString = $.parseJSON(Base64.decode(data));
$('#calendar').fullCalendar('destroy'); $('#calendar').fullCalendar('render'); // $('#calendar').fullCalendar('rerenderEvents'); // varobj = $.parseJSON(document.getElementById('json').getAttribute("value")); $('#calendar').fullCalendar({ header : { left : 'prev,next today', center : 'title', right : 'month,agendaWeek,agendaDay' }, defaultView : 'agendaWeek', minTime : "07:00:00", maxTime : "19:00:00", defaultDate : date, selectable : true, selectHelper : true, select : function(start, end) { var title = "New Appointment"; var eventData; eventData = { title : title, start : start, end : end }; $('#calendar').fullCalendar('renderEvent', eventData, true); …