Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 75665 invoked by uid 500); 11 Jan 2002 16:27:54 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 75627 invoked by uid 500); 11 Jan 2002 16:27:54 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 11 Jan 2002 16:27:53 -0000 Message-ID: <20020111162753.72459.qmail@icarus.apache.org> From: bloritsch@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/java/org/apache/cocoon/matching AbstractRegexpMatcher.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bloritsch 02/01/11 08:27:53 Modified: src/java/org/apache/cocoon Main.java src/java/org/apache/cocoon/matching AbstractRegexpMatcher.java Log: apply fix for bug# 5791 Revision Changes Path 1.7 +16 -16 xml-cocoon2/src/java/org/apache/cocoon/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/Main.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Main.java 10 Jan 2002 20:11:46 -0000 1.6 +++ Main.java 11 Jan 2002 16:27:53 -0000 1.7 @@ -97,7 +97,7 @@ * Command line entry point. * * @author Stefano Mazzocchi - * @version CVS $Revision: 1.6 $ $Date: 2002/01/10 20:11:46 $ + * @version CVS $Revision: 1.7 $ $Date: 2002/01/11 16:27:53 $ */ public class Main { @@ -700,17 +700,21 @@ translatedLinks.put(link, translatedRelativeLink); } - // Process URI - File file = IOUtils.createFile(destDir, NetUtils.decodePath(filename)); - OutputStream output = new BufferedOutputStream(new FileOutputStream(file)); - String type = getPage(deparameterizedURI, parameters, translatedLinks, output); - output.close(); - - if (type == null) { - log.warn(" [broken link]--> " + filename); - resourceUnavailable(file); - } else { - log.info(" [" + type + "]--> " + filename); + try { + // Process URI + File file = IOUtils.createFile(destDir, NetUtils.decodePath(filename)); + OutputStream output = new BufferedOutputStream(new FileOutputStream(file)); + String type = getPage(deparameterizedURI, parameters, translatedLinks, output); + output.close(); + + if (type == null) { + log.warn(" [broken link]--> " + filename); + resourceUnavailable(file); + } else { + log.info(" [" + type + "]--> " + filename); + } + } catch (ResourceNotFoundException rnfe) { + this.log.warn("Could not process URI: " + deparameterizedURI); } return absoluteLinks; @@ -848,11 +852,7 @@ links, stream, this.log); - try { cocoon.process(env); - } catch (ResourceNotFoundException rnfe) { - this.log.warn("Could not process URI: " + deparameterizedURI); - } return env.getContentType(); } 1.2 +24 -8 xml-cocoon2/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java Index: AbstractRegexpMatcher.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractRegexpMatcher.java 3 Jan 2002 12:31:17 -0000 1.1 +++ AbstractRegexpMatcher.java 11 Jan 2002 16:27:53 -0000 1.2 @@ -27,7 +27,7 @@ * @author Giacomo Pati * @author Berin Loritsch * @authos Sylvain Wallez - * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:17 $ + * @version CVS $Revision: 1.2 $ $Date: 2002/01/11 16:27:53 $ */ public abstract class AbstractRegexpMatcher extends AbstractPreparableMatcher implements ThreadSafe { @@ -36,28 +36,44 @@ * Compile the pattern in a org.apache.regexp.REProgram. */ public Object preparePattern(String pattern) throws PatternException { + if (pattern == null) + { + throw new PatternException("null passed as a pattern", null); + } + + if (pattern.length() == 0) + { + pattern = "^$"; + if (getLogger().isWarnEnabled()) { + getLogger().warn("The empty pattern string was rewritten to '^$'" + + " to match for empty strings. If you intended" + + " to match all strings, please change your" + + " pattern to '.*'"); + } + } + try { RECompiler compiler = new RECompiler(); REProgram program = compiler.compile(pattern); return program; - + } catch (RESyntaxException rse) { getLogger().debug("Failed to compile the pattern '" + pattern + "'", rse); throw new PatternException(rse.getMessage(), rse); } } - + /** * Match the prepared pattern against the value returned by {@link #getMatchString(Map, Parameters)}. */ public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) { - + RE re = new RE((REProgram)preparedPattern); String match = getMatchString(objectModel, parameters); - + if (match == null) return null; - + if(re.match(match)) { /* Handle parenthesised subexpressions. XXX: could be faster if we count * parens *outside* the generated code. @@ -71,10 +87,10 @@ return map; } - + return null; } - + /** * Get the string to test against the regular expression. To be defined * by concrete subclasses. ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org