/**
* 主页模块(每个网页中包含了不同的模块,用于存放一个主页中的其中的一个模块信息,比如在一个区域中包含的一个模块名称、地址、模板名称、图标等)
*
* @author 杨伦亮 12:24:35 PM
*/
public class Block {
private String id = "";// 编号
private String sequence = "";// 序号
private String type = "";// 模块类型
private String content = "";// 模块地址
private String title = "";// 模块显示标题
private String tplname = "";// 采用的模板名称
private String lmname = "";// 栏目名称
private String icon = "";// 图标
private String config = "";
private String cCount = "";//列数量
private String rCount = "";//行数量
private String txtLength = "";//文本长度
private String infolist = "";//
private String site = "";
private String picw = "";
private String pich = "";
private String lanmu = "";
private String author = "";//作者
private String css="";
public String getCss() {
return css;
}
……
}
/**
* Block排序
* @author 杨伦亮
* 下午3:16:23
*/
public static class ComparatorBlock implements Comparator{
public int compare(Object o1, Object o2) {
Block b1=(Block)o1;
Block b2=(Block)o2;
//首先比较blockID其次是其类型
int flag=Integer.valueOf(b1.getId()).compareTo(Integer.valueOf(b2.getId()));
if(flag==0){
return b1.getType().compareTo(b2.getType());
}else{
return flag;
}
}
}
使用方法
public static void main(String[] args) {
try{
File file=new File("**.xml");
String express="/page/area[@id='a1']/block";
List<Block>bList=queryBlocks(file, express);
for(Block b:bList){
System.out.println(b.getId());
}
}catch (Exception e) {
e.printStackTrace();
}
}