foray-commit Mailing List for FOray (Page 274)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <vic...@us...> - 2006-04-15 20:25:53
|
Revision: 7035 Author: victormote Date: 2006-04-15 13:25:47 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7035&view=rev Log Message: ----------- General cleanup of the Starter construction. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/AWTStarter.java trunk/foray/foray-app/src/java/org/foray/app/Starter.java trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/AWTStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/AWTStarter.java 2006-04-15 19:32:23 UTC (rev 7034) +++ trunk/foray/foray-app/src/java/org/foray/app/AWTStarter.java 2006-04-15 20:25:47 UTC (rev 7035) @@ -76,7 +76,7 @@ } private void init() throws FOrayException { - this.userMessage = new UserMessage(logger); + this.userMessage = new UserMessage(getLogger()); try { UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); } catch (Exception e) { @@ -134,7 +134,7 @@ protected PreviewDialog createPreviewDialog(AWTRenderer renderer, Translator res) { - PreviewDialog frame = new PreviewDialog(renderer, res, logger); + PreviewDialog frame = new PreviewDialog(renderer, res, getLogger()); frame.validate(); frame.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent we) { @@ -173,11 +173,11 @@ in = url.openStream(); } catch (Exception ex) { - logger.error("Can't find URL to: <" + path + "> " + getLogger().error("Can't find URL to: <" + path + "> " + ex.getMessage()); - logger.error(ex.getMessage()); + getLogger().error(ex.getMessage()); } - return new SecureResourceBundle(in, logger); + return new SecureResourceBundle(in, getLogger()); } } Modified: trunk/foray/foray-app/src/java/org/foray/app/Starter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/Starter.java 2006-04-15 19:32:23 UTC (rev 7034) +++ trunk/foray/foray-app/src/java/org/foray/app/Starter.java 2006-04-15 20:25:47 UTC (rev 7035) @@ -38,7 +38,7 @@ Options options; InputHandler inputHandler; - protected Log logger; + private Log logger; protected SessionConfig sessionConfig; protected OutputConfig outputConfig; @@ -56,4 +56,8 @@ abstract public void run() throws FOrayException; + public Log getLogger() { + return this.logger; + } + } Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 19:32:23 UTC (rev 7034) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 20:25:47 UTC (rev 7035) @@ -64,6 +64,7 @@ int messageType = Project.MSG_VERBOSE; boolean logFiles = true; private boolean force = false; + Log logger; /** * Sets the user configuration file. @@ -243,11 +244,15 @@ } } try { - Starter starter = new FOrayAntTaskStarter(this, log, logFiles); + Starter starter = new FOrayAntTaskStarter(this, log); starter.run(); } catch (FOrayException ex) { throw new BuildException(ex); } } + public Log getLogger() { + return this.logger; + } + } Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:32:23 UTC (rev 7034) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 20:25:47 UTC (rev 7035) @@ -53,9 +53,9 @@ import java.net.URL; class FOrayAntTaskStarter extends Starter { + + /** The parent task for this starter. */ FOrayAntTask task; - Log log; - boolean logFiles; /** Number of fofiles actually processed. */ int actioncount = 0; @@ -64,12 +64,9 @@ */ int skippedcount = 0; - FOrayAntTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) - throws FOrayException { - super(aLogger, null, null); + FOrayAntTaskStarter(FOrayAntTask task, Log logger) throws FOrayException { + super(logger, null, null); this.task = task; - log = aLogger; - logFiles = aLogFiles; } private File replaceExtension(File file, String expectedExt, @@ -86,7 +83,7 @@ Log logger = Logging.makeDefaultLogger(); SessionConfig configuration = new SessionConfig(logger); if (task.userConfig != null) { - new Options (log, configuration, null, task.userConfig); + new Options (this.getLogger(), configuration, null, task.userConfig); } setBaseDirectory(configuration); @@ -232,7 +229,7 @@ private void render(File foFile, File outFile, SessionConfig configuration) throws FOrayException { - InputHandler inputHandler = new FOInputHandler(logger, foFile); + InputHandler inputHandler = new FOInputHandler(getLogger(), foFile); XMLReader parser = inputHandler.getParser(); OutputStream out = null; @@ -244,17 +241,19 @@ throw new BuildException(ex); } - if (logFiles) task.log(foFile + " -> " + outFile, Project.MSG_INFO); + if (this.task.getLogFiles()) { + task.log(foFile + " -> " + outFile, Project.MSG_INFO); + } try { - FOraySession session = new FOraySession(log, configuration, null, - null, null, null); + FOraySession session = new FOraySession(this.getLogger(), + configuration, null, null, null, null); FOrayDocument document = new FOrayDocument(session, inputHandler.getInputSource(), parser); OutputConfig rendererOptions = null; if (getRendererType() == FOrayTarget.RENDER_XML) { - rendererOptions = new OutputConfig(logger); + rendererOptions = new OutputConfig(getLogger()); rendererOptions.parseOption("fineDetail", "true", SessionConfig.PRECEDENCE_DEFAULT); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 19:32:30
|
Revision: 7034 Author: victormote Date: 2006-04-15 12:32:23 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7034&view=rev Log Message: ----------- Simplify logic by extracting some small methods and reducing method parameters. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:23:23 UTC (rev 7033) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:32:23 UTC (rev 7034) @@ -91,18 +91,11 @@ setBaseDirectory(configuration); - int rint = FOrayTarget.getRendererType(task.getFormat()); - String newExtension = FOrayTarget.getMimeExtension(rint); - if (newExtension == null) { - String err = "Unknown renderer: "+ rint; - throw new BuildException(err); - } - this.actioncount = 0; this.skippedcount = 0; - processFile(configuration, rint); - processFileSet(configuration, rint, newExtension); + processFile(configuration); + processFileSet(configuration); if (actioncount + skippedcount == 0) { task.log("No files processed. No files were selected by the filesets " @@ -116,10 +109,9 @@ /** * @param configuration - * @param rint * @throws FOrayException */ - private void processFile(SessionConfig configuration, int rint) + private void processFile(SessionConfig configuration) throws FOrayException { if (task.getFofile() == null) { return; @@ -140,7 +132,7 @@ // output file is older than input file if (task.getForce() || !outf.exists() || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, rint, configuration); + render(task.getFofile(), outf, configuration); actioncount++; } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { skippedcount++; @@ -149,11 +141,11 @@ /** * @param configuration - * @param rint - * @param newExtension * @throws FOrayException */ - private void processFileSet(SessionConfig configuration, int rint, String newExtension) throws FOrayException { + private void processFileSet(SessionConfig configuration) + throws FOrayException { + String newExtension = this.getFileExtension(); GlobPatternMapper mapper = new GlobPatternMapper(); mapper.setFrom("*.fo"); mapper.setTo("*" + newExtension); @@ -200,7 +192,7 @@ // output file is older than input file if (task.getForce() || !outf.exists() || (f.lastModified() > outf.lastModified() )) { - render(f, outf, rint, configuration); + render(f, outf, configuration); actioncount++; } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { skippedcount++; @@ -238,8 +230,8 @@ Project.MSG_DEBUG); } - private void render(File foFile, File outFile, int rendererType, - SessionConfig configuration) throws FOrayException { + private void render(File foFile, File outFile, SessionConfig configuration) + throws FOrayException { InputHandler inputHandler = new FOInputHandler(logger, foFile); XMLReader parser = inputHandler.getParser(); @@ -261,12 +253,12 @@ inputHandler.getInputSource(), parser); OutputConfig rendererOptions = null; - if (rendererType == FOrayTarget.RENDER_XML) { + if (getRendererType() == FOrayTarget.RENDER_XML) { rendererOptions = new OutputConfig(logger); rendererOptions.parseOption("fineDetail", "true", SessionConfig.PRECEDENCE_DEFAULT); } - OutputTarget renderer = document.makeOutputTarget(rendererType, + OutputTarget renderer = document.makeOutputTarget(getRendererType(), rendererOptions); new FOrayTarget(document, renderer, null, out); @@ -277,4 +269,18 @@ } } + private int getRendererType() { + return FOrayTarget.getRendererType(task.getFormat()); + } + + private String getFileExtension() { + int rendererType = getRendererType(); + String extension = FOrayTarget.getMimeExtension(rendererType); + if (extension == null) { + String err = "Unknown renderer: "+ rendererType; + throw new BuildException(err); + } + return extension; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 19:23:29
|
Revision: 7033 Author: victormote Date: 2006-04-15 12:23:23 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7033&view=rev Log Message: ----------- Extract method for clarity. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:16:22 UTC (rev 7032) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:23:23 UTC (rev 7033) @@ -102,7 +102,58 @@ this.skippedcount = 0; processFile(configuration, rint); + processFileSet(configuration, rint, newExtension); + if (actioncount + skippedcount == 0) { + task.log("No files processed. No files were selected by the filesets " + + "and no fofile was set." , Project.MSG_WARN); + } else if (skippedcount > 0) { + task.log(skippedcount + " xslfo file(s) skipped (no change found" + + " since last generation; set force=\"true\" to override)." + , Project.MSG_INFO); + } + } + + /** + * @param configuration + * @param rint + * @throws FOrayException + */ + private void processFile(SessionConfig configuration, int rint) + throws FOrayException { + if (task.getFofile() == null) { + return; + } + if (! task.getFofile().exists()) { + return; + } + File outf = task.getOutfile(); + if (outf == null) { + throw new BuildException("outfile is required when fofile is used"); + } + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (task.getFofile().lastModified() > outf.lastModified() )) { + render(task.getFofile(), outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { + skippedcount++; + } + } + + /** + * @param configuration + * @param rint + * @param newExtension + * @throws FOrayException + */ + private void processFileSet(SessionConfig configuration, int rint, String newExtension) throws FOrayException { GlobPatternMapper mapper = new GlobPatternMapper(); mapper.setFrom("*.fo"); mapper.setTo("*" + newExtension); @@ -157,53 +208,11 @@ } } - - if (actioncount + skippedcount == 0) { - task.log("No files processed. No files were selected by the filesets " - + "and no fofile was set." , Project.MSG_WARN); - } else if (skippedcount > 0) { - task.log(skippedcount + " xslfo file(s) skipped (no change found" - + " since last generation; set force=\"true\" to override)." - , Project.MSG_INFO); - } } /** * @param configuration - * @param rint - * @throws FOrayException */ - private void processFile(SessionConfig configuration, int rint) - throws FOrayException { - if (task.getFofile() == null) { - return; - } - if (! task.getFofile().exists()) { - return; - } - File outf = task.getOutfile(); - if (outf == null) { - throw new BuildException("outfile is required when fofile is used"); - } - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } - - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { - skippedcount++; - } - } - - /** - * @param configuration - */ private void setBaseDirectory(SessionConfig configuration) { if (task.getFofile() == null) { /* We don't care what the base directory is if we are not processing This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 19:16:28
|
Revision: 7032 Author: victormote Date: 2006-04-15 12:16:22 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7032&view=rev Log Message: ----------- Extract method for clarity. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:08:06 UTC (rev 7031) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:16:22 UTC (rev 7032) @@ -57,6 +57,13 @@ Log log; boolean logFiles; + /** Number of fofiles actually processed. */ + int actioncount = 0; + + /** Numer of fofiles skipped because they haven't changed (force = "false") + */ + int skippedcount = 0; + FOrayAntTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) throws FOrayException { super(aLogger, null, null); @@ -91,35 +98,11 @@ throw new BuildException(err); } - // actioncount = # of fofiles actually processed through FOray - int actioncount = 0; - // skippedcount = # of fofiles which haven't changed (force = "false") - int skippedcount = 0; + this.actioncount = 0; + this.skippedcount = 0; - // deal with single source file - if (task.getFofile() != null) { - if (task.getFofile().exists()) { - File outf = task.getOutfile(); - if (outf == null) { - throw new BuildException("outfile is required when fofile is used"); - } - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } + processFile(configuration, rint); - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { - skippedcount++; - } - } - } - GlobPatternMapper mapper = new GlobPatternMapper(); mapper.setFrom("*.fo"); mapper.setTo("*" + newExtension); @@ -187,7 +170,40 @@ /** * @param configuration + * @param rint + * @throws FOrayException */ + private void processFile(SessionConfig configuration, int rint) + throws FOrayException { + if (task.getFofile() == null) { + return; + } + if (! task.getFofile().exists()) { + return; + } + File outf = task.getOutfile(); + if (outf == null) { + throw new BuildException("outfile is required when fofile is used"); + } + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (task.getFofile().lastModified() > outf.lastModified() )) { + render(task.getFofile(), outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { + skippedcount++; + } + } + + /** + * @param configuration + */ private void setBaseDirectory(SessionConfig configuration) { if (task.getFofile() == null) { /* We don't care what the base directory is if we are not processing This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 19:08:10
|
Revision: 7031 Author: victormote Date: 2006-04-15 12:08:06 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7031&view=rev Log Message: ----------- Restructure method for clarity. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:07:31 UTC (rev 7030) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 19:08:06 UTC (rev 7031) @@ -49,6 +49,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; class FOrayAntTaskStarter extends Starter { FOrayAntTask task; @@ -187,26 +189,28 @@ * @param configuration */ private void setBaseDirectory(SessionConfig configuration) { + if (task.getFofile() == null) { + /* We don't care what the base directory is if we are not processing + * on file-by-file basis. */ + return; + } + File newBaseDirectory = null; + if (task.getBasedir() == null) { + newBaseDirectory = task.getFofile().getParentFile(); + } else { + newBaseDirectory = task.getBasedir(); + } + URL url = null; try { - if (task.getFofile() != null) { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - task.getFofile().getParentFile().toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { - - task.log("Error setting base directory: " + e, Project.MSG_ERR); + url = newBaseDirectory.toURL(); + } catch (MalformedURLException e) { + task.log("FOrayAntTask base directory is invalid:\n" + + e, Project.MSG_ERR); } + configuration.setBaseDirectory(url, SessionConfig.PRECEDENCE_DEFAULT); + task.log("FOrayAntTask using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); } private void render(File foFile, File outFile, int rendererType, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 19:07:37
|
Revision: 7030 Author: victormote Date: 2006-04-15 12:07:31 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7030&view=rev Log Message: ----------- Add method allowing direct setting of base directory. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/SessionConfig.java Modified: trunk/foray/foray-app/src/java/org/foray/app/SessionConfig.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/SessionConfig.java 2006-04-15 18:42:33 UTC (rev 7029) +++ trunk/foray/foray-app/src/java/org/foray/app/SessionConfig.java 2006-04-15 19:07:31 UTC (rev 7030) @@ -129,6 +129,10 @@ return (URL) getValue("base-directory"); } + public void setBaseDirectory(URL newBaseDir, int precedence) { + put ("base-directory", newBaseDir, precedence); + } + public boolean optionCacheGraphics() { // Never null. return getBooleanValue("cache-graphics").booleanValue(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 18:42:40
|
Revision: 7029 Author: victormote Date: 2006-04-15 11:42:33 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7029&view=rev Log Message: ----------- Extract method for clarity. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:32:03 UTC (rev 7028) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:42:33 UTC (rev 7029) @@ -80,27 +80,8 @@ new Options (log, configuration, null, task.userConfig); } - try { - if (task.getFofile() != null) { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - task.getFofile().getParentFile().toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { + setBaseDirectory(configuration); - task.log("Error setting base directory: " + e, Project.MSG_ERR); - } - int rint = FOrayTarget.getRendererType(task.getFormat()); String newExtension = FOrayTarget.getMimeExtension(rint); if (newExtension == null) { @@ -202,6 +183,32 @@ } } + /** + * @param configuration + */ + private void setBaseDirectory(SessionConfig configuration) { + try { + if (task.getFofile() != null) { + if (task.getBasedir() != null) { + configuration.parseOption("base-directory", + task.getBasedir().toURL().toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } else { + configuration.parseOption("base-directory", + task.getFofile().getParentFile().toURL(). + toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } + } + task.log("Using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); + } catch (Exception e) { + + task.log("Error setting base directory: " + e, Project.MSG_ERR); + } + } + private void render(File foFile, File outFile, int rendererType, SessionConfig configuration) throws FOrayException { InputHandler inputHandler = new FOInputHandler(logger, foFile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 18:32:10
|
Revision: 7028 Author: victormote Date: 2006-04-15 11:32:03 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7028&view=rev Log Message: ----------- Move some methods that should be standardized to a more central location, also nearer their constants. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/FOrayTarget.java trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/FOrayTarget.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/FOrayTarget.java 2006-04-15 18:07:30 UTC (rev 7027) +++ trunk/foray/foray-app/src/java/org/foray/app/FOrayTarget.java 2006-04-15 18:32:03 UTC (rev 7028) @@ -549,4 +549,68 @@ return this.document; } + /** + * Converts a String description of the desired Renderer to a valid + * renderer code. + * @param format The String description of the desired Renderer, either + * a mime type or a standard description. + * @return One of {@link #RENDER_PDF}, {@link #RENDER_AWT}, + * {@link #RENDER_MIF}, {@link #RENDER_XML}, {@link #RENDER_PRINT}, + * {@link #RENDER_PCL}, {@link #RENDER_PS}, {@link #RENDER_TXT}, + * {@link #RENDER_SVG}, or -1 if the input is not valid. + */ + public static int getRendererType(String format) { + if ((format == null) + || format.equalsIgnoreCase("application/pdf") + || format.equalsIgnoreCase("pdf")) { + return RENDER_PDF; + } + if (format.equalsIgnoreCase("application/postscript") + || format.equalsIgnoreCase("ps")) { + return RENDER_PS; + } + if (format.equalsIgnoreCase("application/vnd.mif") + || format.equalsIgnoreCase("mif")) { + return RENDER_MIF; + } + if (format.equalsIgnoreCase("application/vnd.gp-PCL") + || format.equalsIgnoreCase("pcl")) { + return RENDER_PCL; + } + if (format.equalsIgnoreCase("text/plain") + || format.equalsIgnoreCase("txt")) { + return RENDER_TXT; + } + if (format.equalsIgnoreCase("text/xml") + || format.equalsIgnoreCase("at") + || format.equalsIgnoreCase("xml")) { + return RENDER_XML; + } + return -1; + } + + public static String getMimeExtension(int rendererType) { + switch (rendererType) { + case RENDER_PDF: { + return ".pdf"; + } + case RENDER_PS: { + return ".ps"; + } + case RENDER_MIF: { + return ".mif"; + } + case RENDER_PCL: { + return ".pcl"; + } + case RENDER_TXT: { + return ".txt"; + } + case RENDER_XML: { + return ".xml"; + } + } + return null; + } + } Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:07:30 UTC (rev 7027) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:32:03 UTC (rev 7028) @@ -63,53 +63,6 @@ logFiles = aLogFiles; } - private int determineRenderer(String format) { - if ((format == null) || - format.equalsIgnoreCase("application/pdf") || - format.equalsIgnoreCase("pdf")) { - return FOrayTarget.RENDER_PDF; - } else if (format.equalsIgnoreCase("application/postscript") || - format.equalsIgnoreCase("ps")) { - return FOrayTarget.RENDER_PS; - } else if (format.equalsIgnoreCase("application/vnd.mif") || - format.equalsIgnoreCase("mif")) { - return FOrayTarget.RENDER_MIF; - } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") || - format.equalsIgnoreCase("pcl")) { - return FOrayTarget.RENDER_PCL; - } else if (format.equalsIgnoreCase("text/plain") || - format.equalsIgnoreCase("txt")) { - return FOrayTarget.RENDER_TXT; - } else if (format.equalsIgnoreCase("text/xml") || - format.equalsIgnoreCase("at") || - format.equalsIgnoreCase("xml")) { - return FOrayTarget.RENDER_XML; - } else { - String err = "Couldn't determine renderer to use: "+format; - throw new BuildException(err); - } - } - - private String determineExtension(int renderer) { - switch (renderer) { - case FOrayTarget.RENDER_PDF: - return ".pdf"; - case FOrayTarget.RENDER_PS: - return ".ps"; - case FOrayTarget.RENDER_MIF: - return ".mif"; - case FOrayTarget.RENDER_PCL: - return ".pcl"; - case FOrayTarget.RENDER_TXT: - return ".txt"; - case FOrayTarget.RENDER_XML: - return ".xml"; - default: - String err = "Unknown renderer: "+renderer; - throw new BuildException(err); - } - } - private File replaceExtension(File file, String expectedExt, String newExt) { String name = file.getName(); @@ -148,8 +101,12 @@ task.log("Error setting base directory: " + e, Project.MSG_ERR); } - int rint = determineRenderer(task.getFormat()); - String newExtension = determineExtension(rint); + int rint = FOrayTarget.getRendererType(task.getFormat()); + String newExtension = FOrayTarget.getMimeExtension(rint); + if (newExtension == null) { + String err = "Unknown renderer: "+ rint; + throw new BuildException(err); + } // actioncount = # of fofiles actually processed through FOray int actioncount = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 18:07:35
|
Revision: 7027 Author: victormote Date: 2006-04-15 11:07:30 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7027&view=rev Log Message: ----------- Match class name to class file name. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 18:04:12 UTC (rev 7026) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 18:07:30 UTC (rev 7027) @@ -243,7 +243,7 @@ } } try { - Starter starter = new FOrayTaskStarter(this, log, logFiles); + Starter starter = new FOrayAntTaskStarter(this, log, logFiles); starter.run(); } catch (FOrayException ex) { throw new BuildException(ex); Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:04:12 UTC (rev 7026) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:07:30 UTC (rev 7027) @@ -50,12 +50,12 @@ import java.io.FileOutputStream; import java.io.OutputStream; -class FOrayTaskStarter extends Starter { +class FOrayAntTaskStarter extends Starter { FOrayAntTask task; Log log; boolean logFiles; - FOrayTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) + FOrayAntTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) throws FOrayException { super(aLogger, null, null); this.task = task; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 18:04:20
|
Revision: 7026 Author: victormote Date: 2006-04-15 11:04:12 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7026&view=rev Log Message: ----------- Put each class in a separate file. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java Added Paths: ----------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 17:51:20 UTC (rev 7025) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 18:04:12 UTC (rev 7026) @@ -24,32 +24,17 @@ package org.foray.app.ant; -import org.foray.app.FOInputHandler; -import org.foray.app.FOrayDocument; -import org.foray.app.FOraySession; -import org.foray.app.FOrayTarget; -import org.foray.app.InputHandler; -import org.foray.app.Options; -import org.foray.app.SessionConfig; import org.foray.app.Starter; import org.foray.common.FOrayException; import org.foray.common.Logging; -import org.foray.output.OutputConfig; -import org.foray.output.OutputTarget; import org.apache.commons.logging.Log; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.util.GlobPatternMapper; -import org.xml.sax.XMLReader; - import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -266,239 +251,3 @@ } } - -class FOrayTaskStarter extends Starter { - FOrayAntTask task; - Log log; - boolean logFiles; - - FOrayTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) - throws FOrayException { - super(aLogger, null, null); - this.task = task; - log = aLogger; - logFiles = aLogFiles; - } - - private int determineRenderer(String format) { - if ((format == null) || - format.equalsIgnoreCase("application/pdf") || - format.equalsIgnoreCase("pdf")) { - return FOrayTarget.RENDER_PDF; - } else if (format.equalsIgnoreCase("application/postscript") || - format.equalsIgnoreCase("ps")) { - return FOrayTarget.RENDER_PS; - } else if (format.equalsIgnoreCase("application/vnd.mif") || - format.equalsIgnoreCase("mif")) { - return FOrayTarget.RENDER_MIF; - } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") || - format.equalsIgnoreCase("pcl")) { - return FOrayTarget.RENDER_PCL; - } else if (format.equalsIgnoreCase("text/plain") || - format.equalsIgnoreCase("txt")) { - return FOrayTarget.RENDER_TXT; - } else if (format.equalsIgnoreCase("text/xml") || - format.equalsIgnoreCase("at") || - format.equalsIgnoreCase("xml")) { - return FOrayTarget.RENDER_XML; - } else { - String err = "Couldn't determine renderer to use: "+format; - throw new BuildException(err); - } - } - - private String determineExtension(int renderer) { - switch (renderer) { - case FOrayTarget.RENDER_PDF: - return ".pdf"; - case FOrayTarget.RENDER_PS: - return ".ps"; - case FOrayTarget.RENDER_MIF: - return ".mif"; - case FOrayTarget.RENDER_PCL: - return ".pcl"; - case FOrayTarget.RENDER_TXT: - return ".txt"; - case FOrayTarget.RENDER_XML: - return ".xml"; - default: - String err = "Unknown renderer: "+renderer; - throw new BuildException(err); - } - } - - private File replaceExtension(File file, String expectedExt, - String newExt) { - String name = file.getName(); - if (name.toLowerCase().endsWith(expectedExt)) { - name = name.substring(0, name.length() - expectedExt.length()); - } - name = name.concat(newExt); - return new File(file.getParentFile(), name); - } - - public void run() throws FOrayException { - Log logger = Logging.makeDefaultLogger(); - SessionConfig configuration = new SessionConfig(logger); - if (task.userConfig != null) { - new Options (log, configuration, null, task.userConfig); - } - - try { - if (task.getFofile() != null) { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - task.getFofile().getParentFile().toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { - - task.log("Error setting base directory: " + e, Project.MSG_ERR); - } - - int rint = determineRenderer(task.getFormat()); - String newExtension = determineExtension(rint); - - // actioncount = # of fofiles actually processed through FOray - int actioncount = 0; - // skippedcount = # of fofiles which haven't changed (force = "false") - int skippedcount = 0; - - // deal with single source file - if (task.getFofile() != null) { - if (task.getFofile().exists()) { - File outf = task.getOutfile(); - if (outf == null) { - throw new BuildException("outfile is required when fofile is used"); - } - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } - - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { - skippedcount++; - } - } - } - - GlobPatternMapper mapper = new GlobPatternMapper(); - mapper.setFrom("*.fo"); - mapper.setTo("*" + newExtension); - - // deal with the filesets - for (int i = 0; i < task.filesets.size(); i++) { - FileSet fs = (FileSet) task.filesets.get(i); - DirectoryScanner ds = fs.getDirectoryScanner(task.getProject()); - String[] files = ds.getIncludedFiles(); - - - for (int j = 0; j < files.length; j++) { - File f = new File(fs.getDir(task.getProject()), files[j]); - File outf = null; - if (task.getOutdir() != null && files[j].endsWith(".fo")) { - String[] sa = mapper.mapFileName(files[j]); - outf = new File(task.getOutdir(), sa[0]); - } else { - outf = replaceExtension(f, ".fo", newExtension); - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } - } - try { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - fs.getDir(task.getProject()).toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { - task.log("Error setting base directory: " + e, Project.MSG_ERR); - } - - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (f.lastModified() > outf.lastModified() )) { - render(f, outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { - skippedcount++; - } - - } - } - - if (actioncount + skippedcount == 0) { - task.log("No files processed. No files were selected by the filesets " - + "and no fofile was set." , Project.MSG_WARN); - } else if (skippedcount > 0) { - task.log(skippedcount + " xslfo file(s) skipped (no change found" - + " since last generation; set force=\"true\" to override)." - , Project.MSG_INFO); - } - } - - private void render(File foFile, File outFile, int rendererType, - SessionConfig configuration) throws FOrayException { - InputHandler inputHandler = new FOInputHandler(logger, foFile); - XMLReader parser = inputHandler.getParser(); - - OutputStream out = null; - try { - File dir = outFile.getParentFile(); - dir.mkdirs(); - out = new FileOutputStream(outFile); - } catch (Exception ex) { - throw new BuildException(ex); - } - - if (logFiles) task.log(foFile + " -> " + outFile, Project.MSG_INFO); - - try { - FOraySession session = new FOraySession(log, configuration, null, - null, null, null); - FOrayDocument document = new FOrayDocument(session, - inputHandler.getInputSource(), parser); - - OutputConfig rendererOptions = null; - if (rendererType == FOrayTarget.RENDER_XML) { - rendererOptions = new OutputConfig(logger); - rendererOptions.parseOption("fineDetail", "true", - SessionConfig.PRECEDENCE_DEFAULT); - } - OutputTarget renderer = document.makeOutputTarget(rendererType, - rendererOptions); - new FOrayTarget(document, renderer, null, out); - - session.process(); - out.close(); - } catch (Exception ex) { - throw new BuildException(ex); - } - } - -} Added: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java (rev 0) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java 2006-04-15 18:04:12 UTC (rev 7026) @@ -0,0 +1,287 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.app.ant; + +import org.foray.app.FOInputHandler; +import org.foray.app.FOrayDocument; +import org.foray.app.FOraySession; +import org.foray.app.FOrayTarget; +import org.foray.app.InputHandler; +import org.foray.app.Options; +import org.foray.app.SessionConfig; +import org.foray.app.Starter; +import org.foray.common.FOrayException; +import org.foray.common.Logging; +import org.foray.output.OutputConfig; +import org.foray.output.OutputTarget; + +import org.apache.commons.logging.Log; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.util.GlobPatternMapper; + +import org.xml.sax.XMLReader; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; + +class FOrayTaskStarter extends Starter { + FOrayAntTask task; + Log log; + boolean logFiles; + + FOrayTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) + throws FOrayException { + super(aLogger, null, null); + this.task = task; + log = aLogger; + logFiles = aLogFiles; + } + + private int determineRenderer(String format) { + if ((format == null) || + format.equalsIgnoreCase("application/pdf") || + format.equalsIgnoreCase("pdf")) { + return FOrayTarget.RENDER_PDF; + } else if (format.equalsIgnoreCase("application/postscript") || + format.equalsIgnoreCase("ps")) { + return FOrayTarget.RENDER_PS; + } else if (format.equalsIgnoreCase("application/vnd.mif") || + format.equalsIgnoreCase("mif")) { + return FOrayTarget.RENDER_MIF; + } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") || + format.equalsIgnoreCase("pcl")) { + return FOrayTarget.RENDER_PCL; + } else if (format.equalsIgnoreCase("text/plain") || + format.equalsIgnoreCase("txt")) { + return FOrayTarget.RENDER_TXT; + } else if (format.equalsIgnoreCase("text/xml") || + format.equalsIgnoreCase("at") || + format.equalsIgnoreCase("xml")) { + return FOrayTarget.RENDER_XML; + } else { + String err = "Couldn't determine renderer to use: "+format; + throw new BuildException(err); + } + } + + private String determineExtension(int renderer) { + switch (renderer) { + case FOrayTarget.RENDER_PDF: + return ".pdf"; + case FOrayTarget.RENDER_PS: + return ".ps"; + case FOrayTarget.RENDER_MIF: + return ".mif"; + case FOrayTarget.RENDER_PCL: + return ".pcl"; + case FOrayTarget.RENDER_TXT: + return ".txt"; + case FOrayTarget.RENDER_XML: + return ".xml"; + default: + String err = "Unknown renderer: "+renderer; + throw new BuildException(err); + } + } + + private File replaceExtension(File file, String expectedExt, + String newExt) { + String name = file.getName(); + if (name.toLowerCase().endsWith(expectedExt)) { + name = name.substring(0, name.length() - expectedExt.length()); + } + name = name.concat(newExt); + return new File(file.getParentFile(), name); + } + + public void run() throws FOrayException { + Log logger = Logging.makeDefaultLogger(); + SessionConfig configuration = new SessionConfig(logger); + if (task.userConfig != null) { + new Options (log, configuration, null, task.userConfig); + } + + try { + if (task.getFofile() != null) { + if (task.getBasedir() != null) { + configuration.parseOption("base-directory", + task.getBasedir().toURL().toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } else { + configuration.parseOption("base-directory", + task.getFofile().getParentFile().toURL(). + toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } + } + task.log("Using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); + } catch (Exception e) { + + task.log("Error setting base directory: " + e, Project.MSG_ERR); + } + + int rint = determineRenderer(task.getFormat()); + String newExtension = determineExtension(rint); + + // actioncount = # of fofiles actually processed through FOray + int actioncount = 0; + // skippedcount = # of fofiles which haven't changed (force = "false") + int skippedcount = 0; + + // deal with single source file + if (task.getFofile() != null) { + if (task.getFofile().exists()) { + File outf = task.getOutfile(); + if (outf == null) { + throw new BuildException("outfile is required when fofile is used"); + } + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (task.getFofile().lastModified() > outf.lastModified() )) { + render(task.getFofile(), outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { + skippedcount++; + } + } + } + + GlobPatternMapper mapper = new GlobPatternMapper(); + mapper.setFrom("*.fo"); + mapper.setTo("*" + newExtension); + + // deal with the filesets + for (int i = 0; i < task.filesets.size(); i++) { + FileSet fs = (FileSet) task.filesets.get(i); + DirectoryScanner ds = fs.getDirectoryScanner(task.getProject()); + String[] files = ds.getIncludedFiles(); + + + for (int j = 0; j < files.length; j++) { + File f = new File(fs.getDir(task.getProject()), files[j]); + File outf = null; + if (task.getOutdir() != null && files[j].endsWith(".fo")) { + String[] sa = mapper.mapFileName(files[j]); + outf = new File(task.getOutdir(), sa[0]); + } else { + outf = replaceExtension(f, ".fo", newExtension); + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + } + try { + if (task.getBasedir() != null) { + configuration.parseOption("base-directory", + task.getBasedir().toURL().toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } else { + configuration.parseOption("base-directory", + fs.getDir(task.getProject()).toURL(). + toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } + task.log("Using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); + } catch (Exception e) { + task.log("Error setting base directory: " + e, Project.MSG_ERR); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (f.lastModified() > outf.lastModified() )) { + render(f, outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { + skippedcount++; + } + + } + } + + if (actioncount + skippedcount == 0) { + task.log("No files processed. No files were selected by the filesets " + + "and no fofile was set." , Project.MSG_WARN); + } else if (skippedcount > 0) { + task.log(skippedcount + " xslfo file(s) skipped (no change found" + + " since last generation; set force=\"true\" to override)." + , Project.MSG_INFO); + } + } + + private void render(File foFile, File outFile, int rendererType, + SessionConfig configuration) throws FOrayException { + InputHandler inputHandler = new FOInputHandler(logger, foFile); + XMLReader parser = inputHandler.getParser(); + + OutputStream out = null; + try { + File dir = outFile.getParentFile(); + dir.mkdirs(); + out = new FileOutputStream(outFile); + } catch (Exception ex) { + throw new BuildException(ex); + } + + if (logFiles) task.log(foFile + " -> " + outFile, Project.MSG_INFO); + + try { + FOraySession session = new FOraySession(log, configuration, null, + null, null, null); + FOrayDocument document = new FOrayDocument(session, + inputHandler.getInputSource(), parser); + + OutputConfig rendererOptions = null; + if (rendererType == FOrayTarget.RENDER_XML) { + rendererOptions = new OutputConfig(logger); + rendererOptions.parseOption("fineDetail", "true", + SessionConfig.PRECEDENCE_DEFAULT); + } + OutputTarget renderer = document.makeOutputTarget(rendererType, + rendererOptions); + new FOrayTarget(document, renderer, null, out); + + session.process(); + out.close(); + } catch (Exception ex) { + throw new BuildException(ex); + } + } + +} Property changes on: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTaskStarter.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 17:51:27
|
Revision: 7025 Author: victormote Date: 2006-04-15 10:51:20 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7025&view=rev Log Message: ----------- Make configuration a URL. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java trunk/foray/foray-app/src/java/org/foray/app/Options.java trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java Modified: trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-04-15 15:42:02 UTC (rev 7024) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-04-15 17:51:20 UTC (rev 7025) @@ -33,6 +33,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.MalformedURLException; +import java.net.URL; /** * Options parses the commandline arguments @@ -65,7 +66,7 @@ private static final int AREA_OUTPUT = 9; /* user configuration file */ - File userConfigFile = null; + URL userConfigFile = null; /* input fo file */ File fofile = null; /* xsltfile (xslt transformation as input) */ @@ -153,7 +154,11 @@ throw new FOrayException("if you use '-c', you must " + "specify the name of the configuration file"); } - userConfigFile = new File(args[currentArgument + 1]); + try { + this.userConfigFile = new URL(args[currentArgument + 1]); + } catch (MalformedURLException e) { + throw new FOrayException(e); + } currentArgument++; return true; } @@ -520,7 +525,7 @@ return outfile; } - public File getUserConfigFile() { + public URL getUserConfigFile() { return userConfigFile; } Modified: trunk/foray/foray-app/src/java/org/foray/app/Options.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/Options.java 2006-04-15 15:42:02 UTC (rev 7024) +++ trunk/foray/foray-app/src/java/org/foray/app/Options.java 2006-04-15 17:51:20 UTC (rev 7025) @@ -32,7 +32,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import java.io.File; +import java.net.URL; /** * Options handles loading of configuration files and @@ -53,7 +53,7 @@ } public Options(Log logger, SessionConfig sessionConfig, - OutputConfig renderConfig, File userConfigFile) throws FOrayException { + OutputConfig renderConfig, URL userConfigFile) throws FOrayException { this(logger, sessionConfig, renderConfig); this.loadUserconfiguration(userConfigFile); initOptions(); @@ -70,7 +70,7 @@ // setting clOptions void setCommandLineOptions(CommandLineOptions clOptions) { // load user configuration file,if there is one - File userConfigFile = clOptions.getUserConfigFile(); + URL userConfigFile = clOptions.getUserConfigFile(); if (userConfigFile != null) { this.loadUserconfiguration(userConfigFile); } @@ -82,14 +82,11 @@ } } - public void loadUserconfiguration(String userConfigFile) { - loadUserconfiguration(new File(userConfigFile)); - } - - public void loadUserconfiguration(File userConfigFile) { - if (userConfigFile != null) { - loadUserconfiguration(InputHandler.fileInputSource(userConfigFile)); + public void loadUserconfiguration(URL userConfigFile) { + if (userConfigFile == null) { + return; } + loadUserconfiguration(InputHandler.urlInputSource(userConfigFile)); } public void loadUserconfiguration(InputSource userConfigSource) { Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 15:42:02 UTC (rev 7024) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-15 17:51:20 UTC (rev 7025) @@ -50,6 +50,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -74,7 +75,7 @@ File outDir; String format; //MIME type File baseDir; - File userConfig; + URL userConfig; int messageType = Project.MSG_VERBOSE; boolean logFiles = true; private boolean force = false; @@ -83,7 +84,7 @@ * Sets the user configuration file. * @param userConfig File containing the user configuration. */ - public void setUserconfig (File userConfig) { + public void setUserconfig (URL userConfig) { this.userConfig = userConfig; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 15:42:10
|
Revision: 7024 Author: victormote Date: 2006-04-15 08:42:02 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7024&view=rev Log Message: ----------- Improve message readability. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/Options.java Modified: trunk/foray/foray-app/src/java/org/foray/app/Options.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/Options.java 2006-04-15 15:41:07 UTC (rev 7023) +++ trunk/foray/foray-app/src/java/org/foray/app/Options.java 2006-04-15 15:42:02 UTC (rev 7024) @@ -100,10 +100,10 @@ try { reader.parseDocument(); } catch (FOrayException error) { - logger.error("Could not load user configuration " - + userConfigSource.getSystemId() + " - error: " - + error.getMessage()); - logger.error("using default values"); + logger.error("Could not load user configuration:\n" + + " " + userConfigSource.getSystemId() + "\n" + + " Error: " + error.getMessage() +"\n" + + " Using default values."); dumpError(error); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 15:41:14
|
Revision: 7023 Author: victormote Date: 2006-04-15 08:41:07 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7023&view=rev Log Message: ----------- Add classpath entries for some Ant-related jars, allowing Ant to be run from within this project (to test the FOray Ant task). Modified Paths: -------------- trunk/foray/foray-app/.classpath Modified: trunk/foray/foray-app/.classpath =================================================================== --- trunk/foray/foray-app/.classpath 2006-04-15 00:09:22 UTC (rev 7022) +++ trunk/foray/foray-app/.classpath 2006-04-15 15:41:07 UTC (rev 7023) @@ -27,5 +27,7 @@ <classpathentry kind="var" path="FORAY_LIB_ROOT/commons-logging.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/axslPDF"/> <classpathentry combineaccessrules="false" kind="src" path="/FOrayPDF"/> + <classpathentry kind="var" path="ANT_HOME/lib/ant-launcher.jar"/> + <classpathentry kind="var" path="ANT_HOME/lib/ant-trax.jar"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-15 00:09:28
|
Revision: 7022 Author: victormote Date: 2006-04-14 17:09:22 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7022&view=rev Log Message: ----------- Warn user if he tries to use an unregistered font. Modified Paths: -------------- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java Modified: trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-04-14 23:50:13 UTC (rev 7021) +++ trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-04-15 00:09:22 UTC (rev 7022) @@ -389,6 +389,10 @@ String simulateBackslant = attributes.getValue("simulate-backslant"); RegisteredFont registeredFont = this.fontServer.getRegisteredFont( fontID); + if (registeredFont == null) { + this.logWarning("Font is not registered: " + fontID); + return; + } String encodingName = attributes.getValue("encoding"); if (encodingName == null) { /* Inherit the value from font-family. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 23:50:17
|
Revision: 7021 Author: victormote Date: 2006-04-14 16:50:13 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7021&view=rev Log Message: ----------- Automatically register the remaining Base-14 fonts. Modified Paths: -------------- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java Modified: trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 23:36:49 UTC (rev 7020) +++ trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 23:50:13 UTC (rev 7021) @@ -313,6 +313,21 @@ private void registerBase14Fonts() throws FontException { registerBase14Font("Base14-Courier", "Courier.afm"); + registerBase14Font("Base14-Courier-Oblique", "Courier-Oblique.afm"); + registerBase14Font("Base14-Courier-Bold", "Courier-Bold.afm"); + registerBase14Font("Base14-Courier-BoldOblique", + "Courier-BoldOblique.afm"); + registerBase14Font("Base14-Helvetica", "Helvetica.afm"); + registerBase14Font("Base14-Helvetica-Oblique", "Helvetica-Oblique.afm"); + registerBase14Font("Base14-Helvetica-Bold", "Helvetica-Bold.afm"); + registerBase14Font("Base14-Helvetica-BoldOblique", + "Helvetica-BoldOblique.afm"); + registerBase14Font("Base14-Times", "Times-Roman.afm"); + registerBase14Font("Base14-Times-Italic", "Times-Italic.afm"); + registerBase14Font("Base14-Times-Bold", "Times-Bold.afm"); + registerBase14Font("Base14-Times-BoldItalic", "Times-BoldItalic.afm"); + registerBase14Font("Base14-Symbol", "Symbol.afm"); + registerBase14Font("Base14-ZapfDingbats", "ZapfDingbats.afm"); } private void registerBase14Font(String fontName, String fileName) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 23:36:56
|
Revision: 7020 Author: victormote Date: 2006-04-14 16:36:49 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7020&view=rev Log Message: ----------- Don't try to read past the end of the file. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 23:21:19 UTC (rev 7019) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 23:36:49 UTC (rev 7020) @@ -201,6 +201,10 @@ boolean eol = false; while (!eol) { + if (this.arrayIndex >= this.length()) { + eol = true; + break; + } switch (byteRead = this.readUnsignedByte()) { case -1: case '\n': { @@ -210,6 +214,10 @@ case '\r': { eol = true; long cur = getFilePointer(); + if (this.arrayIndex >= this.length()) { + eol = true; + break; + } if ((this.readUnsignedByte()) != '\n') { seek(cur); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 23:21:24
|
Revision: 7019 Author: victormote Date: 2006-04-14 16:21:19 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7019&view=rev Log Message: ----------- Use ClassLoader to get the Base-14 AFM files from the jar file. Modified Paths: -------------- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java Modified: trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 23:20:15 UTC (rev 7018) +++ trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 23:21:19 UTC (rev 7019) @@ -46,7 +46,6 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -313,19 +312,14 @@ } private void registerBase14Fonts() throws FontException { -// registerBase14Font("Base14-Courier", "Courier.afm"); + registerBase14Font("Base14-Courier", "Courier.afm"); } private void registerBase14Font(String fontName, String fileName) { - URL metricURL; + String resourceName = "org/foray/font/resources/base-14/" + fileName; + ClassLoader loader = ClassLoader.getSystemClassLoader(); + URL metricURL = loader.getResource(resourceName); try { - metricURL = new URL("jar", null, "org/foray/font/resource/base-14/" - + fileName); - } catch (MalformedURLException e) { - this.logger.warn(e); - return; - } - try { registerFont(fontName, null, metricURL, null, "none", null); } catch (FontException e) { this.logger.warn(e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 23:20:25
|
Revision: 7018 Author: victormote Date: 2006-04-14 16:20:15 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7018&view=rev Log Message: ----------- Add a jar file containing the Base-14 metrics to the classpath. Modified Paths: -------------- trunk/foray/foray-font/.classpath Modified: trunk/foray/foray-font/.classpath =================================================================== --- trunk/foray/foray-font/.classpath 2006-04-14 22:25:35 UTC (rev 7017) +++ trunk/foray/foray-font/.classpath 2006-04-14 23:20:15 UTC (rev 7018) @@ -11,5 +11,6 @@ <classpathentry kind="var" path="FORAY_LIB_ROOT/commons-logging.jar"/> <classpathentry kind="var" path="FORAY_LIB_ROOT/xercesImpl-2.7.1.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/FOrayPretty"/> + <classpathentry kind="lib" path="D:/vic/foray/trunk/foray/foray-font/build/ant/foray-font.jar"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 22:25:42
|
Revision: 7017 Author: victormote Date: 2006-04-14 15:25:35 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7017&view=rev Log Message: ----------- Need to increment the array index after reading a byte. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 21:33:15 UTC (rev 7016) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 22:25:35 UTC (rev 7017) @@ -75,7 +75,12 @@ * {@inheritDoc} */ public byte readByte() throws IOException { - return this.byteArray[arrayIndex]; + if (arrayIndex >= this.byteArray.length) { + throw new EOFException(); + } + byte theByte = this.byteArray[arrayIndex]; + arrayIndex ++; + return theByte; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 21:33:23
|
Revision: 7016 Author: victormote Date: 2006-04-14 14:33:15 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7016&view=rev Log Message: ----------- The test must be for whether the file is actually readable or not. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java 2006-04-14 20:53:18 UTC (rev 7015) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java 2006-04-14 21:33:15 UTC (rev 7016) @@ -92,13 +92,12 @@ if (url == null) { throw new IOException("URL is null."); } - if (url.getFile() == null - || url.getFile().equals("")) { - /* If we can't get a file out of it, we need to use the stream - * instead. */ - - } File file = new File(url.getFile()); + if (! file.canRead()) { + /* If we can't get a readable file out of it, we need to use the URL + * implementation instead. */ + return new RandomReaderURL(url); + } return new RandomReaderRAFile(file); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 20:53:39
|
Revision: 7015 Author: victormote Date: 2006-04-14 13:53:18 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7015&view=rev Log Message: ----------- 1. Add new RandomInput implementation suitable for URLs that are not local files. 2. Add method allowing implementations to temporarily release resources. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/RandomInput.java trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java trunk/foray/foray-common/src/java/org/foray/common/RandomReaderRAFile.java Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderURL.java Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomInput.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomInput.java 2006-04-14 19:42:40 UTC (rev 7014) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomInput.java 2006-04-14 20:53:18 UTC (rev 7015) @@ -68,4 +68,15 @@ */ InputStream getInputStream() throws IOException ; + /** + * Releases any resources that can be released without compromising the + * ability to regain access to all resources. + * This is primarily useful for implementations that hold an entire + * resource in memory, and that may wish to release that memory and re-read + * the original URL later. + * Note that if resources are reset, each implementation is responsible to + * reboot those resources when needed. + */ + void reset() ; + } Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java 2006-04-14 19:42:40 UTC (rev 7014) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReader.java 2006-04-14 20:53:18 UTC (rev 7015) @@ -88,9 +88,18 @@ this.realReader = randomInputFactory(description, byteArray); } - private RandomInput randomInputFactory(URL url) throws IOException{ - /* Right now, there is only one available implementation. */ - return new RandomReaderRAFile(url); + private RandomInput randomInputFactory(URL url) throws IOException { + if (url == null) { + throw new IOException("URL is null."); + } + if (url.getFile() == null + || url.getFile().equals("")) { + /* If we can't get a file out of it, we need to use the stream + * instead. */ + + } + File file = new File(url.getFile()); + return new RandomReaderRAFile(file); } private RandomInput randomInputFactory(String description, @@ -725,4 +734,11 @@ return this.realReader.getInputStream(); } + /** + * {@inheritDoc} + */ + public void reset() { + this.realReader.reset(); + } + } Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 19:42:40 UTC (rev 7014) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReaderArray.java 2006-04-14 20:53:18 UTC (rev 7015) @@ -243,4 +243,12 @@ return new ByteArrayInputStream(this.byteArray); } + /** + * {@inheritDoc} + */ + public void reset() { + /* We cannot do anything here as there is no way to reconstruct the + * byte array. */ + } + } Modified: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderRAFile.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderRAFile.java 2006-04-14 19:42:40 UTC (rev 7014) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReaderRAFile.java 2006-04-14 20:53:18 UTC (rev 7015) @@ -24,13 +24,11 @@ package org.foray.common; -import org.foray.common.RandomInput; - import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; -import java.net.URL; /** * Implementation of RandomInput that uses a RandomAccessFile to do the @@ -39,16 +37,14 @@ */ class RandomReaderRAFile implements RandomInput { - private URL url; private File file = null; private RandomAccessFile raFile = null; /** * Constructor. */ - protected RandomReaderRAFile(URL url) throws IOException { - this.url = url; - this.file = new File(url.getFile()); + protected RandomReaderRAFile(File file) throws IOException { + this.file = file; if (file == null) { return; } @@ -136,7 +132,17 @@ * {@inheritDoc} */ public InputStream getInputStream() throws IOException { - return this.url.openStream(); + return new FileInputStream(this.file); } + /** + * {@inheritDoc} + */ + public void reset() { + /* For now, do nothing here. It is possible that nullifying the + * RandomAccessFile instance variable would release some resources, but + * probably not enough to make it worth the cost of restarting later. + */ + } + } Added: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderURL.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/RandomReaderURL.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/RandomReaderURL.java 2006-04-14 20:53:18 UTC (rev 7015) @@ -0,0 +1,237 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.common; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +/** + * Implementation of RandomInput suitable for URLs that are not local files. + * It is actually a thin wrapper around a {@link RandomReaderArray} instance. + * The idea here is to allow the encapsulated byte array to be released when it + * is not used, but to retain the URL in case it needs to be reopened. + * If it does not need to ever be reopended, juse use {@link RandomReaderArray} + * instead. + */ +class RandomReaderURL implements RandomInput { + + private URL url; + + private RandomReaderArray array; + + /** + * Constructor. + * @param url The URL which contains the stream to be used. + */ + protected RandomReaderURL(URL url) { + this.url = url; + } + + private void checkArray() throws IOException { + if (this.array != null) { + return; + } + InputStream input = this.getInputStream(); + byte[] theBytes = IOUtil.toByteArray(input, 20000); + this.array = new RandomReaderArray(this.url.toExternalForm(), theBytes); + } + + /** + * {@inheritDoc} + */ + public void seek(long offset) throws IOException { + checkArray(); + this.array.seek(offset); + } + + /** + * {@inheritDoc} + */ + public int skipBytes(int add) throws IOException { + checkArray(); + return this.array.skipBytes(add); + } + + /** + * {@inheritDoc} + */ + public long length() throws IOException { + checkArray(); + return this.array.length(); + } + + /** + * {@inheritDoc} + */ + public byte readByte() throws IOException { + checkArray(); + return this.array.readByte(); + } + + /** + * {@inheritDoc} + */ + public final int readUnsignedByte() throws IOException { + checkArray(); + return this.array.readUnsignedByte(); + } + + /** + * {@inheritDoc} + */ + public final short readShort() throws IOException { + checkArray(); + return this.array.readShort(); + } + + /** + * {@inheritDoc} + */ + public final int readUnsignedShort() throws IOException { + checkArray(); + return this.array.readUnsignedShort(); + } + + /** + * {@inheritDoc} + */ + public final double readDouble() throws IOException { + checkArray(); + return this.array.readDouble(); + } + + /** + * {@inheritDoc} + */ + public final boolean readBoolean() throws IOException { + checkArray(); + return this.array.readBoolean(); + } + + /** + * {@inheritDoc} + */ + public final void readFully(byte[] b) throws IOException { + checkArray(); + this.array.readFully(b); + } + + /** + * {@inheritDoc} + */ + public final void readFully(byte[] b, int off, int len) throws IOException { + checkArray(); + this.array.readFully(b, off, len); + } + + /** + * {@inheritDoc} + */ + public final long readLong() throws IOException { + checkArray(); + return this.array.readLong(); + } + + /** + * {@inheritDoc} + */ + public final float readFloat() throws IOException { + checkArray(); + return this.array.readFloat(); + } + + /** + * {@inheritDoc} + */ + public final char readChar() throws IOException { + checkArray(); + return this.array.readChar(); + } + + /** + * {@inheritDoc} + */ + public final String readUTF() throws IOException { + checkArray(); + return this.array.readUTF(); + } + + /** + * {@inheritDoc} + */ + public final int readInt() throws IOException { + checkArray(); + return this.array.readInt(); + } + + /** + * {@inheritDoc} + */ + public final String readLine() throws IOException { + checkArray(); + return this.array.readLine(); + } + + /** + * {@inheritDoc} + */ + public long getFilePointer() throws IOException { + checkArray(); + return this.array.getFilePointer(); + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + try { + checkArray(); + } catch (IOException e) { + return this.url.toExternalForm(); + } + return this.array.getDescription(); + } + + /** + * {@inheritDoc} + */ + public InputStream getInputStream() throws IOException { + return this.url.openStream(); + } + + /** + * {@inheritDoc} + */ + public void reset() { + try { + checkArray(); + } catch (IOException e) { + /* Nothing to do here. */ + } + this.array = null; + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/RandomReaderURL.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 19:42:50
|
Revision: 7014 Author: victormote Date: 2006-04-14 12:42:40 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7014&view=rev Log Message: ----------- Steps toward handling metrics files in jar files. Modified Paths: -------------- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java Modified: trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 15:44:36 UTC (rev 7013) +++ trunk/foray/foray-font/src/java/org/foray/font/FOrayFontServer.java 2006-04-14 19:42:40 UTC (rev 7014) @@ -46,6 +46,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -305,11 +306,32 @@ return; } getLogger().info("Setting up fonts."); + registerBase14Fonts(); registerAWTFonts(); readFontConfig(fontConfigFile); setupCompleted = true; } + private void registerBase14Fonts() throws FontException { +// registerBase14Font("Base14-Courier", "Courier.afm"); + } + + private void registerBase14Font(String fontName, String fileName) { + URL metricURL; + try { + metricURL = new URL("jar", null, "org/foray/font/resource/base-14/" + + fileName); + } catch (MalformedURLException e) { + this.logger.warn(e); + return; + } + try { + registerFont(fontName, null, metricURL, null, "none", null); + } catch (FontException e) { + this.logger.warn(e); + } + } + private void registerAWTFonts() { if (! this.usingSystemFonts) { return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 15:44:44
|
Revision: 7013 Author: victormote Date: 2006-04-14 08:44:36 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7013&view=rev Log Message: ----------- Add base-14 fonts to jar file. Modified Paths: -------------- trunk/foray/foray-font/scripts/build.xml Modified: trunk/foray/foray-font/scripts/build.xml =================================================================== --- trunk/foray/foray-font/scripts/build.xml 2006-04-14 14:11:20 UTC (rev 7012) +++ trunk/foray/foray-font/scripts/build.xml 2006-04-14 15:44:36 UTC (rev 7013) @@ -97,6 +97,10 @@ > <classpath refid="libs-build-classpath"/> </javac> + <!-- Copy the base-14 files into the build directory. --> + <copy todir="${classes.dir}/org/foray/font/resources/base-14"> + <fileset dir="${module.dir}/resource/base-14" includes="**"/> + </copy> </target> <!-- =================================================================== --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 14:11:32
|
Revision: 7012 Author: victormote Date: 2006-04-14 07:11:20 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7012&view=rev Log Message: ----------- Rename Ant task class to FOrayAntTask. Added Paths: ----------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java Removed Paths: ------------- trunk/foray/foray-app/src/java/org/foray/app/ant/FOray.java Deleted: trunk/foray/foray-app/src/java/org/foray/app/ant/FOray.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOray.java 2006-04-14 03:26:30 UTC (rev 7011) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOray.java 2006-04-14 14:11:20 UTC (rev 7012) @@ -1,503 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.app.ant; - -import org.foray.app.FOInputHandler; -import org.foray.app.FOrayDocument; -import org.foray.app.FOraySession; -import org.foray.app.FOrayTarget; -import org.foray.app.InputHandler; -import org.foray.app.Options; -import org.foray.app.SessionConfig; -import org.foray.app.Starter; -import org.foray.common.FOrayException; -import org.foray.common.Logging; -import org.foray.output.OutputConfig; -import org.foray.output.OutputTarget; - -import org.apache.commons.logging.Log; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.util.GlobPatternMapper; - -import org.xml.sax.XMLReader; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -/** - * Wrapper for FOray which allows it to be accessed from within an Ant task. - * Accepts the inputs: - * <ul> - * <li>fofile -> formatting objects file to be transformed</li> - * <li>format -> MIME type of the format to generate ex. "application/pdf"</li> - * <li>outfile -> output filename</li> - * <li>baseDir -> directory to work from</li> - * <li>userconfig -> file with user configuration (same as the "-c" command line option)</li> - * <li>messagelevel -> (error | warn | info | verbose | debug) level to output non-error messages</li> - * <li>logFiles -> Controls whether the names of the files that are processed are logged or not</li> - * </ul> - */ -public class FOray extends Task { - - File foFile; - List filesets = new ArrayList(); - File outFile; - File outDir; - String format; //MIME type - File baseDir; - File userConfig; - int messageType = Project.MSG_VERBOSE; - boolean logFiles = true; - private boolean force = false; - - /** - * Sets the user configuration file. - * @param userConfig File containing the user configuration. - */ - public void setUserconfig (File userConfig) { - this.userConfig = userConfig; - } - - /** - * Sets the input file. - * @param foFile The FO input file. - */ - public void setFofile(File foFile) { - this.foFile = foFile; - } - - /** - * Gets the input file - */ - public File getFofile() { - return foFile; - } - - /** - * Adds a set of fo files (nested fileset attribute). - */ - public void addFileset(FileSet set) { - filesets.add(set); - } - - /** - * Set whether to check dependencies, or to always generate; - * optional, default is false. - * - * @param force true if always generate. - */ - public void setForce(boolean force) { - this.force = force; - } - - /** - * Gets the force attribute - * @return the force attribute - */ - public boolean getForce() { - return force; - } - - /** - * Sets the output file - * @param outFile The File to which the output should be written. - */ - public void setOutfile(File outFile) { - this.outFile = outFile; - } - - /** - * Gets the output file - */ - public File getOutfile() { - return this.outFile; - } - - /** - * Sets the output directory - * @param outDir Directory to which the output should be written. - */ - public void setOutdir(File outDir) { - this.outDir = outDir; - } - - /** - * Gets the output directory - */ - public File getOutdir() { - return this.outDir; - } - - /** - * Sets output format (MIME type) - */ - public void setFormat(String format) { - this.format = format; - } - - /** - * Gets the output format (MIME type) - */ - public String getFormat() { - return this.format; - } - - /** - * Sets the message level to be used while processing. - * @param messageLevel String containing (info | verbose | debug). - */ - public void setMessagelevel(String messageLevel) { - if (messageLevel.equalsIgnoreCase("info")) { - messageType = Project.MSG_INFO; - } else if (messageLevel.equalsIgnoreCase("verbose")) { - messageType = Project.MSG_VERBOSE; - } else if (messageLevel.equalsIgnoreCase("debug")) { - messageType = Project.MSG_DEBUG; - } else if (messageLevel.equalsIgnoreCase("err") || messageLevel.equalsIgnoreCase("error")) { - messageType = Project.MSG_ERR; - } else if (messageLevel.equalsIgnoreCase("warn")) { - messageType = Project.MSG_WARN; - } else { - log("messagelevel set to unknown value \"" + messageLevel + - "\"", Project.MSG_ERR); - throw new BuildException("unknown messagelevel"); - } - } - - /** - * Returns the message type corresponding to Property.MSG_(INFO | VERBOSE | DEBUG) - * representing the current message level. - */ - public int getMessageType() { - return messageType; - } - - /** - * Sets the base directory. Currently ignored. - * @param baseDir File to use as a working directory. - */ - public void setBasedir(File baseDir) { - this.baseDir = baseDir; - } - - /** - * Gets the base directory - */ - public File getBasedir() { - return (baseDir != null) ? baseDir : getProject().resolveFile("."); - } - - /** - * Controls whether the filenames of the files that are processed are logged - * or not. - */ - public void setLogFiles(boolean aBoolean) { - logFiles = aBoolean; - } - - public boolean getLogFiles() { - return logFiles; - } - - /** - * Starts execution of this task - */ - public void execute() throws BuildException { - Log log = null; - switch (getMessageType()) { - case Project.MSG_INFO: { - log = Logging.makeDefaultLogger(); - break; - } - case Project.MSG_WARN: { - log = Logging.makeWarningLogger(); - break; - } - case Project.MSG_ERR: { - log = Logging.makeQuietLogger(); - break; - } - case Project.MSG_DEBUG: - case Project.MSG_VERBOSE: { - log = Logging.makeDebugLogger(); - break; - } - default: { - log = Logging.makeDefaultLogger(); - break; - } - } - try { - Starter starter = new FOrayTaskStarter(this, log, logFiles); - starter.run(); - } catch (FOrayException ex) { - throw new BuildException(ex); - } - } - -} - -class FOrayTaskStarter extends Starter { - FOray task; - Log log; - boolean logFiles; - - FOrayTaskStarter(FOray task, Log aLogger, boolean aLogFiles) - throws FOrayException { - super(aLogger, null, null); - this.task = task; - log = aLogger; - logFiles = aLogFiles; - } - - private int determineRenderer(String format) { - if ((format == null) || - format.equalsIgnoreCase("application/pdf") || - format.equalsIgnoreCase("pdf")) { - return FOrayTarget.RENDER_PDF; - } else if (format.equalsIgnoreCase("application/postscript") || - format.equalsIgnoreCase("ps")) { - return FOrayTarget.RENDER_PS; - } else if (format.equalsIgnoreCase("application/vnd.mif") || - format.equalsIgnoreCase("mif")) { - return FOrayTarget.RENDER_MIF; - } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") || - format.equalsIgnoreCase("pcl")) { - return FOrayTarget.RENDER_PCL; - } else if (format.equalsIgnoreCase("text/plain") || - format.equalsIgnoreCase("txt")) { - return FOrayTarget.RENDER_TXT; - } else if (format.equalsIgnoreCase("text/xml") || - format.equalsIgnoreCase("at") || - format.equalsIgnoreCase("xml")) { - return FOrayTarget.RENDER_XML; - } else { - String err = "Couldn't determine renderer to use: "+format; - throw new BuildException(err); - } - } - - private String determineExtension(int renderer) { - switch (renderer) { - case FOrayTarget.RENDER_PDF: - return ".pdf"; - case FOrayTarget.RENDER_PS: - return ".ps"; - case FOrayTarget.RENDER_MIF: - return ".mif"; - case FOrayTarget.RENDER_PCL: - return ".pcl"; - case FOrayTarget.RENDER_TXT: - return ".txt"; - case FOrayTarget.RENDER_XML: - return ".xml"; - default: - String err = "Unknown renderer: "+renderer; - throw new BuildException(err); - } - } - - private File replaceExtension(File file, String expectedExt, - String newExt) { - String name = file.getName(); - if (name.toLowerCase().endsWith(expectedExt)) { - name = name.substring(0, name.length() - expectedExt.length()); - } - name = name.concat(newExt); - return new File(file.getParentFile(), name); - } - - public void run() throws FOrayException { - Log logger = Logging.makeDefaultLogger(); - SessionConfig configuration = new SessionConfig(logger); - if (task.userConfig != null) { - new Options (log, configuration, null, task.userConfig); - } - - try { - if (task.getFofile() != null) { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - task.getFofile().getParentFile().toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { - - task.log("Error setting base directory: " + e, Project.MSG_ERR); - } - - int rint = determineRenderer(task.getFormat()); - String newExtension = determineExtension(rint); - - // actioncount = # of fofiles actually processed through FOray - int actioncount = 0; - // skippedcount = # of fofiles which haven't changed (force = "false") - int skippedcount = 0; - - // deal with single source file - if (task.getFofile() != null) { - if (task.getFofile().exists()) { - File outf = task.getOutfile(); - if (outf == null) { - throw new BuildException("outfile is required when fofile is used"); - } - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } - - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (task.getFofile().lastModified() > outf.lastModified() )) { - render(task.getFofile(), outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { - skippedcount++; - } - } - } - - GlobPatternMapper mapper = new GlobPatternMapper(); - mapper.setFrom("*.fo"); - mapper.setTo("*" + newExtension); - - // deal with the filesets - for (int i = 0; i < task.filesets.size(); i++) { - FileSet fs = (FileSet) task.filesets.get(i); - DirectoryScanner ds = fs.getDirectoryScanner(task.getProject()); - String[] files = ds.getIncludedFiles(); - - - for (int j = 0; j < files.length; j++) { - File f = new File(fs.getDir(task.getProject()), files[j]); - File outf = null; - if (task.getOutdir() != null && files[j].endsWith(".fo")) { - String[] sa = mapper.mapFileName(files[j]); - outf = new File(task.getOutdir(), sa[0]); - } else { - outf = replaceExtension(f, ".fo", newExtension); - if (task.getOutdir() != null) { - outf = new File(task.getOutdir(), outf.getName()); - } - } - try { - if (task.getBasedir() != null) { - configuration.parseOption("base-directory", - task.getBasedir().toURL().toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } else { - configuration.parseOption("base-directory", - fs.getDir(task.getProject()).toURL(). - toExternalForm(), - SessionConfig.PRECEDENCE_DEFAULT); - } - task.log("Using base directory: " + - configuration.optionBaseDirectory(), - Project.MSG_DEBUG); - } catch (Exception e) { - task.log("Error setting base directory: " + e, Project.MSG_ERR); - } - - // Render if "force" flag is set OR - // OR output file doesn't exist OR - // output file is older than input file - if (task.getForce() || !outf.exists() - || (f.lastModified() > outf.lastModified() )) { - render(f, outf, rint, configuration); - actioncount++; - } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { - skippedcount++; - } - - } - } - - if (actioncount + skippedcount == 0) { - task.log("No files processed. No files were selected by the filesets " - + "and no fofile was set." , Project.MSG_WARN); - } else if (skippedcount > 0) { - task.log(skippedcount + " xslfo file(s) skipped (no change found" - + " since last generation; set force=\"true\" to override)." - , Project.MSG_INFO); - } - } - - private void render(File foFile, File outFile, int rendererType, - SessionConfig configuration) throws FOrayException { - InputHandler inputHandler = new FOInputHandler(logger, foFile); - XMLReader parser = inputHandler.getParser(); - - OutputStream out = null; - try { - File dir = outFile.getParentFile(); - dir.mkdirs(); - out = new FileOutputStream(outFile); - } catch (Exception ex) { - throw new BuildException(ex); - } - - if (logFiles) task.log(foFile + " -> " + outFile, Project.MSG_INFO); - - try { - FOraySession session = new FOraySession(log, configuration, null, - null, null, null); - FOrayDocument document = new FOrayDocument(session, - inputHandler.getInputSource(), parser); - - OutputConfig rendererOptions = null; - if (rendererType == FOrayTarget.RENDER_XML) { - rendererOptions = new OutputConfig(logger); - rendererOptions.parseOption("fineDetail", "true", - SessionConfig.PRECEDENCE_DEFAULT); - } - OutputTarget renderer = document.makeOutputTarget(rendererType, - rendererOptions); - new FOrayTarget(document, renderer, null, out); - - session.process(); - out.close(); - } catch (Exception ex) { - throw new BuildException(ex); - } - } - -} Copied: trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java (from rev 6958, trunk/foray/foray-app/src/java/org/foray/app/ant/FOray.java) =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java (rev 0) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/FOrayAntTask.java 2006-04-14 14:11:20 UTC (rev 7012) @@ -0,0 +1,503 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.app.ant; + +import org.foray.app.FOInputHandler; +import org.foray.app.FOrayDocument; +import org.foray.app.FOraySession; +import org.foray.app.FOrayTarget; +import org.foray.app.InputHandler; +import org.foray.app.Options; +import org.foray.app.SessionConfig; +import org.foray.app.Starter; +import org.foray.common.FOrayException; +import org.foray.common.Logging; +import org.foray.output.OutputConfig; +import org.foray.output.OutputTarget; + +import org.apache.commons.logging.Log; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.util.GlobPatternMapper; + +import org.xml.sax.XMLReader; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Wrapper for FOray which allows it to be accessed from within an Ant task. + * Accepts the inputs: + * <ul> + * <li>fofile -> formatting objects file to be transformed</li> + * <li>format -> MIME type of the format to generate ex. "application/pdf"</li> + * <li>outfile -> output filename</li> + * <li>baseDir -> directory to work from</li> + * <li>userconfig -> file with user configuration (same as the "-c" command line option)</li> + * <li>messagelevel -> (error | warn | info | verbose | debug) level to output non-error messages</li> + * <li>logFiles -> Controls whether the names of the files that are processed are logged or not</li> + * </ul> + */ +public class FOrayAntTask extends Task { + + File foFile; + List filesets = new ArrayList(); + File outFile; + File outDir; + String format; //MIME type + File baseDir; + File userConfig; + int messageType = Project.MSG_VERBOSE; + boolean logFiles = true; + private boolean force = false; + + /** + * Sets the user configuration file. + * @param userConfig File containing the user configuration. + */ + public void setUserconfig (File userConfig) { + this.userConfig = userConfig; + } + + /** + * Sets the input file. + * @param foFile The FO input file. + */ + public void setFofile(File foFile) { + this.foFile = foFile; + } + + /** + * Gets the input file + */ + public File getFofile() { + return foFile; + } + + /** + * Adds a set of fo files (nested fileset attribute). + */ + public void addFileset(FileSet set) { + filesets.add(set); + } + + /** + * Set whether to check dependencies, or to always generate; + * optional, default is false. + * + * @param force true if always generate. + */ + public void setForce(boolean force) { + this.force = force; + } + + /** + * Gets the force attribute + * @return the force attribute + */ + public boolean getForce() { + return force; + } + + /** + * Sets the output file + * @param outFile The File to which the output should be written. + */ + public void setOutfile(File outFile) { + this.outFile = outFile; + } + + /** + * Gets the output file + */ + public File getOutfile() { + return this.outFile; + } + + /** + * Sets the output directory + * @param outDir Directory to which the output should be written. + */ + public void setOutdir(File outDir) { + this.outDir = outDir; + } + + /** + * Gets the output directory + */ + public File getOutdir() { + return this.outDir; + } + + /** + * Sets output format (MIME type) + */ + public void setFormat(String format) { + this.format = format; + } + + /** + * Gets the output format (MIME type) + */ + public String getFormat() { + return this.format; + } + + /** + * Sets the message level to be used while processing. + * @param messageLevel String containing (info | verbose | debug). + */ + public void setMessagelevel(String messageLevel) { + if (messageLevel.equalsIgnoreCase("info")) { + messageType = Project.MSG_INFO; + } else if (messageLevel.equalsIgnoreCase("verbose")) { + messageType = Project.MSG_VERBOSE; + } else if (messageLevel.equalsIgnoreCase("debug")) { + messageType = Project.MSG_DEBUG; + } else if (messageLevel.equalsIgnoreCase("err") || messageLevel.equalsIgnoreCase("error")) { + messageType = Project.MSG_ERR; + } else if (messageLevel.equalsIgnoreCase("warn")) { + messageType = Project.MSG_WARN; + } else { + log("messagelevel set to unknown value \"" + messageLevel + + "\"", Project.MSG_ERR); + throw new BuildException("unknown messagelevel"); + } + } + + /** + * Returns the message type corresponding to Property.MSG_(INFO | VERBOSE | DEBUG) + * representing the current message level. + */ + public int getMessageType() { + return messageType; + } + + /** + * Sets the base directory. Currently ignored. + * @param baseDir File to use as a working directory. + */ + public void setBasedir(File baseDir) { + this.baseDir = baseDir; + } + + /** + * Gets the base directory + */ + public File getBasedir() { + return (baseDir != null) ? baseDir : getProject().resolveFile("."); + } + + /** + * Controls whether the filenames of the files that are processed are logged + * or not. + */ + public void setLogFiles(boolean aBoolean) { + logFiles = aBoolean; + } + + public boolean getLogFiles() { + return logFiles; + } + + /** + * Starts execution of this task + */ + public void execute() throws BuildException { + Log log = null; + switch (getMessageType()) { + case Project.MSG_INFO: { + log = Logging.makeDefaultLogger(); + break; + } + case Project.MSG_WARN: { + log = Logging.makeWarningLogger(); + break; + } + case Project.MSG_ERR: { + log = Logging.makeQuietLogger(); + break; + } + case Project.MSG_DEBUG: + case Project.MSG_VERBOSE: { + log = Logging.makeDebugLogger(); + break; + } + default: { + log = Logging.makeDefaultLogger(); + break; + } + } + try { + Starter starter = new FOrayTaskStarter(this, log, logFiles); + starter.run(); + } catch (FOrayException ex) { + throw new BuildException(ex); + } + } + +} + +class FOrayTaskStarter extends Starter { + FOrayAntTask task; + Log log; + boolean logFiles; + + FOrayTaskStarter(FOrayAntTask task, Log aLogger, boolean aLogFiles) + throws FOrayException { + super(aLogger, null, null); + this.task = task; + log = aLogger; + logFiles = aLogFiles; + } + + private int determineRenderer(String format) { + if ((format == null) || + format.equalsIgnoreCase("application/pdf") || + format.equalsIgnoreCase("pdf")) { + return FOrayTarget.RENDER_PDF; + } else if (format.equalsIgnoreCase("application/postscript") || + format.equalsIgnoreCase("ps")) { + return FOrayTarget.RENDER_PS; + } else if (format.equalsIgnoreCase("application/vnd.mif") || + format.equalsIgnoreCase("mif")) { + return FOrayTarget.RENDER_MIF; + } else if (format.equalsIgnoreCase("application/vnd.gp-PCL") || + format.equalsIgnoreCase("pcl")) { + return FOrayTarget.RENDER_PCL; + } else if (format.equalsIgnoreCase("text/plain") || + format.equalsIgnoreCase("txt")) { + return FOrayTarget.RENDER_TXT; + } else if (format.equalsIgnoreCase("text/xml") || + format.equalsIgnoreCase("at") || + format.equalsIgnoreCase("xml")) { + return FOrayTarget.RENDER_XML; + } else { + String err = "Couldn't determine renderer to use: "+format; + throw new BuildException(err); + } + } + + private String determineExtension(int renderer) { + switch (renderer) { + case FOrayTarget.RENDER_PDF: + return ".pdf"; + case FOrayTarget.RENDER_PS: + return ".ps"; + case FOrayTarget.RENDER_MIF: + return ".mif"; + case FOrayTarget.RENDER_PCL: + return ".pcl"; + case FOrayTarget.RENDER_TXT: + return ".txt"; + case FOrayTarget.RENDER_XML: + return ".xml"; + default: + String err = "Unknown renderer: "+renderer; + throw new BuildException(err); + } + } + + private File replaceExtension(File file, String expectedExt, + String newExt) { + String name = file.getName(); + if (name.toLowerCase().endsWith(expectedExt)) { + name = name.substring(0, name.length() - expectedExt.length()); + } + name = name.concat(newExt); + return new File(file.getParentFile(), name); + } + + public void run() throws FOrayException { + Log logger = Logging.makeDefaultLogger(); + SessionConfig configuration = new SessionConfig(logger); + if (task.userConfig != null) { + new Options (log, configuration, null, task.userConfig); + } + + try { + if (task.getFofile() != null) { + if (task.getBasedir() != null) { + configuration.parseOption("base-directory", + task.getBasedir().toURL().toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } else { + configuration.parseOption("base-directory", + task.getFofile().getParentFile().toURL(). + toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } + } + task.log("Using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); + } catch (Exception e) { + + task.log("Error setting base directory: " + e, Project.MSG_ERR); + } + + int rint = determineRenderer(task.getFormat()); + String newExtension = determineExtension(rint); + + // actioncount = # of fofiles actually processed through FOray + int actioncount = 0; + // skippedcount = # of fofiles which haven't changed (force = "false") + int skippedcount = 0; + + // deal with single source file + if (task.getFofile() != null) { + if (task.getFofile().exists()) { + File outf = task.getOutfile(); + if (outf == null) { + throw new BuildException("outfile is required when fofile is used"); + } + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (task.getFofile().lastModified() > outf.lastModified() )) { + render(task.getFofile(), outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (task.getFofile().lastModified() <= outf.lastModified() )) { + skippedcount++; + } + } + } + + GlobPatternMapper mapper = new GlobPatternMapper(); + mapper.setFrom("*.fo"); + mapper.setTo("*" + newExtension); + + // deal with the filesets + for (int i = 0; i < task.filesets.size(); i++) { + FileSet fs = (FileSet) task.filesets.get(i); + DirectoryScanner ds = fs.getDirectoryScanner(task.getProject()); + String[] files = ds.getIncludedFiles(); + + + for (int j = 0; j < files.length; j++) { + File f = new File(fs.getDir(task.getProject()), files[j]); + File outf = null; + if (task.getOutdir() != null && files[j].endsWith(".fo")) { + String[] sa = mapper.mapFileName(files[j]); + outf = new File(task.getOutdir(), sa[0]); + } else { + outf = replaceExtension(f, ".fo", newExtension); + if (task.getOutdir() != null) { + outf = new File(task.getOutdir(), outf.getName()); + } + } + try { + if (task.getBasedir() != null) { + configuration.parseOption("base-directory", + task.getBasedir().toURL().toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } else { + configuration.parseOption("base-directory", + fs.getDir(task.getProject()).toURL(). + toExternalForm(), + SessionConfig.PRECEDENCE_DEFAULT); + } + task.log("Using base directory: " + + configuration.optionBaseDirectory(), + Project.MSG_DEBUG); + } catch (Exception e) { + task.log("Error setting base directory: " + e, Project.MSG_ERR); + } + + // Render if "force" flag is set OR + // OR output file doesn't exist OR + // output file is older than input file + if (task.getForce() || !outf.exists() + || (f.lastModified() > outf.lastModified() )) { + render(f, outf, rint, configuration); + actioncount++; + } else if (outf.exists() && (f.lastModified() <= outf.lastModified() )) { + skippedcount++; + } + + } + } + + if (actioncount + skippedcount == 0) { + task.log("No files processed. No files were selected by the filesets " + + "and no fofile was set." , Project.MSG_WARN); + } else if (skippedcount > 0) { + task.log(skippedcount + " xslfo file(s) skipped (no change found" + + " since last generation; set force=\"true\" to override)." + , Project.MSG_INFO); + } + } + + private void render(File foFile, File outFile, int rendererType, + SessionConfig configuration) throws FOrayException { + InputHandler inputHandler = new FOInputHandler(logger, foFile); + XMLReader parser = inputHandler.getParser(); + + OutputStream out = null; + try { + File dir = outFile.getParentFile(); + dir.mkdirs(); + out = new FileOutputStream(outFile); + } catch (Exception ex) { + throw new BuildException(ex); + } + + if (logFiles) task.log(foFile + " -> " + outFile, Project.MSG_INFO); + + try { + FOraySession session = new FOraySession(log, configuration, null, + null, null, null); + FOrayDocument document = new FOrayDocument(session, + inputHandler.getInputSource(), parser); + + OutputConfig rendererOptions = null; + if (rendererType == FOrayTarget.RENDER_XML) { + rendererOptions = new OutputConfig(logger); + rendererOptions.parseOption("fineDetail", "true", + SessionConfig.PRECEDENCE_DEFAULT); + } + OutputTarget renderer = document.makeOutputTarget(rendererType, + rendererOptions); + new FOrayTarget(document, renderer, null, out); + + session.process(); + out.close(); + } catch (Exception ex) { + throw new BuildException(ex); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-04-14 03:26:41
|
Revision: 7011 Author: victormote Date: 2006-04-13 20:26:30 -0700 (Thu, 13 Apr 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7011&view=rev Log Message: ----------- Handle change in configuration DTD. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/ConfigurationParser.java Modified: trunk/foray/foray-app/src/java/org/foray/app/ConfigurationParser.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ConfigurationParser.java 2006-04-14 03:22:16 UTC (rev 7010) +++ trunk/foray/foray-app/src/java/org/foray/app/ConfigurationParser.java 2006-04-14 03:26:30 UTC (rev 7011) @@ -41,7 +41,8 @@ import javax.xml.parsers.SAXParserFactory; /** - * SAX2 Handler which retrieves the configuration information and stores them in Configuration. + * SAX2 Handler which retrieves the configuration information and stores them + * in Configuration. * Normally this class doesn't need to be accessed directly. */ public class ConfigurationParser extends DefaultHandler { @@ -153,16 +154,22 @@ Attributes attributes) { if (localName.equals("key")) { status += IN_KEY; - } else if (localName.equals("value")) { + return; + } + if (localName.equals("value")) { status += IN_VALUE; - } else if (localName.equals("entry")) { - } else if (localName.equals("configuration")) {} - else { - // to make sure that user knows about false tag - logger.error(getFormattedLocation() + "\nUnknown tag in " + return; + } + if (localName.equals("entry")) { + return; + } + if (localName.equals("foray-config")) { + return; + } + // to make sure that user knows about false tag + logger.error(getFormattedLocation() + "\nUnknown tag in " + "configuration file: " + localName); - } - } // end startElement + } // end startElement /** * stores subentries or entries into their hashes (map for subentries, configuration for entry) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |