refactoring
This commit is contained in:
parent
81503a1fa7
commit
f4fcd5080c
|
@ -0,0 +1,35 @@
|
|||
package com.rusefi.xml;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class XmlUtil {
|
||||
|
||||
public static void writeXml(Object instance, Class<?> modelClass, String fileName) throws JAXBException, IOException {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(modelClass);
|
||||
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
|
||||
StringWriter xmlWriter = new StringWriter();
|
||||
marshaller.marshal(instance, xmlWriter);
|
||||
System.out.println(xmlWriter.toString());
|
||||
|
||||
System.out.println("Writing " + fileName);
|
||||
marshaller.marshal(instance, new FileWriter(fileName));
|
||||
System.out.println("Done " + fileName);
|
||||
}
|
||||
|
||||
public static <T> T readModel(Class<?> modelClass, String fileName) throws Exception {
|
||||
File xmlFile = new File(fileName);
|
||||
JAXBContext jaxbContext;
|
||||
jaxbContext = JAXBContext.newInstance(modelClass);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
return (T) jaxbUnmarshaller.unmarshal(xmlFile);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ public class MdGenerator {
|
|||
//FOLDER = "images/";
|
||||
FOLDER = "overview/TS_generated/";
|
||||
|
||||
ContentModel contentModel = XmlUtil.readModel();
|
||||
ContentModel contentModel = XmlUtil.readModel(ContentModel.class, ScreenGenerator.FILE_NAME);
|
||||
|
||||
generateTopLevel(contentModel);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ScreenGenerator {
|
||||
public static final String FILE_NAME = "output.xml";
|
||||
private static final String PNG = "png";
|
||||
private static ArrayList<AbstractButton> topLevelButtons = new ArrayList<>();
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class ScreenGenerator {
|
|||
|
||||
handleTopLevelButtons(mainFrame, topLevelButtons);
|
||||
|
||||
XmlUtil.writeXml(contentModel);
|
||||
XmlUtil.writeXml(contentModel, ContentModel.class, FILE_NAME);
|
||||
}
|
||||
|
||||
private static void waitForMainFrame(Frame mainFrame) throws InterruptedException {
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package com.rusefi.xml;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class XmlUtil {
|
||||
|
||||
public static final String FILE_NAME = "output.xml";
|
||||
|
||||
public static void writeXml(ContentModel contentModel) throws JAXBException, IOException {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ContentModel.class);
|
||||
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
|
||||
StringWriter xmlWriter = new StringWriter();
|
||||
marshaller.marshal(contentModel, xmlWriter);
|
||||
System.out.println(xmlWriter.toString());
|
||||
|
||||
System.out.println("Writing " + FILE_NAME);
|
||||
marshaller.marshal(contentModel, new FileWriter(FILE_NAME));
|
||||
System.out.println("Done " + FILE_NAME);
|
||||
}
|
||||
|
||||
public static ContentModel readModel() throws Exception {
|
||||
File xmlFile = new File(FILE_NAME);
|
||||
JAXBContext jaxbContext;
|
||||
jaxbContext = JAXBContext.newInstance(ContentModel.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
return (ContentModel) jaxbUnmarshaller.unmarshal(xmlFile);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue