日歷
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 |
|
統計
- 隨筆 - 1
- 文章 - 40
- 評論 - 4
- 引用 - 0
導航
常用鏈接
留言簿(1)
文章分類
文章檔案
相冊
收藏夾
它山之石
聚賢莊
搜索
最新評論

|
XML(area.xml)
<?xml version="1.0" encoding="GBK"?>

<menu>
<locations>
<site>北京</site>
<site>上海</site>
<site>重慶</site>
<site>浙江</site>
<site>廣東</site>
<site>湖北</site>
</locations>
<area location="北京" citysStr="東城區,西城區,海淀區,朝陽區" />

<area location="上海" citysStr="黃浦區,徐匯區,長寧區,靜安區,普陀區,閘北區" />

<area location="重慶" citysStr="渝中區,大渡口區,江北區,沙坪壩區,九龍坡區,南岸區" />

<area location="浙江" citysStr="杭州市,寧波市,溫州市,嘉興市,湖州市,紹興市" />

<area location="廣東" citysStr="廣州市,深圳市,珠海市,佛山市,東莞市" />

<area location="湖北" citysStr="武漢市,黃石市,十堰市,荊州市,宜昌市,咸寧市" />
</menu> Model
Area.java
package org.weibo.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.weibo.lang.Strings;

 public class Area {
private String location;

private String citysStr;

private List<String> citys = new ArrayList<String>();

 public List<String> getCitys() {
return citys;
}

 public void setCitys() {
 if (!Strings.isEmptyValue(citysStr)) {
String cityArray[] = citysStr.split(",");

this.citys = Arrays.asList(cityArray);
}
}

 public void setCitysStr(String citysStr) {
this.citysStr = citysStr;

setCitys();
}

 public void setLocation(String location) {
this.location = location;
}

 public String getLocation() {
return location;
}

 public String getLocations() {
return location;
}
}TheAreaMenu.java
package org.weibo.model;

import java.util.ArrayList;
import java.util.List;

 public class TheAreaMenu {
private List<String> locations = new ArrayList<String>();

private List<Area> areas = new ArrayList<Area>();

 public void addLocations(String location) {
locations.add(location);
}

 public List<String> getLocations() {
return locations;
}

 public void addAreas(Area area) {
areas.add(area);
}

 public List<Area> getAreas() {
return areas;
}
}
 ApplicationCode
 try {

Digester digester = new Digester();
digester.setValidating(false);

digester.addObjectCreate("menu", "org.weibo.model.TheAreaMenu");

digester.addCallMethod("menu/locations/site", "addLocations", 1);
digester.addCallParam("menu/locations/site", 0);

// fdsafafafs0000
digester.addObjectCreate("menu/area", "org.weibo.model.Area");
digester.addSetProperties("menu/area");

digester.addSetNext("menu/area", "addAreas");

TheAreaMenu menu = (TheAreaMenu) digester.parse(getClass()
.getResourceAsStream("/areas.xml"));

List<String> locations = menu.getLocations();

 for (String theLocation : locations) {
System.out.print(theLocation + ",");
}
System.out.println();

List<Area> areas = menu.getAreas();

 for (Area theArea : areas) {
System.out.print(theArea.getLocation() + "=");

List<String> citys = theArea.getCitys();

 for (String theCity : citys) {
System.out.print(theCity + ",");
}
System.out.println();
}

// new InputStreamReader(getClass().getResourceAsStream(
// "/areas.properties"), "GBK");

 } catch (IOException e) {
e.printStackTrace();
 } catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|