Tuesday, 17 April 2012

IFRAME Example


The <iframe> tag specifies an inline frame.
An inline frame is used to embed another document within the current HTML document.

I wanted to have the "src" to be changed dynamically. 

Here is the example of IFRAME where in source can be changed though TextField. 
Whatever you enter into the text box will be given to the Iframe and iframe window will render that page.


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST Page</title>
</head>
<script type="text/javascript" >
function iframeMethod() {
var srcValue =  document.getElementById("text");
var iframe   =  document.getElementById("frame");
iframe.setAttribute('src', srcValue.value);
}
</script>
<body>
<iframe src="http://www.google.com" name="frame" id="frame"
frameborder=0 style="overflow:visible; width:100%; height:600; scrolling="no">
</iframe>
<input type="text" name="text" id="text" target="frame"/>
<input type="submit" name="submit" id="submit" value="Submit" onclick="javascript:iframeMethod();"/>
</body>
</html>

Monday, 9 April 2012

How to set JAVA_HOME environment variable in Ubuntu


    Open /etc/bash.bashrc using sudo command
    e.g. sudo gedit /etc/bash.bashrc.
   
   go to the end of the file and add following lines:

    JAVA_HOME=/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)
    export JAVA_HOME
   
    PATH=$PATH:$JAVA_HOME/bin
    export PATH

   Done. Just reboot your computer.


    echo $JAVA_HOME
    it shows something like this:/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)
 
    echo $PATH
    it shows something like this::/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)/bin 

Thursday, 22 March 2012

Unique constraint and index relationship in Oracle

Dropping Unique Key does not drop the index created for it in Oracle.

I am not very sure for which all versions it happens.

But when I explicitly run the

Drop Index <indexName>;

After execution the same , my unique constraint violation exception issue is fixed.


Tuesday, 7 February 2012

Updating the Cookie for specific time interval


If you want to update the cookies after some time interval using the time then call the below function.
Timer should run with the interval of less than 11 minutes.

updateCookieValue  :  function () {
    var cookies = document.cookie.split(";");
if (cookies.length > 0) {
var nTime = new Date();
//add 11 mins to current time so that the recursive call to update cookie
             (with interval 10 mins)
//gets executed before the cookie gets expired ( 11 * 1000 * 60)
             // time added in millisecond
nTime.setTime(nTime.getTime()+660000);
for (var i = 0; i < cookies.length; i++){
var name = cookies[i].split("=")[0];
name = name.trim();
var value = cookies[i].split("=")[1];
if((name == " cookie_0") || (name == " cookie_1")){
document.cookie = name + "=" +escape( value ) +";expires="
                      + nTime.toGMTString()+";path=/;domain=";
}
        }
}
}

Sunday, 5 February 2012

Encryption and Decryption Technique


import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class EncryptDecryptUtil {

    private static final String UNICODE_FORMAT = "UTF8";
    public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";
    private KeySpec keySpec;
    private SecretKeyFactory secretKeyFactory;
    private Cipher cipher;
    byte[] keyAsBytes;
    private String encryptionKey;
    private String encryptionScheme;
    private SecretKey secretKey;

    public EncryptDecryptUtil() throws Exception
    {
        encryptionKey = "EncryptionKeyForEncryption";
        encryptionScheme = DESEDE_ENCRYPTION_SCHEME;
        keyAsBytes = encryptionKey.getBytes(UNICODE_FORMAT);
        keySpec = new DESedeKeySpec(keyAsBytes);
        secretKeyFactory = SecretKeyFactory.getInstance(encryptionScheme);
        cipher = Cipher.getInstance(encryptionScheme);
        secretKey = secretKeyFactory.generateSecret(keySpec);
    }

    public String encrypt(String unencryptedString) {
        String encryptedString = null;
        try {
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);
            byte[] encryptedText = cipher.doFinal(plainText);
            BASE64Encoder base64encoder = new BASE64Encoder();
            encryptedString = base64encoder.encode(encryptedText);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptedString;
    }
 
    public String decrypt(String encryptedString) {
        String decryptedText=null;
        try {
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            BASE64Decoder base64decoder = new BASE64Decoder();
            byte[] encryptedText = base64decoder.decodeBuffer(encryptedString);
            byte[] plainText = cipher.doFinal(encryptedText);
            decryptedText= bytes2String(plainText);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return decryptedText;
    }
 
    private static String bytes2String(byte[] bytes) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            stringBuffer.append((char) bytes[i]);
        }
        return stringBuffer.toString();
    }
 
     /**
     * Testing The Encryption And Decryption Technique
     */
    public static void main(String args []) throws Exception
    {
    EncryptDecryptUtil myEncryptor = new EncryptDecryptUtil();
    String stringToEncrypt= "theherald";
        String encrypted=myEncryptor.encrypt(stringToEncrypt);
        String decrypted=myEncryptor.decrypt(encrypted);

        System.out.println("The String To be Encrypted : "+stringToEncrypt);
        System.out.println("Encrypted Value of the String : " + encrypted);
        System.out.println("Decrypted Value of the String : "+decrypted);

    }
}  


