Reformat and clean up "provider" package
This commit is contained in:
@@ -29,9 +29,9 @@ import provider.DataFileEntry;
|
||||
import java.util.*;
|
||||
|
||||
public class WZDirectoryEntry extends WZEntry implements DataDirectoryEntry {
|
||||
private List<DataDirectoryEntry> subdirs = new ArrayList<>();
|
||||
private List<DataFileEntry> files = new ArrayList<>();
|
||||
private Map<String, DataEntry> entries = new HashMap<>();
|
||||
private final List<DataDirectoryEntry> subdirs = new ArrayList<>();
|
||||
private final List<DataFileEntry> files = new ArrayList<>();
|
||||
private final Map<String, DataEntry> entries = new HashMap<>();
|
||||
|
||||
public WZDirectoryEntry(String name, int size, int checksum, DataEntity parent) {
|
||||
super(name, size, checksum, parent);
|
||||
|
||||
@@ -25,11 +25,11 @@ import provider.DataEntity;
|
||||
import provider.DataEntry;
|
||||
|
||||
public class WZEntry implements DataEntry {
|
||||
private String name;
|
||||
private int size;
|
||||
private int checksum;
|
||||
private final String name;
|
||||
private final int size;
|
||||
private final int checksum;
|
||||
private int offset;
|
||||
private DataEntity parent;
|
||||
private final DataEntity parent;
|
||||
|
||||
public WZEntry(String name, int size, int checksum, DataEntity parent) {
|
||||
super();
|
||||
|
||||
@@ -42,168 +42,168 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class XMLDomMapleData implements Data {
|
||||
private Node node;
|
||||
private File imageDataDir;
|
||||
private final Node node;
|
||||
private File imageDataDir;
|
||||
|
||||
public XMLDomMapleData(FileInputStream fis, File imageDataDir) {
|
||||
try {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(fis);
|
||||
this.node = document.getFirstChild();
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.imageDataDir = imageDataDir;
|
||||
}
|
||||
public XMLDomMapleData(FileInputStream fis, File imageDataDir) {
|
||||
try {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(fis);
|
||||
this.node = document.getFirstChild();
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.imageDataDir = imageDataDir;
|
||||
}
|
||||
|
||||
private XMLDomMapleData(Node node) {
|
||||
this.node = node;
|
||||
}
|
||||
private XMLDomMapleData(Node node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Data getChildByPath(String path) { // the whole XML reading system seems susceptible to give nulls on strenuous read scenarios
|
||||
String[] segments = path.split("/");
|
||||
if (segments[0].equals("..")) {
|
||||
return ((Data) getParent()).getChildByPath(path.substring(path.indexOf("/") + 1));
|
||||
}
|
||||
@Override
|
||||
public synchronized Data getChildByPath(String path) { // the whole XML reading system seems susceptible to give nulls on strenuous read scenarios
|
||||
String[] segments = path.split("/");
|
||||
if (segments[0].equals("..")) {
|
||||
return ((Data) getParent()).getChildByPath(path.substring(path.indexOf("/") + 1));
|
||||
}
|
||||
|
||||
Node myNode;
|
||||
myNode = node;
|
||||
for (String s : segments) {
|
||||
NodeList childNodes = myNode.getChildNodes();
|
||||
boolean foundChild = false;
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node childNode = childNodes.item(i);
|
||||
if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) {
|
||||
myNode = childNode;
|
||||
foundChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundChild) {
|
||||
return null;
|
||||
}
|
||||
Node myNode;
|
||||
myNode = node;
|
||||
for (String s : segments) {
|
||||
NodeList childNodes = myNode.getChildNodes();
|
||||
boolean foundChild = false;
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node childNode = childNodes.item(i);
|
||||
if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) {
|
||||
myNode = childNode;
|
||||
foundChild = true;
|
||||
break;
|
||||
}
|
||||
|
||||
XMLDomMapleData ret = new XMLDomMapleData(myNode);
|
||||
ret.imageDataDir = new File(imageDataDir, getName() + "/" + path).getParentFile();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (!foundChild) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Data> getChildren() {
|
||||
List<Data> ret = new ArrayList<>();
|
||||
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node childNode = childNodes.item(i);
|
||||
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
XMLDomMapleData child = new XMLDomMapleData(childNode);
|
||||
child.imageDataDir = new File(imageDataDir, getName());
|
||||
ret.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
XMLDomMapleData ret = new XMLDomMapleData(myNode);
|
||||
ret.imageDataDir = new File(imageDataDir, getName() + "/" + path).getParentFile();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Data> getChildren() {
|
||||
List<Data> ret = new ArrayList<>();
|
||||
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node childNode = childNodes.item(i);
|
||||
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
XMLDomMapleData child = new XMLDomMapleData(childNode);
|
||||
child.imageDataDir = new File(imageDataDir, getName());
|
||||
ret.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object getData() {
|
||||
NamedNodeMap attributes = node.getAttributes();
|
||||
DataType type = getType();
|
||||
switch (type) {
|
||||
case DOUBLE:
|
||||
case FLOAT:
|
||||
case INT:
|
||||
case SHORT: {
|
||||
String value = attributes.getNamedItem("value").getNodeValue();
|
||||
Number nval = GameConstants.parseNumber(value);
|
||||
|
||||
@Override
|
||||
public synchronized Object getData() {
|
||||
NamedNodeMap attributes = node.getAttributes();
|
||||
DataType type = getType();
|
||||
switch (type) {
|
||||
case DOUBLE:
|
||||
case FLOAT:
|
||||
case INT:
|
||||
case SHORT: {
|
||||
String value = attributes.getNamedItem("value").getNodeValue();
|
||||
Number nval = GameConstants.parseNumber(value);
|
||||
|
||||
switch (type) {
|
||||
case DOUBLE:
|
||||
return nval.doubleValue();
|
||||
case FLOAT:
|
||||
return nval.floatValue();
|
||||
case INT:
|
||||
return nval.intValue();
|
||||
case SHORT:
|
||||
return nval.shortValue();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
case STRING:
|
||||
case UOL: {
|
||||
String value = attributes.getNamedItem("value").getNodeValue();
|
||||
return value;
|
||||
}
|
||||
case VECTOR: {
|
||||
String x = attributes.getNamedItem("x").getNodeValue();
|
||||
String y = attributes.getNamedItem("y").getNodeValue();
|
||||
return new Point(Integer.parseInt(x), Integer.parseInt(y));
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized DataType getType() {
|
||||
String nodeName = node.getNodeName();
|
||||
|
||||
switch (nodeName) {
|
||||
case "imgdir":
|
||||
return DataType.PROPERTY;
|
||||
case "canvas":
|
||||
return DataType.CANVAS;
|
||||
case "convex":
|
||||
return DataType.CONVEX;
|
||||
case "sound":
|
||||
return DataType.SOUND;
|
||||
case "uol":
|
||||
return DataType.UOL;
|
||||
case "double":
|
||||
return DataType.DOUBLE;
|
||||
case "float":
|
||||
return DataType.FLOAT;
|
||||
case "int":
|
||||
return DataType.INT;
|
||||
case "short":
|
||||
return DataType.SHORT;
|
||||
case "string":
|
||||
return DataType.STRING;
|
||||
case "vector":
|
||||
return DataType.VECTOR;
|
||||
case "null":
|
||||
return DataType.IMG_0x00;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized DataEntity getParent() {
|
||||
Node parentNode;
|
||||
parentNode = node.getParentNode();
|
||||
if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
case DOUBLE:
|
||||
return nval.doubleValue();
|
||||
case FLOAT:
|
||||
return nval.floatValue();
|
||||
case INT:
|
||||
return nval.intValue();
|
||||
case SHORT:
|
||||
return nval.shortValue();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
XMLDomMapleData parentData = new XMLDomMapleData(parentNode);
|
||||
parentData.imageDataDir = imageDataDir.getParentFile();
|
||||
return parentData;
|
||||
}
|
||||
}
|
||||
case STRING:
|
||||
case UOL: {
|
||||
String value = attributes.getNamedItem("value").getNodeValue();
|
||||
return value;
|
||||
}
|
||||
case VECTOR: {
|
||||
String x = attributes.getNamedItem("x").getNodeValue();
|
||||
String y = attributes.getNamedItem("y").getNodeValue();
|
||||
return new Point(Integer.parseInt(x), Integer.parseInt(y));
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String getName() {
|
||||
return node.getAttributes().getNamedItem("name").getNodeValue();
|
||||
}
|
||||
@Override
|
||||
public synchronized DataType getType() {
|
||||
String nodeName = node.getNodeName();
|
||||
|
||||
@Override
|
||||
public synchronized Iterator<Data> iterator() {
|
||||
return getChildren().iterator();
|
||||
}
|
||||
switch (nodeName) {
|
||||
case "imgdir":
|
||||
return DataType.PROPERTY;
|
||||
case "canvas":
|
||||
return DataType.CANVAS;
|
||||
case "convex":
|
||||
return DataType.CONVEX;
|
||||
case "sound":
|
||||
return DataType.SOUND;
|
||||
case "uol":
|
||||
return DataType.UOL;
|
||||
case "double":
|
||||
return DataType.DOUBLE;
|
||||
case "float":
|
||||
return DataType.FLOAT;
|
||||
case "int":
|
||||
return DataType.INT;
|
||||
case "short":
|
||||
return DataType.SHORT;
|
||||
case "string":
|
||||
return DataType.STRING;
|
||||
case "vector":
|
||||
return DataType.VECTOR;
|
||||
case "null":
|
||||
return DataType.IMG_0x00;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized DataEntity getParent() {
|
||||
Node parentNode;
|
||||
parentNode = node.getParentNode();
|
||||
if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
|
||||
return null;
|
||||
}
|
||||
XMLDomMapleData parentData = new XMLDomMapleData(parentNode);
|
||||
parentData.imageDataDir = imageDataDir.getParentFile();
|
||||
return parentData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String getName() {
|
||||
return node.getAttributes().getNamedItem("name").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Iterator<Data> iterator() {
|
||||
return getChildren().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class XMLWZFile implements DataProvider {
|
||||
private File root;
|
||||
private WZDirectoryEntry rootForNavigation;
|
||||
private final File root;
|
||||
private final WZDirectoryEntry rootForNavigation;
|
||||
|
||||
public XMLWZFile(File fileIn) {
|
||||
root = fileIn;
|
||||
|
||||
Reference in New Issue
Block a user