📄 personutils.java
字号:
package com.swing.game.crystal.utils;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger;
import org.dom4j.Element;
import java.util.Map;
import java.util.HashMap;
import java.io.File;
import java.util.List;
import org.dom4j.io.SAXReader;
import org.dom4j.Document;
import java.util.Iterator;
public class PersonUtils {
public static Logger logger = Logger.getLogger(PersonUtils.class);
static {
PropertyConfigurator.configure("./cfg/Log4j.properties");
}
public static final String fileName = "./xml/Person.xml";
public static Map initPerson() {
Map m = new HashMap();
try {
SAXReader reader = new SAXReader();
Document document = reader.read(new File(fileName));
Element root = document.getRootElement();
List l = root.selectNodes("//Persons/person");
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Element e = (Element) iter.next();
Person p = new Person();
p.hp = Integer.parseInt(e.selectSingleNode("hp").getText());
p.power = Integer.parseInt(e.selectSingleNode("power").getText());
p.attack = Integer.parseInt(e.selectSingleNode("attack").getText());
p.defense = Integer.parseInt(e.selectSingleNode("defense").getText());
p.resurrection = Integer.parseInt(e.selectSingleNode("resurrection").getText());
p.agility = Integer.parseInt(e.selectSingleNode("agility").getText());
p.shoe = e.selectSingleNode("shoe").getText();
p.suit = e.selectSingleNode("suit").getText();
p.capacity = Integer.parseInt(e.selectSingleNode("capacity").getText());
List w = e.selectNodes("weapon/Element");
for (Iterator i = w.iterator(); i.hasNext(); )
p.weapon.add(((Element)i.next()).attributeValue("id"));
m.put(e.attributeValue("id"), p);
}
}
catch (Exception e) {
logger.error(e);
}
return m;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -