giacomo 00/07/19 15:20:05 Modified: . Tag: xml-cocoon2 todo.xml 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 HttpRequest.java src/org/apache/cocoon/matching Tag: xml-cocoon2 BrowserMatcherFactory.java MatcherFactory.java WildcardURIMatcherFactory.java src/org/apache/cocoon/selection Tag: xml-cocoon2 BrowserSelectorFactory.java SelectorFactory.java src/org/apache/cocoon/sitemap Tag: xml-cocoon2 XSLTMatcherFactoryLoader.java XSLTSelectorFactoryLoader.java xdocs/drafts Tag: xml-cocoon2 sitemap-working-draft.xmap Added: lib Tag: xml-cocoon2 jakarta-regexp-1.1.jar src/org/apache/cocoon/matching Tag: xml-cocoon2 RegexpURIMatcherFactory.java Log: Saving day work Revision Changes Path No revision No revision 1.6.2.9 +5 -1 xml-cocoon/todo.xml Index: todo.xml =================================================================== RCS file: /home/cvs/xml-cocoon/todo.xml,v retrieving revision 1.6.2.8 retrieving revision 1.6.2.9 diff -u -r1.6.2.8 -r1.6.2.9 --- todo.xml 2000/06/19 20:29:00 1.6.2.8 +++ todo.xml 2000/07/19 22:19:46 1.6.2.9 @@ -4,7 +4,7 @@ @@ -22,6 +22,10 @@ + + Write URLHandler for the protocols defined in the sitemap, e.g. class://. cvs:// + + Make Cocoon 2 Avalon-aware using the Component api from Avalon. No revision No revision 1.1.2.1 +109 -0 xml-cocoon/lib/Attic/jakarta-regexp-1.1.jar <> No revision No revision 1.1.2.10 +106 -34 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.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- sitemap.xsl 2000/07/18 22:55:38 1.1.2.9 +++ sitemap.xsl 2000/07/19 22:19:49 1.1.2.10 @@ -21,8 +21,9 @@ package ; - + import java.io.OutputStream; + import java.io.IOException; import java.util.Map; import java.util.Stack; @@ -35,21 +36,24 @@ import org.apache.cocoon.Request; import org.apache.cocoon.Response; - import org.apache.cocoon.selection.Selector; - import org.apache.cocoon.transformation.Transformer; import org.apache.cocoon.generation.Generator; import org.apache.cocoon.matching.Matcher; + import org.apache.cocoon.reading.Reader; + import org.apache.cocoon.selection.Selector; import org.apache.cocoon.serialization.Serializer; import org.apache.cocoon.sitemap.AbstractSitemapProcessor; - import org.apache.cocoon.sitemap.SitemapProcessor; + import org.apache.cocoon.sitemap.ProcessingException; import org.apache.cocoon.sitemap.ResourcePipeline; + import org.apache.cocoon.sitemap.SitemapProcessor; + import org.apache.cocoon.transformation.Transformer; + import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; /** * * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> - * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/07/18 22:55:38 $ + * @version CVS $Revision: 1.1.2.10 $ $Date: 2000/07/19 22:19:49 $ */ public class extends AbstractSitemapProcessor { @@ -58,6 +62,9 @@ private Generator generator_error_handler = null; + /* FIXME: only for testing */ + private boolean read (Request req, Response res, OutputStream out, String s, String a) {} + /** The generators */ @@ -69,6 +76,11 @@ private Transformer transformer_ = null; + /** The readers */ + + private Reader reader_ = null; + + /** The serializers */ private Serializer serializer_ = null; @@ -86,7 +98,7 @@ /** The sub sitemaps */ - SitemapProcessor sitemap_ = null; + SitemapProcessor sitemap_ = null; /** The generated matchers */ @@ -97,9 +109,10 @@ - - private Map _matcher_ (Request request) { - + matcher_ + + private Map (String pattern, Request request) { + } @@ -112,20 +125,34 @@ - - private boolean _selector_ (Request request) { - + selector_ + + private boolean (String test, Request request) { + } + + /** * Pass a <code>Configuration</code> instance to this * <code>Configurable</code> class. */ public void setConfiguration(Configuration xconf) throws ConfigurationException { - AttributeImpl attr = new AttributeImpl(); + AttributesImpl attr = new AttributesImpl(); /* Configure generators */ @@ -143,6 +170,14 @@ + + /* Configure readers */ + + reader + Reader + + /* Configure serializers */ @@ -169,18 +204,18 @@ /* Configure mounted sitemaps */ - SitemapManager sm = SitemapManager.getInstance(); - sm.beginRegistration (this); + /* SitemapManager sm = SitemapManager.getInstance(); */ + /* sm.beginRegistration (this); */ - sitemap_ = sm.registerSitemap (this, ""); - sitemap_.setConfiguration (null); + /* sitemap_ = sm.registerSitemap (this, ""); */ + sitemap_.setConfiguration (null); - sm.endRegistration (this); + /* sm.endRegistration (this); */ } private boolean resource_ (ResourcePipeline pipeline, - Stack mapStack, Request req, Response res, OutputStream out) + Stack mapStack, Request request, Response response, OutputStream out) throws SAXException, IOException, ProcessingException { Map map = null; Parameters param = null; @@ -232,7 +267,26 @@ true - if ((map = matcher_.match ("", request)) != null) { + + + + + + + matcher_.match + + + matcher_ + + + + cannot choose a matcher name + + + + + + if ((map = ("", request)) != null) { mapStack.push (map); } @@ -252,7 +306,26 @@ true - if (selector_.select ("", request)) { + + + + + + + selector_.select + + + selector_ + + + + cannot choose a selector name + + + + + + if ( ("", request)) { } @@ -289,23 +362,22 @@ return pipeline.process (request, response, out); + + + + setReader + reader + + return reader_.process (request, response, out); + + - - - - - - - + + /* environment.addUriPrefix (""); */ return sitemap_.process(request, response, out); - - return read (request, response, out, - "", ""); - - @@ -402,7 +474,7 @@ confBuilder.endElement("", "", ""); - confBuilder.endPrefixMapping("",""); + confBuilder.endPrefixMapping(""); No revision No revision 1.1.2.2 +3 -3 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.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- HttpEnvironment.java 2000/07/18 22:59:32 1.1.2.1 +++ HttpEnvironment.java 2000/07/19 22:19:50 1.1.2.2 @@ -34,10 +34,10 @@ * and HttpServletResponse objects */ public HttpEnvironment (HttpServletRequest req, HttpServletResponse res) { - this.req = new HttpRequest (req); - this.res = new HttpResponse (res); - this.uri = this.req.getRequestURI(true); + this.uri = req.getRequestURI(); this.view = req.getHeader("cocoon-view"); + this.req = new HttpRequest (req, this); + this.res = new HttpResponse (res); } /** * Adds an prefix to the overall stripped off prefix from the request uri 1.1.2.2 +7 -8 xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest.java Index: HttpRequest.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- HttpRequest.java 2000/07/18 22:59:33 1.1.2.1 +++ HttpRequest.java 2000/07/19 22:19:51 1.1.2.2 @@ -31,16 +31,16 @@ /** The real HttpServletRequest object */ private HttpServletRequest req = null; + /** The HttpEnvironment object */ + private HttpEnvironment env = null; + /** * Creates a HttpServletRequest based on a real HttpServletRequest object */ - protected HttpRequest (HttpServletRequest req) { + protected HttpRequest (HttpServletRequest req, HttpEnvironment env) { super (); this.req = req; - } - - protected String getRequestURI(boolean dummy) { - return this.req.getRequestURI(); + this.env = env; } /* The HttpServletRequest interface methods */ @@ -109,9 +109,8 @@ return this.req.getRequestedSessionId(); } - public String getRequestURI() throws IllegalStateException { - throw new IllegalStateException ("you must call the getUri() from the Environment"); - //return this.req.getRequestURI(); + public String getRequestURI() { + return this.env.getUri(); } public String getServletPath() { No revision No revision 1.1.2.5 +36 -4 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.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- BrowserMatcherFactory.java 2000/07/18 22:56:19 1.1.2.4 +++ BrowserMatcherFactory.java 2000/07/19 22:19:53 1.1.2.5 @@ -10,19 +10,51 @@ import java.util.Stack; import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.traversal.TreeWalker; +import org.w3c.dom.traversal.NodeFilter; + +import org.apache.xerces.dom.TreeWalkerImpl; /** * This class generates source code which matches a specific browser pattern * for request URIs * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/18 22:56:19 $ + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/07/19 22:19:53 $ */ public class BrowserMatcherFactory implements MatcherFactory { - public String generate (String test_expression, DocumentFragment conf) { + public String generateMethodLevel (String prefix, String test_expression, DocumentFragment conf) throws Exception { StringBuffer sb = new StringBuffer(); - sb.append("return null;"); - return (sb.toString()); + TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null, false); + Node node = null; + Node nodea = null; + NamedNodeMap nm = null; + + sb.append ("/*\n"); + while ((node = tw.nextNode()) != null) { + sb.append("name=") + .append(node.getNodeName()) + .append(" type=") + .append(node.getNodeType()) + .append(" value="+node.getNodeValue()+"\n"); + nm = node.getAttributes(); + if (nm != null) { + int i = nm.getLength(); + for (int j = 0; j < i; j++) { + nodea = nm.item(j); + sb.append("name="+nodea.getNodeName()) + .append(" type="+nodea.getNodeType()) + .append(" value="+nodea.getNodeValue()+"\n"); + } + } + } + return sb.append("*/\nreturn null;").toString(); + } + + public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) throws Exception { + return ""; } } 1.1.2.3 +3 -2 xml-cocoon/src/org/apache/cocoon/matching/Attic/MatcherFactory.java Index: MatcherFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/MatcherFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- MatcherFactory.java 2000/07/17 21:06:11 1.1.2.2 +++ MatcherFactory.java 2000/07/19 22:19:53 1.1.2.3 @@ -18,9 +18,10 @@ * sitemap code generation. * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/17 21:06:11 $ + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/19 22:19:53 $ */ public interface MatcherFactory { - public String generate (String pattern, DocumentFragment conf) throws Exception; + public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) throws Exception; + public String generateMethodLevel (String prefix, String pattern, DocumentFragment conf) throws Exception; } 1.1.2.3 +27 -15 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.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- WildcardURIMatcherFactory.java 2000/07/17 21:06:12 1.1.2.2 +++ WildcardURIMatcherFactory.java 2000/07/19 22:19:55 1.1.2.3 @@ -17,7 +17,7 @@ * for request URIs * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/17 21:06:12 $ + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/19 22:19:55 $ */ public class WildcardURIMatcherFactory /*extends PatternTranslator*/ implements MatcherFactory { @@ -33,29 +33,40 @@ protected int[] sourcePattern=null; /** - * Generates the matcher method source code + * Generates the matcher method level source code */ - public String generate (String pattern, DocumentFragment conf) + public String generateMethodLevel (String prefix, String pattern, DocumentFragment conf) throws PatternException { StringBuffer result = new StringBuffer(); + return result.append ("Stack stack = new Stack();") + .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (stack, request.getUri(), ") + .append(prefix).append("_expr))") + .append ("return (Map) stack;") + .append ("else return null;").toString(); + } + + /** + * Generates the matcher class level source code + */ + public String generateClassLevel (String prefix, String pattern, DocumentFragment conf) + throws PatternException { + StringBuffer result = new StringBuffer(); this.setPattern (pattern); - result.append ("Stack stack = new Stack();"); - result.append ("/* pattern=\""+pattern+"\" */"); - result.append ("int expr[] = {"); + result.append ("/* pattern=\""+pattern+"\" */") + .append ("int expr[] = {"); int j = sourcePattern.length-1; char c; for (int i = 0; i < j; i++) { - result.append (sourcePattern[i]); - result.append (','); + result.append (sourcePattern[i]) + .append (','); } - result.append (sourcePattern[j]); - result.append ("};"); - result.append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (stack, request.getUri(), expr))"); - result.append ("return (Map) stack;"); - result.append ("else return null;"); - return result.toString(); + return result.append (sourcePattern[j]) + .append ("};") + .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (stack, request.getUri(), expr))") + .append ("return (Map) stack;") + .append ("else return null;").toString(); } /** @@ -142,7 +153,8 @@ if (argv.length<1) return; System.out.println("Matching Expr. \""+argv[0]+"\""); WildcardURIMatcherFactory wm = new WildcardURIMatcherFactory(); - System.out.println(wm.generate (argv[0], null)); + System.out.println(wm.generateClassLevel ("", argv[0], null)); + System.out.println(wm.generateMethodLevel ("", argv[0], null)); } catch (Exception e) { System.out.println(e.getClass().getName()); System.out.println(e.getMessage()); No revision No revision 1.1.2.1 +74 -0 xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java No revision No revision 1.1.2.3 +7 -2 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.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- BrowserSelectorFactory.java 2000/07/17 21:06:12 1.1.2.2 +++ BrowserSelectorFactory.java 2000/07/19 22:19:57 1.1.2.3 @@ -14,11 +14,16 @@ * agains the requesting user-agent * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/17 21:06:12 $ + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/19 22:19:57 $ */ public class BrowserSelectorFactory implements SelectorFactory { - public String generate (String test_expression, DocumentFragment conf) { + + public String generateClassLevel (String test, String prefix, DocumentFragment conf) throws Exception { + return ""; + } + + public String generateMethodLevel (String test, String prefix, DocumentFragment conf) throws Exception { return "return true;"; } } 1.1.2.3 +3 -2 xml-cocoon/src/org/apache/cocoon/selection/Attic/SelectorFactory.java Index: SelectorFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/SelectorFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- SelectorFactory.java 2000/07/17 21:06:13 1.1.2.2 +++ SelectorFactory.java 2000/07/19 22:19:58 1.1.2.3 @@ -18,9 +18,10 @@ * sitemap code generation. * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/17 21:06:13 $ + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/19 22:19:58 $ */ public interface SelectorFactory { - public String generate (String test, DocumentFragment conf) throws Exception; + public String generateClassLevel (String test, String prefix, DocumentFragment conf) throws Exception; + public String generateMethodLevel (String test, String prefix, DocumentFragment conf) throws Exception; } No revision No revision 1.1.2.4 +23 -5 xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTMatcherFactoryLoader.java Index: XSLTMatcherFactoryLoader.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTMatcherFactoryLoader.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- XSLTMatcherFactoryLoader.java 2000/07/17 21:06:14 1.1.2.3 +++ XSLTMatcherFactoryLoader.java 2000/07/19 22:20:00 1.1.2.4 @@ -7,6 +7,8 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; +import java.util.Hashtable; + import org.apache.cocoon.matching.MatcherFactory; import org.w3c.dom.DocumentFragment; @@ -17,15 +19,31 @@ * generated source code. * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/17 21:06:14 $ + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/07/19 22:20:00 $ */ public class XSLTMatcherFactoryLoader { + + Hashtable obj = new Hashtable (); - public String getSource (String matcherFactoryClassname, String pattern, DocumentFragment conf) + public String getSource (String level, String matcherFactoryClassname, String pattern, + String prefix, DocumentFragment conf) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { - Class cl = this.getClass().getClassLoader().loadClass(matcherFactoryClassname); - MatcherFactory factory = (MatcherFactory) cl.newInstance(); - return factory.generate (pattern, conf); + MatcherFactory factory = null; +/* + MatcherFactory factory = (MatcherFactory) obj.get(matcherFactoryClassname); + if (factory == null) { +*/ + Class cl = this.getClass().getClassLoader().loadClass(matcherFactoryClassname); + factory = (MatcherFactory) cl.newInstance(); +/* + obj.put (matcherFactoryClassname, factory); + } +*/ + if ("class".equals(level)) { + return factory.generateClassLevel (pattern, prefix, conf); + } else { + return factory.generateMethodLevel (pattern, prefix, conf); + } } } 1.1.2.3 +23 -5 xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTSelectorFactoryLoader.java Index: XSLTSelectorFactoryLoader.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/XSLTSelectorFactoryLoader.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- XSLTSelectorFactoryLoader.java 2000/07/17 21:06:14 1.1.2.2 +++ XSLTSelectorFactoryLoader.java 2000/07/19 22:20:00 1.1.2.3 @@ -7,6 +7,8 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; +import java.util.Hashtable; + import org.apache.cocoon.selection.SelectorFactory; import org.w3c.dom.DocumentFragment; @@ -17,15 +19,31 @@ * generated source code. * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/07/17 21:06:14 $ + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/19 22:20:00 $ */ public class XSLTSelectorFactoryLoader { + + Hashtable obj = new Hashtable (); - public String getSource (String selectorFactoryClassname, String test, DocumentFragment conf) + public String getSource (String level, String selectorFactoryClassname, String test, + String prefix, DocumentFragment conf) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { - Class cl = this.getClass().getClassLoader().loadClass(selectorFactoryClassname); - SelectorFactory factory = (SelectorFactory) cl.newInstance(); - return factory.generate (test, conf); + SelectorFactory factory = null; +/* + SelectorFactory factory = (SelectorFactory ) obj.get(selectorFactoryClassname); + if (factory == null) { +*/ + Class cl = this.getClass().getClassLoader().loadClass(selectorFactoryClassname); + factory = (SelectorFactory) cl.newInstance(); +/* + obj.put (selectorFactoryClassname, factory); + } +*/ + if ("class".equals(level)) { + return factory.generateClassLevel (test, prefix, conf); + } else { + return factory.generateMethodLevel (test, prefix, conf); + } } } No revision No revision 1.1.2.11 +66 -49 xml-cocoon/xdocs/drafts/Attic/sitemap-working-draft.xmap Index: sitemap-working-draft.xmap =================================================================== RCS file: /home/cvs/xml-cocoon/xdocs/drafts/Attic/sitemap-working-draft.xmap,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- sitemap-working-draft.xmap 2000/07/17 21:06:15 1.1.2.10 +++ sitemap-working-draft.xmap 2000/07/19 22:20:02 1.1.2.11 @@ -133,7 +133,7 @@ - + ... @@ -149,11 +149,19 @@ - - + + + + + + + @@ -209,9 +217,13 @@ ... - - ... - + + ... + + + + ... + ... @@ -225,15 +237,15 @@ depending on the matcher own logic (this is up to the matcher implementation). --> - + ... - + ... - + baz red @@ -320,42 +332,46 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + @@ -502,7 +519,7 @@ - +