Outputting partial updated definitions

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@369 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Jared Gould 2006-11-29 17:25:44 +00:00
parent a4dc9282cc
commit 86e0fc214f
4 changed files with 142 additions and 6 deletions

View File

@ -17,6 +17,7 @@ public class Rom implements Serializable {
private Vector<Table> tables = new Vector<Table>();
private ECUEditor container;
private byte[] binData;
private String parent = "";
public Rom() {
}
@ -159,4 +160,12 @@ public class Rom implements Serializable {
this.fullFileName = fullFileName;
this.setFileName(fullFileName.getName());
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
}

View File

@ -1,14 +1,125 @@
package enginuity.newmaps.definition.translate;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import enginuity.maps.Rom;
import enginuity.maps.RomID;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.Vector;
import javax.imageio.metadata.IIOMetadataNode;
public class DefinitionBuilder {
Vector<Rom> roms;
Vector<Rom> roms;
public DefinitionBuilder(Vector<Rom> roms) {
public DefinitionBuilder(Vector<Rom> roms, File folder) {
this.roms = roms;
OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
of.setIndent(1);
of.setIndenting(true);
//
// Iterate through ROMs for processing
//
Iterator it = roms.iterator();
while (it.hasNext()) {
Rom rom = (Rom)it.next();
IIOMetadataNode node = buildRom(rom);
//
// Output to file
//
try {
FileOutputStream fos = new FileOutputStream(new File(folder.getAbsolutePath() + "/" + rom.getRomIDString() + ".xml"));
XMLSerializer serializer = new XMLSerializer(fos, of);
serializer.serialize(node);
fos.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private IIOMetadataNode buildRom(Rom rom) {
IIOMetadataNode node = new IIOMetadataNode("rom");
//
// Set all attributes
//
// Start by getting base rom if it exists
Rom parentRom = new Rom();
boolean child = false;
try {
parentRom = get(rom.getParent());
child = true;
} catch (Exception ex) {
// Rom wasn't found, not a child
}
System.out.println("Building " + rom.getRomID().getXmlid() + " ...");
// Set all RomID data (now in Rom tag)
node.setAttribute("name", rom.getRomID().getXmlid());
if (rom.getParent().length() > 0 && (!child || !rom.getParent().equalsIgnoreCase(parentRom.getParent())))
node.setAttribute("base", rom.getParent());
if (buildDescription(rom.getRomID()).length() > 0 && (!child || !buildDescription(rom.getRomID()).equalsIgnoreCase(buildDescription(parentRom.getRomID()))))
node.setAttribute("description", buildDescription(rom.getRomID()));
if (rom.getRomID().getInternalIdAddress() > 0 && (!child || rom.getRomID().getInternalIdAddress() != parentRom.getRomID().getInternalIdAddress()))
node.setAttribute("idaddress", rom.getRomID().getInternalIdAddress()+"");
if (rom.getRomID().getInternalIdString().length() > 0 && (!child || !rom.getRomID().getInternalIdString().equalsIgnoreCase(parentRom.getRomID().getInternalIdString())))
node.setAttribute("idstring", rom.getRomID().getInternalIdString());
if (rom.getRomID().getMemModel().length() > 0 && (!child || !rom.getRomID().getMemModel().equalsIgnoreCase(parentRom.getRomID().getMemModel())))
node.setAttribute("memmodel", rom.getRomID().getMemModel());
if (rom.getRomID().getFlashMethod().length() > 0 && (!child || !rom.getRomID().getFlashMethod().equalsIgnoreCase(parentRom.getRomID().getFlashMethod())))
node.setAttribute("flashmethod", rom.getRomID().getFlashMethod());
if (rom.getRomID().getCaseId().length() > 0 && (!child || !rom.getRomID().getCaseId().equalsIgnoreCase(parentRom.getRomID().getCaseId())))
node.setAttribute("caseid", rom.getRomID().getCaseId());
if (rom.getRomID().isObsolete() && (!child || rom.getRomID().isObsolete() != parentRom.getRomID().isObsolete()))
node.setAttribute("obsolete", rom.getRomID().isObsolete()+"");
return node;
}
public String buildDescription(RomID id) {
StringBuffer output = new StringBuffer();
if (id.getYear().length() > 0) output.append(id.getYear() + " ");
if (id.getMarket().length() > 0) output.append(id.getMarket() + " ");
if (id.getMake().length() > 0) output.append(id.getMake() + " ");
if (id.getModel().length() > 0) output.append(id.getModel() + " ");
if (id.getSubModel().length() > 0) output.append(id.getSubModel() + " ");
return new String(output).trim();
}
public Vector<Rom> getRoms() {
return roms;
}
private Rom get(String name) throws Exception {
Iterator it = roms.iterator();
while (it.hasNext()) {
Rom rom = (Rom)it.next();
if (rom.getRomIDString().equalsIgnoreCase(name)) {
return rom;
}
}
throw new Exception();
}
}

View File

@ -122,6 +122,7 @@ public final class FirstGenDefinitionHandler {
if (!unmarshallAttribute(rootNode, "base", "none").equalsIgnoreCase("none")) {
rom = get(unmarshallAttribute(rootNode, "base", "none"));
rom.getRomID().setObsolete(false);
rom.setParent(unmarshallAttribute(rootNode, "base", ""));
}

View File

@ -9,30 +9,45 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class FirstGenTranslator {
public FirstGenTranslator() {
}
public static void main(String args[]) {
FirstGenDefinitionHandler handler = new FirstGenDefinitionHandler();
File file = new File("ecu_defs.xml");
File inputFile = new File("ecu_defs.xml");
File outputFolder = new File("/newdefs/");
try {
//
// Parse existing definitions
//
System.out.println("*******************************\n" +
"* Parsing old definitions ... *\n" +
"*******************************");
DOMParser parser = new DOMParser();
InputSource src = new InputSource(new FileInputStream(file));
InputSource src = new InputSource(new FileInputStream(inputFile));
parser.parse(src);
Document doc = parser.getDocument();
System.out.println("\n***************************************\n" +
"* Building old definition objects ... *\n" +
"***************************************");
// Create old ROMs
Vector<Rom> roms = handler.unmarshallXMLDefinition(doc.getDocumentElement());
//
// Create new document
//
DefinitionBuilder builder = new DefinitionBuilder(roms);
System.out.println("\n*****************************\n" +
"* Generating XML output ... *\n" +
"*****************************");
DefinitionBuilder builder = new DefinitionBuilder(roms, outputFolder);
System.out.println("\n*************\n" +
"* Finished! *\n" +
"*************");
} catch (Exception ex) {
ex.printStackTrace();