Mobile-Web Integration with Open Source Tools (2)

Preview:

DESCRIPTION

This is the first half of the talk given by Lukhnos and Mikimoto Chuang. They talk about how to use open source tools and libraries to integrate mobile client software with server-side services. Some thoughts and best practices are given. The cast study is TapExpense, an iPhone expense tracker. Also featuring their experiences in tackling wacky wifi/3G connections and CSV/XLS formats. The talk is given at OSDC.tw 2009 on April 19, 2009

Citation preview

Mobile-Web Integration Mobile-Web Integration with Open Source Tools(2)with Open Source Tools(2)MikimotoMikimoto

CEO, Y.Tiger DIGITAL Inc.CEO, Y.Tiger DIGITAL Inc.

Mikimoto Mikimoto 美樹本美樹本

資深系統工程師、系統架構師、顧問資深系統工程師、系統架構師、顧問

過往專案經歷:族繁不及備載過往專案經歷:族繁不及備載

目前在玩目前在玩電子發票、國內外押匯、信用賒銷、電子發票、國內外押匯、信用賒銷、海運提單等金融系統海運提單等金融系統

專研軟體工程、系統分析專研軟體工程、系統分析

Server-Side AgendaServer-Side Agenda

Server side skeletonServer side skeleton

CSV ParserCSV Parser

Excel APIExcel API

CakePHP Framework CakePHP Framework

Google Graph APIGoogle Graph API

DemoDemo

Web Service’s Web Service’s NEXT NEXT STEPSTEP??

ª›®œ•Œ QuickTime˛ ©M°ß°®∏—¿£¡Yæπ

®”¿Àµ¯¶ππœµe°C

Web ServiceWeb Service

已經廣泛被各界所使用已經廣泛被各界所使用

有效減低系統複雜度、耦合度等問題有效減低系統複雜度、耦合度等問題

Cloud Computing (Cloud Computing ( 雲端運算雲端運算 ) ?) ?

其實其實移動式裝置移動式裝置才是才是

最需要最需要 Cloud ComputingCloud Computing 的對象的對象

Server-Side Server-Side 設計理念:設計理念:

Client Client 端視為離線裝置端視為離線裝置

Shoot and forgetShoot and forget

InterfaceInterface

Java CSV ParserJava CSV Parser

String.split(regular express)String.split(regular express)

But... But... 有規則就會有例外有規則就會有例外

資料中含有分隔字元資料中含有分隔字元 (( 貨貨幣幣 ...)...)

123,456.00 123,456.00 123.456,00123.456,00

xxxxxx, xxxxxx, xxxxxx, xxxxxx, "aaa,bbb,c ""aaa,bbb,c "

分行字元 分行字元 ??

OpenCSV OpenCSV ((http://opencsv.sourceforge.http://opencsv.sourceforge.netnet))

Read a CSV fileRead a CSV file

new CSVReader(FileReader, new CSVReader(FileReader, <quote>,<sp>,<skip line>)<quote>,<sp>,<skip line>)

String line = CSVReader.readNext();String line = CSVReader.readNext();

List<String> list = CSVReader.readAll();List<String> list = CSVReader.readAll();

List<YourObject> list =List<YourObject> list = CSVToBean.parse( CSVToBean.parse( ColumnPositionMappingStrategy, ColumnPositionMappingStrategy, Reader );Reader );

Write a CSV file: Write a CSV file:

CSVWriter writer = new CSVWriter(CSVWriter writer = new CSVWriter( new FileWriter("yourfile.csv"), '\t'); new FileWriter("yourfile.csv"), '\t');

String[] entries = {" first ", " second ", String[] entries = {" first ", " second ", "third "}"third "}

writer.writeNext(entries);writer.writeNext(entries);

writer.close();writer.close();

Write a CSV file: Write a CSV file:

java.sql.ResultSet myResultSet = ....java.sql.ResultSet myResultSet = ....

writer.writeAll(myResultSet, writer.writeAll(myResultSet, includeHeaders);includeHeaders);

Java Excel APIJava Excel API((http://jexcelapi.sourceforge.http://jexcelapi.sourceforge.netnet//))

workbook = Workbook.getWorkbook(workbook = Workbook.getWorkbook( new new File("myfile.xls"));File("myfile.xls"));Sheet sheet = workbook.getSheet(0);Sheet sheet = workbook.getSheet(0);

Cell a1 = sheet.getCell(0,0); Cell a1 = sheet.getCell(0,0); Cell b2 = sheet.getCell(1,1); Cell b2 = sheet.getCell(1,1); Cell c2 = sheet.getCell(2,1); Cell c2 = sheet.getCell(2,1);

if (a1.getType() == CellType.LABEL) { if (a1.getType() == CellType.LABEL) { LabelCell lc = (LabelCell) a1; LabelCell lc = (LabelCell) a1; stringa1 = lc.getString(); stringa1 = lc.getString(); }}

if (b2.getType() == CellType.NUMBER) { if (b2.getType() == CellType.NUMBER) { NumberCell nc = (NumberCell) b2; NumberCell nc = (NumberCell) b2; numberb2 = nc.getValue(); numberb2 = nc.getValue(); } }

workbook = Workbook.createWorkbook(workbook = Workbook.createWorkbook( new new File("output.xls"));File("output.xls"));WritableSheet sheet = workbook.WritableSheet sheet = workbook. createSheet("First Sheet", createSheet("First Sheet", 0);0);

Label label = new Label(0, 2, "A label record"); Label label = new Label(0, 2, "A label record"); sheet.addCell(label); sheet.addCell(label);

Number number = new Number(3, 4, 3.1459); Number number = new Number(3, 4, 3.1459); sheet.addCell(number);sheet.addCell(number);

workbook.write();workbook.write();

世事無絕對,對人要更世事無絕對,對人要更好 好 ......

Excel TimeStampExcel TimeStamp

Excel PCExcel PC 上序列值以 上序列值以 1900-1-1 1900-1-1 為 為 11 ,每過一天,每過一天加 加 11

Excel Mac Excel Mac 上序列值以 上序列值以 1904-1-1 1904-1-1 為 為 11

用 用 Mac Mac 打開 打開 PC PC 版本,版本, Copy/Paste Copy/Paste 不會出錯,不會出錯,自己打就會出錯自己打就會出錯

Unix Unix 以 以 1970-1-1 00:00:00 UTC1970-1-1 00:00:00 UTC ,每一秒加 ,每一秒加 11

Excel Bug: Excel Bug:

From Lotus 1-2-3 From Lotus 1-2-3 當年為了市佔率當年為了市佔率

1900 1900 並不是閏年,但被當成閏年處理 (並不是閏年,但被當成閏年處理 ( 1900-1900-1-1 ~ 1900-3-1, 1-1 ~ 1900-3-1, 會出現 會出現 1900-2-291900-2-29 ))

CakePHP FrameworkCakePHP Framework((http://cakephp.orghttp://cakephp.org//))

近似 近似 RoR RoR 的 的 PHP FrameworkPHP Framework

Model : post.phpModel : post.php

Controller : posts_controller.phpController : posts_controller.php

Less than 10 lines codeLess than 10 lines code

It’s fucking working!! (It’s fucking working!! ( 感謝 感謝 Mat)Mat)

Google Graph APIGoogle Graph API

http://code.google.com/intl/zh-TW/apis/chart/http://code.google.com/intl/zh-TW/apis/chart/

http://code.google.com/intl/zh-TW/apis/chart/tyhttp://code.google.com/intl/zh-TW/apis/chart/types.htmlpes.html

http://chart.apis.google.com/chart?http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hellcht=p3&chd=t:60,40&chs=250x100&chl=Hello|o|WorldWorld

實際 實際 DemoDemo

成果展示成果展示

Recommended