Skip to content

Commit

Permalink
- added creation information to Dictionary schema documents
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux committed Dec 30, 2014
1 parent 7057900 commit 2dd6533
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 25 deletions.
24 changes: 23 additions & 1 deletion regxmllib/src/com/sandflow/smpte/regxml/dict/MetaDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

/**
*
Expand Down Expand Up @@ -272,7 +275,7 @@ public static String createQualifiedSymbol(String namespace, String symbol) {
}
}

public void toXML(Writer writer) throws JAXBException, IOException {
public void writeXML(Writer writer) throws JAXBException, IOException {

JAXBContext ctx = JAXBContext.newInstance(MetaDictionary.class);

Expand All @@ -281,6 +284,25 @@ public void toXML(Writer writer) throws JAXBException, IOException {
m.marshal(this, writer);
writer.close();
}

public Document toXML() {

Document doc = null;

try {

doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Marshaller m = JAXBContext.newInstance(MetaDictionary.class).createMarshaller();
m.marshal(this, doc);

} catch (JAXBException | ParserConfigurationException e) {

throw new RuntimeException(e);

}

return doc;
}

public static MetaDictionary fromXML(Reader reader) throws JAXBException, IOException, IllegalDefinitionException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
Expand All @@ -52,7 +53,7 @@
*/
public class GenerateDictionaryXMLSchema {

private final static String USAGE = "Generate XML Schema for RegXML Metadictionaries.\n"
private final static String USAGE = "Generate XML Schema for RegXML Metadictionaries.\n"
+ " Usage:\n"
+ " GenerateDictionaryXMLSchema -d regxmldictionary1 regxmldictionary2 regxmldictionary3 ... -o outputdir\n"
+ " GenerateDictionaryXMLSchema -?\n";
Expand Down Expand Up @@ -97,6 +98,21 @@ public static void main(String[] args) throws IOException, EOFException, KLVExce

Document doc = sb.xmlSchemaFromDictionary(md);

/* date and build version */
Date now = new java.util.Date();
doc.insertBefore(
doc.createComment("Created: " + now.toString()),
doc.getDocumentElement()
);
doc.insertBefore(
doc.createComment("By: regxmllib build " + BuildVersionSingleton.getBuildVersion()),
doc.getDocumentElement()
);
doc.insertBefore(
doc.createComment("See: https://github.com/sandflow/regxmllib"),
doc.getDocumentElement()
);

Transformer tr = TransformerFactory.newInstance().newTransformer();

tr.setOutputProperty(OutputKeys.INDENT, "yes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ public static void main(String[] args) throws FileNotFoundException, ExcelCSVPar

File baseDir = new File(args[3]);

/* ctx.generateSchema(new SchemaOutputResolver() {
int seq = -1;
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
seq++;
return new StreamResult(new File(baseDir, c.getSimpleName() + (seq == 0 ? "" : "." + seq) + ".xsd"));
}
});
*/
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

Expand Down
8 changes: 8 additions & 0 deletions regxmllib/src/com/sandflow/smpte/tools/RegXMLDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -189,6 +190,13 @@ public static void main(String[] args) throws IOException, EOFException, KLVExce

doc.setXmlStandalone(true);

/* date and build version */
Date now = new java.util.Date();
doc.appendChild(doc.createComment("Created: " + now.toString()));
doc.appendChild(doc.createComment("From: " + args[args.length - 1]));
doc.appendChild(doc.createComment("By: regxmllib build " + BuildVersionSingleton.getBuildVersion()));
doc.appendChild(doc.createComment("See: https://github.com/sandflow/regxmllib"));

try {
if ("-ed".equals(args[0])) {

Expand Down
49 changes: 38 additions & 11 deletions regxmllib/src/com/sandflow/smpte/tools/XMLRegistersToDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

/**
*
Expand Down Expand Up @@ -69,11 +76,10 @@ public static void main(String[] args) throws FileNotFoundException, ExcelCSVPar

return;
}

/* mute logging */
/* TODO: add switch to enable warnings */
//Logger.getLogger("").setLevel(Level.OFF);

FileReader fe = new FileReader(args[1]);
FileReader fg = new FileReader(args[5]);
FileReader ft = new FileReader(args[7]);
Expand All @@ -83,19 +89,40 @@ public static void main(String[] args) throws FileNotFoundException, ExcelCSVPar
TypesRegister treg = TypesRegister.fromXML(ft);

MetaDictionaryGroup mds = fromRegister(treg, greg, ereg);

for(MetaDictionary md : mds.getDictionaries()) {


Transformer tr = TransformerFactory.newInstance().newTransformer();

tr.setOutputProperty(OutputKeys.INDENT, "yes");

for (MetaDictionary md : mds.getDictionaries()) {

/* create file name from the Scheme URI */

String fname = md.getSchemeURI().getAuthority() + md.getSchemeURI().getPath();

File f = new File(args[8], fname.replaceAll("[^a-zA-Z0-9]", "-") + ".xml");

md.toXML(new FileWriter(f));

Document doc = md.toXML();

/* date and build version */
Date now = new java.util.Date();
doc.insertBefore(
doc.createComment("Created: " + now.toString()),
doc.getDocumentElement()
);
doc.insertBefore(
doc.createComment("By: regxmllib build " + BuildVersionSingleton.getBuildVersion()),
doc.getDocumentElement()
);
doc.insertBefore(
doc.createComment("See: https://github.com/sandflow/regxmllib"),
doc.getDocumentElement()
);

tr.transform(
new DOMSource(doc),
new StreamResult(f)
);
}



}
}

0 comments on commit 2dd6533

Please sign in to comment.