Saturday, August 30, 2014

How to integrate Dynamic Image at JasperReport using java

This post is help full for integration dynamic image at jasper when your image data in blob or longblob in database.

there is following step to get your desire output:

Step-1: Make your field  in Jasper through palette:

Name:logo
field Class: java.lang.object

Step-2: Drop image box from palette and provide properties as:

Image Expression  :  net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[])$F{logo})
Expression Class    java.awt.Image

Step-3: Java variable
         set logo as java.lang.Object datatype and set image data (byte[]) in logo variable .
              
               private Object logo;

Example:

 Java Code:
 
public class DemoJasperData{

private Object logo;

public Object getLogo() {
        return logo;
    }

    public void setLogo(byte[] yourImagebyteData) {
        this.logo = yourImagebyteData;
    }

}

.jrxml :

<field name="logo" class="java.lang.Object"/>
<image scaleImage="FillFrame">
                <reportElement x="9" y="8" width="100" height="98" uuid="053b21f7-00a3-4387-a6b3-c33475287f4c"/>
                <imageExpression><![CDATA[net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[])$F{logo})]]></imageExpression>
            </image>

Now your dynamic image is ready on jesper Report

Wednesday, July 16, 2014

mailgun_validator.js for email validation

$.fn.mailgun_validator = function(options) {
    return this.each(function() {
        $(this).focusout(function() {
            run_validator($(this).val(), options);
        });
    });
};
function run_validator(address_text, options) {
    // don't run validator without input
    if (!address_text) {
        return;
    }
    // length check
    if (address_text.length > 512) {
        error_message = 'Stream exceeds maxiumum allowable length of 512.';
        if (options && options.error) {
           options.error(error_message);
        }
        else {
            console.log(error_message);
        }
        return;
    }
    // validator is in progress
    if (options && options.in_progress) {
        options.in_progress();
    }
    // require api key
    if (options && options.api_key == undefined) {
        console.log('Please pass in api_key to mailgun_validator.')
    }
    var success = false;
    // make ajax call to get validation results
    $.ajax({
        type: "GET",
        url: 'https://api.mailgun.net/v2/address/validate?callback=?',
        data: { address: address_text, api_key: options.api_key },
        dataType: "jsonp",
        crossDomain: true,
        success: function(data, status_text) {
           success = true;
            if (options && options.success) {
                options.success(data);
            }
        },
        error: function(request, status_text, error) {
            success = true;
            error_message = 'Error occurred, unable to validate address.';
            if (options && options.error) {
                options.error(error_message);
            }
            else {
               console.log(error_message);
            }
        }
    });
    // timeout incase of some kind of internal server error
    setTimeout(function() {
        error_message = 'Error occurred, unable to validate address.';
        if (!success) {
            if (options && options.error) {
                options.error(error_message);
            }
            else {
                console.log(error_message);
            }
        }
    }, 30000);
}

email validation


Here we use an "mailgun_validator.js"  for email validation .  

 //Html Code  

<form>
      <div>
        <label for="email">Email address</label><br>         <input type="email" name="email" id="email">         <div id="status"></div>       </div>       <div>         <button type="submit" id="validate_submit">Validate</button>       </div>  </form> //java script      <script src="mailgun_validator.js"></script>
// document ready
      $(function() {   // capture all enter and do nothing         $('#email').keypress(function(e) {           if(e.which == 13) {            $('#email').trigger('focusout');            return false;           }         });  // capture clicks on validate and do nothing         $("#validate_submit").click(function() {           return false;         });  // attach jquery plugin to validate address         $('#email').mailgun_validator({           api_key: 'MAILGUN_PUBKEY', // replace this with your Mailgun public API key           in_progress: validation_in_progress,           success: validation_success,           error: validation_error,         });       }); // if email successfull validated
      function validation_success(data) {
        $('#status').html(get_suggestion_str(data['is_valid'], data['did_you_mean']));       }  // if email is invalid       function validation_error(error_message) {         $('#status').html(error_message);       } // suggest a valid email       function get_suggestion_str(is_valid, alternate) {         if (alternate) {           return '<span class="warning">Did you mean <em>' + alternate + '</em>?</span>';         } else if (is_valid) {           return '<span class="success">Address is valid.</span>';         } else {           return '<span class="error">Address is invalid.</span>';         }       } MAILGUN_PUBKEY: pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7

 

Wednesday, January 29, 2014

Java keyword: assert