Monday, March 11, 2013

MySql Encrypt and Decrypt Function

       Mysql supports many compression and encryption functions. One such technique is AES(Advanced Encryption Standard) algorithm. Using this, one can encrypt or decrypt the datas in table. General Syntax for Encrypt/Decrypt are
  
   AES_ENCRYPT(str,key_str)
   AES_DECRYPT(crypt_str,key_str)
 
      AES_ENCRYPT() encrypts a string and returns a binary string. AES_DECRYPT() decrypts the encrypted string and returns the original string. The input arguments may be any length and can contain alphanumeric characters. Basic Insert Query with and without Encrytion are as follows.
 
INSERT INTO `myTable`(myName,myPass) VALUES('Jimmy',AES_ENCRYPT('password1','key:test'));
INSERT INTO `myTable`(myName,myPass) VALUES('David','password2');
 
 
myName myPass
Jimmy ÙjˆçésŸ·
David password2
 
     To update plain text to Encrypted value, execute
 
UPDATE myTable SET myPass = AES_ENCRYPT('password2','key:test') WHERE myName='David';

myNamemyPass
David¦ã bf;× ÀäiO W

    For updating password column to encrypted value in an existing table you can either use the query directly as   

UPDATE myTable SET mypass = AES_ENCRYPT(mypass,'key:test');
 
  or can export data files alone and reinsert by using the below query.

 LOAD DATA INFILE 'C:/Sample.csv' INTO TABLE myTable(myname,@mypass) SET mypass=AES_ENCRYPT(@mypass,'key:test');
   
     Finally, to view the table datas, use decrypt query by passing the key value. Remeber that, if the given key value does not match with that of the key used while insertion, then it will return NULL value.
 
SELECT AES_DECRYPT(mypass,'key:test') FROM myTable;
myNamemyPass
Jimmypassword1
Davidpassword2

Friday, March 1, 2013

Displaying InfoWindow in Maps V3


      InfoWindows displays content in a floating window above the map. It has a content area and tapered stem, where the tip of the stem is at specified location of marker on the map. You can see the info window by clicking particular markers on Google map. To make the info window visible, you need to call the open() method, passing google maps and marker. If no marker is provided, then the info window will open at this position property. InfoWindow needs a Info Window options object, which specifies a set of initial parameters for displaying info window.
 
Sample Code for InfoWindow:

 InfoWindowOptions infoWindowOptions = InfoWindowOptions.create();
 infoWindowOptions.setContent(location);
 InfoWindow infoWindow = InfoWindow.create(infoWindowOptions);
 infoWindow.open(mapWidget, marker);

(For Creation of mapWidget and marker refer previous post).

Monday, February 25, 2013

Display .gif Images marker in google maps V3

       Showing .gif images in maps V3 is simple, but in default it is disabled. The only thing you need to do is set markeroptions optimized to false. The coding example will help you to use MarkerOptions, MarkerImage, Anchor Positions and using Animated Images.
 
Sample Code for displaying .gif Image:
VerticalPanel vp = new VerticalPanel();
  vp.setSize("1200", "800");
  LatLng myLatLng = LatLng.create(13.029603, 80.271800);
  MapOptions myOptions = MapOptions.create();
  myOptions.setZoom(8.0);
  myOptions.setCenter(myLatLng);
  myOptions.setScaleControl(true);
  myOptions.setMapTypeId(MapTypeId.ROADMAP);
  GoogleMap mapWidget = GoogleMap.create(vp.getElement(), myOptions);
  add(panel);
 
  MarkerOptions markerOptions = MarkerOptions.create();
  markerOptions.setDraggable(true);
  markerOptions.setOptimized(false);
  MarkerImage image = MarkerImage.create(Flower.gif);
  image.setAnchor(Point.create(23, 65));
  Marker marker = Marker.create(markerOptions);
  marker.setPosition(myLatLng);
  marker.setMap(mapWidget);

Friday, February 22, 2013

Overlay panel to Maps V3

    Overlays are objects on the map that are tied to latitude/longitude coordinates. Normally, in V2 overlays are added by using map's addOverlay() method. In V3 you may add an overlay to the map directly by using the overlay's setMap() method. Unlike markers, other widgets or panels cannot be added in the same way in both versions. You will probably need some code changes and need to style the panel using CSS.

Sample code for V2:
  ContentPanel panel = new ContentPanel();
     FlexTable fTable = new FlexTable();
     fTable.setWidget(0, 1, new HTML("TEST1"));
     fTable.setWidget(1, 1, new HTML("TEST2"));
     panel.add(fTable);
     panel.setStyleName("cssstyle");
     MapWidget map = new MapWidget();
     map.addControlWidget(panel);
 
     In Maps V3 we dont have addControlWidget() method. Instead, you can create your own controls to handle interaction with the user. Controls are stationary widgets which float on top of a map at absolute positions. Custom controls are positioned on the map by placing them at appropriate positions within the Map object's controls property. (Here is the List of Control Positioning).

