Skip to content

Commit

Permalink
Merge pull request #1 from AdeelIlyas2014/master
Browse files Browse the repository at this point in the history
Aspose.Barcode Java for Struts 1.3 - v1.0 - Plugin added
  • Loading branch information
aspose-barcode-gists committed Jul 10, 2015
2 parents df15fce + 7174444 commit f3fecb4
Show file tree
Hide file tree
Showing 21 changed files with 856 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Plugins/Aspose_Barcode_for_Struts/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
29 changes: 29 additions & 0 deletions Plugins/Aspose_Barcode_for_Struts/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Aspose_Barcode_for_Struts</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions Plugins/Aspose_Barcode_for_Struts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Aspose.Barcode Java for Struts 1.3

Aspose Barcode Java for Struts is a Maven based struts 1.3 web project that demonstrates the usage of Aspose.Barcode for Java API (for generating barcode images) within Apache Struts 1.3 Web MVC and Maven frameworks.

The project can be built through mvn command line without any IDE support.

However the project can also be easily imported in any IDE i.e IntelliJ IDEA and NetBeans etc.

You should have Apache Tomcat pre-installed. After building the project .war file, just copy it to webapp folder.

For complete documentation of the project, check Aspose.Barcode Java for Struts confluence wiki

http://www.aspose.com/docs/display/barcodejava/1.+Aspose.Barcode+Java+For+Struts

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.books;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.actions.DispatchAction;

import com.books.aspose.AsposeAPI;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
*
* @author Adeel
*
*/

public class BookActions extends DispatchAction {
public ActionForward AddBook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Add Book Page");
return mapping.findForward("addBook");
}

public ActionForward EditBook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Edit Book Page");
int bookId = Integer.parseInt(request.getParameter("bookId"));

Books b = Books.getInstance();
Map bookDet = b.searchBook(bookId);

// Used form bean class methods to fill the form input elements with
// selected book values.
BookForm bf = (BookForm) form;
bf.setBookName(bookDet.get("BookName").toString());
bf.setAuthorName(bookDet.get("AuthorName").toString());
bf.setBookCost((Integer) bookDet.get("BookCost"));
bf.setBookId((Integer) bookDet.get("BookId"));
return mapping.findForward("editBook");
}

public ActionForward SaveBook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Save Book");
// Used form bean class methods to get the value of form input elements.
BookForm bf = (BookForm) form;
String bookName = bf.getBookName();
String authorName = bf.getAuthorName();
int bookCost = bf.getBookCost();

Books b = Books.getInstance();
b.storeBook(bookName, authorName, bookCost);
return new ActionForward("/showbooks.do", true);
}

public ActionForward UpdateBook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Update Book");
BookForm bf = (BookForm) form;
String bookName = bf.getBookName();
String authorName = bf.getAuthorName();
int bookCost = bf.getBookCost();
int bookId = bf.getBookId();

Books b = Books.getInstance();
b.updateBook(bookId, bookName, authorName, bookCost);
return new ActionForward("/showbooks.do", true);
}

public ActionForward DeleteBook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Delete Book");
int bookId = Integer.parseInt(request.getParameter("bookId"));
Books b = Books.getInstance();
b.deleteBook(bookId);
return new ActionForward("/showbooks.do", true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.books;

import org.apache.struts.action.ActionForm;

public class BookForm extends ActionForm {

private String bookName;
private String authorName;
private int bookCost;
private int bookId;

public BookForm() {
super();
}

public String getBookName() {
return bookName;
}

public void setBookName(String bookName) {
this.bookName = bookName;
}

public String getAuthorName() {
return authorName;
}

public void setAuthorName(String authorName) {
this.authorName = authorName;
}

public int getBookCost() {
return bookCost;
}

public void setBookCost(int bookCost) {
this.bookCost = bookCost;
}

public int getBookId() {
return bookId;
}

public void setBookId(int bookId) {
this.bookId = bookId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.books;

import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;

class Books {

int bookIdCount = 1000;
Map<Integer, StoreBook> bookMap = new HashMap<Integer, StoreBook>();
private static Books books = null;

private Books() {
}

public static Books getInstance() {
if (books == null) {
books = new Books();
books.storeBook("Mastering Java", "John Zakowsi", 200);
books.storeBook(
"Struts in Action",
"Cedric Dumoulin, David Winterfeldt, George Franciscus, and Ted Husted",
500);

}
return books;
}

public void storeBook(String bookName, String authorName, int bookCost) {
StoreBook sb = new StoreBook();
bookIdCount++;
sb.addBook(bookIdCount, bookName, authorName, bookCost);
bookMap.put(bookIdCount, sb);
}

public void updateBook(int bookId, String bookName, String authorName,
int bookCost) {
StoreBook sb = bookMap.get(bookId);
sb.updateBook(bookName, authorName, bookCost);
}

public Map searchBook(int bookId) {
return bookMap.get(bookId).getBooks();
}

public void deleteBook(int bookId) {
bookMap.remove(bookId);
}

// Inner Class used to persist the app data ie) book details.
class StoreBook {

private String bookName;
private String authorName;
private int bookCost;
private int bookId;

StoreBook() {
}

public void addBook(int bookId, String bookName, String authorName,
int bookCost) {
this.bookId = bookId;
this.bookName = bookName;
this.authorName = authorName;
this.bookCost = bookCost;
}

public void updateBook(String bookName, String authorName, int bookCost) {
this.bookName = bookName;
this.authorName = authorName;
this.bookCost = bookCost;
}

public Map getBooks() {
Map books = new HashMap();
books.put("BookId", this.bookId);
books.put("BookName", this.bookName);
books.put("AuthorName", this.authorName);
books.put("BookCost", this.bookCost);
return books;
}
}

public List getBookList() {
List booksList = new ArrayList();
Set s = bookMap.keySet();
Iterator itr = s.iterator();
while (itr.hasNext()) {
booksList.add(bookMap.get((Integer) itr.next()).getBooks());
}
return booksList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.books;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ShowBooks extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Show Books List");
Books b = Books.getInstance();
request.setAttribute("booksList", b.getBookList());
return mapping.findForward("success");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.books.aspose;

import javax.servlet.ServletOutputStream;

import com.aspose.barcode.BarCodeBuilder;
import com.aspose.barcode.BarCodeImageFormat;
import com.aspose.barcode.CodeLocation;

/*
* @author: Adeel Ilyas
* Company: Aspose Pty Ltd.
*
*/
public class AsposeAPI {
public static void createAsposeBarCode(String billAmount,
ServletOutputStream out, String symbology) {

BarCodeBuilder bb = new BarCodeBuilder();

// Set up code text (data to be encoded)
bb.setCodeText(billAmount);

// Set up code text color
bb.setCodeTextColor(java.awt.Color.RED);

// Set the location of the code text to above the barcode
bb.setCodeLocation(CodeLocation.Above);

// Increase the space between code text and barcode to 1 point
bb.setCodeTextSpace(1.0f);

// Set the symbology type
bb.setSymbologyType(Long.valueOf(symbology));

bb.save(out, BarCodeImageFormat.Png);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.books.aspose;

/**
* Created by Adeel Ilyas on 7/6/2015.
*/
/*
* @author: Adeel Ilyas
* Company: Aspose Pty Ltd.
*/

public interface AsposeAPIConfiguration {

public static final String BarcodeServiceURL = "/asposeBarcode.do";

public static final String BarcodeTypeConstantClass="com.aspose.barcode.Symbology";
}

Loading

0 comments on commit f3fecb4

Please sign in to comment.