The output is ::::::

The String To be Encrypted : theherald
Encrypted Value of the String :b6WaWLvUO7XznWLKxDzGXw==
Decrypted Value of the String :theherald

Tuesday, 8 November 2011

Multiple core in Solr

Multiple cores allows you create seperate index files for every single module of your application. Here each core has its own configuration file e.g every core can have its own data-config.xml, solr-config.xml and schema.xml. We can make the seperate index file for each core. You can also administer those cores using http://localhost:8080/solr/ . 


Cores are created on the fly by using http://localhost:8080/solr/admin/cores?action=CREATE&name=coreX&instanceDir=path_to_instance_directory&config=config_file_name.xml&schema=schem_file_name.xml&dataDir=data. Here the Create is action name for creating core, name is the unique name for the core, instanceDir is the path solr home, config is the path of the solrConfig.xml, schema is the path of schema.xml and finally the dataDir is the path where one wants to store the index files.


In my case it was : http://localhost:8080/solr/admin/cores?action=CREATE&name=9476067&instanceDir=/home/abashetti/Downloads/abhijit/solr/&config=/home/abashetti/Downloads/abhijit/solr/conf/solrconfig.xml&schema=/home/abashetti/Downloads/abhijit/solr/conf/schema.xml&dataDir=/home/abashetti/Downloads/abhijit/solr/9476067/document/data 


This will create an entry in the solr.xml file.


The default solr.xml file will look like : 
The defaultCoreName must be mentioned the xml file
If the default core name is missing you will get the error on the browser as :








<?xml version="1.0" encoding="UTF-8" ?>

<solr persistent="false">
 <cores adminPath="/admin/cores" defaultCoreName="collection1">
    <core name="collection1" instanceDir="." />
  </cores>
</solr>

To create core on fly one need to modify the solr.xml , the attribute persistent ="true" is the change for it.



<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
<cores adminPath="/admin/cores" defaultCoreName="collection1">
    <core name="collection1" instanceDir="." />
    <core name="9476067" instanceDir="./"             config="/home/abashetti/Downloads/abhijit/solr/conf/solrconfig.xml"
schema=/home/abashetti/Downloads/abhijit/solr/conf/schema.xml
dataDir="/home/abashetti/Downloads/abhijit/solr/9476067/data"
/>
    <core name="12385546" instanceDir="./" 

config="/home/abashetti/Downloads/abhijit/solr/conf/solrconfig.xml"
schema=/home/abashetti/Downloads/abhijit/solr/conf/schema.xml

dataDir="/home/abashetti/Downloads/abhijit/solr/12385546/data"/>

</cores>

   

</solr>


The core can be reloaded, removed on the fly. To remove/unload the core on fly use the url
         
http://localhost:8080/solr/admin/cores?action=UNLOAD&core=9476067&deleteIndex=true


The above url will remove the entry of core from solr.xml and remove the index files from the dataDir.



Here the UNLOAD is the action for removing the core and core attribute asks you for the core name and if you want to delete the index files then set deleteIndex value is true. If deleteIndex is false then solr will remove only the core entry from the solr.xml.

The url to check all the core is http://localhost:8080/solr/admin/ 




Saturday, 15 October 2011

oracle case insensitive

Searching on column which contains the document name and document name is in Lower case and Upper case. To find the document with document name the query would be:

Select d.document_name from document d where LOWER(d.document_name) like LOWER('%java%')

Select d.document_name from document d where UPPER(d.document_name) like UPPER('%java%')