Sample code for V3:
  VerticalPanel vp = new VerticalPanel();
  vp.setSize("1200", "800");
  LatLng myLatLng = LatLng.create(13.029603, 80.271800);
  MapOptions myOptions = MapOptions.create();
  myOptions.setZoom(8.0);
  myOptions.setCenter(myLatLng);
  myOptions.setScaleControl(true);
  myOptions.setMapTypeId(MapTypeId.ROADMAP);
  GoogleMap mapWidget = GoogleMap.create(vp.getElement(), myOptions);

  ContentPanel panel = new ContentPanel();
     FlexTable fTable = new FlexTable();
     fTable.setWidget(0, 1, new HTML("TEST1"));
     fTable.setWidget(1, 1, new HTML("TEST2"));
     panel.add(fTable);
     panel.setStyleName("cssstyle");
  mapWidget.getControls()
    .get(new Double(ControlPosition.TOP_RIGHT.getValue())
      .intValue()).push(panel.getElement());
  add(panel);
 
CSS (for V2 & V3):
 .cssstyle {
         z-index: 1;
         float: right;
         position: absolute;
   }
 

Thursday, February 21, 2013

Marker GWT Maps V3 Single and Double ClickHandler


        GWT Maps V2 supports both single click and double click handler for a single marker in the same window. Whereas, in V3, both methods are available but only single click handler triggers if used for the same marker. In my scenario, I need single click handler for showing InfoWindow and double click handler to navigate to other page(another tab) within application. Normally if u want to implement both in maps V3, single click handler needs a delay or need some asynchronous calls. Here, I have used Geocoder in single click for getting address of particular marker(getting latlng) and showing in InfoWindow.

Sample Code for using both Handlers:

 VerticalPanel panel = new VerticalPanel();
  panel.setSize("1200", "800");
  LatLng myLatLng = LatLng.create(13.029603, 80.271800);
  MapOptions myOptions = MapOptions.create();
  myOptions.setZoom(8.0);
  myOptions.setCenter(myLatLng);
  myOptions.setScaleControl(true);
  myOptions.setMapTypeId(MapTypeId.ROADMAP);
  GoogleMap mapWidget = GoogleMap.create(panel.getElement(), myOptions);
  MarkerOptions newMarkerOpts = MarkerOptions.create();
  newMarkerOpts.setPosition(myLatLng);
  newMarkerOpts.setTitle("Hello World!");
  final Marker marker = Marker.create(newMarkerOpts);
  marker.setMap(mapWidget);
 marker.addClickListener(new ClickHandler() {
   @Override
   public void handle(MouseEvent event) {
    Geocoder geocoder = Geocoder.create();
    GeocoderRequest request = GeocoderRequest.create();
    request.setLocation(event.getLatLng());
    geocoder.geocode(request, new Callback() {
     @Override
     public void handle(JsArray<GeocoderResult> a,
       GeocoderStatus b) {
      if (b == GeocoderStatus.OK) {
       if (a.length() > 0) {
        GeocoderResult geocoderResult = a.get(0);
        StringBuffer sb = new StringBuffer();
        JsArray<GeocoderAddressComponent> addressComponents = geocoderResult
          .getAddressComponents();
        for (int i = 0; i < addressComponents.length(); i++) {
         if (i > 0) {
          sb.append(", ");
         }
         sb.append(addressComponents.get(i)
           .getLongName());
        }
        String location = sb.toString();
        InfoWindowOptions infoWindowOptions = InfoWindowOptions.create();
        infoWindowOptions.setContent(location);
        InfoWindow infoWindow = InfoWindow.create(infoWindowOptions);
        infoWindow.open(mapWidget, marker);
       }
      }
     }
    });
   }
  });
 
  marker.addDblClickListener(new DblClickHandler() {
   @Override
   public void handle(MouseEvent event) {
    Window.alert("Double Click Demo");
   }
  });
 

 

Friday, February 15, 2013

Maps V3(gwt-maps-3.8.0) using GWT - 2.4.0


Google Maps V3 API allows you to add Map functionality to your application. To get started, download gwt-maps-3.8.0 here. One of the common issue faced by the developers in displaying maps V3 is its "Size". Previously, Maps V2 provided Map as a widget, which can be added to other widgets directly. Also, Size of the Maps can be varied by just using 'setSize(width,height)' method.

       Unlike Maps V2, V3 Maps doesn't have setSize(width,height) method. Instead, Map Size depends on panel size in which map is added.

Sample Code for Displaying Maps V3 in Application:

public class MapTest extends HorizontalPanel {
    GoogleMap map;
    VerticalPanel mapVp = new VerticalPanel();

    public MapTest(){
        mapVp.setSize("1200", "800");
        LatLng myLatLng = LatLng.create(30.440099, 36.843498);
        MapOptions myOptions = MapOptions.create();
        myOptions.setZoom(5);
        myOptions.setCenter(myLatLng);
        myOptions.setMapTypeId(MapTypeId.TERRAIN);
        myOptions.setMapTypeControl(true);
        map = GoogleMap.create(mapVp.getElement(), myOptions);
        add(mapVp)
    }
}

Basically, if you try to display map in multiple windows using the same piece of code(In two or three different tabs), the map will not be fully loaded. Instead, half of the map will be grayed out. May be map canvas did not get fully rendered before google map was accessing it. So, I solved this by adding a short delay using gwt-Timer.

LatLng myLatLng = LatLng.create(24.440099, 46.843498);
final MapOptions myOptions = MapOptions.create();
myOptions.setZoom(5);
myOptions.setCenter(myLatLng);
myOptions.setMapTypeId(MapTypeId.TERRAIN);
myOptions.setMapTypeControl(true);
Timer load = new Timer() {

@Override
public void run() {
map = GoogleMap.create(mapVp.getElement(), myOptions);
}
};
load.schedule(1000);

Thursday, January 18, 2007

Hai.This is C.Ameenur Rahman.