CS220 Scripting Language Final Project Portfolio

We have done working on our project, the project is finally complete. If you don’t have any idea about the project, you can find out by clicking here.

Within the project, my role was to prepare the front-end of the website while supporting Hugo to prepare the back-end. We used PHP to do the project with using CodeIgniter as the framework and MySQL is used for database of the website.

I use a template for the front-end of the website while using the design student (Clara Wibisono) website as a guidance. All the content like the company profile is obtained from the design student website.

CodeIgniter is very great thing to learn, even though I need some time to learn how the CodeIgniter works, but after getting to know better about it, it helps me a lot to develop a website faster than without using a framework. Many functions are already provided through the CodeIgniter. With CodeIgniter it saves me a lot of time to finish this project.

If you need the source code for this project, you can find it by simply clicking here.

You can also watch a preview video of the website to see what it looks like.

Regards,

Timothy Viandy

Using Spring for Java Development

Spring Tutorial

Spring framework is an open source Java platform that provides comprehensive infrastructure support for developing robust Java applications very easily and very rapidly.

Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.

This tutorial has been written based on Spring Framework version 4.1.6 released in Mar 2015.

Audience

This tutorial is designed for Java programmers with a need to understand the Spring framework in detail along with its architecture and actual usage. This tutorial will bring you at intermediate level of expertise from where you can take yourself at higher level of expertise.

Prerequisites

Before proceeding with this tutorial you should have a good understanding of Java programming language. A basic understanding of NetBeans IDE is also required because all the examples have been compiled using NetBeans IDE.

Spring Framework – Overview

 

Spring is the most popular application development framework for enterprise Java. Millions of developers around the world use Spring Framework to create high performing, easily testable, reusable code.

Spring framework is an open source Java platform and it was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.

Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.

The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based programming model.

Benefits of Using Spring Framework:

Following is the list of few of the great benefits of using Spring Framework:

  • Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product such as an application server but you have the option of using only a robust servlet container such as Tomcat or some commercial product.
  • Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about ones you need and ignore the rest.
  • Spring does not reinvent the wheel instead, it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, other view technologies.
  • Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data.
  • Spring’s web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.
  • Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.
  • Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources.
  • Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example).

Dependency Injection (DI):

The technology that Spring is most identified with is the Dependency Injection (DI) flavor of Inversion of Control. The Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.

When writing a complex Java application, application classes should be as independent as possible of other Java classes to increase the possibility to reuse these classes and to test them independently of other classes while doing unit testing. Dependency Injection helps in gluing these classes together and same time keeping them independent.

What is dependency injection exactly? Let’s look at these two words separately. Here the dependency part translates into an association between two classes. For example, class A is dependent on class B. Now, let’s look at the second part, injection. All this means is that class B will get injected into class A by the IoC.

Dependency injection can happen in the way of passing parameters to the constructor or by post-construction using setter methods. As Dependency Injection is the heart of Spring Framework, so I will explain this concept in a separate chapter with a nice example.

Aspect Oriented Programming (AOP):

One of the key components of Spring is the Aspect oriented programming (AOP) framework. The functions that span multiple points of an application are called cross-cutting concerns and these cross-cutting concerns are conceptually separate from the application’s business logic. There are various common good examples of aspects including logging, declarative transactions, security, and caching etc.

The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Whereas DI helps you decouple your application objects from each other, AOP helps you decouple cross-cutting concerns from the objects that they affect.

The AOP module of Spring Framework provides aspect-oriented programming implementation allowing you to define method-interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated. I will discuss more about Spring AOP concepts in a separate chapter.

Spring Framework – ArchitectureSpring could potentially be a one-stop shop for all your enterprise applications, however, Spring is modular, allowing you to pick and choose which modules are applicable to you, without having to bring in the rest. Following section gives detail about all the modules available in Spring Framework.

The Spring Framework provides about 20 modules which can be used based on an application requirement.

Spring Framework Architecture

Core Container:

The Core Container consists of the Core, Beans, Context, and Expression Language modules whose detail is as follows:

  • The Core module provides the fundamental parts of the framework, including the IoC and Dependency Injection features.
  • The Bean module provides BeanFactory which is a sophisticated implementation of the factory pattern.
  • The Context module builds on the solid base provided by the Core and Beans modules and it is a medium to access any objects defined and configured. The ApplicationContext interface is the focal point of the Context module.
  • The SpEL module provides a powerful expression language for querying and manipulating an object graph at runtime.

Data Access/Integration:

The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules whose detail is as follows:

  • The JDBC module provides a JDBC-abstraction layer that removes the need to do tedious JDBC related coding.
  • The ORM module provides integration layers for popular object-relational mapping APIs, including JPA, JDO, Hibernate, and iBatis.
  • The OXM module provides an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream.
  • The Java Messaging Service JMS module contains features for producing and consuming messages.
  • The Transaction module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs.

Web:

The Web layer consists of the Web, Web-MVC, Web-Socket, and Web-Portlet modules whose detail is as follows:

  • The Web module provides basic web-oriented integration features such as multipart file-upload functionality and the initialization of the IoC container using servlet listeners and a web-oriented application context.
  • The Web-MVC module contains Spring’s model-view-controller (MVC) implementation for web applications.
  • The Web-Socket module provides support for WebSocket-based, two-way communication between client and server in web applications.
  • The Web-Portlet module provides the MVC implementation to be used in a portlet environment and mirrors the functionality of Web-Servlet module.

Miscellaneous:

There are few other important modules like AOP, Aspects, Instrumentation, Web and Test modules whose detail is as follows:

  • The AOP module provides aspect-oriented programming implementation allowing you to define method-interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
  • The Aspects module provides integration with AspectJ which is again a powerful and mature aspect oriented programming (AOP) framework.
  • The Instrumentation module provides class instrumentation support and class loader implementations to be used in certain application servers.
  • The Messaging module provides support for STOMP as the WebSocket sub-protocol to use in applications. It also supports an annotation programming model for routing and processing STOMP messages from WebSocket clients.
  • The Test module supports the testing of Spring components with JUnit or TestNG frameworks.

 

This tutorial will guide you on how to prepare a development environment to start your work with Spring Framework. This tutorial will also teach you how to setup JDK, Tomcat and NetBeans on your machine before you setup Spring Framework:

Step 1 – Setup Java Development Kit (JDK):

You can download the latest version of SDK from Oracle’s Java site: Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

If you are running Windows and installed the JDK in C:\jdk1.6.0_15, you would have to put the following line in your C:\autoexec.bat file.

set PATH=C:\jdk1.6.0_15\bin;%PATH%
set JAVA_HOME=C:\jdk1.6.0_15

Alternatively, on Windows NT/2000/XP, you could also right-click on My Computer, select Properties, then Advanced, then Environment Variables. Then, you would update the PATH value and press the OK button.

On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the C shell, you would put the following into your .cshrc file.

setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.6.0_15

Alternatively, if you use an Integrated Development Environment (IDE) like NetBeans, Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, compile and run a simple program to confirm that the IDE knows where you installed Java, otherwise do proper setup as given document of the IDE.

Step 2 – Install Apache Common Logging API:

You can download the latest version of Apache Commons Logging API from http://commons.apache.org/logging/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\commons-logging-1.1.1 on windows, or /usr/local/commons-logging-1.1.1 on Linux/Unix. This directory will have following jar files and other supporting documents etc.

Common Logging API

Make sure you set your CLASSPATH variable on this directory properly otherwise you will face problem while running your application.

Step 3 – Setup NetBeans IDE

You can download Netbeans IDE here.

Accept the License and Agreement, then download the Java SE and Netbeans Cobundle (JDK 8u91 and NB 8.1) by click the link in download column that suitable with you computer system. By now, because I use Windows 7 64 bit. I choose:

Windows x64 305.83 MB jdk-8u91-nb-8_1-windows-x64.exe

