日历
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
24 | 25 | 26 | 27 | 28 | 29 | 30 | 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 | 31 | 1 | 2 | 3 | 4 |
|
统计
- 随笔 - 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(); }
|