Wednesday, 15 October 2014

Web services-Part 01

Web services is a technology, using which applications of two different technologies can communicate with each other.

the application which implements web services is called provider

and the application which uses these web services is callled consumer.

W3C organization has provided some set of guidelines to implement web services.

Initially W3C has released a document with set of guidelines that document is called BP 1.0 (Basic profile).

Java has provided JAVA-RPC specification to follow these guidelines and to implement web services

later W3C has provided a document another set of guidelines called BP1.1. java has provided JAVA-WS API to implement these guidelines

Once we implement web services using any of the above API, we need to provide their details using WSDL.

WSDL stands for web services description language, using which we can provide details about our services and methods and heir parameters

When a consumer wants to use these web services, they can refer this WSDL document.


once this WSDL is ready, and if you want to make your web services public, we can add this WSDL in UDDI

UDDI stands for universal desciption,directory integration.
we can add details about our web services in UDDI.

read our next article to understand more about web services


What is XSD


Hello and welcome to this article... in this article, we will see some basic details of XSD

XSD stands for XML Schema definition.

in XSD root tag is mandatory, all other tags should come under this XSD.

as we already know,XML can contain either simple tag or compound tag.

to define simple tag, we can use

<xs: element name="itemcode" type="xs:string">

to define complex attributes, XSD provides xs:complexType as shown below.


<xs:complexType name="address">
<xs:sequence> or <xs:all>
 <xs: element name="street" type="xs:string">
<xs:element name="state" type="xs:string">
</xs:sequence> or </xs:all>
</xs:complexType>

when we use xs:sequence, it specifies the all the nested elements should come in the same order
 
when we use xs:all, these attributes can come in any order

once we define a complex element, we can refere them in any other complex types

<xs:element name="permentaddr" type="address">

</xs:element>


Working with multipole XSDs
________________________________

If you want to refer one XSD in another XSD, we can use import or include.

if both XSDs are in same location, we  can use include

if both XSDs are in different locations, we use import

<xs:schema targetNamespace="xxxx">
</xs:schema>

<xs:schema targetnamespace="XXX">

<xs:include schemalocation="po1.xsd"

</xs:schema?



Sunday, 28 September 2014

What are different JSP scriptlets ?

JSP provides different scriptlets to use java code in JSP.

1.Directives Tag

<%@ %>
-------------

This tag is used to include external content in our jsp

this tag has mainly three attributes

1.Page
2.taglib
3.include

<%@ taglib uri="relative UR""  prefix=""%>

when we have predefined,custom tags, we can include them in our JSP and use them with prefix.

<%@ page import="relaive url" %>

this works similar to import statement in Java.

<%@ include file="relative url"%>

include attribute can be used  to include external js,jsp and css files

file will  be included in our file during the translation phase.

II. Declarative tag
-----------------------
<%! %>
This tag is used to declare variables in JSP

<%! int a;%>

III. Expression tag
--------------------------

This tag is used to write any expressions which result in string.

<%=Expression%>

we should not use semicolon at the end of the expression


IV. JSP comments
-----------------------

<% -- comments---%>

used to write comments in JSP

What do you know about JSP life Cycle?

Hey Guys.... here I will try to explain basic details of JSP which might be useful for the people who are beginners.

JSP :JSP stands for JAva Server Pages.

Most of you know might know about HTML which is used to display static content.Using JSP we can write pages which displays dynamic content to the user based on server response.

Main advantage of JSP is it is built on Servlet API so it has acess to all Java API like JDBC,JNDI,JAXP.

Let me explain lifeCycle of JSP:

JSP life cycle has below three steps:

1.Initilisation
2.Execution
3.CleanUp

Initilisation :

jspInit() method is executed during phase. this method will execute when JSP is loaded into memory.

once JSP is loaded, JSP container converts it to servlet and compiles it.

Then JSP container passes request to servlet container. Servlet container then executes the servlet which sends the response to client

Execution Phase 

:During this phase, jsp will process all requests from users and sends the response.

_jspService(HttpServletRequesst,HttpServletResponse) method is used to process all user requests.

This method will be executed once for each request.

CleanUP :

during this phase,the resources which are allocated during initilisation phase are cleaned.
jspDestroy( ) method will be executed during this phase.
 

Sunday, 5 February 2012

Jquery Data table

Datatable is a plug in for Jquery using which we can display the reports with rich Interface.
It by default provides pagination and searching capabilities. It also supports different themes provided by Jquery.








To use JQuery in our application we need to include jquery.Datatables.js.
In order to render Datatable, the targeted table HTML should be formatted with thead  and tbody attributes as shown in the below piece of code.

<table id="table_id">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>etc</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1 Data 1</td>
            <td>Row 1 Data 2</td>
            <td>etc</td>
        </tr>
        <tr>
            <td>Row 2 Data 1</td>
            <td>Row 2 Data 2</td>
            <td>etc</td>
        </tr>
    </tbody>
</table>


To convert above Table into JQuery data table we need to use below statement.
$(document).ready(function()
{
            $('table_id’).Datatable();
} );
I.e. we need to invoke Datatable method using table object.
This Datatable method also has different options[attributes] using which we can configure it according to our requirements
When Datatable is rendered its columns will be of fixed width i.e. we can not resize them.
To make the columns resizable we need to include one plug-in called ColReorderWithResize.js and we need to set bAutoWidth attribute to false;
$(document).ready(function()
{
$('table_id’).Datatable
(
{
“bAutoWidth  ”:false,
“sPaginationType”,”full_numbers”
}
);
} );
Datatable by default provides pagination also. We can also configure the pagination types using sPaginationType attribute.
$(document).ready(function()
{
$('table_id’).Datatable
(
{
“bDestroy”:true,
“sPaginationType”,”full_numbers”
}
);
} );

If you want to refresh the Datatable again and again with new data then we need to set “bDestroy”  attribute to true.
$(document).ready(function()
{
$('table_id’).Datatable
(
{
bDestroy:true;
}
);
} );
Data table also provides the support to export the data to different formats like excel,pdf.
To export the data to excel and pdf we need to include one plugin called ‘Tanbletools.js’
And one .swf file  “copy_cvs_xls_pdf.swf”.
Once we include above two files ,using below attribute we can add export facility in our Data table.
"oTableTools": {
                        "sSwfPath" :  " cvs_xls_pdf.swf"
}
‘sSwfPath’ is the location of the swf file.
By default when we use “oTableTools” attribute,export to excel,pdf and print buttons are provided.
We can also change the buttons displayed using  ‘aButtons’ attribute.
"oTableTools": {
                        "aButtons": ["xls"],
                        "sSwfPath" :  "cvs_xls_pdf.swf"
            },
Below statement specifies to include only export to excel button in our Data table.
You could also refer to the below link for more information about data tables.


Tuesday, 27 December 2011

Object Oriented JavaScript

Even though JavaScript is a loosely typed scripting language ,it supports object oriented features.
Even though it supports OO concepts it doesn’t have classes. The only thing java script supports is object. Before going to this concept let me briefly explain about the data types supported by JavaScript .
JavaScript basically supports
1.       Primitive Data types
2.       User defined data types(objects)
Primitive data types: they will be similar to the data types(integer,float,string,boolean) in other programming languages.
 JavaScript provides only one keyword var to declare variables of all (primitive)data types.
The data type of the variable will be decided on the value which is assigned to it first.
Example:
 Var   xint=5;
Then the data type of xint will be considered as integer.
Similarly if you say var xbool=false. Then x bool will be treated as Boolean variable.
Typeof operator
 This operator will be useful to identify the data type of the variable .If you say typeof(xbool) then it will return Boolean
Object
An Object in JavaScript is nothing but collection of properties. These properties can be primitive data types or other objects and functions.
JavaScript provides three different categories of objects:
1.       Host objects
2.       Native Objects
3.       User-Defined objects.
Host-objects:
Host Objects are provided by browser environment examples of Host objects are Window, document and forms.
Native Objects:
Native objects are provided by JavaScript library. String, Array and Image is examples of Native Objects.
To create Native objects we need to user new operator. EX
Var img1=new Image();
var pimitiveString1 = "This is a primitive string";  
var pimitiveString2 = String("This is a primitive string");  
var  stringObject = new String("This is a String object");  
 
// pimitiveString1.prop = "This is a property";  
// pimitiveString2.prop = "This is a property";  
//stringObject.prop = "This is a property";  
 
alert(pimitiveString1 .prop) // displays "undefined"  
alert(pimitiveString2 .prop) // displays "undefined"  
alert(stringObject.length) // displays "This is a property"
Note: all other constructors must be called with the new keyword, or they simply return a value, instead of a new object
Ex 1:
function myFunc(){
 return 5;
}

var myObject = myFunc();
alert(typeof myObject); //number
Can you guess what the alert box will return? May be you are right the alert will be display as number. Because here we have not used new operator so it will just invoke it is a normal method.
Now let us see how to create object of myFunc .(User defined objects)
EX:2
function myFunc(){
}

var myObject = new myFunc();
alert(typeof myObject); //myFunc
Now alert box will return as myFunc . I.e. if you use new operator the object of myFunc will be created. If you carefully observe the above statement here we have created an object of myFunc i.e. here myFunc is similar to Class in a any other Object oriented languages.
i.e. There is no separate syntax for creating classes in JavaScript . Creating classes is simple as writing as normal functions. Based on the way they are invoked they will be treated either as a function or class (As explained by examples)
Great.we have learnt how to create classes now let us see
How to add properties to the class.
Example:
function myFunc(){  
    this.var1;
        this.var2;
}  
Var object=new myFunc()
Object.var1=5;
Object.var2=5;
In the above example var1 and var2 are properties of the class myFunc. If you observe the difference here we haven’t used var keyword which is used to declare normal variables.
i.e. There is no need to use var keyword while declaring member variables but we need to prefix them with this.  Here this refers to the current class/object
So We have learnt
How to create classes
How to declare member variables and how to aces them.
Now let us see
how to added member functions in JavaScript classes
There are three different ways in which we can add member functions to a JavaScript class . I will try to explain the method which is used most often.
function myFunc()
{  
  this.var1;//member variable 1
this.var2;  //member variable 2
this.getVar1=function()  //member method1
{
                return this.var1;
}
this.getVar2=function() //member method w
{
return this.var2;
}
}
In the above example
myFunc is a class
var1,var2 are member variables of the class
getVar1 and getVar2 are member functions.
to declare object we need to use the syntax mentioned below
var object1=new myFunc();
object1.var1=5;
alert(object1.getVar1());//returns 5.
So finally we have learnt how to create classes and objects in JavaScript .JavaScript also provides Inheritance You can go through below links for more detailed understating of Object Oriented Concepts in JavaScript.
Thanks,
Vijay

Sunday, 11 December 2011

Creating WORD files using iTEXT

1.       In some applications we may come across the situations where we need to create MS-Word files from the given data.
2.       When you search in Google for JAVA APIs for creating MS-Word files the first solution you will get is POI API.
3.       Apache provides this POI API to handle MS office files such as doc(x), xls(x) and ppt(x) files.
4.       POI API is excellent to handle with Excel files but its API is not very comfortable to deal doc or docx files.
5.       So another alternate to create word file is using iTEXT.
6.       Using iTEXT we can create RTF files which can be opened using word.
7.       A rich text file, or RTF file, is a file that is supported by Microsoft Word. This means that you can open any RTF file within Word.
8.       Another advantage is there is no need to learn separate API for word. We can use the same API which can be used for creating PDF.
9.       Only difference is we need to user RTFWriter instead of PDFWriter everything else will be similar to creating PDF
To create PDF using iTEXT
                Document document = new Document ();
                File fl = new File(path+ ".pdf");
                FileOutputStream  fos = new FileOutputStream(fl);
                PdfWriter.getInstance(document, fos);
                document.open();
To create RTF file using iTEXT
Document document = new Document();

File fl = new File(path+ ".rtf");
FileOutputStream fos = new FileOutputStream(fl);
RtfWriter  writer=RtfWriter.getInstance(document, fos);

  
Hope this information helps you some where …..

Cheers,
Vijay Satlawar

Search This Blog