foray-commit Mailing List for FOray (Page 287)
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
(4) |
Dec
(23) |
| 2026 |
Jan
(119) |
Feb
(335) |
Mar
(103) |
Apr
(43) |
May
(154) |
Jun
(107) |
Jul
(187) |
Aug
(4) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <vic...@us...> - 2006-07-18 02:13:28
|
Revision: 7790 Author: victormote Date: 2006-07-17 19:13:25 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7790&view=rev Log Message: ----------- Improve error message a bit. Modified Paths: -------------- trunk/foray/foray-fotree/src/java/org/foray/fotree/value/ExprMultiplicativeOper.java Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/value/ExprMultiplicativeOper.java =================================================================== --- trunk/foray/foray-fotree/src/java/org/foray/fotree/value/ExprMultiplicativeOper.java 2006-07-18 01:56:23 UTC (rev 7789) +++ trunk/foray/foray-fotree/src/java/org/foray/fotree/value/ExprMultiplicativeOper.java 2006-07-18 02:13:25 UTC (rev 7790) @@ -39,13 +39,13 @@ ExprUnary operand2, byte operation) throws PropertyException { if (operand1.unitPower() < 0) { - throw new PropertyException("MultiplicativeExpr: Non-numeric " - + "operand: " + operand1.toString()); + throw new PropertyException(this.getClass().getName() + + ": Non-numeric operand: " + operand1.toString()); } this.operand1 = operand1; if (operand2.unitPower() < 0) { - throw new PropertyException("MultiplicativeExpr: Non-numeric " - + "operand: " + operand2.toString()); + throw new PropertyException(this.getClass().getName() + + "Non-numeric operand: " + operand2.toString()); } this.operand2 = operand2; /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-18 01:56:26
|
Revision: 7789 Author: victormote Date: 2006-07-17 18:56:23 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7789&view=rev Log Message: ----------- Was using wrong variable to throw exception. Modified Paths: -------------- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/SimplePageMaster.java Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/SimplePageMaster.java =================================================================== --- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/SimplePageMaster.java 2006-07-18 01:50:35 UTC (rev 7788) +++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/SimplePageMaster.java 2006-07-18 01:56:23 UTC (rev 7789) @@ -117,7 +117,7 @@ } private void duplicateRegionClass(Region region) throws FOTreeException { - regionBefore.throwException("Duplicate " + region.getFullName() + region.throwException("Duplicate " + region.getFullName() + " in same simple-page-master."); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-18 01:50:39
|
Revision: 7788 Author: victormote Date: 2006-07-17 18:50:35 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7788&view=rev Log Message: ----------- Use JAXP instead of Trax. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java trunk/foray/foray-app/src/java/org/foray/app/CommandLineStarter.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-07-17 13:04:28 UTC (rev 7787) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-07-18 01:50:35 UTC (rev 7788) @@ -31,7 +31,6 @@ import org.foray.core.FOrayException; import org.foray.core.InputHandler; import org.foray.core.SessionConfig; -import org.foray.core.TraxInputHandler; import org.foray.output.OutputConfig; import org.apache.commons.logging.Log; @@ -47,13 +46,13 @@ public class CommandLineOptions { /** Constant indicating that the input mode has not been set. */ - private static final int INPUT_NOT_SET = 0; + public static final int INPUT_NOT_SET = 0; /** Constant indicating that the input is XSL-FO. */ - private static final int INPUT_FO = 1; + public static final int INPUT_FO = 1; /** Constant indicating that the input is XML + XSLT. */ - private static final int INPUT_XSLT = 2; + public static final int INPUT_XSLT = 2; /** The user configuration file. */ URL userConfig = null; @@ -434,14 +433,10 @@ * */ public InputHandler getInputHandler() throws FOrayException { - switch (inputmode) { - case INPUT_FO: + if (inputmode == INPUT_FO) { return new FOInputHandler(log, foInput); - case INPUT_XSLT: - return new TraxInputHandler(log, xmlInput, xsltInput); - default: - return new FOInputHandler(log, foInput); } + return null; } public OutputConfig getRendererOptions() { Modified: trunk/foray/foray-app/src/java/org/foray/app/CommandLineStarter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/CommandLineStarter.java 2006-07-17 13:04:28 UTC (rev 7787) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineStarter.java 2006-07-18 01:50:35 UTC (rev 7788) @@ -44,7 +44,14 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamSource; + /** * Superclass for all classes which start FOray from the commandline. */ @@ -84,15 +91,43 @@ * Multiple documents can be instantiated, and they will be processed * in the order submitted. */ - InputSource saxInputSource; - try { - saxInputSource = inputHandler.getInputSource(); - } catch (IOException e) { - throw new FOrayException(e); + FOrayDocument document = null; + if (this.commandLineOptions.inputmode == CommandLineOptions.INPUT_FO) { + InputSource saxInputSource; + try { + saxInputSource = inputHandler.getInputSource(); + } catch (IOException e) { + throw new FOrayException(e); + } + XMLReader parser = inputHandler.getParser(); + document = new FOrayDocument(session, saxInputSource, + parser); + } else { + InputStream xmlInputStream = null; + try { + xmlInputStream = commandLineOptions.getXMLFile() + .openStream(); + } catch (IOException e) { + throw new FOrayException(e); + } + Source xmlSource = new StreamSource(xmlInputStream); + InputStream xsltInputStream = null; + try { + xsltInputStream = commandLineOptions.getXSLFile() + .openStream(); + } catch (IOException e) { + throw new FOrayException(e); + } + Source xsltSource = new StreamSource(xsltInputStream); + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = null; + try { + transformer = factory.newTransformer(xsltSource); + } catch (TransformerConfigurationException e) { + throw new FOrayException(e); + } + document = new FOrayDocument(session, transformer, xmlSource); } - XMLReader parser = inputHandler.getParser(); - FOrayDocument document = new FOrayDocument(session, saxInputSource, - parser); /* * Instantiate and configure the OutputTarget. The makeOutputTarget() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-17 13:04:47
|
Revision: 7787 Author: victormote Date: 2006-07-17 06:04:28 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7787&view=rev Log Message: ----------- Make remaining command-line inputs URLs. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.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-07-15 23:51:05 UTC (rev 7786) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-07-17 13:04:28 UTC (rev 7787) @@ -26,6 +26,7 @@ import org.foray.common.Logging; import org.foray.common.url.URLFactory; +import org.foray.common.url.URLUtil; import org.foray.core.FOInputHandler; import org.foray.core.FOrayException; import org.foray.core.InputHandler; @@ -58,13 +59,13 @@ URL userConfig = null; /** The input XSL-FO. Should be null for XSLT input. */ - File foInput = null; + URL foInput = null; /** The input XSLT. Should be null for XSL-FO input. */ - File xsltInput = null; + URL xsltInput = null; /** The input XML file. Should be null for XSL-FO input. */ - File xmlInput = null; + URL xmlInput = null; /** The output file. */ public File outfile = null; @@ -173,12 +174,13 @@ throw new FOrayException("you must specify the fo file " + "for the '-fo' option"); } - foInput = new File(args[currentArgument + 1]); + String foString = args[currentArgument + 1]; try { - this.sessionConfig.setBaseDocument(foInput.toURL()); + this.foInput = URLFactory.createURL(foString); } catch (MalformedURLException e) { - // Ignore. + throw new FOrayException("Malformed URL: " + foString); } + this.sessionConfig.setBaseDocument(this.foInput); currentArgument++; return true; } @@ -189,7 +191,12 @@ throw new FOrayException("you must specify the stylesheet " + "file for the '-xsl' option"); } - xsltInput = new File(args[currentArgument + 1]); + String xsltString = args[currentArgument + 1]; + try { + xsltInput = URLFactory.createURL(xsltString); + } catch (MalformedURLException e) { + throw new FOrayException("Malformed URL: " + xsltString); + } currentArgument++; return true; } @@ -200,12 +207,13 @@ throw new FOrayException("you must specify the input file " + "for the '-xml' option"); } - xmlInput = new File(args[currentArgument + 1]); + String xmlString = args[currentArgument + 1]; try { - this.sessionConfig.setBaseDocument(xmlInput.toURL()); + this.xmlInput = URLFactory.createURL(xmlString); } catch (MalformedURLException e) { - // Ignore. + throw new FOrayException("Malformed URL: " + xmlString); } + this.sessionConfig.setBaseDocument(xmlInput); currentArgument++; return true; } @@ -293,7 +301,11 @@ if (args[currentArgument].charAt(0) != '-') { if (inputmode == INPUT_NOT_SET) { inputmode = INPUT_FO; - foInput = new File(args[currentArgument]); + try { + foInput = URLFactory.createURL(args[currentArgument]); + } catch (MalformedURLException e) { + throw new FOrayException(e); + } } else if (outputmode == INPUT_NOT_SET) { outputmode = OutputTargetFactory.RENDER_PDF; outfile = new File(args[currentArgument]); @@ -377,22 +389,18 @@ // warning if fofile has been set in xslt mode if (foInput != null) { log.warn("Can't use fo file with transform mode! Ignoring.\n" - + "Your input is " + "\n xmlfile: " - + xmlInput.getAbsolutePath() - + "\nxsltfile: " - + xsltInput.getAbsolutePath() - + "\n fofile: " - + foInput.getAbsolutePath()); + + "Your input is:\n" + + " xmlfile: " + xmlInput.toExternalForm() + "\n" + + " xsltfile: " + xsltInput.toExternalForm() + "\n" + + " fofile: " + foInput.toExternalForm()); } - if (!xmlInput.exists()) { - throw new FileNotFoundException("xml file " - + xmlInput.getAbsolutePath() - + " not found "); + if (! URLUtil.exists(xmlInput)) { + throw new FileNotFoundException("XML file not found: " + + xmlInput.toExternalForm()); } - if (!xsltInput.exists()) { - throw new FileNotFoundException("xsl file " - + xsltInput.getAbsolutePath() - + " not found "); + if (! URLUtil.exists(xsltInput)) { + throw new FileNotFoundException("XSLT file not found: " + + xsltInput.toExternalForm()); } } else if (inputmode == INPUT_FO) { @@ -401,10 +409,9 @@ log.error("xml file: " + xmlInput.toString()); log.error("xslt file: " + xsltInput.toString()); } - if (!foInput.exists()) { - throw new FileNotFoundException("fo file " - + foInput.getAbsolutePath() - + " not found "); + if (! URLUtil.exists(foInput)) { + throw new FileNotFoundException("FO input not found: " + + foInput.toExternalForm()); } } @@ -486,15 +493,15 @@ return outputmode; } - public File getFOFile() { + public URL getFOFile() { return foInput; } - public File getXMLFile() { + public URL getXMLFile() { return xmlInput; } - public File getXSLFile() { + public URL getXSLFile() { return xsltInput; } @@ -510,19 +517,19 @@ return language; } - /** - * return either the fofile or the xmlfile - */ - public File getInputFile() { - switch (inputmode) { - case INPUT_FO: - return foInput; - case INPUT_XSLT: - return xmlInput; - default: - return foInput; - } - } +// /** +// * return either the fofile or the xmlfile +// */ +// public File getInputFile() { +// switch (inputmode) { +// case INPUT_FO: +// return foInput; +// case INPUT_XSLT: +// return xmlInput; +// default: +// return foInput; +// } +// } /** * shows the commandline syntax including a summary of all available Modified: trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java 2006-07-15 23:51:05 UTC (rev 7786) +++ trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java 2006-07-17 13:04:28 UTC (rev 7787) @@ -27,6 +27,7 @@ import org.foray.app.FOraySpecific; import org.foray.app.OutputTargetFactory; import org.foray.common.Logging; +import org.foray.common.url.URLFactory; import org.foray.core.FOInputHandler; import org.foray.core.FOrayDocument; import org.foray.core.FOrayException; @@ -266,9 +267,8 @@ if (xsl == null) { inputHandler = new FOInputHandler(log, xmlFile); } else { - inputHandler = new TraxInputHandler(log, xmlFile, - new File(baseDir + "/" - + xsl)); + inputHandler = new TraxInputHandler(log, xmlFile.toURL(), + URLFactory.createURL(baseDir + "/" + xsl)); } FOraySession session = FOraySpecific.makeFOraySession( Modified: trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java 2006-07-15 23:51:05 UTC (rev 7786) +++ trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java 2006-07-17 13:04:28 UTC (rev 7787) @@ -24,8 +24,11 @@ package org.foray.common.url; +import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.ArrayList; import java.util.List; @@ -200,4 +203,24 @@ return useInput; } + /** + * Intended to be the equivalent of {@link File#exists()}. + * @param url The URL whose existence is to be tested. + * @return True if the URL exists, false otherwise. + * "Existence" is defined + * as + */ + public static boolean exists(URL url) { + if (url == null) { + return false; + } + URLConnection connection = null; + try { + connection = url.openConnection(); + } catch (IOException e) { + return false; + } + return connection != null; + } + } Modified: trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java 2006-07-15 23:51:05 UTC (rev 7786) +++ trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java 2006-07-17 13:04:28 UTC (rev 7787) @@ -34,6 +34,8 @@ import org.xml.sax.XMLReader; import java.io.File; +import java.io.IOException; +import java.net.URL; import javax.xml.transform.Source; import javax.xml.transform.Transformer; @@ -52,11 +54,15 @@ private StreamSource xmlSource; private Source xsltSource; - public TraxInputHandler(Log logger, File xmlfile, File xsltfile) + public TraxInputHandler(Log logger, URL xmlfile, URL xsltfile) throws FOrayException { super(logger); - xmlSource = new StreamSource(xmlfile); - xsltSource = new StreamSource(xsltfile); + try { + xmlSource = new StreamSource(xmlfile.openStream()); + xsltSource = new StreamSource(xsltfile.openStream()); + } catch (IOException e) { + throw new FOrayException(e); + } initTransformer(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 23:51:10
|
Revision: 7786 Author: victormote Date: 2006-07-15 16:51:05 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7786&view=rev Log Message: ----------- Minor refactoring and documentation. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.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-07-15 23:38:12 UTC (rev 7785) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-07-15 23:51:05 UTC (rev 7786) @@ -45,28 +45,37 @@ */ public class CommandLineOptions { - /* input not set */ - private static final int NOT_SET = 0; - /* input: fo file */ - private static final int FO_INPUT = 1; - /* input: xml+xsl file */ - private static final int XSLT_INPUT = 2; + /** Constant indicating that the input mode has not been set. */ + private static final int INPUT_NOT_SET = 0; - /* user configuration file */ - URL userConfigFile = null; - /* input fo file */ - File fofile = null; - /* xsltfile (xslt transformation as input) */ - File xsltfile = null; - /* xml file (xslt transformation as input) */ - File xmlfile = null; - /* output file */ + /** Constant indicating that the input is XSL-FO. */ + private static final int INPUT_FO = 1; + + /** Constant indicating that the input is XML + XSLT. */ + private static final int INPUT_XSLT = 2; + + /** The user configuration file. */ + URL userConfig = null; + + /** The input XSL-FO. Should be null for XSLT input. */ + File foInput = null; + + /** The input XSLT. Should be null for XSL-FO input. */ + File xsltInput = null; + + /** The input XML file. Should be null for XSL-FO input. */ + File xmlInput = null; + + /** The output file. */ public File outfile = null; - /* input mode */ - int inputmode = NOT_SET; - /* output mode */ - int outputmode = NOT_SET; - /* language for user information */ + + /** The input mode. */ + int inputmode = INPUT_NOT_SET; + + /** The output mode. */ + int outputmode = INPUT_NOT_SET; + + /** Language for user information */ String language = null; private SessionConfig sessionConfig; @@ -142,7 +151,7 @@ + "specify the name of the configuration file"); } try { - this.userConfigFile = URLFactory.createURL( + this.userConfig = URLFactory.createURL( args[currentArgument + 1]); } catch (MalformedURLException e) { throw new FOrayException(e); @@ -158,15 +167,15 @@ return success; } if (args[currentArgument].equals("-fo")) { - inputmode = FO_INPUT; + inputmode = INPUT_FO; if ((currentArgument + 1 == args.length) || (args[currentArgument + 1].charAt(0) == '-')) { throw new FOrayException("you must specify the fo file " + "for the '-fo' option"); } - fofile = new File(args[currentArgument + 1]); + foInput = new File(args[currentArgument + 1]); try { - this.sessionConfig.setBaseDocument(fofile.toURL()); + this.sessionConfig.setBaseDocument(foInput.toURL()); } catch (MalformedURLException e) { // Ignore. } @@ -174,26 +183,26 @@ return true; } if (args[currentArgument].equals("-xsl")) { - inputmode = XSLT_INPUT; + inputmode = INPUT_XSLT; if ((currentArgument + 1 == args.length) || (args[currentArgument + 1].charAt(0) == '-')) { throw new FOrayException("you must specify the stylesheet " + "file for the '-xsl' option"); } - xsltfile = new File(args[currentArgument + 1]); + xsltInput = new File(args[currentArgument + 1]); currentArgument++; return true; } if (args[currentArgument].equals("-xml")) { - inputmode = XSLT_INPUT; + inputmode = INPUT_XSLT; if ((currentArgument + 1 == args.length) || (args[currentArgument + 1].charAt(0) == '-')) { throw new FOrayException("you must specify the input file " + "for the '-xml' option"); } - xmlfile = new File(args[currentArgument + 1]); + xmlInput = new File(args[currentArgument + 1]); try { - this.sessionConfig.setBaseDocument(xmlfile.toURL()); + this.sessionConfig.setBaseDocument(xmlInput.toURL()); } catch (MalformedURLException e) { // Ignore. } @@ -282,10 +291,10 @@ return true; } if (args[currentArgument].charAt(0) != '-') { - if (inputmode == NOT_SET) { - inputmode = FO_INPUT; - fofile = new File(args[currentArgument]); - } else if (outputmode == NOT_SET) { + if (inputmode == INPUT_NOT_SET) { + inputmode = INPUT_FO; + foInput = new File(args[currentArgument]); + } else if (outputmode == INPUT_NOT_SET) { outputmode = OutputTargetFactory.RENDER_PDF; outfile = new File(args[currentArgument]); } else { @@ -334,7 +343,7 @@ } private void setOutputMode(int mode) throws FOrayException { - if (outputmode == NOT_SET) { + if (outputmode == INPUT_NOT_SET) { outputmode = mode; } else { throw new FOrayException("you can only set one output method"); @@ -346,55 +355,55 @@ * way */ private void checkSettings() throws FOrayException, FileNotFoundException { - if (inputmode == NOT_SET) { + if (inputmode == INPUT_NOT_SET) { throw new FOrayException("No input file specified"); } - if (outputmode == NOT_SET) { + if (outputmode == INPUT_NOT_SET) { throw new FOrayException("No output file specified"); } - if (inputmode == XSLT_INPUT) { + if (inputmode == INPUT_XSLT) { // check whether xml *and* xslt file have been set - if (xmlfile == null) { + if (xmlInput == null) { throw new FOrayException("XML file must be specified for the " + "transform mode"); } - if (xsltfile == null) { + if (xsltInput == null) { throw new FOrayException("XSLT file must be specified for the " + "transform mode"); } // warning if fofile has been set in xslt mode - if (fofile != null) { + if (foInput != null) { log.warn("Can't use fo file with transform mode! Ignoring.\n" + "Your input is " + "\n xmlfile: " - + xmlfile.getAbsolutePath() + + xmlInput.getAbsolutePath() + "\nxsltfile: " - + xsltfile.getAbsolutePath() + + xsltInput.getAbsolutePath() + "\n fofile: " - + fofile.getAbsolutePath()); + + foInput.getAbsolutePath()); } - if (!xmlfile.exists()) { + if (!xmlInput.exists()) { throw new FileNotFoundException("xml file " - + xmlfile.getAbsolutePath() + + xmlInput.getAbsolutePath() + " not found "); } - if (!xsltfile.exists()) { + if (!xsltInput.exists()) { throw new FileNotFoundException("xsl file " - + xsltfile.getAbsolutePath() + + xsltInput.getAbsolutePath() + " not found "); } - } else if (inputmode == FO_INPUT) { - if (xmlfile != null || xsltfile != null) { + } else if (inputmode == INPUT_FO) { + if (xmlInput != null || xsltInput != null) { log.warn("fo input mode, but xmlfile or xslt file are set:"); - log.error("xml file: " + xmlfile.toString()); - log.error("xslt file: " + xsltfile.toString()); + log.error("xml file: " + xmlInput.toString()); + log.error("xslt file: " + xsltInput.toString()); } - if (!fofile.exists()) { + if (!foInput.exists()) { throw new FileNotFoundException("fo file " - + fofile.getAbsolutePath() + + foInput.getAbsolutePath() + " not found "); } @@ -419,12 +428,12 @@ */ public InputHandler getInputHandler() throws FOrayException { switch (inputmode) { - case FO_INPUT: - return new FOInputHandler(log, fofile); - case XSLT_INPUT: - return new TraxInputHandler(log, xmlfile, xsltfile); + case INPUT_FO: + return new FOInputHandler(log, foInput); + case INPUT_XSLT: + return new TraxInputHandler(log, xmlInput, xsltInput); default: - return new FOInputHandler(log, fofile); + return new FOInputHandler(log, foInput); } } @@ -478,15 +487,15 @@ } public File getFOFile() { - return fofile; + return foInput; } public File getXMLFile() { - return xmlfile; + return xmlInput; } public File getXSLFile() { - return xsltfile; + return xsltInput; } public File getOutputFile() { @@ -494,7 +503,7 @@ } public URL getUserConfigFile() { - return userConfigFile; + return userConfig; } public String getLanguage() { @@ -506,12 +515,12 @@ */ public File getInputFile() { switch (inputmode) { - case FO_INPUT: - return fofile; - case XSLT_INPUT: - return xmlfile; + case INPUT_FO: + return foInput; + case INPUT_XSLT: + return xmlInput; default: - return fofile; + return foInput; } } @@ -591,17 +600,17 @@ } log.debug("Input mode: "); switch (inputmode) { - case NOT_SET: + case INPUT_NOT_SET: log.debug("not set"); break; - case FO_INPUT: + case INPUT_FO: log.debug("FO "); - log.debug("fo input file: " + fofile.toString()); + log.debug("fo input file: " + foInput.toString()); break; - case XSLT_INPUT: + case INPUT_XSLT: log.debug("xslt transformation"); - log.debug("xml input file: " + xmlfile.toString()); - log.debug("xslt stylesheet: " + xsltfile.toString()); + log.debug("xml input file: " + xmlInput.toString()); + log.debug("xslt stylesheet: " + xsltInput.toString()); break; default: log.debug("unknown input type"); @@ -652,9 +661,9 @@ } log.debug("OPTIONS"); - if (userConfigFile != null) { + if (userConfig != null) { log.debug("user configuration file: " - + userConfigFile.toString()); + + userConfig.toString()); } else { log.debug("no user configuration file is used [default]"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 23:38:25
|
Revision: 7785 Author: victormote Date: 2006-07-15 16:38:12 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7785&view=rev Log Message: ----------- Remove some no-longer-needed methods. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java 2006-07-15 23:09:14 UTC (rev 7784) +++ trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java 2006-07-15 23:38:12 UTC (rev 7785) @@ -24,19 +24,13 @@ package org.foray.common.url; - -import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; /** - * This utility class is used to build URLs from Strings. The String can be - * normal URLs but also just filenames. The filenames get converted to a - * file URL. - * - * @author Jeremias Maerki + * This utility class contains various URL-related static utility methods. */ public class URLUtil { @@ -45,52 +39,6 @@ } /** - * Build an URL based on a String. The String can be a normal URL or a - * filename. Filenames get automatically converted to to URLs. - * - * @param spec A URL or a filename - * @return The requested URL - * @throws MalformedURLException If spec cannot be converted to a URL. - */ - public static URL buildURL(String spec) throws MalformedURLException { - if (spec == null) { - throw new NullPointerException("spec must not be null"); - } - File f = new File(spec); - if (f.exists()) { - return f.toURL(); - } - return URLFactory.createURL(spec); - } - - - /** - * Build an URL based on a String. The String can be a normal URL or a - * filename. Filenames get automatically converted to to URLs. - * - * @param baseURL Base URL for relative paths - * @param spec A URL or a filename - * @return The requested URL - * @throws MalformedURLException If spec cannot be converted to a URL. - */ - public static URL buildURL(URL baseURL, String spec) - throws MalformedURLException { - if (spec == null) { - throw new NullPointerException("spec must not be null"); - } - try { - URL u1 = buildURL(spec); - return u1; - } catch (MalformedURLException mfue) { - if (baseURL == null) { - throw mfue; - } - URL u2 = URLFactory.createURL(baseURL, spec); - return u2; - } - } - - /** * <p>This method is an attempt to standardize the way that URLs are * constructed, and, more importantly, how they are converted into * Streams or other i/o resources. There is no way to know when a URL Modified: trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 23:09:14 UTC (rev 7784) +++ trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 23:38:12 UTC (rev 7785) @@ -26,7 +26,6 @@ import org.foray.common.Environment; import org.foray.common.RandomReader; -import org.foray.common.url.URLUtil; import org.foray.common.url.URLFactory; import org.foray.ps.encode.EncodingParser; import org.foray.ps.encode.EncodingVector; @@ -367,7 +366,7 @@ if (xmlBase != null && !xmlBase.equals("")) { try { /* Update the current xml base. */ - this.currentXMLBase = URLUtil.buildURL(this.previousXMLBase, + this.currentXMLBase = URLFactory.createURL(this.previousXMLBase, xmlBase); } catch (MalformedURLException e) { logError("Unable to create URL from " @@ -562,7 +561,7 @@ } try { /* Update the current xml base. */ - this.currentXMLBase = URLUtil.buildURL(this.currentXMLBase, + this.currentXMLBase = URLFactory.createURL(this.currentXMLBase, xmlBase); } catch (MalformedURLException e) { logError("Unable to create URL from " Modified: trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java 2006-07-15 23:09:14 UTC (rev 7784) +++ trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java 2006-07-15 23:38:12 UTC (rev 7785) @@ -25,7 +25,7 @@ package org.foray.font.format; import org.foray.common.Logging; -import org.foray.common.url.URLUtil; +import org.foray.common.url.URLFactory; import org.apache.commons.logging.Log; @@ -52,7 +52,7 @@ /** * The main method (accessible from command-line) for the TTFReader tool. - * @param args Command-line arguments: <ttc-file> + * @param args The command-line arguments. <ttc-file> */ public static void main(String[] args) { TTFReader app = new TTFReader(); @@ -79,7 +79,7 @@ } FontFileReader reader = null; try { - URL url = URLUtil.buildURL(fileName); + URL url = URLFactory.createURL(fileName); reader = new FontFileReader(logger, url); } catch (MalformedURLException e1) { logger.error("Malformed URL: " + fileName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 23:09:38
|
Revision: 7784 Author: victormote Date: 2006-07-15 16:09:14 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7784&view=rev Log Message: ----------- Move and rename URL utility class. Modified Paths: -------------- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtURI.java trunk/foray/foray-graphic/src/java/org/foray/graphic/FOrayGraphicServer.java Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java Removed Paths: ------------- trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java Deleted: trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java 2006-07-15 22:29:14 UTC (rev 7783) +++ trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -1,256 +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.common; - -import org.foray.common.url.URLFactory; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -/** - * This utility class is used to build URLs from Strings. The String can be - * normal URLs but also just filenames. The filenames get converted to a - * file URL. - * - * @author Jeremias Maerki - */ -public class URLBuilder { - - /** Private constructor (should not be instantiated). */ - private URLBuilder() { - } - - /** - * Build an URL based on a String. The String can be a normal URL or a - * filename. Filenames get automatically converted to to URLs. - * - * @param spec A URL or a filename - * @return The requested URL - * @throws MalformedURLException If spec cannot be converted to a URL. - */ - public static URL buildURL(String spec) throws MalformedURLException { - if (spec == null) { - throw new NullPointerException("spec must not be null"); - } - File f = new File(spec); - if (f.exists()) { - return f.toURL(); - } - return URLFactory.createURL(spec); - } - - - /** - * Build an URL based on a String. The String can be a normal URL or a - * filename. Filenames get automatically converted to to URLs. - * - * @param baseURL Base URL for relative paths - * @param spec A URL or a filename - * @return The requested URL - * @throws MalformedURLException If spec cannot be converted to a URL. - */ - public static URL buildURL(URL baseURL, String spec) - throws MalformedURLException { - if (spec == null) { - throw new NullPointerException("spec must not be null"); - } - try { - URL u1 = buildURL(spec); - return u1; - } catch (MalformedURLException mfue) { - if (baseURL == null) { - throw mfue; - } - URL u2 = URLFactory.createURL(baseURL, spec); - return u2; - } - } - - /** - * <p>This method is an attempt to standardize the way that URLs are - * constructed, and, more importantly, how they are converted into - * Streams or other i/o resources. There is no way to know when a URL - * is constructed whether it can actually be opened or not. So it is - * frequently the case that resources identified by URL must be tried - * several times as various possibilities are attempted. To standardize - * this, three possibilities were considered:</p> - * - * <ol> - * <li>Loop through the possibilities here, attempting to open each - * one. When one is successfully opened, return the URL.</li> - * <li>Set up something stateful that would create the next possible URL - * on demand.</li> - * <li>Build and return a collection of possibilities & let the client - * manage the process.</li> - * </ol> - * - * <p>Of these three, 1 forces the URL to be opened twice, which was deemed - * wasteful. 2 seems like way too much trouble for such a simple task. - * An object would have to be created to manage the state information. - * 3, while somewhat wasteful, seems much less wasteful than the other two, - * and is the plan that was adopted.</p> - * - * @param baseURLs Array of URLs containing possible paths that should be - * tried used as the base for relative URLs. - * @param urlSpecified String containing the name of the URL. - * @return A List of URLs that the client should try to open, in the order - * that they should be tried. - * @throws MalformedURLException If it is unable to create even one - * URL instance. - */ - public static List buildURLList(URL[] baseURLs, String urlSpecified) - throws MalformedURLException { - if (urlSpecified == null) { - return null; - } - ArrayList list = new ArrayList(); - URL newURL = null; - - // Try the raw urlSpecified first. - try { - newURL = URLFactory.createURL(urlSpecified); - } catch (MalformedURLException e) { - // Ignore. - } - if (newURL != null) { - list.add(newURL); - } - - // Try it with the "file" protocol prepended. - newURL = null; - try { - newURL = URLFactory.createURL("file:" + urlSpecified); - } catch (MalformedURLException e) { - // Ignore. - } - if (newURL != null) { - list.add(newURL); - } - - // Now try it as a relative URL - newURL = null; - /* - * The following piece of code is based on the following statement in - * RFC2396 section 5.2: - * - * 3) If the scheme component is defined, indicating that the - * reference starts with a scheme name, then the reference is - * interpreted as an absolute URI and we are done. Otherwise, - * the reference URI's scheme is inherited from the base URI's - * scheme component. - * - * Due to a loophole in prior specifications [RFC1630], some - * parsers allow the scheme name to be present in a relative - * URI if it is the same as the base URI scheme. Unfortunately, - * this can conflict with the correct parsing of - * non-hierarchical URI. For backwards compatibility, an - * implementation may work around such references by removing - * the scheme if it matches that of the base URI and the scheme - * is known to always use the <hier_part> syntax. - * - * The URL class does not implement this work around, so we do. - */ - if (baseURLs != null) { - for (int i = 0; i < baseURLs.length; i++) { - URL baseURL = baseURLs[i]; - if (baseURL == null) { - continue; - } - String scheme = baseURL.getProtocol() + ":"; - // Copy the string to avoid side effects - String relativeURL = new String(urlSpecified); - if (urlSpecified.startsWith(scheme)) { - relativeURL = relativeURL.substring(scheme.length()); - } - try { - newURL = URLFactory.createURL(baseURL, relativeURL); - } catch (MalformedURLException e1) { - // Ignore - } - if (newURL != null) { - list.add(newURL); - } - } - } - - if (list.size() < 1) { - throw new MalformedURLException("Cannot build a valid URL " - + "from " + urlSpecified + "."); - } - return list; - } - - /** - * Converts standard-based uri-specification to a normalized String from - * which a java.net.URL instance can be constructed. Some standards, - * XSL-FO among them, require that uri-specification consists of the URI - * preceded by "url(" and followed by ")". This method validates and - * normalizes that input. - * @param input The uri-specification as defined in the XSL-FO Standard 1.0, - * Section 5.11. - * @return The normalized String, or null if the input is not valid. - */ - public static String normalizeURISpecification(String input) { - if (input == null) { - return null; - } - // Make a copy - String useInput = new String(input); - useInput = useInput.trim(); - if (! (useInput.startsWith("url("))) { - return null; - } - if (! (useInput.endsWith(")"))) { - return null; - } - // Strip off the leading "url(", the trailing ")". - useInput = useInput.substring(4, useInput.indexOf(")")); - // Strip off the optional whitespace - useInput = useInput.trim(); - boolean doubleQuotesUsed = false; - if (useInput.startsWith("'")) { - if (useInput.endsWith("'")) { - useInput = useInput.substring(1, useInput.length() - 1); - } else { - return null; - } - } else if (useInput.startsWith("\"")) { - if (useInput.endsWith("\"")) { - useInput = useInput.substring(1, useInput.length() - 1); - doubleQuotesUsed = true; - } else { - return null; - } - } - if (useInput.indexOf("'") != -1 && ! doubleQuotesUsed) { - return null; - } - return useInput; - } - -} Added: trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -0,0 +1,255 @@ +/* + * 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.common.url; + + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +/** + * This utility class is used to build URLs from Strings. The String can be + * normal URLs but also just filenames. The filenames get converted to a + * file URL. + * + * @author Jeremias Maerki + */ +public class URLUtil { + + /** Private constructor (should not be instantiated). */ + private URLUtil() { + } + + /** + * Build an URL based on a String. The String can be a normal URL or a + * filename. Filenames get automatically converted to to URLs. + * + * @param spec A URL or a filename + * @return The requested URL + * @throws MalformedURLException If spec cannot be converted to a URL. + */ + public static URL buildURL(String spec) throws MalformedURLException { + if (spec == null) { + throw new NullPointerException("spec must not be null"); + } + File f = new File(spec); + if (f.exists()) { + return f.toURL(); + } + return URLFactory.createURL(spec); + } + + + /** + * Build an URL based on a String. The String can be a normal URL or a + * filename. Filenames get automatically converted to to URLs. + * + * @param baseURL Base URL for relative paths + * @param spec A URL or a filename + * @return The requested URL + * @throws MalformedURLException If spec cannot be converted to a URL. + */ + public static URL buildURL(URL baseURL, String spec) + throws MalformedURLException { + if (spec == null) { + throw new NullPointerException("spec must not be null"); + } + try { + URL u1 = buildURL(spec); + return u1; + } catch (MalformedURLException mfue) { + if (baseURL == null) { + throw mfue; + } + URL u2 = URLFactory.createURL(baseURL, spec); + return u2; + } + } + + /** + * <p>This method is an attempt to standardize the way that URLs are + * constructed, and, more importantly, how they are converted into + * Streams or other i/o resources. There is no way to know when a URL + * is constructed whether it can actually be opened or not. So it is + * frequently the case that resources identified by URL must be tried + * several times as various possibilities are attempted. To standardize + * this, three possibilities were considered:</p> + * + * <ol> + * <li>Loop through the possibilities here, attempting to open each + * one. When one is successfully opened, return the URL.</li> + * <li>Set up something stateful that would create the next possible URL + * on demand.</li> + * <li>Build and return a collection of possibilities & let the client + * manage the process.</li> + * </ol> + * + * <p>Of these three, 1 forces the URL to be opened twice, which was deemed + * wasteful. 2 seems like way too much trouble for such a simple task. + * An object would have to be created to manage the state information. + * 3, while somewhat wasteful, seems much less wasteful than the other two, + * and is the plan that was adopted.</p> + * + * @param baseURLs Array of URLs containing possible paths that should be + * tried used as the base for relative URLs. + * @param urlSpecified String containing the name of the URL. + * @return A List of URLs that the client should try to open, in the order + * that they should be tried. + * @throws MalformedURLException If it is unable to create even one + * URL instance. + */ + public static List buildURLList(URL[] baseURLs, String urlSpecified) + throws MalformedURLException { + if (urlSpecified == null) { + return null; + } + ArrayList list = new ArrayList(); + URL newURL = null; + + // Try the raw urlSpecified first. + try { + newURL = URLFactory.createURL(urlSpecified); + } catch (MalformedURLException e) { + // Ignore. + } + if (newURL != null) { + list.add(newURL); + } + + // Try it with the "file" protocol prepended. + newURL = null; + try { + newURL = URLFactory.createURL("file:" + urlSpecified); + } catch (MalformedURLException e) { + // Ignore. + } + if (newURL != null) { + list.add(newURL); + } + + // Now try it as a relative URL + newURL = null; + /* + * The following piece of code is based on the following statement in + * RFC2396 section 5.2: + * + * 3) If the scheme component is defined, indicating that the + * reference starts with a scheme name, then the reference is + * interpreted as an absolute URI and we are done. Otherwise, + * the reference URI's scheme is inherited from the base URI's + * scheme component. + * + * Due to a loophole in prior specifications [RFC1630], some + * parsers allow the scheme name to be present in a relative + * URI if it is the same as the base URI scheme. Unfortunately, + * this can conflict with the correct parsing of + * non-hierarchical URI. For backwards compatibility, an + * implementation may work around such references by removing + * the scheme if it matches that of the base URI and the scheme + * is known to always use the <hier_part> syntax. + * + * The URL class does not implement this work around, so we do. + */ + if (baseURLs != null) { + for (int i = 0; i < baseURLs.length; i++) { + URL baseURL = baseURLs[i]; + if (baseURL == null) { + continue; + } + String scheme = baseURL.getProtocol() + ":"; + // Copy the string to avoid side effects + String relativeURL = new String(urlSpecified); + if (urlSpecified.startsWith(scheme)) { + relativeURL = relativeURL.substring(scheme.length()); + } + try { + newURL = URLFactory.createURL(baseURL, relativeURL); + } catch (MalformedURLException e1) { + // Ignore + } + if (newURL != null) { + list.add(newURL); + } + } + } + + if (list.size() < 1) { + throw new MalformedURLException("Cannot build a valid URL " + + "from " + urlSpecified + "."); + } + return list; + } + + /** + * Converts standard-based uri-specification to a normalized String from + * which a java.net.URL instance can be constructed. Some standards, + * XSL-FO among them, require that uri-specification consists of the URI + * preceded by "url(" and followed by ")". This method validates and + * normalizes that input. + * @param input The uri-specification as defined in the XSL-FO Standard 1.0, + * Section 5.11. + * @return The normalized String, or null if the input is not valid. + */ + public static String normalizeURISpecification(String input) { + if (input == null) { + return null; + } + // Make a copy + String useInput = new String(input); + useInput = useInput.trim(); + if (! (useInput.startsWith("url("))) { + return null; + } + if (! (useInput.endsWith(")"))) { + return null; + } + // Strip off the leading "url(", the trailing ")". + useInput = useInput.substring(4, useInput.indexOf(")")); + // Strip off the optional whitespace + useInput = useInput.trim(); + boolean doubleQuotesUsed = false; + if (useInput.startsWith("'")) { + if (useInput.endsWith("'")) { + useInput = useInput.substring(1, useInput.length() - 1); + } else { + return null; + } + } else if (useInput.startsWith("\"")) { + if (useInput.endsWith("\"")) { + useInput = useInput.substring(1, useInput.length() - 1); + doubleQuotesUsed = true; + } else { + return null; + } + } + if (useInput.indexOf("'") != -1 && ! doubleQuotesUsed) { + return null; + } + return useInput; + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/url/URLUtil.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native Modified: trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 22:29:14 UTC (rev 7783) +++ trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -26,7 +26,7 @@ import org.foray.common.Environment; import org.foray.common.RandomReader; -import org.foray.common.URLBuilder; +import org.foray.common.url.URLUtil; import org.foray.common.url.URLFactory; import org.foray.ps.encode.EncodingParser; import org.foray.ps.encode.EncodingVector; @@ -367,7 +367,7 @@ if (xmlBase != null && !xmlBase.equals("")) { try { /* Update the current xml base. */ - this.currentXMLBase = URLBuilder.buildURL(this.previousXMLBase, + this.currentXMLBase = URLUtil.buildURL(this.previousXMLBase, xmlBase); } catch (MalformedURLException e) { logError("Unable to create URL from " @@ -562,7 +562,7 @@ } try { /* Update the current xml base. */ - this.currentXMLBase = URLBuilder.buildURL(this.currentXMLBase, + this.currentXMLBase = URLUtil.buildURL(this.currentXMLBase, xmlBase); } catch (MalformedURLException e) { logError("Unable to create URL from " Modified: trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java 2006-07-15 22:29:14 UTC (rev 7783) +++ trunk/foray/foray-font/src/java/org/foray/font/format/TTFReader.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -25,7 +25,7 @@ package org.foray.font.format; import org.foray.common.Logging; -import org.foray.common.URLBuilder; +import org.foray.common.url.URLUtil; import org.apache.commons.logging.Log; @@ -79,7 +79,7 @@ } FontFileReader reader = null; try { - URL url = URLBuilder.buildURL(fileName); + URL url = URLUtil.buildURL(fileName); reader = new FontFileReader(logger, url); } catch (MalformedURLException e1) { logger.error("Malformed URL: " + fileName); Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtURI.java =================================================================== --- trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtURI.java 2006-07-15 22:29:14 UTC (rev 7783) +++ trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtURI.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -24,7 +24,7 @@ package org.foray.fotree.value; -import org.foray.common.URLBuilder; +import org.foray.common.url.URLUtil; import java.util.ArrayList; @@ -57,7 +57,7 @@ * @return The created UriDT instance, or null if input is invalid. */ public static DtURI makeUriDT(String input) { - String useInput = URLBuilder.normalizeURISpecification(input); + String useInput = URLUtil.normalizeURISpecification(input); if (useInput == null) { return null; } Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/FOrayGraphicServer.java =================================================================== --- trunk/foray/foray-graphic/src/java/org/foray/graphic/FOrayGraphicServer.java 2006-07-15 22:29:14 UTC (rev 7783) +++ trunk/foray/foray-graphic/src/java/org/foray/graphic/FOrayGraphicServer.java 2006-07-15 23:09:14 UTC (rev 7784) @@ -25,7 +25,7 @@ package org.foray.graphic; import org.foray.common.Logging; -import org.foray.common.URLBuilder; +import org.foray.common.url.URLUtil; import org.foray.graphic.factory.BMPFactory; import org.foray.graphic.factory.EPSFactory; import org.foray.graphic.factory.GIFFactory; @@ -144,7 +144,7 @@ List urlList; // An exception was thrown in buildURLList if urlList is null. try { - urlList = URLBuilder.buildURLList(baseURLs, href); + urlList = URLUtil.buildURLList(baseURLs, href); } catch (MalformedURLException e) { throw new GraphicException(e.getMessage()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 22:29:20
|
Revision: 7783 Author: victormote Date: 2006-07-15 15:29:14 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7783&view=rev Log Message: ----------- Minor refactoring and cleanup. 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-07-15 22:29:05 UTC (rev 7782) +++ trunk/foray/foray-app/src/java/org/foray/app/Options.java 2006-07-15 22:29:14 UTC (rev 7783) @@ -26,7 +26,6 @@ import org.foray.core.ConfigurationParser; import org.foray.core.FOrayException; -import org.foray.core.InputHandler; import org.foray.core.SessionConfig; import org.foray.output.OutputConfig; @@ -94,7 +93,9 @@ return; } try { - loadUserconfiguration(InputHandler.urlInputSource(userConfigFile)); + InputSource inputSource = new InputSource( + userConfigFile.openStream()); + loadUserconfiguration(inputSource); } catch (IOException e) { throw new FOrayException(e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 22:29:13
|
Revision: 7782 Author: victormote Date: 2006-07-15 15:29:05 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7782&view=rev Log Message: ----------- Minor refactoring and cleanup. Modified Paths: -------------- trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java Modified: trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java 2006-07-15 21:08:38 UTC (rev 7781) +++ trunk/foray/foray-core/src/java/org/foray/core/FOInputHandler.java 2006-07-15 22:29:05 UTC (rev 7782) @@ -57,7 +57,8 @@ if (fofile != null) { return super.fileInputSource(fofile); } - return super.urlInputSource(foURL); + InputSource inputSource = new InputSource(foURL.openStream()); + return inputSource; } public XMLReader getParser() throws FOrayException { Modified: trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-15 21:08:38 UTC (rev 7781) +++ trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-15 22:29:05 UTC (rev 7782) @@ -37,7 +37,6 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URL; import javax.xml.parsers.SAXParserFactory; @@ -45,16 +44,13 @@ Log logger; - public abstract InputSource getInputSource() throws IOException ; - public abstract XMLReader getParser() throws FOrayException; - public InputHandler(Log logger) { this.logger = logger; } - public static InputSource urlInputSource(URL url) throws IOException { - return new InputSource(url.openStream()); - } +// public static InputSource urlInputSource(URL url) throws IOException { +// return new InputSource(url.openStream()); +// } /** * create an InputSource from a File @@ -81,25 +77,38 @@ } /** - * creates a SAX parser - * - * @return the created SAX parser + * Creates a SAX parser. + * @return The newly-created SAX parser. */ protected XMLReader createParser() throws FOrayException { + SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = null; try { - SAXParserFactory spf - = javax.xml.parsers.SAXParserFactory.newInstance(); - spf.setNamespaceAware(true); - XMLReader xmlReader = spf.newSAXParser().getXMLReader(); - this.logger.info("FO Parsing: Using " - + xmlReader.getClass().getName() + " as SAX2 Parser."); - return xmlReader; + xmlReader = spf.newSAXParser().getXMLReader(); } catch (javax.xml.parsers.ParserConfigurationException e) { throw new FOrayException(e); } catch (SAXException e) { throw new FOrayException(e); } + if (this.logger.isDebugEnabled()) { + this.logger.debug("FO Parsing: Using " + + xmlReader.getClass().getName() + " as SAX2 Parser."); + } + return xmlReader; } + /** + * Provides the SAX InputSource. + * @return The SAX InputSource for this handler. + * @throws IOException + */ + public abstract InputSource getInputSource() throws IOException ; + + /** + * Provides the SAX parser for the SAX InputSource. + * @return The SAX parser for the SAX InputSource. + */ + public abstract XMLReader getParser() throws FOrayException; + } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 21:09:23
|
Revision: 7781 Author: victormote Date: 2006-07-15 14:08:38 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7781&view=rev Log Message: ----------- Use new URL factory methods instead of URL constructors. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java trunk/foray/foray-app/src/java/org/foray/app/ant/RunTest.java trunk/foray/foray-common/src/java/org/foray/common/Configuration.java trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java trunk/foray/foray-font/src/java/org/foray/font/charset/CharSetParser.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFImageElementBridge.java trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFTranscoder.java trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.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-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-app/src/java/org/foray/app/CommandLineOptions.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -25,6 +25,7 @@ package org.foray.app; import org.foray.common.Logging; +import org.foray.common.url.URLFactory; import org.foray.core.FOInputHandler; import org.foray.core.FOrayException; import org.foray.core.InputHandler; @@ -141,7 +142,8 @@ + "specify the name of the configuration file"); } try { - this.userConfigFile = new URL(args[currentArgument + 1]); + this.userConfigFile = URLFactory.createURL( + args[currentArgument + 1]); } catch (MalformedURLException e) { throw new FOrayException(e); } Modified: trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -27,6 +27,7 @@ import org.foray.area.FOrayAreaTreeFactory; import org.foray.common.Logging; import org.foray.common.XMLParser; +import org.foray.common.url.URLFactory; import org.foray.core.FOrayException; import org.foray.core.FOraySession; import org.foray.core.SessionConfig; @@ -149,7 +150,7 @@ urls[0] = configuration.getBaseDocument(); urls[1] = configuration.optionBaseDirectory(); try { - urls[2] = new URL(System.getProperty("user.dir")); + urls[2] = URLFactory.createURL(System.getProperty("user.dir")); } catch (MalformedURLException e) { // Ignore this -- just leave the null value in the array } Modified: trunk/foray/foray-app/src/java/org/foray/app/ant/RunTest.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/ant/RunTest.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-app/src/java/org/foray/app/ant/RunTest.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -25,6 +25,7 @@ package org.foray.app.ant; import org.foray.common.Logging; +import org.foray.common.url.URLFactory; import org.apache.commons.logging.Log; import org.apache.tools.ant.BuildException; @@ -89,7 +90,7 @@ Log logger = Logging.makeDefaultLogger(); try { ClassLoader loader = new URLClassLoader(new URL[] { - new URL("file:build/fop.jar") + URLFactory.createURL("file:build/fop.jar") }); HashMap diff = runConverter(loader, "areatree", "reference/output/"); @@ -133,7 +134,7 @@ // } else { try { ClassLoader loader = new URLClassLoader(new URL[] { - new URL("file:" + referenceJar) + URLFactory.createURL("file:" + referenceJar) }); boolean failed = false; Modified: trunk/foray/foray-common/src/java/org/foray/common/Configuration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/Configuration.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-common/src/java/org/foray/common/Configuration.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -24,6 +24,8 @@ package org.foray.common; +import org.foray.common.url.URLFactory; + import org.apache.commons.logging.Log; import java.io.File; @@ -224,13 +226,13 @@ URL baseURL = null; try { if (directory == null) { - return new URL("."); + return URLFactory.createURL("."); } File dir = new File(directory); if (dir.isDirectory()) { return dir.toURL(); } - baseURL = new URL(directory); + baseURL = URLFactory.createURL(directory); } catch (MalformedURLException e) { this.getLogger().error("Invalid " + key + ": " + directory + " (" + e.getMessage() + ")"); Modified: trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-common/src/java/org/foray/common/URLBuilder.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -24,6 +24,8 @@ package org.foray.common; +import org.foray.common.url.URLFactory; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; @@ -59,7 +61,7 @@ if (f.exists()) { return f.toURL(); } - return new URL(spec); + return URLFactory.createURL(spec); } @@ -84,7 +86,7 @@ if (baseURL == null) { throw mfue; } - URL u2 = new URL(baseURL, spec); + URL u2 = URLFactory.createURL(baseURL, spec); return u2; } } @@ -131,7 +133,7 @@ // Try the raw urlSpecified first. try { - newURL = new URL(urlSpecified); + newURL = URLFactory.createURL(urlSpecified); } catch (MalformedURLException e) { // Ignore. } @@ -142,7 +144,7 @@ // Try it with the "file" protocol prepended. newURL = null; try { - newURL = new URL("file:" + urlSpecified); + newURL = URLFactory.createURL("file:" + urlSpecified); } catch (MalformedURLException e) { // Ignore. } @@ -186,7 +188,7 @@ relativeURL = relativeURL.substring(scheme.length()); } try { - newURL = new URL(baseURL, relativeURL); + newURL = URLFactory.createURL(baseURL, relativeURL); } catch (MalformedURLException e1) { // Ignore } Modified: trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-core/src/java/org/foray/core/InputHandler.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -26,6 +26,8 @@ +import org.foray.common.url.URLFactory; + import org.apache.commons.logging.Log; import org.xml.sax.InputSource; @@ -71,7 +73,8 @@ path = '/' + path; } try { - return new InputSource(new URL("file", null, path).toString()); + return new InputSource(URLFactory.createURL("file", null, + path).toString()); } catch (MalformedURLException e) { throw new Error("unexpected MalformedURLException"); } Modified: trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-font/src/java/org/foray/font/FontConfigParser.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -27,6 +27,7 @@ import org.foray.common.Environment; import org.foray.common.RandomReader; import org.foray.common.URLBuilder; +import org.foray.common.url.URLFactory; import org.foray.ps.encode.EncodingParser; import org.foray.ps.encode.EncodingVector; import org.foray.ps.encode.GlyphList; @@ -136,7 +137,7 @@ this.fontServer = server; this.filename = filename; try { - this.currentXMLBase = new URL("file", null, "."); + this.currentXMLBase = URLFactory.createURL("file", null, "."); } catch (MalformedURLException e) { /* This shouldn't fail, but if it does, there isn't much that can * be done. */ @@ -467,7 +468,8 @@ URL fontFileURL = null; if (fontFile != null) { try { - fontFileURL = new URL(this.currentXMLBase, fontFile); + fontFileURL = URLFactory.createURL(this.currentXMLBase, + fontFile); } catch (MalformedURLException e) { this.logError("Malformed URL in font configuration:\n" + " " + fontFile); @@ -480,7 +482,8 @@ URL metricsFileURL = null; if (metricsFile != null) { try { - metricsFileURL = new URL(this.currentXMLBase, metricsFile); + metricsFileURL = URLFactory.createURL(this.currentXMLBase, + metricsFile); } catch (MalformedURLException e) { this.logError("Malformed URL in font configuration:\n" + " " + metricsFile); @@ -635,7 +638,7 @@ if (dir.isDirectory()) { this.currentXMLBase = dir.toURL(); } else { - this.currentXMLBase = new URL(directory); + this.currentXMLBase = URLFactory.createURL(directory); } } catch (MalformedURLException e1) { logError("Cannot create URL from current directory: " @@ -645,7 +648,7 @@ } try { String modifiedBase = replaceParameters(this.parsedRootXMLBase); - this.currentXMLBase = new URL(modifiedBase); + this.currentXMLBase = URLFactory.createURL(modifiedBase); } catch (MalformedURLException e) { logError("Cannot create URL from: " + this.parsedRootXMLBase); } @@ -672,7 +675,7 @@ } URL url; try { - url = new URL(encodingFile); + url = URLFactory.createURL(encodingFile); } catch (MalformedURLException e) { logError("Unable to create URL: " + encodingFile); return; @@ -736,7 +739,7 @@ } URL url; try { - url = new URL(file); + url = URLFactory.createURL(file); } catch (MalformedURLException e) { logError("Unable to create URL: " + file); return; Modified: trunk/foray/foray-font/src/java/org/foray/font/charset/CharSetParser.java =================================================================== --- trunk/foray/foray-font/src/java/org/foray/font/charset/CharSetParser.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-font/src/java/org/foray/font/charset/CharSetParser.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -27,6 +27,7 @@ import org.foray.common.Logging; import org.foray.common.RandomReader; import org.foray.common.StringUtil; +import org.foray.common.url.URLFactory; import org.foray.ps.encode.EncodingParser; import org.foray.ps.encode.GlyphList; @@ -220,7 +221,7 @@ } URL url = null; try { - url = new URL(args[0]); + url = URLFactory.createURL(args[0]); } catch (MalformedURLException e) { logger.error("Unable to create URL for: " + args[0] + "\n"); logger.error(" " + e.getMessage()); Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -25,6 +25,7 @@ package org.foray.hyphenR; import org.foray.common.Logging; +import org.foray.common.url.URLFactory; import org.axsl.hyphenR.HyphenationException; @@ -40,7 +41,6 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; /** @@ -146,7 +146,8 @@ path = '/' + path; } try { - return new InputSource(new URL("file", null, path).toString()); + return new InputSource(URLFactory.createURL("file", null, + path).toString()); } catch (MalformedURLException e) { throw new HyphenationException("unexpected MalformedURLException"); } Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFImageElementBridge.java =================================================================== --- trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFImageElementBridge.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFImageElementBridge.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -49,7 +49,8 @@ Element e, ParsedURL purl) { try { - JpegImage jpeg = new JpegImage(new URL(purl.toString())); + JpegImage jpeg = new JpegImage(URLFactory.createURL( + purl.toString())); PDFFilter filter = jpeg.getPDFFilter(); PDFJpegNode node = new PDFJpegNode(jpeg); Rectangle2D bounds = node.getPrimitiveBounds(); Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFTranscoder.java =================================================================== --- trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFTranscoder.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-pdf/src/java/org/foray/pdf/svg/batik/PDFTranscoder.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -24,6 +24,8 @@ package org.foray.pdf.svg.batik; +import org.foray.common.url.URLFactory; + import org.axsl.fontR.FontUse; import org.axsl.pdfW.PDFException; @@ -62,7 +64,6 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.net.MalformedURLException; -import java.net.URL; /** * This class enables to transcode an input to a pdf document. @@ -202,7 +203,7 @@ AffineTransform Px; String ref = null; try { - ref = new URL(uri).getRef(); + ref = URLFactory.createURL(uri).getRef(); } catch (MalformedURLException ex) { // nothing to do, catched previously } Modified: trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java =================================================================== --- trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -26,6 +26,7 @@ import org.foray.common.StringUtil; import org.foray.common.XMLUtil; +import org.foray.common.url.URLFactory; import java.io.IOException; import java.io.InputStream; @@ -482,14 +483,14 @@ URL[] urlsToCompare = new URL[args.length]; URL context = null; try { - context = new URL("file", null, "."); + context = URLFactory.createURL("file", null, "."); } catch (MalformedURLException e1) { System.out.println("Unable to get URL context."); } for (int i = 0; i < args.length; i++) { URL url = null; try { - url = new URL(context, args[i]); + url = URLFactory.createURL(context, args[i]); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + args[i]); System.exit(1); Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -27,6 +27,7 @@ import org.foray.common.Logging; import org.foray.common.RandomReader; import org.foray.common.StringUtil; +import org.foray.common.url.URLFactory; import org.apache.commons.logging.Log; @@ -442,7 +443,7 @@ } URL url = null; try { - url = new URL(args[0]); + url = URLFactory.createURL(args[0]); } catch (MalformedURLException e) { logger.error("Unable to create URL for: " + args[0] + "\n"); logger.error(" " + e.getMessage()); Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java =================================================================== --- trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -26,6 +26,7 @@ import org.foray.common.Logging; import org.foray.common.RandomReader; +import org.foray.common.url.URLFactory; import org.apache.commons.logging.Log; @@ -337,7 +338,7 @@ } URL url = null; try { - url = new URL(args[0]); + url = URLFactory.createURL(args[0]); } catch (MalformedURLException e) { logger.error("Unable to create URL for: " + args[0] + "\n"); logger.error(" " + e.getMessage()); Modified: trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java =================================================================== --- trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -24,6 +24,7 @@ package org.foray.render.awt; +import org.foray.common.url.URLFactory; import org.foray.output.OutputConfig; import org.foray.render.Renderer; import org.foray.render.awt.viewer.ProgressListener; @@ -532,7 +533,7 @@ String urlString = img.getURL().toString(); try { - URL url = new URL(urlString); + URL url = URLFactory.createURL(urlString); ImageIcon icon = new ImageIcon(url); Image image = icon.getImage(); @@ -843,7 +844,7 @@ * float height, Vector transform) { * // What is with transformations? * try { - * URL url = new URL(href); + * URL url = URLFactory.createURL(href); * ImageIcon imageIcon = new ImageIcon(url); * AffineTransform fullTransform = new AffineTransform(); * AffineTransform aTransform; Modified: trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java =================================================================== --- trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2006-07-15 21:07:38 UTC (rev 7780) +++ trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2006-07-15 21:08:38 UTC (rev 7781) @@ -373,7 +373,7 @@ // // String urlString = img.getURL().toString(); // try { -// URL url = new URL(urlString); +// URL url = URLFactory.createURL(urlString); // // ImageIcon icon = new ImageIcon(url); // Image image = icon.getImage(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-15 21:07:43
|
Revision: 7780 Author: victormote Date: 2006-07-15 14:07:38 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7780&view=rev Log Message: ----------- Use the method designed to get the right strategy. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 22:05:19 UTC (rev 7779) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-15 21:07:38 UTC (rev 7780) @@ -146,7 +146,7 @@ * been registered. */ public static URLStreamHandler getURLStreamHandler(String protocol) { - return strategy.getURLStreamHandler(protocol); + return getRegistrationStrategy().getURLStreamHandler(protocol); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 22:05:27
|
Revision: 7779 Author: victormote Date: 2006-07-08 15:05:19 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7779&view=rev Log Message: ----------- Add factory class for creating URL instances. Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/url/URLFactory.java Added: trunk/foray/foray-common/src/java/org/foray/common/url/URLFactory.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/URLFactory.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/url/URLFactory.java 2006-07-08 22:05:19 UTC (rev 7779) @@ -0,0 +1,196 @@ +/* + * 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.url; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLStreamHandler; + +/** + * Creates URL instances using the FOray custom {@link URLStreamHandler} + * capabilities. + * The public methods in this class have a one-to-one correspondence with + * the {@link URL} constructors, and are intended to be a replacement for them. + * This class essentially interposes itself between the calling code and the + * {@link URL} constructors to use its own {@link URLStreamHandler} resolution. + * This is needed because there is no clean way to be assured that the + * {@link URL} constructors use the desired custom {@link URLStreamHandler} + * implementation. + * + * @see ProtocolRegistrationBroker where the various strategies for dealing with + * custom {@link URLStreamHandler} implementations are discussed, and where + * one can be selected. + */ +public class URLFactory { + + /** + * Private constructor. This should never be instantiated. + */ + private URLFactory() { } + + /** + * @see URL#URL(java.lang.String) which this method mimics. + */ + public static URL createURL(String spec) throws MalformedURLException { + /* Mimics logic in URL. */ + return createURL(null, spec); + } + + /** + * @see URL#URL(java.lang.String, java.lang.String, int, java.lang.String) + * which this method mimics. + */ + public static URL createURL(String protocol, String host, int port, + String file) throws MalformedURLException { + /* Mimics logic in URL. */ + return createURL(protocol, host, port, file, null); + } + + /** + * @see URL#URL(java.lang.String, java.lang.String, int, java.lang.String, + * java.net.URLStreamHandler) which this method mimics. + */ + public static URL createURL(String protocol, String host, int port, + String file, URLStreamHandler handler) + throws MalformedURLException { + if (handler == null) { + /* Interposes to use the custom URLStreamHandler registration. */ + handler = getCustomURLStreamHandler(protocol); + } + /* Now uses the regular URL constructor. */ + return new URL(protocol, host, port, file, handler); + } + + /** + * @see URL#URL(java.lang.String, java.lang.String, java.lang.String) + * which this method mimics. + */ + public static URL createURL(String protocol, String host, String file) + throws MalformedURLException { + /* Mimics logic in URL. */ + return createURL(protocol, host, -1, file); + } + + /** + * @see URL#URL(java.net.URL, java.lang.String) which this method mimics. + */ + public static URL createURL(URL context, String spec) + throws MalformedURLException { + /* Mimics logic in URL. */ + return createURL(context, spec, null); + } + + /** + * @see URL#URL(java.net.URL, java.lang.String, java.net.URLStreamHandler) + * which this method mimics. + */ + public static URL createURL(URL context, String spec, + URLStreamHandler handler) throws MalformedURLException { + if (handler == null) { + /* Interposes to use the custom URLStreamHandler registration. */ + String protocol = parseProtocol(spec); + handler = getCustomURLStreamHandler(protocol); + } + /* Now uses the regular URL constructor. */ + return new URL(context, spec, handler); + } + + private static URLStreamHandler getCustomURLStreamHandler(String protocol) { + return ProtocolRegistrationBroker.getURLStreamHandler(protocol); + } + + /** + * Extracts the protocol portion of a URL specification. + * @param spec The URL specifications from which a protocol should be + * extracted. + * @return The extracted protocol. + * @see URL#URL(java.net.URL, java.lang.String, java.net.URLStreamHandler) + * from which this code is derived. + */ + public static String parseProtocol(String spec) { + int i, limit, c; + int start = 0; + String newProtocol = null; + boolean aRef=false; + + limit = spec.length(); + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) { + limit--; //eliminate trailing whitespace + } + while ((start < limit) && (spec.charAt(start) <= ' ')) { + start++; // eliminate leading whitespace + } + + if (spec.regionMatches(true, start, "url:", 0, 4)) { + start += 4; + } + if (start < spec.length() && spec.charAt(start) == '#') { + /* we're assuming this is a ref relative to the context URL. + * This means protocols cannot start w/ '#', but we must parse + * ref URL's like: "hello:there" w/ a ':' in them. + */ + aRef=true; + } + for (i = start ; !aRef && (i < limit) && + ((c = spec.charAt(i)) != '/') ; i++) { + if (c == ':') { + String s = spec.substring(start, i).toLowerCase(); + if (isValidProtocol(s)) { + newProtocol = s; + start = i + 1; + } + break; + } + } + return newProtocol; + } + + /** + * Returns true if specified string is a valid protocol name. + * This method is derived from the {@link URL} method with the same + * signature. + */ + public static boolean isValidProtocol(String protocol) { + int len = protocol.length(); + if (len < 1) { + return false; + } + char c = protocol.charAt(0); + if (! Character.isLetter(c)) { + return false; + } + for (int i = 1; i < len; i++) { + c = protocol.charAt(i); + if (! Character.isLetterOrDigit(c) + && c != '.' + && c != '+' + && c != '-') { + return false; + } + } + return true; + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/url/URLFactory.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-07-08 21:56:40
|
Revision: 7778 Author: victormote Date: 2006-07-08 14:56:34 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7778&view=rev Log Message: ----------- Add method to return a registered Handler if possible. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationStrategy.java trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 19:46:39 UTC (rev 7777) +++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 21:56:34 UTC (rev 7778) @@ -87,4 +87,13 @@ != null; } + /** + * {@inheritDoc} + */ + public URLStreamHandler getURLStreamHandler(String protocol) { + URLStreamHandlerFactory factory = + FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); + return factory.createURLStreamHandler(protocol); + } + } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 19:46:39 UTC (rev 7777) +++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 21:56:34 UTC (rev 7778) @@ -130,4 +130,11 @@ System.setProperty(javaProperty, searchPath); } + /** + * {@inheritDoc} + */ + public URLStreamHandler getURLStreamHandler(String protocol) { + return (URLStreamHandler) this.protocols.get(protocol); + } + } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 19:46:39 UTC (rev 7777) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 21:56:34 UTC (rev 7778) @@ -26,6 +26,7 @@ package org.foray.common.url; +import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; /** @@ -137,4 +138,15 @@ return strategy; } + /** + * Convenience method making registered protocol handler available in a + * static way. + * @param protocol The protocol for which a Handler is sought. + * @return The Handler for <code>protocol</code>, or null if it has not + * been registered. + */ + public static URLStreamHandler getURLStreamHandler(String protocol) { + return strategy.getURLStreamHandler(protocol); + } + } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationStrategy.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationStrategy.java 2006-07-08 19:46:39 UTC (rev 7777) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationStrategy.java 2006-07-08 21:56:34 UTC (rev 7778) @@ -42,4 +42,13 @@ * used for URLs whose protocol is <code>protocol</code>. */ void registerProtocolHandler(String protocol, URLStreamHandler handler); + + /** + * Finds the registered URLStreamHandler for a given protocol. + * @param protocol The protocol for which a URLStreamHandler is desired. + * @return The URLStreamHandler registered with this registration scheme, + * or null if the protocol has not been registered. + */ + URLStreamHandler getURLStreamHandler(String protocol) ; + } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 19:46:39 UTC (rev 7777) +++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 21:56:34 UTC (rev 7778) @@ -76,4 +76,11 @@ delegate.registerProtocolHandler(protocol, handler); } + /** + * {@inheritDoc} + */ + public URLStreamHandler getURLStreamHandler(String protocol) { + return delegate.getURLStreamHandler(protocol); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 19:46:42
|
Revision: 7777 Author: victormote Date: 2006-07-08 12:46:39 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7777&view=rev Log Message: ----------- Add some more doc. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 19:24:24 UTC (rev 7776) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 19:46:39 UTC (rev 7777) @@ -26,9 +26,35 @@ package org.foray.common.url; +import java.net.URLStreamHandlerFactory; + /** - * Manages which {@link ProtocolRegistrationStrategy} is used to register new + * <p>Manages which {@link ProtocolRegistrationStrategy} is used to register new * custom URL protocol handlers. + * Only one strategy can be used within a session. + * Java provides two methods for registering these protocol handlers, one found + * in {@link URLStreamHandlerFactory} (the Factory scheme), and the other + * using the "java.protocol.handler.pkgs" Java property (the Property scheme). + * Each of these schemes has drawbacks.</p> + * + * <p>This class can register the following implementations using its + * {@link #setStandardRegistrationStrategy(int)} method:</p> + * <ul> + * <li>Factory. Uses the Factory scheme exclusively.</li> + * <li>Property. Uses the Property scheme exclusively.</li> + * <li>Universal. Uses the best scheme that it can find. Tries the Factory + * scheme first, then uses the Property scheme as a fallback.</li> + * </ul> + * + * <p>In addition to the standard strategies described above, custom strategies + * can be registered using + * {@link #setRegistrationStrategy(ProtocolRegistrationStrategy)}. + * This may be useful in cases where a {@link URLStreamHandlerFactory} has been + * registered by some third-party and the developer wishes to use it to get + * URL handlers registered. + * {@link AbstractProtocolRegistration} is an abstract implementation of + * {@link ProtocolRegistrationStrategy} which may be a useful starting place for + * custom implementations.</p> */ public class ProtocolRegistrationBroker { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 19:24:27
|
Revision: 7776 Author: victormote Date: 2006-07-08 12:24:24 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7776&view=rev Log Message: ----------- Make the Factory implementation a subclass of the Abstract one again. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775) +++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 19:24:24 UTC (rev 7776) @@ -39,8 +39,7 @@ * URLStreamHandlers, but instead attempts to use only a * {@link URLStreamHandlerFactory}. */ -public class FactoryProtocolRegistration - implements ProtocolRegistrationStrategy { +public class FactoryProtocolRegistration extends AbstractProtocolRegistration { /** * Package-private constructor. @@ -54,8 +53,7 @@ /** * {@inheritDoc} */ - public void registerProtocolHandler(String protocol, - URLStreamHandler handler) { + public void doRegister(String protocol, URLStreamHandler handler) { /* Get the Factory instance. */ FOrayURLStreamHandlerFactory factory = FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 19:08:47
|
Revision: 7775 Author: victormote Date: 2006-07-08 12:08:42 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7775&view=rev Log Message: ----------- Add factory method to the broker, and make the implementation constructors package-private, as per Vincent Hennebert's suggestion. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774) +++ trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775) @@ -29,9 +29,7 @@ import java.net.URLStreamHandler; /** - * Abstract implementation of ProtocolHandlerRegistry which factorizes out - * things common two both registration methods: by using the - * URL.setURLStreamHandlerFactory of the "java.protocol.handler.pkgs" property. + * Abstract implementation of {@link ProtocolRegistrationStrategy}. */ public abstract class AbstractProtocolRegistration implements ProtocolRegistrationStrategy { Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774) +++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775) @@ -42,6 +42,12 @@ public class FactoryProtocolRegistration implements ProtocolRegistrationStrategy { + /** + * Package-private constructor. + * Use + * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)} + * to use this standard registration scheme. + */ public FactoryProtocolRegistration() { } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774) +++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775) @@ -49,10 +49,12 @@ protected Map protocols = new HashMap(); /** - * Constructor. - * @see ProtocolRegistrationBroker#getRegistrationStrategy + * Package-private constructor. + * Use + * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)} + * to use this standard registration scheme. */ - public PropertyProtocolRegistration() { + PropertyProtocolRegistration() { } void doRegister(String protocol, URLStreamHandler handler) { Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 18:46:02 UTC (rev 7774) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 19:08:42 UTC (rev 7775) @@ -32,10 +32,48 @@ */ public class ProtocolRegistrationBroker { + public static final byte UNIVERSAL_REGISTRATION_STRATEGY = 1; + public static final byte PROPERTY_REGISTRATION_STRATEGY = 2; + public static final byte FACTORY_REGISTRATION_STRATEGY = 3; + /** The singleton instance of {@link ProtocolRegistrationStrategy}. */ private static ProtocolRegistrationStrategy strategy = null; /** + * Factory method that knows how to create any of the standard URL Protocol + * Registration strategies. + * @param strategy One of {@link #UNIVERSAL_REGISTRATION_STRATEGY}, + * {@link #PROPERTY_REGISTRATION_STRATEGY}, or + * {@link #FACTORY_REGISTRATION_STRATEGY}. + */ + public static synchronized void setStandardRegistrationStrategy( + int strategy) { + checkAlreadySet(); + switch (strategy) { + case UNIVERSAL_REGISTRATION_STRATEGY: { + ProtocolRegistrationBroker.strategy = + new UniversalProtocolRegistration(); + break; + } + case PROPERTY_REGISTRATION_STRATEGY: { + ProtocolRegistrationBroker.strategy = + new PropertyProtocolRegistration(); + break; + } + case FACTORY_REGISTRATION_STRATEGY: { + ProtocolRegistrationBroker.strategy = + new FactoryProtocolRegistration(); + break; + } + default: { + throw new IllegalArgumentException( + ProtocolRegistrationBroker.class.getName() + + ": invalid standard strategy."); + } + } + } + + /** * Sets the strategy which will be used within the application for * registering custom URL protocol handlers. * This method is provided to accommodate applications that prefer a custom @@ -48,11 +86,15 @@ */ public static synchronized void setRegistrationStrategy ( ProtocolRegistrationStrategy strategy) { + checkAlreadySet(); + ProtocolRegistrationBroker.strategy = strategy; + } + + private static void checkAlreadySet() { if (strategy != null) { String className = ProtocolRegistrationBroker.class.getName(); throw new RuntimeException(className + ": strategy already set"); } - ProtocolRegistrationBroker.strategy = strategy; } /** Modified: trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774) +++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775) @@ -54,9 +54,12 @@ private ProtocolRegistrationStrategy delegate; /** - * Constructor. + * Package-private constructor. + * Use + * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)} + * to use this standard registration scheme. */ - public UniversalProtocolRegistration() { + UniversalProtocolRegistration() { FactoryProtocolRegistration factory = new FactoryProtocolRegistration(); if (factory.isValid()) { delegate = factory; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 18:46:07
|
Revision: 7774 Author: victormote Date: 2006-07-08 11:46:02 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7774&view=rev Log Message: ----------- Rename methods (per Vincent Hennebert's suggestion). Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 18:42:47 UTC (rev 7773) +++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774) @@ -50,7 +50,7 @@ /** * Constructor. - * @see ProtocolRegistrationBroker#getStrategy + * @see ProtocolRegistrationBroker#getRegistrationStrategy */ public PropertyProtocolRegistration() { } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 18:42:47 UTC (rev 7773) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 18:46:02 UTC (rev 7774) @@ -43,10 +43,10 @@ * The default strategy is {@link UniversalProtocolRegistration}, and it * will be selected automatically unless this method is used to set a * different strategy <em>before the first call</em> to the - * {@link #getStrategy} method. + * {@link #getRegistrationStrategy} method. * @param strategy the registry used to record custom URL protocol handlers */ - public static synchronized void setStrategy( + public static synchronized void setRegistrationStrategy ( ProtocolRegistrationStrategy strategy) { if (strategy != null) { String className = ProtocolRegistrationBroker.class.getName(); @@ -61,7 +61,8 @@ * @return The {@link ProtocolRegistrationStrategy} to be used for custom * URL handler registration for this session. */ - public static synchronized ProtocolRegistrationStrategy getStrategy() { + public static synchronized ProtocolRegistrationStrategy + getRegistrationStrategy() { if (strategy == null) { strategy = new UniversalProtocolRegistration(); } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 18:42:47 UTC (rev 7773) +++ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 18:46:02 UTC (rev 7774) @@ -81,7 +81,7 @@ if (!alreadyRegistered) { URLStreamHandler handler = new Handler(); ProtocolRegistrationStrategy registry = - ProtocolRegistrationBroker.getStrategy(); + ProtocolRegistrationBroker.getRegistrationStrategy(); registry.registerProtocolHandler(Handler.PROTOCOL, handler); alreadyRegistered = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 18:42:52
|
Revision: 7773 Author: victormote Date: 2006-07-08 11:42:47 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7773&view=rev Log Message: ----------- Fix typo (per Vincent Henneber patch). Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 18:29:35 UTC (rev 7772) +++ trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 18:42:47 UTC (rev 7773) @@ -37,7 +37,7 @@ implements ProtocolRegistrationStrategy { /** - * Construtor. + * Constructor. */ public AbstractProtocolRegistration() { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 18:29:40
|
Revision: 7772 Author: victormote Date: 2006-07-08 11:29:35 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7772&view=rev Log Message: ----------- Use delegate scheme, as per Vincent Hennebert's latest patch. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:27:56 UTC (rev 7771) +++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:29:35 UTC (rev 7772) @@ -78,4 +78,9 @@ factory.registerProtocol(protocol, handler); } + public boolean isValid() { + return FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory() + != null; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 18:27:59
|
Revision: 7771 Author: victormote Date: 2006-07-08 11:27:56 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7771&view=rev Log Message: ----------- Use delegate scheme, as per Vincent Hennebert's latest patch. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 18:04:47 UTC (rev 7770) +++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 18:27:56 UTC (rev 7771) @@ -38,57 +38,39 @@ * Registers URL protocols in a universal manner, attempting first to register * using a {@link URLStreamHandlerFactory}, then using the Java properties * method as a fallback. - * @see PropertyProtocolRegistration which registers only using the Java - * properties method. + * @see FactoryProtocolRegistration which registers using only the + * {@link URLStreamHandlerFactory} scheme. + * @see PropertyProtocolRegistration which registers using only the Java + * properties scheme. */ public class UniversalProtocolRegistration - extends AbstractProtocolRegistration { + implements ProtocolRegistrationStrategy { /** + * The object which will actually do the registration. The + * URLStreamHandlerFactory will first be tried; if it fails, the + * property-based method will be used as a fallback. + */ + private ProtocolRegistrationStrategy delegate; + + /** * Constructor. */ public UniversalProtocolRegistration() { + FactoryProtocolRegistration factory = new FactoryProtocolRegistration(); + if (factory.isValid()) { + delegate = factory; + } else { + delegate = new PropertyProtocolRegistration(); + } } /** * {@inheritDoc} */ - public void doRegister(String protocol, URLStreamHandler handler) { - /* Get the Factory instance. */ - FOrayURLStreamHandlerFactory factory = - FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); - - if (factory == null) { - /* If factory is null, it is because something got registered in - * URL.setURLStreamHandlerFactory(URLStreamHandlerFactory) - * before our FOrayURLStreamHandlerFactory could register. - * Therefore, the best we can do is register ours with the Java - * environment "java.protocol.handler.pkgs". */ - /* The FOray Factory will not be able to register itself with Java - * in a case where other software running has already registered - * another URLStreamHandlerFactory first. - * Therefore, we will give Java another opportunity to find our - * custom handler by placing its location in the Java environment. - */ - PropertyProtocolRegistration.propertyRegistration(protocol, - handler); - return; - } - - /* See if this protocol is already registered with the factory. */ - URLStreamHandler registeredHandler = factory.createURLStreamHandler( - protocol); - if (registeredHandler != null) { - /* If already registed, that one is the one being used, and there - * is no way to change it. If it has in fact not yet been used, - * then registering this now would make the new one used instead - * of the old one. However, until we have some indication that this - * would be the "right" thing to do, we will not. */ - return; - } - - /* Register the protocol with the Factory. */ - factory.registerProtocol(protocol, handler); + public void registerProtocolHandler(String protocol, + URLStreamHandler handler) { + delegate.registerProtocolHandler(protocol, handler); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 18:04:52
|
Revision: 7770 Author: victormote Date: 2006-07-08 11:04:47 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7770&view=rev Log Message: ----------- Add new Factory-only implementation, per Vincent Hennebert's request. Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java Added: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:04:47 UTC (rev 7770) @@ -0,0 +1,81 @@ +/* + * 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$ + */ + +/* Known contributors: + * Vincent Hennebert (original author) + */ + +package org.foray.common.url; + +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; + +/** + * An implementation of {#link ProtocolHandlerRegistry} which does not attempt + * to use the "java.protocol.handler.pkgs" property to register new + * URLStreamHandlers, but instead attempts to use only a + * {@link URLStreamHandlerFactory}. + */ +public class FactoryProtocolRegistration + implements ProtocolRegistrationStrategy { + + public FactoryProtocolRegistration() { + } + + /** + * {@inheritDoc} + */ + public void registerProtocolHandler(String protocol, + URLStreamHandler handler) { + /* Get the Factory instance. */ + FOrayURLStreamHandlerFactory factory = + FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); + + if (factory == null) { + /* If factory is null, it is because something got registered in + * URL.setURLStreamHandlerFactory(URLStreamHandlerFactory) + * before our FOrayURLStreamHandlerFactory could register. + * There is nothing that can be done. */ + return; + } + + /* See if this protocol is already registered with the factory. */ + URLStreamHandler registeredHandler = factory.createURLStreamHandler( + protocol); + if (registeredHandler != null) { + /* If already registed, that one is the one being used, and there + * is no way to change it. If it has in fact not yet been used, + * then registering this now would make the new one used instead + * of the old one. However, until we have some indication that this + * would be the "right" thing to do, we will not. */ + return; + } + + /* Register the protocol with the Factory. */ + factory.registerProtocol(protocol, handler); + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.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-07-08 02:42:15
|
Revision: 7769 Author: victormote Date: 2006-07-07 19:42:11 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7769&view=rev Log Message: ----------- Minor doc changes. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:38:24 UTC (rev 7768) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:42:11 UTC (rev 7769) @@ -56,9 +56,10 @@ } /** - * Provides access to a ProtocolHandlerRegistry instance, creating it and - * registering it with Java if needed. - * @return The custom ProtocolHandlerRegistry instance for this session. + * Provides access to the chosen protocol registration strategy, or to a + * default one if none has been set. + * @return The {@link ProtocolRegistrationStrategy} to be used for custom + * URL handler registration for this session. */ public static synchronized ProtocolRegistrationStrategy getStrategy() { if (strategy == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 02:38:30
|
Revision: 7768 Author: victormote Date: 2006-07-07 19:38:24 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7768&view=rev Log Message: ----------- 1. Rename variables and methods for clarity. 2. Minor doc changes. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 02:27:21 UTC (rev 7767) +++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 02:38:24 UTC (rev 7768) @@ -50,7 +50,7 @@ /** * Constructor. - * @see ProtocolRegistrationBroker#getRegistry + * @see ProtocolRegistrationBroker#getStrategy */ public PropertyProtocolRegistration() { } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:27:21 UTC (rev 7767) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:38:24 UTC (rev 7768) @@ -27,28 +27,32 @@ package org.foray.common.url; /** - * Class that returns an instance of ProtocolHandlerRegistry which is - * unique within the whole application. + * Manages which {@link ProtocolRegistrationStrategy} is used to register new + * custom URL protocol handlers. */ public class ProtocolRegistrationBroker { - /** The singleton instance of ProtocolHandlerRegistry. */ - private static ProtocolRegistrationStrategy registry = null; + /** The singleton instance of {@link ProtocolRegistrationStrategy}. */ + private static ProtocolRegistrationStrategy strategy = null; /** - * Sets the registry which will be used within the application for - * registering custom URL protocol handlers. This method may be called only - * once at the beginning, before any call to the {@link #getRegistry} - * method. - * @param registry the registry used to record custom URL protocol handlers + * Sets the strategy which will be used within the application for + * registering custom URL protocol handlers. + * This method is provided to accommodate applications that prefer a custom + * strategy over the default strategy. + * The default strategy is {@link UniversalProtocolRegistration}, and it + * will be selected automatically unless this method is used to set a + * different strategy <em>before the first call</em> to the + * {@link #getStrategy} method. + * @param strategy the registry used to record custom URL protocol handlers */ - public static synchronized void setRegistry( - ProtocolRegistrationStrategy registry) { - if (registry != null) { - throw new RuntimeException("ProtocolHandlerRegistryBroker: " - + "registry already set"); + public static synchronized void setStrategy( + ProtocolRegistrationStrategy strategy) { + if (strategy != null) { + String className = ProtocolRegistrationBroker.class.getName(); + throw new RuntimeException(className + ": strategy already set"); } - ProtocolRegistrationBroker.registry = registry; + ProtocolRegistrationBroker.strategy = strategy; } /** @@ -56,11 +60,11 @@ * registering it with Java if needed. * @return The custom ProtocolHandlerRegistry instance for this session. */ - public static synchronized ProtocolRegistrationStrategy getRegistry() { - if (registry == null) { - registry = new UniversalProtocolRegistration(); + public static synchronized ProtocolRegistrationStrategy getStrategy() { + if (strategy == null) { + strategy = new UniversalProtocolRegistration(); } - return registry; + return strategy; } } Modified: trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 02:27:21 UTC (rev 7767) +++ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 02:38:24 UTC (rev 7768) @@ -81,7 +81,7 @@ if (!alreadyRegistered) { URLStreamHandler handler = new Handler(); ProtocolRegistrationStrategy registry = - ProtocolRegistrationBroker.getRegistry(); + ProtocolRegistrationBroker.getStrategy(); registry.registerProtocolHandler(Handler.PROTOCOL, handler); alreadyRegistered = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 02:27:25
|
Revision: 7767 Author: victormote Date: 2006-07-07 19:27:21 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7767&view=rev Log Message: ----------- Make the Universal strategy the default one. Applications that wish to use a different one should use the "set" method to select the one they want. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:24:28 UTC (rev 7766) +++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 02:27:21 UTC (rev 7767) @@ -57,13 +57,10 @@ * @return The custom ProtocolHandlerRegistry instance for this session. */ public static synchronized ProtocolRegistrationStrategy getRegistry() { - /* Here a mechanism will have to be added to choose between the two - * methods of registering a protocol handler: URLStreamHandlerFactory - * or Java property - */ if (registry == null) { - registry = new PropertyProtocolRegistration(); + registry = new UniversalProtocolRegistration(); } return registry; } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-07-08 02:24:31
|
Revision: 7766 Author: victormote Date: 2006-07-07 19:24:28 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7766&view=rev Log Message: ----------- Make constructors public so that they can be created in external packages and registered with the broker. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 02:20:35 UTC (rev 7765) +++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 02:24:28 UTC (rev 7766) @@ -27,12 +27,14 @@ package org.foray.common.url; import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; /** - * An implementation of {#link ProtocolHandlerRegistry} which modifies the + * An implementation of {#link ProtocolHandlerRegistry} which does not attempt + * to use a {@link URLStreamHandlerFactory}, but instead modifies the * "java.protocol.handler.pkgs" property to register new URLStreamHandlers. */ public class PropertyProtocolRegistration @@ -47,10 +49,10 @@ protected Map protocols = new HashMap(); /** - * Package-private constructor. + * Constructor. * @see ProtocolRegistrationBroker#getRegistry */ - PropertyProtocolRegistration() { + public PropertyProtocolRegistration() { } void doRegister(String protocol, URLStreamHandler handler) { Modified: trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 02:20:35 UTC (rev 7765) +++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 02:24:28 UTC (rev 7766) @@ -45,6 +45,12 @@ extends AbstractProtocolRegistration { /** + * Constructor. + */ + public UniversalProtocolRegistration() { + } + + /** * {@inheritDoc} */ public void doRegister(String protocol, URLStreamHandler handler) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |