mobile-web integration with open source tools (2)

32
Mobile-Web Integration Mobile-Web Integration with Open Source with Open Source Tools(2) Tools(2) Mikimoto Mikimoto CEO, Y.Tiger DIGITAL Inc. CEO, Y.Tiger DIGITAL Inc.

Upload: mikimoto-chuang

Post on 31-May-2015

896 views

Category:

Technology


6 download

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

TRANSCRIPT

Page 1: Mobile-Web Integration with Open Source Tools (2)

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.

Page 2: Mobile-Web Integration with Open Source Tools (2)

Mikimoto Mikimoto 美樹本美樹本

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

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

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

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

Page 3: Mobile-Web Integration with Open Source Tools (2)

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

Page 4: Mobile-Web Integration with Open Source Tools (2)

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

Page 5: Mobile-Web Integration with Open Source Tools (2)

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

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

Page 6: Mobile-Web Integration with Open Source Tools (2)

Web ServiceWeb Service

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

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

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

Page 7: Mobile-Web Integration with Open Source Tools (2)

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

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

Page 8: Mobile-Web Integration with Open Source Tools (2)

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

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

Shoot and forgetShoot and forget

InterfaceInterface

Page 9: Mobile-Web Integration with Open Source Tools (2)

Java CSV ParserJava CSV Parser

Page 10: Mobile-Web Integration with Open Source Tools (2)

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

Page 11: Mobile-Web Integration with Open Source Tools (2)

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

Page 12: Mobile-Web Integration with Open Source Tools (2)

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

Page 13: Mobile-Web Integration with Open Source Tools (2)

123,456.00 123,456.00 123.456,00123.456,00

Page 14: Mobile-Web Integration with Open Source Tools (2)

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

Page 15: Mobile-Web Integration with Open Source Tools (2)

分行字元 分行字元 ??

Page 16: Mobile-Web Integration with Open Source Tools (2)

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

Page 17: Mobile-Web Integration with Open Source Tools (2)

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();

Page 18: Mobile-Web Integration with Open Source Tools (2)

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

Page 19: Mobile-Web Integration with Open Source Tools (2)

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();

Page 20: Mobile-Web Integration with Open Source Tools (2)

Write a CSV file: Write a CSV file:

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

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

Page 21: Mobile-Web Integration with Open Source Tools (2)

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

Page 22: Mobile-Web Integration with Open Source Tools (2)

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);

Page 23: Mobile-Web Integration with Open Source Tools (2)

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(); } }

Page 24: Mobile-Web Integration with Open Source Tools (2)

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();

Page 25: Mobile-Web Integration with Open Source Tools (2)

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

Page 26: Mobile-Web Integration with Open Source Tools (2)

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

Page 27: Mobile-Web Integration with Open Source Tools (2)

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 ))

Page 28: Mobile-Web Integration with Open Source Tools (2)

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

Page 29: Mobile-Web Integration with Open Source Tools (2)

近似 近似 RoR RoR 的 的 PHP FrameworkPHP Framework

Page 30: Mobile-Web Integration with Open Source Tools (2)

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)

Page 31: Mobile-Web Integration with Open Source Tools (2)

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

Page 32: Mobile-Web Integration with Open Source Tools (2)

成果展示成果展示