Thursday, November 26, 2015

Angular JS : Escaping the html from the string

Angular JS : Escaping the html from the string

Is there an angular JS command that will do HTML escaping on text?

How to escape HTML from string in AngularJS ?

Need a filter which can be used to escape the html tags from the string.

Escaping HTML is different then sanitizing HTML.

No in build command to escape the HTML from string in angular.


angular.module('app').filter('EscapeHtml', function() {

var tokenMap = {
'&': '&',
'<': '<',
    '>': '>',
'"': '"',
'\'': ''',
'/': '/',
'`': '`',
'=': '='
};

return function(str) {
 return String(str).replace(/[&<>"'`=\/]/g, function(s) {
   return tokenMap[s];
  });
};
});

Friday, October 26, 2012

In IE Jquery offset().top not returning correct value.

In IE Jquery offset().top not returning correct value.

There is some issue with Jquery offset().top calculation for any element if the browser is IE.
To fix this issue you can use the native java script for calculating the element offset top and left, and use it accordingly. Here-under the java script method that returns the object for calculated top and left for any element in document and it will work for all browser:

function findElementTotalOffset(obj) {
       var oleft = otop = 0;
       if (obj.offsetParent) {
         do {
           oleft += obj.offsetLeft;
           otop += obj.offsetTop;
         }while (obj = obj.offsetParent);
       }
       return {left : oleft, top : otop};
    }

Example: var jscripteltTop = findTotalOffset(elt).top;
where elt is the element of the document.

Tuesday, January 3, 2012

IzPack - A simple tutorial to create a JAVA based Installer

Hi friends, hereunder is the easy steps for creating the java installer (executable jars) using the IzPack.

Where to get IzPack

Download the IzPack distribution from http://get.izpack.org/izpack/4.3.5.
Prerequisite for IzPack is that you should have java installed in your host and path should be set to java/bin folder.

How to Install

If the native platform is windows, open the cmd client and type the following command for installation:
cd <download dir>
java -jar <downloaded IzPack jar>

If the native platform is linux, open the terminal and first navigate to download dir and launch the command for installing the IzPack.
cd <download dir>
java -jar <downloaded IzPack jar>

Follow the steps of installer it will install the IzPack on your host.

How to Use

IzPack having following component:
  1. install.xml : Used as a controller for all the installation process.
  2. userInputSpec.xml : Used for creating the installer panels.
  3. antActionSpec.xml : Used for calling different ant files based on the installation flow.
  4. RegistrySpec.xml : Used for registering the installed product to windows registry.
  5. ShortCutSpec.xml : Used for creating application shortcuts in program menu.
Sample Example

Assume you have a build file say build.xml which is responsible to create a war file for your deployment, you want to create a database in mysql and for that you have createdb.xml file. Now you need to create a installer which check the java version first, call the build.xml for creating your application war, copy your war to tomcat server and create database in mysql for you application along with automated uninstaller and program application registry for your application. Following code is a sample for doing these with help of IzPack :

Assumption

  1. build.xml : Build file for your project gives the final deploy-able application war.
  2. copyWar.xml: ant file having copyWar target which is responsible to copy the war file to selected server webapps directory.
  3. createDB.xml: ant file having createMySQLDB target which is having sql task to execute your database creation sql and needed the connector jar.
Steps for Creating Installer

Create a directory called MyInstaller inside your project say WatchEyeUI and follow these steps:
Project Structure for IzPack Installer



Step1: Configuring the install.xml

Create one xml file say install.xml and add the content like as:




    
        WatchEyeInstaller
        04012012
        
            
        
        http://www.mycompany.com
        1.6
    

    
  
  
    

    
        
    

    
    
    
    

    
        
    
 
  
 
 
        
    
    
        
    

    
        
        
        
            
        
    

    
    
        
        
        
        
        
        
               
    

    
        
        
        
    

    
    
        
        
        
        
             
        
        
        
        
        
    

    
 
        
            The set of base files.
            
            
            
        
        
            
        
       
           
        
        
           
        
    


Step2: Configuring the userInputSpec.xml

Create one xml file say userInputSpec.xml and add the content like as for creating the panel for taking the db parameter and server location:

       
            
               
            
            
            
               
            
                
                
            
               
            
                
                
            
               
            
                
                
            
               
            
                
                
                
                    
              
               
            
            
            
               
            
                
                
                                                                                                                                                                                                                   
Step3: Configuring the antActionSpec.xml

 
  
        
   
  
 
 
  
   
   
   
  
 
 
  
   
   
   
   
   
   
  
    

   Step4: Configuring the RegistrySpec.xml
     
           
  
  
   
   
   
   
       
   
        
  
  
  
    
             
  
 

  Step5: Configuring the ShortCutSpecSpec.xml
 
 
  
  
  
  
  
  
  
  
 
    Step6: Compiling the installer       Go to the bin directory of IzPack installation by following command:             cd C:\Program Files\IzPack\bin Use compile command to make the MyApplication.jar executable.Assume Project is in C:\WatchEye folder.
     compile C:\WatchEye\WatchEyeUI\installer\data\install.xml -b C:\WatchEye\WatchEyeUI\installer\data\ -o MyApplication.jar
It will create MyApplication.jar as executable. To launch the installer double click on your jar or type command java -jar MyApplication.jar for launching your installer.
References:
As per the request hereunder the sample createDB.xml file.
 
      
       
       
       
       
       
       
  
   
    
        
  
  
  
   
   
  
  
   
   
  
  
   
    
   
  
 
Sample: DBConnectionValidator class
package com.izforge.izpack.util;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.SQLException;
import com.izforge.izpack.installer.AutomatedInstallData;
import com.izforge.izpack.installer.DataValidator;

public class DBConnectionValidator implements DataValidator {  
 private String dbType="";
 private String cause="";
 @Override  
 public boolean getDefaultAnswer() {  
  return true;  
 }  

 @Override  
 public String getErrorMessageId() {  
  return "Can not connect to "+ dbType+" database." + cause;  
 }  

 @Override  
 public String getWarningMessageId() {  
  return "OPS-101";  
 }  

 @Override  
 public Status validateData(AutomatedInstallData arg) {  
  Connection connection = null;  
  try
  {
   URL urls [] = {};
   JarFileLoader cl = new JarFileLoader (urls);
   cl.addFile (arg.getVariable("jarFile.loc"));
   dbType=arg.getVariable("databasetype");
   java.sql.Driver driver=null;
   java.util.Properties props=null;

   System.out.println(arg.getVariable("jarFile.loc"));

   if(dbType.equalsIgnoreCase("MySQL")){
    Class cls = cl.loadClass ("com.mysql.jdbc.Driver");
    driver = (java.sql.Driver)cls.newInstance(); 
    props = new java.util.Properties();
    props.put("user", arg.getVariable("user"));
    props.put("password", arg.getVariable("password"));
    connection = driver.connect("jdbc:mysql://"+arg.getVariable("dbhostname")+":"+arg.getVariable("portno")+"/", props);
   }else if(dbType.equalsIgnoreCase("MS SQL Server")){
    Class cls = cl.loadClass ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    driver = (java.sql.Driver)cls.newInstance(); 
    props = new java.util.Properties();
    props.put("user", arg.getVariable("user"));
    props.put("password", arg.getVariable("password"));
    // The replacement in the following is done to discard the % with \ while creating the connection URL with named instance.
    connection = driver.connect("jdbc:sqlserver://"+arg.getVariable("dbhostname").replace('%', '\\')+":"+arg.getVariable("portno"),props);
   }else if(dbType.equalsIgnoreCase("ORACLE")){
    Class cls = cl.loadClass ("oracle.jdbc.driver.OracleDriver");
    driver = (java.sql.Driver)cls.newInstance(); 
    props = new java.util.Properties();
    props.put("user", arg.getVariable("user"));
    props.put("password", arg.getVariable("password"));
    connection = driver.connect("jdbc:oracle:thin:@"+arg.getVariable("dbhostname")+":"+arg.getVariable("portno")+":"+arg.getVariable("instanceName"),props);
   }
  }
  catch (ClassNotFoundException e) {  
   e.printStackTrace();
   cause = "\nCause: Connector Jar is not valid for selected database!";
   if(dbType.equalsIgnoreCase("MySQL"))
    cause = cause + "\n\nYou can dowload the Connector Jar for MySQL form:\nhttp://dev.mysql.com/downloads/connector/j/5.0.html";
   else if (dbType.equalsIgnoreCase("MS SQL Server"))
    cause = cause + "\n\nYou can dowload the Connector Jar for MS SQL Server form:\nhttp://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21599";
   else if (dbType.equalsIgnoreCase("ORACLE"))
    cause = cause + "\n\nYou can dowload the Connector Jar for Oracle form:\nhttp://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html";
   cause = cause +"\n\nAfter selecting proper Connector Jar, proceed with the installation.";
   
   return Status.ERROR;  
  } catch (SQLException e) {  
   e.printStackTrace();
   cause = "\nCause: Invalid connection parameter(s) OR the database service is not started!";
   return Status.ERROR;  
  } catch (MalformedURLException e) {
   e.printStackTrace();
   return Status.ERROR;  
  } catch (InstantiationException e) {
   e.printStackTrace();
   return Status.ERROR;  
  } catch (IllegalAccessException e) {
   return Status.ERROR;  
  } finally {  
   if (connection != null) {  
    try {  
     connection.close();  
    } catch (SQLException e) {  
     return Status.ERROR;  
    }  
   }  
  }  
  return Status.OK;  
 }

 public static class JarFileLoader extends URLClassLoader
 {
  public JarFileLoader (URL[] urls)
  {
   super (new URL[]{});
  }

  public void addFile (String path) throws MalformedURLException
  {
   String urlPath = "jar:file:///" + path + "!/";
   addURL (new URL (urlPath));
  }
 }  
} 

Thursday, December 29, 2011

Web Service pre-configuration through python


Configuration of SOAPpy, fpconst and pyXml along with the python 2.6.0
--------------------------------------------------------------------------------------------
Packages & Versions
--------------------------------------------------------------------------------------------
1- Python 2.6.2
2- fpconst 0.7.2
3- PyXML 0.8.4
4- SOAPpy 0.12.0


--------------------------------------------------------------------------------------------
Installation Instruction
--------------------------------------------------------------------------------------------
1- Install Python 2.6.2
                1.1 Set the environment variable for class path : Ex: classpath="c:\python26"

2- Install fpconst
                2.1 Extract the zip file fpconst-0.7.2.tar.gz
                2.2 cd fpconst-0.7.2
                2.3 execute command: python setup.py install

3- Install PyXML
                3.1 Extract the zip file PyXML-0.8.4.tar.gz
                3.2 cd PyXML-0.8.4
                3.3 execute command: python setup.py install (causes some error) then the last command need to fire
                3.4 execute command: python setup.py install --force --skip-build (Showing that script/lib can not be created but its ok, Now verify the version)

4- Install SOAPpy
                4.1 Extract the zip file SOAPpy-0.12.0.zip.
                4.2 cd SOAPpy-0.12.0
                4.3 Go to the SOAPpy-0.12.0\SOAPpy directory
                4.4 Edit the Client.py file
                                4.4.1 find "from __future__ import nested_scopes" line
                                4.4.2 cut it and paste at the first line of file
                4.5 Edit the Server.py file
                                4.5.1 find "from __future__ import nested_scopes" line
                                4.5.2 cut it and paste at the first line of file
                4.6 Edit the Types.py file
                                4.6.1 find "from __future__ import nested_scopes" line
                                4.6.2 cut it and paste at the first line of file
                4.7 execute command: python setup.py install

Once finished, do verify all these installations.
 
---------------------------------------
Verifications
---------------------------------------
Open python ( type : python on command line).
1) Verify PyXml

                >>> import xml
                >>> xml.__version__
                '0.8.4'

2) Verify fpConstants
      >>> import fpconst
      >>> fpconst.__version__
     '0.7.2'

3) Verify SOAPpy
       >>> import SOAPpy
       >>> SOAPpy.__version__
       '0.12.0'

Tomcat service start-up failure on Windows Operating Systems

On particular flavors of Windows Operating System, the Tomcat Services fail to start even after being registered successfully. There might be the following reason behind this failure:
The type of the service runner (tomcat6.exe or tomcat7.exe) does not match with the destined Windows Operating System’s JRE configuration. There needs to be four different service runner files for the 4 different combinations:
  •  For 32-bit JRE6 (Or JDK6-whichever is applicable), use tomcat6.exe available with the Apache Tomcat 6 package for Windows 32-bit.
  •   For 64-bit JRE6, use tomcat6.exe available with the Apache Tomcat 6 package for Windows 64-bit.
  •   For 32-bit JRE7, use tomcat7.exe available with the Apache Tomcat 7 package for Windows 32-bit.
  •   For 64-bit JRE7, use tomcat7.exe available with the Apache Tomcat 7 package for Windows 64-bit.   
You can use environment variables for making decisions on runtime.

Tuesday, December 27, 2011

Configuration of SVN over http in Linux

Prerequisite:
                   1- Apache Server 2.0 or later.
                   2- finch dependency
                   3- libpurple dependency
                   4- apr and apr-util dependency

Installation of SVN :

• In terminal execute:
   [root@upload /]# yum install mod_dav_svn subversion
• It will resolve the dependency for SVN and then installed the distribution according to the default configuration.
• If you don't have Apache installed already, it'll go ahead and drag that down as well.

Configuration of Apache Server :

• First we need to check that apache is working fine or not...
   [root@upload /]# service httpd start
   [root@upload /]# chkconfig httpd on
• Check the server is on or not by entering the url
• http://localhost

Sub Versions Apache Configuration :

Next step to configure svn for apache.

• Navigate to directory of httpd config
  [root@upload /]# cd /etc/httpd/conf.d/
• Open the subversion.conf file in editor mode
  [root@upload /]# vim subversion.conf
• Make sure you uncomment the following if they are commented out
   LoadModule dav_svn_module modules/mod_dav_svn.so 
   LoadModule authz_svn_module modules/mod_authz_svn.so
• Add the following to allow a basic authentication and point Apache to where the actual repository resides.

<Location /repos>
DAV svn
SVNParentPath /var/www/svn
AuthType Basic
AuthName "Subversion repos"
AuthUserFile /etc/svn-auth-conf
Require valid-user
</Location>

• The location is what Apache will pass in the URL bar. For instance: http://localhost/repos points to the SVNPath that you have specified.

User and Password Configuration:

Next we have to actually create the password file that you specifie previous step. Initially you'll use the -cm arguments. This creates the file and also encrypts the password with MD5. If you need to add users make sure simply use the -m flag, and not the -c after the initial creation.

[root@upload /]# htpasswd -cm /etc/svn-auth-conf
username1
New password:
Re-type new password:
Adding password for user username1

[root@upload /]# htpasswd -m /etc/svn-auth-conf
username2
New password:
Re-type new password:
Adding password for user username2

Configure your Repository :

Next thing you need to do is to create the actual repository from which you will check in and out your files.

[root@upload /]# cd /var/www/
[root@upload /]# mkdir svn
[root@upload /]# cd svn
[root@upload /]# svnadmin create repos
[root@upload /]# chown -R apache.apache repos
[root@upload /]# service httpd restart

• Check access your repository from a web browser: http://localhost/ repos. You should get a popup box asking for a username and password.Put the username password username1 and password for that.
• Now you can access your repository from http://.

CheckOut :

 [root@upload /]# svn checkout http://localhost/repos
 Authentication realm: <http://localhost:80> Subversion repos
 Password for 'root': [Ex-root]
 Authentication realm: <http://localhost:80> Subversion repos
 Username: username1
 Password for 'user': [Ex-username1]
 Checked out revision 0.


Feel free to ask if you have any query.

Thank You