GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.21 -r1.22
--- Main.java 30 Apr 2010 16:58:54 -0000 1.21
+++ Main.java 7 Dec 2010 20:16:46 -0000 1.22
@@ -8,6 +8,7 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.logging.Logger;
import javax.swing.filechooser.FileFilter;
@@ -22,10 +23,11 @@
import org.lcsim.util.xml.ElementFactory;
/**
+ * This class is the front end for generating LCDD output from the compact description.
*
* @author tonyj
+ * @author jeremym
*/
-// TODO Add command line option to turn off validation for debugging.
public class Main implements Converter
{
private boolean validate = true;
@@ -33,62 +35,69 @@
/**
* @param args the command line arguments
*/
- public static void main(String[] args) throws Exception
+ public static void main( String[] args ) throws Exception
{
- if (args.length < 1 || args.length > 2)
+ if ( args.length < 1 || args.length > 2 )
usage();
- InputStream in = new BufferedInputStream(new FileInputStream(args[0]));
- OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream(new FileOutputStream(args[1]));
- new Main(true).convert(args[0], in, out);
- }
-
- public Main(boolean validate) throws Exception
- {
- this.validate = validate;
- }
-
+ InputStream in = new BufferedInputStream( new FileInputStream( args[ 0 ] ) );
+ OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream( new FileOutputStream( args[ 1 ] ) );
+ new Main().convert( args[ 0 ], in, out );
+ }
+
public Main() throws Exception
{
- this(true);
+ setValidationFromSystemProperty();
+ }
+
+ private void setValidationFromSystemProperty()
+ {
+ boolean validateProp = Boolean.parseBoolean( System.getProperty(
+ "org.lcsim.geometry.compact.converter.lcdd.validate",
+ "true" ) );
+ this.validate = validateProp;
+ if ( validateProp == false )
+ {
+ Logger.getLogger( Main.class.getName() ).warning( "XML output validation is turned OFF." );
+ }
}
- public void convert(String inputFileName, InputStream in, OutputStream out) throws Exception
- {
+ public void convert( String inputFileName, InputStream in, OutputStream out ) throws Exception
+ {
ElementFactory factory = new LCDDElementFactory();
- CompactReader reader = new CompactReader(factory);
- Detector det = reader.read(in);
- Document doc = ((LCDDDetector) det).writeLCDD(inputFileName);
+ CompactReader reader = new CompactReader( factory );
+ Detector det = reader.read( in );
+ Document doc = ( ( LCDDDetector ) det ).writeLCDD( inputFileName );
XMLOutputter outputter = new XMLOutputter();
- if (validate)
+ if ( validate )
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
- outputter.output(doc, stream);
+ outputter.output( doc, stream );
stream.close();
SAXBuilder builder = new SAXBuilder();
- builder.setEntityResolver(new ClasspathEntityResolver());
+ builder.setEntityResolver( new ClasspathEntityResolver() );
- builder.setValidation(true);
- builder.setFeature("http://apache.org/xml/features/validation/schema", true);
+ builder.setValidation( true );
+ builder.setFeature( "http://apache.org/xml/features/validation/schema", true );
- builder.build(new ByteArrayInputStream(stream.toByteArray()));
+ builder.build( new ByteArrayInputStream( stream.toByteArray() ) );
}
- if (out != null)
+ if ( out != null )
{
- outputter.setFormat(Format.getPrettyFormat());
- outputter.output(doc, out);
+ outputter.setFormat( Format.getPrettyFormat() );
+ outputter.output( doc, out );
out.close();
}
}
private static void usage()
{
- System.out.println("java " + Main.class.getName() + " <compact> [<lcdd>]");
- System.exit(0);
+ System.out.println( "java " + Main.class.getName() + " <compact> [<lcdd>]" );
+ System.exit( 0 );
}
public String getOutputFormat()
@@ -103,14 +112,14 @@
private static class LCDDFileFilter extends FileFilter
{
- public boolean accept(java.io.File file)
+ public boolean accept( java.io.File file )
{
- return file.isDirectory() || file.getName().endsWith(".heprep");
+ return file.isDirectory() || file.getName().endsWith( ".lcdd" );
}
public String getDescription()
{
- return "HepRep file (*.heprep)";
+ return "LCDD file (*.lcdd)";
}
}
}
\ No newline at end of file