Pages

Sunday, January 24, 2016

BarCode Generation Example



Maven Dependencies:
<!-- BarCode generator Dependency -->
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<!-- BarCode generator Dependency -->


Java Code:

package com.dipak;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;

import org.apache.commons.codec.binary.Base64;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;

public class BarCodeGenerator {
static int WIDTH = 150;
static int HEIGHT = 80;
private static BitMatrix getBitMatrix(String barCode) throws WriterException {
return new Code128Writer().encode(barCode, BarcodeFormat.CODE_128, WIDTH, HEIGHT, null);
}

public static BufferedImage toBufferedImage(String barCode) throws WriterException {
BufferedImage img   = MatrixToImageWriter.toBufferedImage(getBitMatrix(barCode));
return img;
}
public static void writeToStream(String barCode, String format, OutputStream out) throws FileNotFoundException, IOException, WriterException {
       MatrixToImageWriter.writeToStream(getBitMatrix(barCode), format, out);
       System.out.println("Code128 Barcode Generated.");
}
public static void writeToFile(String barCode, String format, String filePath) throws FileNotFoundException, IOException, WriterException {
writeToStream(barCode, format, new FileOutputStream(new File(filePath)));
System.out.println("Code128 Barcode Generated.");
}
    public static String generateQRCode(String str)
    {  
        ByteArrayOutputStream qrCodeByteOutputStream = QRCode.from(str).to(ImageType.PNG).stream();                   
        return Base64.encodeBase64String(qrCodeByteOutputStream.toByteArray());
    }
}


reference: http://aboutyusata.blogspot.in/2012/10/generate-code128-qrcode-pdf417-barcode.html

Wednesday, January 13, 2016

Web Services - WSDL to Java

folder/
axis-1.4.jar
axis-wsdl4j-1.3.jar
commons-discovery-0.4.jar
commons-logging-1.1.1.jar
javax.xml.soap-api-1.3.7.jar
jaxrpc-api-1.1.jar
saaj-api-1.3.5.jar

Command to run:

cd /folder

java -cp  *  org.apache.axis.wsdl.WSDL2Java "Url/WSDL"

Wednesday, April 22, 2015

Custom Logger:

package myapp.misc;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;

public class CustomLogger {

    private static String BASE_PATH = "/var/log/custom/";
    private static String CLASS_NAME = "myapp.misc.CustomLogger";
   
    private static Logger customLogger1;
    static {
        init();
    }

    public static void logDebug(String msg) {
        customLogger1.log(CLASS_NAME, Level.DEBUG, msg, null);
    }

    public static void logInfo(String msg) {
        customLogger1.log(CLASS_NAME, Level.INFO, msg, null);
    }
   
    public static void logWarn(String msg) {
        customLogger1.log(CLASS_NAME, Level.WARN, msg, null);
    }
   
    public static void logError(String msg) {
        customLogger1.log(CLASS_NAME, Level.ERROR, msg, null);
    }

    public static void logError(String msg, Throwable throwable) {
        customLogger1.log(CLASS_NAME, Level.ERROR, msg, throwable);
    }