Follow the instruction from the NetBeans Installer and everything should be fine.

Launch the NetBeans IDE and the Interface should be look like this:

Step 4 – Setup Spring Framework Libraries

Now if everything is fine, then you can proceed to setup your Spring framework. Following are the simple steps to download and install the framework on your machine.

  • Make a choice whether you want to install Spring on Windows, or Unix and then proceed to the next step to download .zip file for windows and .tz file for Unix.
  • Download the latest version of Spring framework binaries from http://repo.spring.io/release/org/springframework/spring.
  • At the time of writing this tutorial, I downloaded spring-framework-4.1.6.RELEASE-dist.zip on my Windows machine and when you unzip the downloaded file it will give you directory structure inside spring as follows.

Spring Directories

You will find all the Spring libraries in the directory spring\libs. Make sure you set your CLASSPATH variable on this directory properly otherwise you will face problem while running your application.

Now let’s proceed for the first Spring Example.

Let us start actual programming with Spring Framework. Before you start writing your first example using Spring framework, you have to make sure that you have setup your Spring environment properly as explained in Spring – Environment Setup tutorial. I also assume that you have a little bit working knowledge with NetBeans IDE.

So let us proceed to write a simple Spring Application which will print “Hello World!” or any other message based on the configuration done in Spring Beans Configuration file.

Step 1 – Create Java Project:

The first step is to create a simple Java Project using Eclipse IDE. Follow the option File -> New Project and finally select Java Project wizard from the wizard list. Now name your project as HelloSpring using the wizard window as follows:

 

After open the spring-framework-4.1.6.RELEASE-dist.zip then click Finish.
Once the project is created successfully, you will have following content in your Project Explorer:

Step 2 – Add Required Libraries:

As a second step let us add Spring Framework and common logging API libraries in our project. To do this, right click on your project name HelloSpring and then follow the following option available in context menu: Properties -> Libraries -> Add Jar/Folder to display window as follows:

Now use Add External JARs button available under Libraries tab to add the following core JARs from Spring Framework and Common Logging installation directories:

  • commons-logging-1.1.1
  • spring-aop-4.1.6.RELEASE
  • spring-aspects-4.1.6.RELEASE
  • spring-beans-4.1.6.RELEASE
  • spring-context-4.1.6.RELEASE
  • spring-context-support-4.1.6.RELEASE
  • spring-core-4.1.6.RELEASE
  • spring-expression-4.1.6.RELEASE
  • spring-instrument-4.1.6.RELEASE
  • spring-instrument-tomcat-4.1.6.RELEASE
  • spring-jdbc-4.1.6.RELEASE
  • spring-jms-4.1.6.RELEASE
  • spring-messaging-4.1.6.RELEASE
  • spring-orm-4.1.6.RELEASE
  • spring-oxm-4.1.6.RELEASE
  • spring-test-4.1.6.RELEASE
  • spring-tx-4.1.6.RELEASE
  • spring-web-4.1.6.RELEASE
  • spring-webmvc-4.1.6.RELEASE
  • spring-webmvc-portlet-4.1.6.RELEASE
  • spring-websocket-4.1.6.RELEASE

Step 3 – Create Source Files:

Now let us create actual source files under the HelloSpring project. First we need to create a package called blog.ea To do this, right click on Source Packages in package explorer section and follow the option :

New -> Java Package.

Next we will create HelloWorld.java and MainApp.java files under the com.tutorialspoint package.

New -> Java Class.

Here is the content of HelloWorld.java file:

package blog.ea;

public class HelloWorld {
   private String message;

   public void setMessage(String message){
      this.message  = message;
   }

   public void getMessage(){
      System.out.println("Your Message : " + message);
   }
}

Following is the content of the second file MainApp.java:

package blog.ea;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = 
             new ClassPathXmlApplicationContext("Beans.xml");

      HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

      obj.getMessage();
   }
}

There are following two important points to note about the main program:

  • First step is to create application context where we used framework API ClassPathXmlApplicationContext(). This API loads beans configuration file and eventually based on the provided API, it takes care of creating and initializing all the objects ie. beans mentioned in the configuration file.
  • Second step is used to get required bean using getBean() method of the created context. This method uses bean ID to return a generic object which finally can be casted to actual object. Once you have object, you can use this object to call any class method.

Step 4 – Create Bean Configuration File:

You need to create a Bean Configuration file which is an XML file and acts as cement that glues the beans ie. classes together. This file needs to be created under the src directory as shown below:

Usually developers keep this file name as Beans.xml, but you are independent to choose any name you like. You have to make sure that this file is available in CLASSPATH and use the same name in main application while creating application context as shown in MainApp.java file.

The Beans.xml is used to assign unique IDs to different beans and to control the creation of objects with different values without impacting any of the Spring source files. For example, using below file you can pass any value for “message” variable and so you can print different values of message without impacting HelloWorld.java and MainApp.java files. Let us see how it works:

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

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
       <property name="message" value="Hello World!"/>
   </bean>

</beans>

When Spring application gets loaded into the memory, Framework makes use of the above configuration file to create all the beans defined and assign them a unique ID as defined in <bean> tag. You can use <property> tag to pass the values of different variables used at the time of object creation.

Step 5 – Running the Program:

Once you are done with creating source and beans configuration files, you are ready for this step which is compiling and running your program. To do this, Keep MainApp.Java file tab active and use either Run option available in the NetBeans IDE or use F6 to compile and run your MainApp application. If everything is fine with your application, this will print the following message in Eclipse IDE’s console:

Your Message : Hello World!

Congratulations, you have created your first Spring Application successfully.

Final Project 2016 – CS220 Scripting Language

Final Project 2016 – CS220 Scripting Language. For the Scripting Languages project, we are given a project to create an e-commerce website based on Batik Lasem that created by the Art and Design students, we are going to sell Batik using the website. We are going to have the flexibility  to determine the design and what the website will look like. We have to use the assets from Art and Design student and meet the minimum requirements in order to pass this course.

The minimum requirements for the project is:

We have to use a PHP framework to create this project. CodeIgniter is the suggested framework to be use to create this project. Inside the website we have to create the primary navigation bar, it could be implemented as an image map or as a table of images, text or buttons. We have to create a help and login pages, use appropriate href and/or alt for iamges tags for each menu item. Use title tag to create an appropriate title in every pages. We also have to create a user registration form, a login/user authorization table in a database. Create administrator page. Use a shopping cart. The login form should contain space for name, address, phone, email, gender, etc. The website suppose to be dynamically interactive. We have to define styles using css and use them to give attribute to the html elements. Use javaScript function, use form elements to gather user input or preferences, use the date object to write the date from the server. Create an inventory table in the database, and display the inventory by category upon request from the main page.

My team is consist of:

  1. Timothy Viandy (Me) – 1701319810, who is responsible for developing the front-end.
  2. Michael Ferikson – 1701320794, who is responsible in designing the system and quality control.
  3. Enrico Hugo – 1701320642, who is responsible for developing the back-end and CMS.

The following are the weekly activities that our group will do for the project before going live:

Week 1

  • Gather and document user requirements
  • Design database based on requirements
  • Determine functions to be prepared

Week 2

  • Remake design of existing website
  • Create design for CMS

Week 3

  • Create basic web services as a bridge to database
  • Implement automation for product page
  • Implement automation for navigation bar

Week 4

  • Improve web services
  • Implement design for CMS
  • Create Registration and Login features

Week 5

  • Implement CMS features such as:
    • add / edit / remove products
    • add / edit / remove users
    • add / edit / remove orders
  • Implement new design to old website

Week 6

  • Alpha testing
  • Check and improve functionalities of website

Week 7

  • Beta testing
  • Fix errors and improve from user feedbacks

The finished website will be stored and used locally, and therefore uploaded to the class’ dropbox to be evaluated by Mr. Raymond Bahana.