RecordGeneratorpublic class RecordGenerator extends Object
Methods Summary |
---|
private static void | generateRecords(java.lang.String defintionsDir, java.lang.String recordStyleDir, java.lang.String destSrcPathDir, java.lang.String testSrcPathDir)
File definitionsFile = new File(defintionsDir);
for (int i = 0; i < definitionsFile.listFiles().length; i++) {
File file = definitionsFile.listFiles()[i];
if (file.isFile() &&
(file.getName().endsWith("_record.xml") ||
file.getName().endsWith("_type.xml")
)
) {
// Get record name and package
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);
Element record = document.getDocumentElement();
String extendstg = record.getElementsByTagName("extends").item(0).getFirstChild().getNodeValue();
String suffix = record.getElementsByTagName("suffix").item(0).getFirstChild().getNodeValue();
String recordName = record.getAttributes().getNamedItem("name").getNodeValue();
String packageName = record.getAttributes().getNamedItem("package").getNodeValue();
packageName = packageName.replace('.", '/");
// Generate record
String destinationPath = destSrcPathDir + "/" + packageName;
File destinationPathFile = new File(destinationPath);
destinationPathFile.mkdirs();
String destinationFilepath = destinationPath + "/" + recordName + suffix + ".java";
transform(file, new File(destinationFilepath), new File(recordStyleDir + "/" + extendstg.toLowerCase() + ".xsl"));
System.out.println("Generated " + suffix + ": " + destinationFilepath);
// Generate test (if not already generated)
destinationPath = testSrcPathDir + "/" + packageName;
destinationPathFile = new File(destinationPath);
destinationPathFile.mkdirs();
destinationFilepath = destinationPath + "/Test" + recordName + suffix + ".java";
if (new File(destinationFilepath).exists() == false) {
String temp = (recordStyleDir + "/" + extendstg.toLowerCase() + "_test.xsl");
transform(file, new File(destinationFilepath), new File(temp));
System.out.println("Generated test: " + destinationFilepath);
} else {
System.out.println("Skipped test generation: " + destinationFilepath);
}
}
}
| public static void | main(java.lang.String[] args)The main program for the RecordGenerator class
// Force load so that we don't start generating records and realise this hasn't compiled yet.
Class.forName("org.apache.poi.generator.FieldIterator");
if (args.length != 4) {
System.out.println("Usage:");
System.out.println(" java org.apache.poi.hssf.util.RecordGenerator RECORD_DEFINTIONS RECORD_STYLES DEST_SRC_PATH TEST_SRC_PATH");
} else {
generateRecords(args[0], args[1], args[2], args[3]);
}
| private static void | transform(java.io.File in, java.io.File out, java.io.File xslt)Executes an XSL transformation. This process transforms an XML input
file into a text output file controlled by an XSLT specification.
final Reader r = new FileReader(xslt);
final StreamSource ss = new StreamSource(r);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t;
try
{
t = tf.newTransformer(ss);
}
catch (TransformerException ex)
{
System.err.println("Error compiling XSL style sheet " + xslt);
throw ex;
}
final Properties p = new Properties();
p.setProperty(OutputKeys.METHOD, "text");
t.setOutputProperties(p);
final Result result = new StreamResult(out);
t.transform(new StreamSource(in), result);
|
|