com.daxie.xops.xml.WeaponDataXMLParser Maven / Gradle / Ivy
package com.daxie.xops.xml;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.daxie.basis.vector.Vector;
import com.daxie.log.LogFile;
import com.daxie.tool.ExceptionFunctions;
import com.daxie.xops.openxops.WeaponSpecifierConverter;
import com.daxie.xops.weapon.WeaponData;
import com.daxie.xops.weapon.WeaponScopeMode;
import com.daxie.xops.weapon.WeaponShootingStance;
/**
* Loads weapon data from a XML file created using this library.
* @author Daba
*
*/
public class WeaponDataXMLParser {
private Map weapon_data_map;
private boolean openxops_compatible_flag;
public WeaponDataXMLParser() {
weapon_data_map=new HashMap<>();
openxops_compatible_flag=true;
}
public void SetOpenXOPSCompatibleFlag(boolean openxops_compatible_flag) {
this.openxops_compatible_flag=openxops_compatible_flag;
}
/**
* Loads weapon data from a XML file.
* @param xml_filename Filename
* @return -1 on error and 0 on success
*/
public int LoadWeaponDataXML(String xml_filename) {
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=null;
try {
builder=factory.newDocumentBuilder();
}
catch(ParserConfigurationException e) {
String str=ExceptionFunctions.GetPrintStackTraceString(e);
LogFile.WriteWarn("[WeaponDataXMLParser-LoadWeaponDataXML] Below is the stack trace.",true);
LogFile.WriteWarn(str,false);
return -1;
}
Document document=null;
try {
document=builder.parse(Paths.get(xml_filename).toFile());
}
catch(Exception e) {
String str=ExceptionFunctions.GetPrintStackTraceString(e);
LogFile.WriteWarn("[WeaponDataXMLParser-LoadWeaponDataXML] Below is the stack trace.",true);
LogFile.WriteWarn(str,false);
return -1;
}
Element el_weapon_data_list=document.getDocumentElement();
NodeList node_list=el_weapon_data_list.getChildNodes();
for(int i=0;i GetWeaponDataMap(){
return new HashMap<>(weapon_data_map);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy