giacomo 00/07/30 12:08:58
Modified: src/org/apache/cocoon/components/language/markup/sitemap/java
Tag: xml-cocoon2 sitemap.xsl
src/org/apache/cocoon/environment/http Tag: xml-cocoon2
HttpEnvironment.java
src/org/apache/cocoon/matching Tag: xml-cocoon2
RegexpURIMatcherFactory.java
Log:
Allow pattern be written as "\\." to escape in the sense of regexp. The \\
will be replaced by \ in the RegexpMatcherFactor code.
Also make uri-prefix more failure resistant for sitemap maintainers because
upi-refix should always end in a /.
Revision Changes Path
No revision
No revision
1.1.2.17 +49 -14
xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
Index: sitemap.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
retrieving revision 1.1.2.16
retrieving revision 1.1.2.17
diff -u -r1.1.2.16 -r1.1.2.17
--- sitemap.xsl 2000/07/28 16:20:06 1.1.2.16
+++ sitemap.xsl 2000/07/30 19:08:57 1.1.2.17
@@ -2,7 +2,7 @@
<!-- Sitemap Core logicsheet for the Java language -->
<!--
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.16 $ $Date: 2000/07/28 16:20:06 $
+ * @version CVS $Revision: 1.1.2.17 $ $Date: 2000/07/30 19:08:57 $
-->
<xsl:stylesheet
@@ -106,8 +106,12 @@
<xsl:variable name="default"><xsl:if test="$type =
../@default">true</xsl:if></xsl:variable>
<xsl:variable name="config"><xsl:copy-of select="."/></xsl:variable>
<xsl:for-each
select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:[EMAIL
PROTECTED] or (not(@type) and $default!='')]">
- <xsl:variable name="matcher-name1" select="translate(@pattern,'/-
*?@:{}()[].#^\\$|!','_')"/>
- <xsl:variable name="matcher-name">matcher_<xsl:value-of
select='translate($matcher-name1,"'","")'/></xsl:variable>
+ <xsl:variable name="matcher-name">
+ <xsl:call-template name="mangle-name">
+ <xsl:with-param name="prefix">matcher_</xsl:with-param>
+ <xsl:with-param name="value" select="@pattern"/>
+ </xsl:call-template>
+ </xsl:variable>
<xsl:value-of
select="java:getClassSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
private List <xsl:value-of select="$matcher-name"/> (String pattern,
Environment environment) {
<xsl:value-of
select="java:getMethodSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
@@ -122,10 +126,14 @@
<xsl:variable name="default"><xsl:if test="$type =
../@default">true</xsl:if></xsl:variable>
<xsl:variable name="config"><xsl:copy-of select="."/></xsl:variable>
<xsl:for-each
select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:when[../map:select/@type=$type
or (not(../map:select/@type) and $default!='')]">
- <xsl:variable name="selector-name1" select="translate(@test,'/-
*?@:{}()[].#^\\$|!','_')"/>
- <xsl:variable name="selector-name">selector_<xsl:value-of
select='translate($selector-name1,"'","")'/></xsl:variable>
+ <xsl:variable name="selector-name">
+ <xsl:call-template name="mangle-name">
+ <xsl:with-param name="prefix">selector_</xsl:with-param>
+ <xsl:with-param name="value" select="@test"/>
+ </xsl:call-template>
+ </xsl:variable>
<xsl:value-of
select="java:getClassSource($factory-loader,string($factory),string($selector-name),string(@pattern),$config)"/>
- private boolean <xsl:value-of select="$selector-name"/> (String
test, Environment environment) {
+ private boolean <xsl:value-of select="$selector-name"/> (String
pattern, Environment environment) {
<xsl:value-of
select="java:getMethodSource($factory-loader,string($factory),string($selector-name),string(@pattern),$config)"/>
}
</xsl:for-each>
@@ -256,8 +264,11 @@
<xsl:with-param name="required">true</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="matcher-name1" select="translate(@pattern,'/-
*?@:{}()[].#^\\$|!','_')"/>
- <xsl:variable name="matcher-name2"
select='translate($matcher-name1,"'","")'/>
+ <xsl:variable name="matcher-name2">
+ <xsl:call-template name="mangle-name">
+ <xsl:with-param name="value"><xsl:value-of
select="@pattern"/></xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
<xsl:variable name="matcher-name">
<xsl:for-each
select="/map:sitemap/map:components/map:matchers/map:[EMAIL PROTECTED]">
<xsl:choose>
@@ -276,8 +287,8 @@
</xsl:for-each>
</xsl:variable>
if ((list = <xsl:value-of select="$matcher-name"/> ("<xsl:value-of
select="$pattern-value"/>", environment)) != null) {
- listOfLists.add (list);
- <xsl:apply-templates/>
+ listOfLists.add (list);
+ <xsl:apply-templates/>
}
</xsl:template> <!-- match="map:match" -->
@@ -294,9 +305,12 @@
<xsl:with-param name="parname">test</xsl:with-param>
<xsl:with-param name="required">true</xsl:with-param>
</xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="selector-name2">
+ <xsl:call-template name="mangle-name">
+ <xsl:with-param name="value" select="@test"/>
+ </xsl:call-template>
</xsl:variable>
- <xsl:variable name="selector-name1" select="translate($test-value,'/-
*?@:{}()[].#^\\$|!','_')"/>
- <xsl:variable name="selector-name2"
select='translate($selector-name1,"'","")'/>
<xsl:variable name="selector-name">
<xsl:for-each
select="/map:sitemap/map:components/map:selectors/map:[EMAIL PROTECTED]">
<xsl:choose>
@@ -364,7 +378,6 @@
<xsl:template match="map:mount">
<xsl:variable name="src" select="@src"/>
- <xsl:variable name="pos"><xsl:value-of select="translate(./@uri-prefix,
'- /{}', '___')"/></xsl:variable>
<xsl:variable name="check-reload">
<xsl:choose>
<xsl:when test="@check-reload='yes'">true</xsl:when>
@@ -381,7 +394,21 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- return sitemapManager.invoke (environment,
substitute(listOfLists,"<xsl:value-of select="@uri-prefix"/>"),
substitute(listOfLists,"<xsl:value-of select="@src"/>"), <xsl:value-of
select="$check-reload"/>, out);
+ <xsl:choose>
+ <xsl:when test="substring(@uri-prefix,string-length(@uri-prefix))='/'">
+ return sitemapManager.invoke (environment,
substitute(listOfLists,"<xsl:value-of select="@uri-prefix"/>"),
substitute(listOfLists,"<xsl:value-of select="@src"/>"), <xsl:value-of
select="$check-reload"/>, out);
+ </xsl:when>
+ <xsl:when test="substring(@uri-prefix,string-length(@uri-prefix))='}'">
+ String uri_prefix<xsl:value-of
select="count(.)"/>=substitute(listOfLists,"<xsl:value-of
select="@uri-prefix"/>");
+ if (uri_prefix<xsl:value-of
select="count(.)"/>.charAt(uri_prefix<xsl:value-of
select="count(.)"/>.length()-1)=='/')
+ return sitemapManager.invoke (environment, uri_prefix<xsl:value-of
select="count(.)"/>, substitute(listOfLists,"<xsl:value-of select="@src"/>"),
<xsl:value-of select="$check-reload"/>, out);
+ else
+ return sitemapManager.invoke (environment, uri_prefix<xsl:value-of
select="count(.)"/>+"/", substitute(listOfLists,"<xsl:value-of
select="@src"/>"), <xsl:value-of select="$check-reload"/>, out);
+ </xsl:when>
+ <xsl:otherwise>
+ return sitemapManager.invoke (environment,
substitute(listOfLists,"<xsl:value-of select="@uri-prefix"/>/"),
substitute(listOfLists,"<xsl:value-of select="@src"/>"), <xsl:value-of
select="$check-reload"/>, out);
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template> <!-- match="map:mount" -->
<xsl:template match="map:redirect-to">
@@ -554,6 +581,14 @@
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="mangle-name">
+ <xsl:param name="value"/>
+ <xsl:param name="prefix"/>
+ <xsl:param name="suffix"/>
+ <xsl:variable name="value1" select="translate($value,'/-
*?@:{}()[].#^\\$|!~\','_')"/>
+ <xsl:value-of select="$prefix"/><xsl:value-of
select='translate($value1,"'","")'/><xsl:value-of select="$suffix"/>
</xsl:template>
<!-- Utility templates -->
No revision
No revision
1.1.2.7 +2 -0
xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
Index: HttpEnvironment.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- HttpEnvironment.java 2000/07/28 16:20:14 1.1.2.6
+++ HttpEnvironment.java 2000/07/30 19:08:57 1.1.2.7
@@ -65,6 +65,7 @@
*/
public void changeContext(String prefix, String context)
throws MalformedURLException {
+System.out.print
("HttpEnvironment.changeContext(prefix=\""+prefix+"\",context=\""+context+"\")
=> ");
if (uri.startsWith (prefix)) {
this.prefix.append (prefix);
uri = uri.substring(prefix.length());
@@ -76,6 +77,7 @@
} else {
//FIXME: should we throw an error here ?
}
+System.out.println ("uri=\""+uri+"\",this.context=\""+this.context+"\"");
}
/**
No revision
No revision
1.1.2.5 +24 -5
xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java
Index: RegexpURIMatcherFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- RegexpURIMatcherFactory.java 2000/07/27 21:49:03 1.1.2.4
+++ RegexpURIMatcherFactory.java 2000/07/30 19:08:58 1.1.2.5
@@ -20,7 +20,7 @@
* for request URIs
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/27 21:49:03 $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/30 19:08:58 $
*/
public class RegexpURIMatcherFactory implements MatcherFactory {
@@ -32,11 +32,12 @@
RECompiler r = new RECompiler();
String name = prefix;
String instructions = name + "PatternInstructions";
+ String pat = correctPattern (pattern);
sb.append("\n // Pre-compiled regular expression '")
- .append(pattern).append("'\n")
+ .append(pat).append("'\n")
.append(" static char[] ");
sb.append(instructions).append(" = \n {");
- REProgram program = r.compile(pattern);
+ REProgram program = r.compile(pat);
int numColumns = 7;
char[] p = program.getInstructions();
for (int j = 0; j < p.length; j++) {
@@ -67,18 +68,36 @@
StringBuffer sb = new StringBuffer ();
String name = prefix;
String instructions = name + "PatternInstructions";
+ String pat = correctPattern (pattern);
sb.append("java.util.ArrayList list = new java.util.ArrayList ();")
.append("if
(").append(name).append("Pattern.match(environment.getUri())) {");
// Count number of parens
int i = 0;
int j = -1;
- while ((j = pattern.indexOf('(', j+1)) != -1) {
- if (j == 0 || pattern.charAt(j-1) != '\\') {
+ while ((j = pat.indexOf('(', j+1)) != -1) {
+ if (j == 0 || pat.charAt(j-1) != '\\') {
sb.append("list.add
(").append(name).append("Pattern.getParen(")
.append(++i).append("));");
}
}
sb.append("return list; } else { return null; }");
return sb.toString();
+ }
+
+ private String correctPattern (String pattern) {
+ char[] pat = new char[pattern.length()];
+ pattern.getChars (0, pattern.length(), pat, 0);
+ int j = 0;
+ int i = 0;
+ while (i < pat.length-1) {
+ if (pat[i] == '\\') {
+ if (pat[i+1] == '\\') {
+ i++;
+ }
+ }
+ pat[j++]=pat[i++];
+ }
+ pat[j]=pat[i];
+ return new String(pat,0,j+1);
}
}