[jboss-svn-commits] JBL Code SVN: r21127 - labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jul 19 01:37:29 EDT 2008


Author: stevearoonie
Date: 2008-07-19 01:37:29 -0400 (Sat, 19 Jul 2008)
New Revision: 21127

Modified:
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/ExternalSpreadsheetCompiler.java
Log:
Add constructors to allow clients to pass in their own streams

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/ExternalSpreadsheetCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/ExternalSpreadsheetCompiler.java	2008-07-18 22:25:32 UTC (rev 21126)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/ExternalSpreadsheetCompiler.java	2008-07-19 05:37:29 UTC (rev 21127)
@@ -32,110 +32,160 @@
 
 public class ExternalSpreadsheetCompiler {
 
-	public String compile(final String xls, final String template,
-			int startRow, int startCol) {
-		return compile(xls, template, InputType.XLS, startRow, startCol);
+    public String compile(final String xls,
+                          final String template,
+                          int startRow,
+                          int startCol) {
+        return compile( xls,
+                        template,
+                        InputType.XLS,
+                        startRow,
+                        startCol );
 
-	}
+    }
 
-	public String compile(final String xls, final String template,
-			InputType type, int startRow, int startCol) {
-		final InputStream xlsStream = this.getClass().getResourceAsStream(xls);
-		final InputStream templateStream = this.getClass().getResourceAsStream(
-				template);
-		return compile(xlsStream, templateStream, type, startRow, startCol);
+    public String compile(final String xls,
+                          final String template,
+                          InputType type,
+                          int startRow,
+                          int startCol) {
+        final InputStream xlsStream = this.getClass().getResourceAsStream( xls );
+        final InputStream templateStream = this.getClass().getResourceAsStream( template );
+        return compile( xlsStream,
+                        templateStream,
+                        type,
+                        startRow,
+                        startCol );
 
-	}
+    }
 
-	public String compile(final String xls, final String worksheetName,
-			final String template, int startRow, int startCol) {
-		final InputStream xlsStream = this.getClass().getResourceAsStream(xls);
-		final InputStream templateStream = this.getClass().getResourceAsStream(
-				template);
-		return compile(xlsStream, worksheetName, templateStream, startRow,
-				startCol);
+    public String compile(final String xls,
+                          final String worksheetName,
+                          final String template,
+                          int startRow,
+                          int startCol) {
+        final InputStream xlsStream = this.getClass().getResourceAsStream( xls );
+        final InputStream templateStream = this.getClass().getResourceAsStream( template );
+        return compile( xlsStream,
+                        worksheetName,
+                        templateStream,
+                        startRow,
+                        startCol );
 
-	}
+    }
 
-	public String compile(final InputStream xlsStream,
-			final InputStream templateStream, InputType type, int startRow,
-			int startCol) {
-		TemplateContainer tc = new DefaultTemplateContainer(templateStream);
-		closeStream(templateStream);
-		return compile(xlsStream, type, new TemplateDataListener(startRow,
-				startCol, tc));
-	}
+    public String compile(final InputStream xlsStream,
+                          final InputStream templateStream,
+                          int startRow,
+                          int startCol) {
+        return compile( xlsStream,
+                        templateStream,
+                        InputType.XLS,
+                        startRow,
+                        startCol );
+    }
 
-	public String compile(final InputStream xlsStream,
-			final String worksheetName, final InputStream templateStream,
-			int startRow, int startCol) {
-		TemplateContainer tc = new DefaultTemplateContainer(templateStream);
-		closeStream(templateStream);
-		return compile(xlsStream, worksheetName, new TemplateDataListener(
-				startRow, startCol, tc));
-	}
+    public String compile(final InputStream xlsStream,
+                          final InputStream templateStream,
+                          InputType type,
+                          int startRow,
+                          int startCol) {
+        TemplateContainer tc = new DefaultTemplateContainer( templateStream );
+        closeStream( templateStream );
+        return compile( xlsStream,
+                        type,
+                        new TemplateDataListener( startRow,
+                                                  startCol,
+                                                  tc ) );
+    }
 
-	public void compile(final String xls, InputType type, final List<DataListener> listeners) {
-		final InputStream xlsStream = this.getClass().getResourceAsStream(xls);
-		compile(xlsStream, type, listeners);
-	}
+    public String compile(final InputStream xlsStream,
+                          final String worksheetName,
+                          final InputStream templateStream,
+                          int startRow,
+                          int startCol) {
+        TemplateContainer tc = new DefaultTemplateContainer( templateStream );
+        closeStream( templateStream );
+        return compile( xlsStream,
+                        worksheetName,
+                        new TemplateDataListener( startRow,
+                                                  startCol,
+                                                  tc ) );
+    }
 
-	public void compile(final String xls, final Map<String, List<DataListener>> listeners) {
-		final InputStream xlsStream = this.getClass().getResourceAsStream(xls);
-		compile(xlsStream, listeners);
-	}
+    public void compile(final String xls,
+                        InputType type,
+                        final List<DataListener> listeners) {
+        final InputStream xlsStream = this.getClass().getResourceAsStream( xls );
+        compile( xlsStream,
+                 type,
+                 listeners );
+    }
 
-	public void compile(final InputStream xlsStream, InputType type,
-			final List<DataListener> listeners) {
-		final DecisionTableParser parser = type.createParser(listeners);
-		parser.parseFile(xlsStream);
-		closeStream(xlsStream);
-	}
+    public void compile(final String xls,
+                        final Map<String, List<DataListener>> listeners) {
+        final InputStream xlsStream = this.getClass().getResourceAsStream( xls );
+        compile( xlsStream,
+                 listeners );
+    }
 
-	public void compile(final InputStream xlsStream, final Map<String, List<DataListener>> listeners) {
-		final DecisionTableParser parser = new ExcelParser(listeners);
-		parser.parseFile(xlsStream);
-		closeStream(xlsStream);
-	}
+    public void compile(final InputStream xlsStream,
+                        InputType type,
+                        final List<DataListener> listeners) {
+        final DecisionTableParser parser = type.createParser( listeners );
+        parser.parseFile( xlsStream );
+        closeStream( xlsStream );
+    }
 
-	/**
-	 * Generates DRL from the input stream containing the spreadsheet.
-	 * 
-	 * @param xlsStream
-	 *            The stream to the spreadsheet. Uses the first worksheet found
-	 *            for the decision tables, ignores others.
-	 * @param type
-	 *            The type of the file - InputType.CSV or InputType.XLS
-	 * @param listener
-	 * @return DRL xml, ready for use in drools.
-	 * @throws IOException
-	 */
-	public String compile(final InputStream xlsStream, final InputType type,
-			final TemplateDataListener listener) {
-		ArrayList<DataListener> listeners = new ArrayList<DataListener>();
-		listeners.add(listener);
-		compile(xlsStream, type, listeners);
-		return listener.renderDRL();
-	}
+    public void compile(final InputStream xlsStream,
+                        final Map<String, List<DataListener>> listeners) {
+        final DecisionTableParser parser = new ExcelParser( listeners );
+        parser.parseFile( xlsStream );
+        closeStream( xlsStream );
+    }
 
-	public String compile(final InputStream xlsStream,
-			final String worksheetName, final TemplateDataListener listener) {
-		Map<String, List<DataListener>> listeners = new HashMap<String, List<DataListener>>();
-		List<DataListener> l = new ArrayList<DataListener>();
-		l.add(listener);
-		listeners.put(worksheetName, l);
-		compile(xlsStream, listeners);
-		return listener.renderDRL();
-	}
+    /**
+     * Generates DRL from the input stream containing the spreadsheet.
+     * 
+     * @param xlsStream
+     *            The stream to the spreadsheet. Uses the first worksheet found
+     *            for the decision tables, ignores others.
+     * @param type
+     *            The type of the file - InputType.CSV or InputType.XLS
+     * @param listener
+     * @return DRL xml, ready for use in drools.
+     * @throws IOException
+     */
+    public String compile(final InputStream xlsStream,
+                          final InputType type,
+                          final TemplateDataListener listener) {
+        ArrayList<DataListener> listeners = new ArrayList<DataListener>();
+        listeners.add( listener );
+        compile( xlsStream,
+                 type,
+                 listeners );
+        return listener.renderDRL();
+    }
 
-	private void closeStream(final InputStream stream) {
-		try {
-			stream.close();
-		} catch (final Exception e) {
-			System.err.print("WARNING: Wasn't able to "
-					+ "correctly close stream for decision table. "
-					+ e.getMessage());
-		}
-	}
+    public String compile(final InputStream xlsStream,
+                          final String worksheetName,
+                          final TemplateDataListener listener) {
+        Map<String, List<DataListener>> listeners = new HashMap<String, List<DataListener>>();
+        List<DataListener> l = new ArrayList<DataListener>();
+        l.add( listener );
+        listeners.put( worksheetName,
+                       l );
+        compile( xlsStream,
+                 listeners );
+        return listener.renderDRL();
+    }
 
+    private void closeStream(final InputStream stream) {
+        try {
+            stream.close();
+        } catch ( final Exception e ) {
+            System.err.print( "WARNING: Wasn't able to " + "correctly close stream for decision table. " + e.getMessage() );
+        }
+    }
+
 }




More information about the jboss-svn-commits mailing list