bloritsch 00/10/25 09:02:21
Modified: src/org/apache/cocoon Tag: xml-cocoon2 CodeFactory.java
src/org/apache/cocoon/components/language/markup/sitemap/java
Tag: xml-cocoon2 sitemap.xsl
src/org/apache/cocoon/matching Tag: xml-cocoon2
BrowserMatcherFactory.java
RegexpURIMatcherFactory.java
WildcardURIMatcherFactory.java
src/org/apache/cocoon/selection Tag: xml-cocoon2
BrowserSelectorFactory.java
src/org/apache/cocoon/sitemap Tag: xml-cocoon2
XSLTFactoryLoader.java
webapp Tag: xml-cocoon2 sitemap.xmap
Log:
Cleaned up some of the generated sitemap code. It now allows one method per
matcher/selector, with a compiled expression.
Revision Changes Path
No revision
No revision
1.1.2.2 +6 -2 xml-cocoon/src/org/apache/cocoon/Attic/CodeFactory.java
Index: CodeFactory.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/CodeFactory.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- CodeFactory.java 2000/09/06 23:22:21 1.1.2.1
+++ CodeFactory.java 2000/10/25 16:02:15 1.1.2.2
@@ -21,13 +21,17 @@
* sitemap code generation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/09/06 23:22:21 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/10/25 16:02:15 $
*/
public interface CodeFactory {
+ public String generateParameterSource (DocumentFragment conf)
+ throws ConfigurationException;
+
public String generateClassSource (String test, String prefix,
DocumentFragment conf)
throws ConfigurationException;
- public String generateMethodSource (String test, String prefix,
DocumentFragment conf)
+ public String generateMethodSource (DocumentFragment conf)
throws ConfigurationException;
}
No revision
No revision
1.1.2.54 +16 -15
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.53
retrieving revision 1.1.2.54
diff -u -r1.1.2.53 -r1.1.2.54
--- sitemap.xsl 2000/10/24 17:46:32 1.1.2.53
+++ sitemap.xsl 2000/10/25 16:02:16 1.1.2.54
@@ -74,7 +74,8 @@
* This is the automatically generated class from the sitemap definitions
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo
Pati</a>
- * @version CVS $Revision: 1.1.2.53 $ $Date: 2000/10/24 17:46:32 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin
Loiritsch</a>
+ * @version CVS $Revision: 1.1.2.54 $ $Date: 2000/10/25 16:02:16 $
*/
public class <xsl:value-of select="@file-name"/> extends AbstractSitemap
{
static {
@@ -91,6 +92,9 @@
<xsl:variable name="type" select="@name"/>
<xsl:variable name="default" select="$type = ../@default"/>
<xsl:variable name="config"><xsl:copy-of
select="."/></xsl:variable>
+ private List <xsl:value-of select="$type"/>Match (<xsl:value-of
select="java:getParameterSource($factory-loader, string($src),$config)"/>
pattern, Map objectModel) {
+ <xsl:value-of select="java:getMethodSource($factory-loader,
string($src),$config)"/>
+ }
<!-- process all map:match elements with a type attribute refering
to the current matcher factory iteration -->
<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-name">
@@ -101,9 +105,6 @@
</xsl:variable>
/** The generated matcher for a pattern of "<xsl:value-of
select="@pattern"/>" */
<xsl:value-of
select="java:getClassSource($factory-loader,string($src),string($matcher-name),string(@pattern),$config)"/>
- private List <xsl:value-of select="$matcher-name"/> (String
pattern, Map objectModel) {
- <xsl:value-of
select="java:getMethodSource($factory-loader,string($src),string($matcher-name),string(@pattern),$config)"/>
- }
</xsl:for-each>
</xsl:if>
</xsl:for-each>
@@ -115,6 +116,9 @@
<xsl:variable name="type" select="@name"/>
<xsl:variable name="default" select="$type = ../@default"/>
<xsl:variable name="config"><xsl:copy-of
select="."/></xsl:variable>
+ private boolean <xsl:value-of select="$type"/>Select (<xsl:value-of
select="java:getParameterSource($factory-loader, string($src),$config)"/>
pattern, Map objectModel) {
+ <xsl:value-of select="java:getMethodSource($factory-loader,
string($src),$config)"/>
+ }
<!-- process all map:when elements with are in a map:chooser
element having a type attribute
refering to the current selector factory iteration -->
<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)]">
@@ -130,9 +134,6 @@
<xsl:if test="not(preceding::map:[EMAIL PROTECTED] =
$this-test])">
/** The generated selector for a test of "<xsl:value-of
select="@test"/>" */
<xsl:value-of
select="java:getClassSource($factory-loader,string($src),string(@test),string($selector-name),$config)"/>
- private boolean <xsl:value-of select="$selector-name"/>
(String pattern, Map objectModel) {
- <xsl:value-of
select="java:getMethodSource($factory-loader,string($src),string(@test),string($selector-name),$config)"/>
- }
</xsl:if>
</xsl:for-each>
</xsl:if>
@@ -144,6 +145,9 @@
<xsl:variable name="type" select="@name"/>
<xsl:variable name="default" select="$type = ../@default"/>
<xsl:variable name="config"><xsl:copy-of select="."/></xsl:variable>
+ private List <xsl:value-of select="$type"/>Match (<xsl:value-of
select="java:getParameterSource($factory-loader, string($factory),$config)"/>
pattern, Map objectModel) {
+ <xsl:value-of select="java:getMethodSource($factory-loader,
string($factory),$config)"/>
+ }
<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-name">
<xsl:call-template name="generate-name">
@@ -152,9 +156,6 @@
</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, Map objectModel) {
- <xsl:value-of
select="java:getMethodSource($factory-loader,string($factory),string($matcher-name),string(@pattern),$config)"/>
- }
</xsl:for-each>
</xsl:for-each>
@@ -164,7 +165,9 @@
<xsl:variable name="type" select="@name"/>
<xsl:variable name="default" select="$type = ../@default"/>
<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)]">
+ private boolean <xsl:value-of select="$type"/>Select (<xsl:value-of
select="java:getParameterSource($factory-loader, string($factory),$config)"/>
pattern, Map objectModel) {
+ <xsl:value-of select="java:getMethodSource($factory-loader,
string($factory),$config)"/>
+ } <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-name">
<xsl:call-template name="generate-name">
<xsl:with-param name="prefix">selector_</xsl:with-param>
@@ -176,9 +179,6 @@
</xsl:variable>
<xsl:if test="not(preceding::map:[EMAIL PROTECTED] = $this-test])">
<xsl:value-of
select="java:getClassSource($factory-loader,string($factory),string(@test),string($selector-name),$config)"/>
- private boolean <xsl:value-of select="$selector-name"/> (String
pattern, Map objectModel) {
- <xsl:value-of
select="java:getMethodSource($factory-loader,string($factory),string(@test),string($selector-name),$config)"/>
- }
</xsl:if>
</xsl:for-each>
</xsl:for-each>
@@ -424,7 +424,8 @@
</xsl:variable>
<!-- this is the actual code produced -->
- if ((list = <xsl:value-of select="$matcher-name"/> ("<xsl:value-of
select="$pattern-value"/>", objectModel)) != null) {
+ if ((list = <xsl:value-of select="$matcher-type"/>Match(<xsl:value-of
select="$matcher-name"/>_expr,
+ objectModel)) != null) {
listOfLists.add (list);
<xsl:apply-templates/>
listOfLists.remove (list);
No revision
No revision
1.1.2.9 +10 -5
xml-cocoon/src/org/apache/cocoon/matching/Attic/BrowserMatcherFactory.java
Index: BrowserMatcherFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/BrowserMatcherFactory.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- BrowserMatcherFactory.java 2000/09/27 16:07:20 1.1.2.8
+++ BrowserMatcherFactory.java 2000/10/25 16:02:17 1.1.2.9
@@ -23,14 +23,14 @@
* This class generates source code which matches a specific browser pattern
* for request URIs
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/09/27 16:07:20 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/10/25 16:02:17 $
*/
public class BrowserMatcherFactory implements MatcherFactory {
- public String generateMethodSource (String prefix, String
test_expression,
- DocumentFragment conf)
+ public String generateMethodSource (DocumentFragment conf)
throws ConfigurationException {
StringBuffer sb = new StringBuffer();
TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null,
false);
@@ -62,6 +62,11 @@
public String generateClassSource (String prefix, String pattern,
DocumentFragment conf)
throws ConfigurationException {
- return "";
+ return "\n// Dummy values\nstatic String " + prefix + "_expr = \"" +
pattern + "\";\n";
+ }
+
+ public String generateParameterSource (DocumentFragment conf)
+ throws ConfigurationException {
+ return "String";
}
}
1.1.2.12 +13 -11
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.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- RegexpURIMatcherFactory.java 2000/10/23 21:17:47 1.1.2.11
+++ RegexpURIMatcherFactory.java 2000/10/25 16:02:17 1.1.2.12
@@ -20,10 +20,16 @@
* for request URIs
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.11 $ $Date: 2000/10/23 21:17:47 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.12 $ $Date: 2000/10/25 16:02:17 $
*/
public class RegexpURIMatcherFactory implements MatcherFactory {
+ public String generateParameterSource (DocumentFragment conf)
+ throws ConfigurationException {
+ return "RE";
+ }
+
public String generateClassSource (String prefix, String pattern,
DocumentFragment conf)
throws ConfigurationException {
@@ -53,7 +59,7 @@
sb.append("\n };")
.append("\n static RE ")
.append(name)
- .append("Pattern = new RE(new REProgram(")
+ .append("_expr = new RE(new REProgram(")
.append(instructions)
.append("));");
return sb.toString();
@@ -62,24 +68,20 @@
}
}
- public String generateMethodSource (String prefix, String pattern,
- DocumentFragment conf)
+ public String generateMethodSource (DocumentFragment conf)
throws ConfigurationException {
StringBuffer sb = new StringBuffer ();
- String name = prefix;
- String instructions = name + "PatternInstructions";
- String pat = correctPattern (pattern);
sb.append("ArrayList list = new ArrayList ();")
-
.append("if(").append(name).append("Pattern.match(((HttpServletRequest)objectModel.get(Cocoon.REQUEST_OBJECT)).getRequestURI()))
{");
+
.append("if(pattern.match(((HttpServletRequest)objectModel.get(Cocoon.REQUEST_OBJECT)).getRequestURI()))
{");
// Count number of parens
- int i = 0;
+/* int i = 0;
int 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(")
+ sb.append("list.add (pattern.getParen(")
.append(++i).append("));");
}
- }
+ }*/
sb.append("return list; } else { return null; }");
return sb.toString();
}
1.1.2.17 +15 -12
xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java
Index: WildcardURIMatcherFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java,v
retrieving revision 1.1.2.16
retrieving revision 1.1.2.17
diff -u -r1.1.2.16 -r1.1.2.17
--- WildcardURIMatcherFactory.java 2000/10/23 19:44:45 1.1.2.16
+++ WildcardURIMatcherFactory.java 2000/10/25 16:02:17 1.1.2.17
@@ -17,8 +17,9 @@
* for request URIs
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.16 $ $Date: 2000/10/23 19:44:45 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.17 $ $Date: 2000/10/25 16:02:17 $
*/
public class WildcardURIMatcherFactory implements MatcherFactory {
@@ -38,17 +39,19 @@
protected int[] sourcePattern = null;
/**
+ * Generates the matcher parameter level source code
+ */
+ public String generateParameterSource (DocumentFragment conf)
+ throws ConfigurationException {
+ return "int []";
+ }
+
+ /**
* Generates the matcher method level source code
*/
- public String generateMethodSource (String prefix, String pattern,
- DocumentFragment conf)
+ public String generateMethodSource (DocumentFragment conf)
throws ConfigurationException {
- StringBuffer result = new StringBuffer();
- return result.append ("ArrayList list = new ArrayList();")
- .append ("if (WildcardURIMatcher.match
(list,((HttpServletRequest)objectModel.get(Cocoon.REQUEST_OBJECT)).getRequestURI(),
")
- .append(prefix).append("_expr))")
- .append ("return list;")
- .append ("else return null;").toString();
+ return " ArrayList list = new ArrayList();\n if
(WildcardURIMatcher.match (list, ((HttpServletRequest)
objectModel.get(Cocoon.REQUEST_OBJECT))\n
.getRequestURI(), pattern)) {\n return list;\n } else {\n
return null;\n }\n";
}
/**
@@ -61,7 +64,7 @@
try {
this.setPattern (pattern);
- result.append ("// wildcard pattern = \"" + pattern + "\"\n\t")
+ result.append ("\n// wildcard pattern = \"" + pattern + "\"\n\t")
.append ("static int[] ").append(prefix).append("_expr =
{");
int j = sourcePattern.length - 1;
@@ -71,7 +74,7 @@
.append (',');
}
return result.append (sourcePattern[j])
- .append ("};").toString();
+ .append ("};\n").toString();
} catch (NullPointerException pe) {
throw new ConfigurationException (pe.getMessage());
}
No revision
No revision
1.1.2.8 +11 -20
xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java
Index: BrowserSelectorFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- BrowserSelectorFactory.java 2000/10/08 21:07:34 1.1.2.7
+++ BrowserSelectorFactory.java 2000/10/25 16:02:18 1.1.2.8
@@ -25,18 +25,24 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/08 21:07:34 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/10/25 16:02:18 $
*/
public class BrowserSelectorFactory implements CodeFactory {
+ public String generateParameterSource (DocumentFragment conf)
+ throws ConfigurationException {
+ return "String";
+ }
+
public String generateClassSource (String test, String prefix,
DocumentFragment conf)
throws ConfigurationException {
- return "";
+ return "\nstatic String " + prefix + "_expr = \"" + test + "\";\n";
}
- public String generateMethodSource (String test, String prefix,
DocumentFragment conf)
+ public String generateMethodSource (DocumentFragment conf)
throws ConfigurationException {
TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null,
false);
Node node = null;
@@ -47,23 +53,8 @@
StringBuffer sb = new StringBuffer();
sb.append("if (pattern != null && objectModel.get(\"request\") !=
null) {")
.append("javax.servlet.http.HttpServletRequest request =
(javax.servlet.http.HttpServletRequest) objectModel.get(\"request\");")
- .append("String userAgent = request.getHeader(\"User-Agent\");");
- while ((node = tw.nextNode()) != null) {
- if (node.getNodeName().equals("browser") &&
- node.getNodeType() == Node.ELEMENT_NODE) {
- nm = node.getAttributes();
- if (nm != null) {
- nodeattrname = nm.getNamedItem("name");
- nodeattruseragent = nm.getNamedItem("useragent");
- if (nodeattrname != null && nodeattruseragent != null
- && nodeattrname.getNodeValue().equals(test)) {
- sb.append("if (userAgent.indexOf(\"")
- .append(nodeattruseragent.getNodeValue())
- .append("\") != -1) return true;");
- }
- }
- }
- }
+ .append("String userAgent = request.getHeader(\"User-Agent\");")
+ .append("if (userAgent.indexOf(pattern) != -1) return true;");
return sb.append("} return false;").toString();
}
}
No revision
No revision
1.1.2.4 +19 -4
xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTFactoryLoader.java
Index: XSLTFactoryLoader.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTFactoryLoader.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- XSLTFactoryLoader.java 2000/10/08 21:09:26 1.1.2.3
+++ XSLTFactoryLoader.java 2000/10/25 16:02:19 1.1.2.4
@@ -21,7 +21,8 @@
* <code>SelectorFactory</code>s to get the generated source code.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/10/08 21:09:26 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
+ * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/10/25 16:02:19 $
*/
public class XSLTFactoryLoader {
@@ -41,15 +42,29 @@
throw new Exception ("Wrong class \"" + factory.getClass().getName()
+ "\". Should implement the CodeFactory
interface");
}
-
- public String getMethodSource(String className, String prefix, String
pattern, DocumentFragment conf)
+
+ public String getParameterSource(String className, DocumentFragment conf)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException, Exception {
+ Object factory = obj.get(className);
+ if (factory == null) factory = ClassUtils.newInstance(className);
+ obj.put (className, factory);
+
+ if (factory instanceof CodeFactory) {
+ return ((CodeFactory) factory).generateParameterSource(conf);
+ }
+
+ throw new Exception ("Wrong class \"" + factory.getClass().getName()
+ + "\". Should implement the CodeFactory
interface");
+ }
+
+ public String getMethodSource(String className, DocumentFragment conf)
throws ClassNotFoundException, InstantiationException,
IllegalAccessException, Exception {
Object factory = obj.get(className);
if (factory == null) factory = ClassUtils.newInstance(className);
obj.put (className, factory);
if (factory instanceof CodeFactory) {
- return ((CodeFactory) factory).generateMethodSource(prefix,
pattern, conf);
+ return ((CodeFactory) factory).generateMethodSource(conf);
}
throw new Exception ("Wrong class \"" + factory.getClass().getName()
No revision
No revision
1.1.2.22 +3 -3 xml-cocoon/webapp/Attic/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/xml-cocoon/webapp/Attic/sitemap.xmap,v
retrieving revision 1.1.2.21
retrieving revision 1.1.2.22
diff -u -r1.1.2.21 -r1.1.2.22
--- sitemap.xmap 2000/10/09 06:43:59 1.1.2.21
+++ sitemap.xmap 2000/10/25 16:02:20 1.1.2.22
@@ -72,9 +72,9 @@
</map:selectors>
- <map:matchers default="uri">
- <map:matcher name="uri"
factory="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
- <map:matcher name="uri-regexp"
factory="org.apache.cocoon.matching.RegexpURIMatcherFactory"/>
+ <map:matchers default="wildcard">
+ <map:matcher name="wildcard"
factory="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
+ <map:matcher name="regexp"
factory="org.apache.cocoon.matching.RegexpURIMatcherFactory"/>
</map:matchers>
</map:components>