    private static void init() {
        customLogger1 = Logger.getLogger(CustomLogger.class);

        if (customLogger1.getAppender("RollingFileAppender_custom1") == null) {
            RollingFileAppender rollingFileAppender = new RollingFileAppender();
            rollingFileAppender.setName("RollingFileAppender_custom1");
            rollingFileAppender.setFile(BASE_PATH + "catalog.log");
            rollingFileAppender.setLayout(new PatternLayout("%d{yyyy-MM-dd HH:mm:ss,SSS/zzz} [%t] %5p [%C %M() : line %L] :: %m%n"));
            rollingFileAppender.setThreshold(Level.INFO);
            rollingFileAppender.setAppend(true);
            rollingFileAppender.setMaxFileSize("50MB");
            rollingFileAppender.setMaxBackupIndex(100);
            rollingFileAppender.activateOptions();

            customLogger1.addAppender(rollingFileAppender);
        }
        
        if (customLogger1.getAppender("RollingFileAppender_custom1_error") == null) {
            RollingFileAppender rollingFileAppenderError = new RollingFileAppender();
            rollingFileAppenderError.setName("RollingFileAppender_custom1_error");
            rollingFileAppenderError.setFile(BASE_PATH + "catalog_error.log");
            rollingFileAppenderError.setLayout(new PatternLayout("%d{yyyy-MM-dd HH:mm:ss,SSS/zzz} [%t] %5p [%C %M() : line %L] :: %m%n"));
            rollingFileAppenderError.setThreshold(Level.WARN);
            rollingFileAppenderError.setAppend(true);
            rollingFileAppenderError.setMaxFileSize("50MB");
            rollingFileAppenderError.setMaxBackupIndex(100);
            rollingFileAppenderError.activateOptions();
            customLogger1.addAppender(rollingFileAppenderError);           
        }
       
        if (customLogger1.getAppender("RollingFileAppender_custom1_console") == null) {
            ConsoleAppender consoleAppender = new ConsoleAppender();
            consoleAppender.setName("RollingFileAppender_custom1_console");
            consoleAppender.setLayout(new PatternLayout("%d{yyyy-MM-dd HH:mm:ss,SSS/zzz} [%t] %5p [%C %M() : line %L] :: %m%n"));
            consoleAppender.setThreshold(Level.INFO);
            consoleAppender.activateOptions();
            // customLogger1.addAppender(consoleAppender);
        }
    }
   
}

Thursday, March 26, 2015

sendmail using threading...

public static void sendMail(final String mailFrom, final String mailTo[], final String mailSubject, final String mailBody) {

newFixedThreadPool.execute(new Runnable() {
@Override
public void run() {
Thread.currentThread().setName("POST_MAIL_SENDER");
try {
long starttime = System.nanoTime();
log.info("Mailer Starts " + Arrays.asList(mailTo).toString() + ", " + mailFrom + ", " + mailSubject + ", " + Thread.currentThread().getId());
Date authInDate = new Date();
Session session = Session.getDefaultInstance(properties, null);
session.setDebug(false);

Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(mailFrom);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[mailTo.length];
for (int i = 0; i < mailTo.length; i++) {
addressTo[i] = new InternetAddress(mailTo[i]);
addressTo[i].validate();
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(mailSubject);
msg.setContent(mailBody, MAIL_CONTENT_FORMAT);

Transport.send(msg);

String[] headers = msg.getHeader("Message-ID");
String sMessageId = "";
if (null != headers && headers.length > 0) {
sMessageId = headers[0];
}

Date authOutDate = new Date();
log.info(Arrays.asList(mailTo).toString() + ", " + mailFrom + ", " + mailSubject + ", " + sMessageId + ", " + CommonUtility.getTimeDifference(authInDate, authOutDate) / 1000.000000 + ", " + Thread.currentThread().getId());
long endTime = System.nanoTime();
log.info("Mailer Ends Time Taken = " + CommonUtility.getDifference(starttime, endTime));
} catch (Exception ex) {
ex.printStackTrace();
log.error("FAILURE," + Arrays.asList(mailTo).toString() + ", " + ex.getMessage());
log.error("FAILURE," + Arrays.asList(mailTo).toString() + ", " + ex.getMessage());
}
}
});
}

Thursday, February 12, 2015

Utility JavaScript based on JQuery

// Whole-script strict mode syntax
//"use strict";

if (!window.console) {
window.console = {
log : function(s) {
// alert(s);
}
};
}

var app = {
ajax : {},
util : {}
};

(function($) {

jQuery.fn.visible = function() {
   return this.css('visibility', 'visible');
};

jQuery.fn.invisible = function() {
   return this.css('visibility', 'hidden');
};

jQuery.fn.visibilityToggle = function() {
   return this.css('visibility', function(i, visibility) {
       return (visibility == 'visible') ? 'hidden' : 'visible';
   });
};

$(document).on('click', 'table.list_table tr', function(){
app.util.toggleCssClass(this, 'highlightSelectRow');
});

app.ajax.doAjaxCall = function(callURL, dataString, responsDivId, isToShowLoading) {

var showLoading = true;

if(null != isToShowLoading){
showLoading = isToShowLoading;
}

var startTime = +new Date();
$.ajax({
type : 'POST',
url : callURL,
data : dataString,
divId : responsDivId,
startTime : startTime,
beforeSend : function(request) {
if(showLoading){
$('#loading_div_wrapper').show();
}
},
complete : function(request) {
if(showLoading){
$('#loading_div_wrapper').hide();
}
},
success : function(html) {
var endTime = +new Date();
console.log('time required for ajax call =' + (endTime - this.startTime) / 1000.0 + 'sec');
app.util.handleResponse.call(this, html);
},

error : function(xhr, ajaxOptions, thrownError) {
app.util.showErrorMessage('Network is slow !! Please check with IT Support.');
console.log('Network is slow, Pleach check with IT Support  !!! \n' + thrownError);
$('#loading_div_wrapper').hide();
}
});

return false;
};

app.util.handleResponse = function(html) {
html = app.ajax.clearResponse(html);

var id = this.divId;

var isMessagePresent = false;
var isBodyPresent = false;

if (html.indexOf('<div id=\"main_message_div_id\">') !== -1) {
isMessagePresent = true;
}

if (html.indexOf('<div class=\"center_content\" id=\"center_content\">') !== -1) {
isBodyPresent = true;
}

if (isMessagePresent && !isBodyPresent) {
$('#dummy_div').empty();
$('#dummy_div').html(html);
}
else {

$('#' + id).slideDown();

if (id == 'light_box_popup_content_div_iframe_wrapper') {

$('#light_box_popup_content_div').hide();

var element = document.getElementById('light_box_popup_content_div_iframe');
var doc = element.contentDocument;
       if (doc == undefined || doc == null){
        doc = element.contentWindow.document;
       }
doc.body.innerHTML = html;

$('#light_box_popup_div').slideDown();
}else if (id == 'light_box_popup_content_div'){
$('#' + id).empty();
$('#' + id).html(html);

$('#light_box_popup_content_div_iframe_wrapper').hide();
$('#light_box_popup_div').slideDown();
}else{
$('#' + id).empty();
$('#' + id).html(html);
}
}

if (isMessagePresent) {
$('#main_message_div_id_wrapper').show();
setTimeout("$('#dummy_div').empty();$('#main_message_div_id_wrapper').slideUp()", 4000);
}
};

app.util.showHideDiv = function(id, effect) {

var obj = document.getElementById(id);

if (obj) {
if (effect == 'TOGGLE')
$(obj).toggle();
else if (obj.style.display == 'none') {
if (effect == 'FADE') {
$(obj).fadeIn();
}
if (effect == 'SLIDE')
$(obj).slideDown();

}
else {
if (effect == 'FADE')
$(obj).fadeOut();
if (effect == 'SLIDE')
$(obj).slideUp();
}
}
};

// Removes leading whitespaces
app.util.LTrim = function(value) {
var re = /\s*((\S+\s*)*)/;
return value.replace(re, '$1');
};

// Removes ending whitespaces
app.util.RTrim = function(value) {
var re = /((\s*\S+)*)\s*/;
return value.replace(re, '$1');
};

// Removes leading and ending whitespaces
app.util.trim = function(value) {
return app.util.LTrim(app.util.RTrim(value));
};

app.util.isEmpty = function(inputStr) {
if (null == inputStr || '' == app.util.trim(inputStr)) {
return true;
}
return false;
};

app.util.isNumber = function(inputStr) {
return !isNaN(parseFloat(inputStr)) && isFinite(inputStr);
};

app.util.replaceNonAlphaNum = function(inputStr) {
alert(inputStr);
if(!isEmpty(inputStr)){
return inputStr.replace(/[^a-zA-Z0-9-]/g,'');
}
alert(inputStr);
return inputStr;
};

app.ajax.clearResponse = function(html) {
if (html.indexOf('.dtd') != -1)
html = html.substr(html.indexOf('.dtd') + 6, html.length);

return html;
};

// Replaces commonly-used Windows 1252 encoded chars that do not exist in ASCII or ISO-8859-1 with ISO-8859-1 cognates.
app.util.replaceWordChars = function(text) {
   var s = text;
   // smart single quotes and apostrophe
   s = s.replace(/[\u2018|\u2019|\u201A]/g, "\'");
   // smart double quotes
   s = s.replace(/[\u201C|\u201D|\u201E]/g, "\"");
   // ellipsis
   s = s.replace(/\u2026/g, "...");
   // dashes
   s = s.replace(/[\u2013|\u2014]/g, "-");
   // circumflex
   s = s.replace(/\u02C6/g, "^");
   // open angle bracket
   s = s.replace(/\u2039/g, "<");
   // close angle bracket
   s = s.replace(/\u203A/g, ">");
   // spaces
   s = s.replace(/[\u02DC|\u00A0]/g, " ");

   return s;
};


app.ajax.doAjaxCallWithForm = function(formId, responsDivId) {
var str = "";
var arrElements = [];
var arrElementsValue = [];
var fobj = document.getElementById(formId);

for ( var i = 0; i < fobj.elements.length; i++) {

if (null != fobj.elements[i].type && undefined != fobj.elements[i].type && 'undefined' != fobj.elements[i].type && !$(fobj.elements[i]).hasClass('hidden')) {

if (fobj.elements[i].type.toLowerCase() == "text") {
str += fobj.elements[i].name + "=" + encodeURIComponent(app.util.replaceWordChars(fobj.elements[i].value)) + "&";
arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
else if (fobj.elements[i].type.toLowerCase() == "checkbox") {
if (fobj.elements[i].checked)
str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";

arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
else if (fobj.elements[i].type.toLowerCase() == "radio") {
if (fobj.elements[i].checked == true)
str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";

arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
else if (fobj.elements[i].type.toLowerCase() == "hidden") {
str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
else if (fobj.elements[i].type.toLowerCase() == "password") {
str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
else if (fobj.elements[i].tagName.toLowerCase() == 'select') {
var value = '';

if (fobj.elements[i].type.toLowerCase() == 'select-one') {
str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
value = fobj.elements[i].options[fobj.elements[i].selectedIndex].value;
}
else {
for ( var index = 0; index < fobj.elements[i].options.length; index++) {
if (fobj.elements[i].options[index].selected == true) {
str = str + fobj.elements[i].name + "=" + fobj.elements[i].options[index].value + "&";
value = value + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + ',';
}
}
}

arrElements.push(fobj.elements[i]);
arrElementsValue.push(value);
}
else if (fobj.elements[i].tagName.toLowerCase() == 'textarea') {
str += fobj.elements[i].name + "=" + encodeURIComponent(app.util.replaceWordChars(fobj.elements[i].value)) + "&";
arrElements.push(fobj.elements[i]);
arrElementsValue.push(fobj.elements[i].value);
}
}
}
str = str.substr(0, (str.length - 1));

if (!app.util.validateFields(arrElements, arrElementsValue)) {
return false;
}

app.ajax.doAjaxCall(fobj.action, str, responsDivId);
};

app.util.toTitle = function(str) {

str = typeof str === 'string' ? str : "";

return str.toLowerCase().replace(/\b\w/g, function(a, b) {
return a.toUpperCase();
});

};

app.util.clearForm = function(form) {
form.find('input:text, input:password, input:file, select, textarea').val('');
form.find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
};

app.util.clearFormWithHidden = function(form) {
app.util.clearForm(form);
form.find('input:hidden').val('');
};

app.util.validateFields = function(arrElements, arrElementsValue) {

var isValidationPassed = true;
for ( var i = 0; i < arrElements.length; i++) {
var elementObj = arrElements[i];
if ($(elementObj).attr('validation_type')) {
errorMessage = app.util.doValidation($(elementObj).attr('validation_type'), arrElementsValue[i]);
if (errorMessage) {
$(elementObj).addClass('mandatory_error');
isValidationPassed = false;
}
else {
$(elementObj).removeClass('mandatory_error');
}
}
}

if (!isValidationPassed) {
errorMessage = 'Please check form and data !!!!';
app.util.showErrorMessage(errorMessage);
}

return isValidationPassed;
};

app.util.showErrorMessage = function(errorMessage) {

$('#main_message_div_id2').empty();

$('#main_message_div_id2').html(errorMessage);

$('#main_message_div_id_wrapper2').slideDown();

setTimeout("$('#main_message_div_id2').empty();$('#main_message_div_id_wrapper2').slideUp()", 4000);
};

app.util.doValidation = function(validationType, value) {

var message = null;
switch (validationType) {
case 'string':
if (app.util.isEmpty(value)) {
message = 'field cant be empty';
}
break;
case 'number':
if (!app.util.isNumber(value)) {
message = 'field cant be empty and have numeric value';
}
break;
default:
message = 'check the validation type';
}

return message;
};

app.util.closeLightBoxDiv = function() {
$('#light_box_popup_div').hide('slow');
};

app.util.applyAutocomplete_dummy = function(xmlDataDivId, xmlProperty, inputElementId) {
app.util.applyAutocomplete($('#'+xmlDataDivId).html(), xmlProperty, inputElementId);
};

app.util.applyAutocomplete = function(xmlData, xmlProperty, inputElement) {

var authorArr = [];

xmlDoc = $.parseXML(xmlData),
   $xml = $(xmlDoc),
   $property = $xml.find(xmlProperty);

$property.each(function() {
authorArr.push($(this).text());
});

$(inputElement).autocomplete({
source : authorArr,
minLength : 1,
select : function(event, ui) {
$(inputElement).val(ui.item.value);
}
});
};

app.util.trackFormChanges = function(formId) {

$("#" + formId).data("formChanged", false);

if (formId == null) {
return;
}

var selectId = "#" + formId + " select";
var inputId = "#" + formId + " input";
var textAreaId = "#" + formId + " textarea";

$(document).on('change', selectId, function(){
$("#" + formId).data("formChanged", true);
});

$(document).on('change keypress', inputId, function(){
$("#" + formId).data("formChanged", true);
});

$(document).on('change keypress', textAreaId, function(){
$("#" + formId).data("formChanged", true);
});
};

app.util.toggleCssClass = function (elemObj, cssClass) {
$('.' + cssClass).removeClass(cssClass);
$(elemObj).addClass(cssClass);
};

app.util.doesExist = function(ref) {
return $(ref).length > 0;
};

app.util.isFormChanged = function(formId, tinyMceIdArray) {

if (formId == null) {
return false;
}

if (tinyMceIdArray != null) {
var i = 0;
for (i=0; i < tinyMceIdArray.length; i++) {
if (tinyMCE.get(tinyMceIdArray[i]).isDirty()) {
return true;
}
}
}

if ($("#" + formId).data("formChanged")) {
return true;
}

return false;
};

app.util.autofillTitle = function (element){

var urlToCall =  $(element).val();

if(!app.util.isEmpty(urlToCall)) {

var titleElem = $('#'+$(element).attr('id')+'_title');
$(titleElem).attr('validation_type', 'string');
$(titleElem).addClass('mandatory');

$.ajax({
type : 'GET',
url : 'urlTitleAjaxCall.action',
data : 'url='+urlToCall,
beforeSend : function(request) {
$('#loading_div_wrapper').show();
},
success : function(html) {
$('#loading_div_wrapper').hide();
if(!app.util.isEmpty(html)){
$(titleElem).val(html);
}
},
error : function(xhr, ajaxOptions, thrownError) {
$('#loading_div_wrapper').hide();
alert('Server not responding !!! \n' + thrownError);
}
});
}else{
$(element).removeClass('mandatory');
$(element).removeClass('mandatory_error');
$(element).attr('validation_type', '');
$(element).val('');

var titleElem = $('#'+$(element).attr('id')+'_title');
$(titleElem).removeClass('mandatory');
$(titleElem).removeClass('mandatory_error');
$(titleElem).attr('validation_type', '');
$(titleElem).val('');
}
};

app.util.trackInputLength = function (selector) {

// set default content with some empty space,
// so that page does not flicker later
var defaultContent = '&nbsp;&nbsp;&nbsp;&nbsp;';

// function which actually does the work
showInputLength = function(e) {
var length = this.value.length;
if (length == 0) {
length = defaultContent;
} else if (length < 10) {
length = '0' + length;
}
$(this).siblings().first().html(length);
};

// register handler
$(selector).keyup(showInputLength);

// show the current input length
$(selector).each(function() {
$(this).after('<span>' + defaultContent + '<span>');
showInputLength.call(this);
});
};


app.util.updateCurrentSelected = function (className, elementToBeSelected) {
$('.'+className).removeClass(className);
$(elementToBeSelected).addClass(className);
};

app.util.showConfirmationBox = function (message, yesCallback, noCallback){
$('#customized_confirmation_box_wrapper').html(message);
$('#customized_confirmation_box_wrapper').dialog({
     resizable: false,
     height:160,
     width:400,
     modal: true,
     closeOnEscape: true,
     title:'Editor\'s Confirmation !',
     buttons: {
       'No': function() {
         $( this ).dialog( "close" );
         noCallback();
       },
       'Yes': function() {
         $( this ).dialog( "close" );
         yesCallback();
       }
     }
   });
};

app.util.showAlertBox = function (message){
$('#customized_confirmation_box_wrapper').html(message);
$('#customized_confirmation_box_wrapper').dialog({
     resizable: false,
     height:160,
     width:400,
     modal: true,
     closeOnEscape: true,
     title:'System Alert !',
     buttons: {
         'Okey': function() {
           $( this ).dialog( "close" );
         }
       }
   });
};

app.util.alertConfirm = function (formId, tinyMceEditorId, fallbackFx){
var tinyId = null;

if(null != tinyMceEditorId){
tinyId = [tinyMceEditorId];
}

if (app.util.isFormChanged(formId, tinyId)) {

app.util.showConfirmationBox('Do you want to save your changes ?', function () {
$('#is_data_got_changed').val(true);
$('#'+formId).trigger('submit');
}, fallbackFx);
}else{
fallbackFx();
}
};

app.util.showHide = function (ele, key){
if($(ele).attr('id')=='show'){
$.cookie(key, true);
$(ele).hide();
$('#hide').show();
$('#search_form_wrapper').slideDown();
}else{
$.cookie(key, false);
$(ele).hide();
$('#show').show();
$('#search_form_wrapper').slideUp();
}
};

app.util.checkShowHide = function (key){
if($.cookie(key)=='false'){
$('#hide').hide();
$('#search_form_wrapper').hide();
}else{
$('#show').hide();
$('#search_form_wrapper').show();
}
};

/** For TinyMCE and ShowMore related link **/
app.util.backyardAppsTriggerSave = function () {
tinyMCE.triggerSave(false, true);
};

app.util.previewImage = function (imageSrc) {
$('#light_box_popup_content_div').empty();
$('#light_box_popup_content_div').append('<div style="text-align:center;"><img style="width:400px;" src="'+imageSrc+'"/></>');
$('#light_box_popup_div').show();
};

app.util.browser = function(){
 var N= navigator.appName, ua= navigator.userAgent, tem;
 var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
 if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
 M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?'];
 return M;
};

$(document).keyup(function(e) {
// close preview light box on ESCAPE key
        if(e.which == 27){
        $('#light_box_popup_div').hide('slow');
        }
    });

})(jQuery);

Thursday, January 16, 2014

Strict Password Validation in Java

Below is the code snippet for Validation of the strong password.

public void passwordChecker(String password) {
boolean flag = true;
   //Check for minimum 8 character
if(password.length() < 8){
flag = false;
}
//check for at least on Alphanumeric (including combination of Capital and Small letters) characters
flag = password.matches(".*[A-Z].*") && password.matches(".*[a-z].*") && password.matches(".*[1-9].*");
System.out.println(flag);

if(flag){
//Check for at least one Special Characters
flag = password.matches(".*[!@#$%^&*|_+-].*");
System.out.println(flag);
}

//System.out.println(flag);

System.out.println("test : " + flag);

}

Check out and share feedback....

Wednesday, August 14, 2013

Oracle - PHP - command line

Connecting Oracle in PHP using command line, will need to set some environment variable as below.

Below is the code snippet for Shell script, all export variable are necessary in  term of command line execution.

------------------------------------------------------
### Cron for Purpose

#export ORACLE_SID=ONLDB
export ORACLE_BASE=/usr/local/oracle92/
export ORACLE_HOME=$ORACLE_BASE
#export ORACLE_TERM=vt100
#export NLS_LANG=american
#export ORA_NLS33=$ORACLE_BASE/ocommon/nls/admin/data
#export LD_LIBRARY_PATH=$ORACLE_BASE/lib:/lib:/usr/lib:/usr/local/lib
export PATH=$PATH:$ORACLE_BASE/bin
#export ORACLE_BIN=$ORACLE_BASE/bin

### Unpublished Product Job since last 3 days
php /path/to/cron/file.php
--------------------------------------------------------------------