vgritsenko 02/02/05 20:40:28 Modified: src/java/org/apache/cocoon/components/language/markup AbstractMarkupLanguage.java src/java/org/apache/cocoon/components/language/markup/sitemap SitemapMarkupLanguage.java src/java/org/apache/cocoon/components/language/markup/xsp XSPMarkupLanguage.java src/java/org/apache/cocoon/components/language/markup/xsp/java cookie.xsl session.xsl xscript-lib.xsl xsp.xsl Added: src/java/org/apache/cocoon/components/language/markup CocoonMarkupLanguage.java src/java/org/apache/cocoon/components/language/markup/xsp/java XSLTExtension.java Log: Markup engine fixes: - Move commonalities from sitemap and xsp languages into CocoonMarkupLanguage - Quote PCDATA text using XSLT extension class. Fixes bug with logicsheets containing text - Fix xscript logicsheet Revision Changes Path 1.11 +31 -2 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java Index: AbstractMarkupLanguage.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AbstractMarkupLanguage.java 4 Feb 2002 12:22:22 -0000 1.10 +++ AbstractMarkupLanguage.java 6 Feb 2002 04:40:28 -0000 1.11 @@ -102,7 +102,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> - * @version CVS $Id: AbstractMarkupLanguage.java,v 1.10 2002/02/04 12:22:22 cziegeler Exp $ + * @version CVS $Id: AbstractMarkupLanguage.java,v 1.11 2002/02/06 04:40:28 vgritsenko Exp $ */ public abstract class AbstractMarkupLanguage extends AbstractLoggable @@ -115,6 +115,9 @@ /** Prefix for cache keys to avoid name clash with the XSLTProcessor */ private static final String CACHE_PREFIX = "logicsheet:"; + /** This language name */ + protected String name; + /** The supported language table */ protected HashMap languages; @@ -136,11 +139,16 @@ /** The URL factory source resolver used to resolve URIs */ private URLFactorySourceResolver urlResolver; + + /** + * Stores the list of logicsheets required by the currently + * loaded program. + */ private final LinkedList logicSheetList = new LinkedList(); /** The default constructor. */ - public AbstractMarkupLanguage() throws SAXException, IOException { + public AbstractMarkupLanguage() { // Initialize language table this.languages = new HashMap(); } @@ -154,6 +162,8 @@ */ public void configure(Configuration conf) throws ConfigurationException { try { + name = conf.getAttribute("name"); + // Set up each target-language Configuration[] l = conf.getChildren("target-language"); for (int i = 0; i < l.length; i++) { @@ -233,11 +243,17 @@ this.urlResolver = new URLFactorySourceResolver(this.urlFactory, manager); } + /** + * Recycle this component: clear logic sheet list and dependencies. + */ public void recycle() { this.logicSheetList.clear(); } + /** + * Release all resources. + */ public void dispose() { if (this.logicsheetCache != null) this.manager.release(this.logicsheetCache); @@ -261,13 +277,25 @@ } /** + * Return the markup language name. Two markup languages are + * well-know at the moment: sitemap and xsp. + * + * @return The language name. + */ + public String getName() { + return this.name; + } + + /** * Return the source document's encoding. This can be <code>null</code> for * the platform's default encoding. The default implementation returns * <code>null</code>, but derived classes may override it if encoding applies to * their concrete languages. + * * FIXME: There should be a way to get the * XML document's encoding as seen by the parser; unfortunately, this * information is not returned by current DOM or SAX parsers... + * * @return The document-specified encoding */ public String getEncoding() { @@ -317,6 +345,7 @@ * Add a dependency on an external file to the document for inclusion in * generated code. This is used to populate a list of <code>File</code>'s * tested for change on each invocation; this information is used to assert whether regeneration is necessary. + * * @param location The file path of the dependent file * @see <code>AbstractMarkupLanguage</code>, <code>ServerPagesGenerator</code> and <code>AbstractServerPage</code> */ 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/CocoonMarkupLanguage.java Index: CocoonMarkupLanguage.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache Cocoon" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.cocoon.components.language.markup; import org.apache.avalon.framework.logger.Loggable; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.components.language.programming.ProgrammingLanguage; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLFilterImpl; import org.xml.sax.helpers.XMLReaderFactory; import org.xml.sax.helpers.AttributesImpl; import org.apache.log.Logger; import java.util.Map; import java.util.Stack; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.io.File; import java.io.IOException; /** * Base implementation of <code>MarkupLanguage</code>. This class uses * logicsheets as the only means of code generation. Code generation * should be decoupled from this context!!! * * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Sahuc</a> * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @version CVS $Id: CocoonMarkupLanguage.java,v 1.1 2002/02/06 04:40:28 vgritsenko Exp $ */ public abstract class CocoonMarkupLanguage extends AbstractMarkupLanguage { /** * Store the dependencies of the currently loaded program. */ private final Set dependencies = new HashSet(); /** The default constructor. */ public CocoonMarkupLanguage() { } /** * Recycle this component: clear logic sheet list and dependencies. */ public void recycle() { super.recycle(); this.dependencies.clear(); } /** * Prepare the input source for logicsheet processing and code generation * with a preprocess filter. * The return <code>XMLFilter</code> object is the first filter on the * transformer chain. * * The markup language preprocess filter adds information on the root element * such as creation-date, file-name and file-path, plus it use the the passed * programming language to quote <code>Strings</code> on PCDATA node. * * @param filename The source filename * @param language The target programming language * @return The preprocess filter * * @see DefautlMarkupLanguage.PreProcessFilter */ protected XMLFilter getPreprocessFilter(String filename, ProgrammingLanguage language) { PreProcessFilter filter = new PreProcessFilter(filename, language); filter.setLogger(getLogger()); return filter; } /** * Returns a filter that chain on the fly the requested transformers for source * code generation. This method scans the input SAX events for * <?xml-logicsheet?> processing instructions and top-level * <prefix:logicsheet> elements. Logicsheet declarations are removed from * the input document. * * @param logicsheetMarkupGenerator the logicsheet markup generator * @param language the language descriptor * @param resolver the entity resolver * @return XMLFilter the filter that build on the fly the transformer chain */ protected TransformerChainBuilderFilter getTransformerChainBuilder( LogicsheetCodeGenerator logicsheetMarkupGenerator, SourceResolver resolver) { CocoonTransformerChainBuilderFilter filter = new CocoonTransformerChainBuilderFilter( logicsheetMarkupGenerator, resolver); filter.setLogger(getLogger()); return filter; } // This is required here to avoid IllegalAccessError when // CocoonTransformerChainBuilderFilter invokes the method. protected void addLogicsheetToList(LanguageDescriptor language, String logicsheetLocation, SourceResolver resolver) throws IOException, SAXException, ProcessingException { super.addLogicsheetToList(language, logicsheetLocation, resolver); } /** * Add a dependency on an external file to the document for inclusion in * generated code. This is used to populate a list of <code>File</code>'s * tested for change on each invocation; this information is used to assert * whether regeneration is necessary. XSP uses <xsp:dependency> * elements for this purpose. * * @param location The file path of the dependent file * @see <code>AbstractMarkupLanguage</code>, <code>ServerPagesGenerator</code> * and <code>AbstractServerPage</code> */ protected void addDependency(String location) { dependencies.add(location); } /** * Returns the namespace URI for this language. */ public String getURI() { return super.uri; } /** * Returns the root element for this language. */ public abstract String getRootElement(); // // Inner classes // /** * Preprocess filter for Cocoon Markup languages. * It looks for PI event other that <?xml-logisheet href="..."> * for quoting them; * It adds creation-date, file-name and file-path attributes to the root * Element; * And it quotes the PCDATA based by calling the quote method of the * programming language. * * @see org.xml.sax.ContentHandler */ public class PreProcessFilter extends XMLFilterImpl implements Loggable { protected Logger log; protected String filename; protected boolean isRootElem; protected ProgrammingLanguage language; protected String localPrefix; /** * @param filename the filename * @param the programming language */ public PreProcessFilter (String filename, ProgrammingLanguage language) { super (); this.filename = filename; this.language = language; } public void setLogger(Logger logger) { if (this.log == null) { this.log = logger; } } public void startDocument() throws SAXException { super.startDocument(); isRootElem = true; } public void processingInstruction(String target, String data) throws SAXException { if (!"xml-logicsheet".equals(target)) { data = this.language.quoteString(data); } super.processingInstruction(target, data); } public void startPrefixMapping(String prefix, String uri) throws SAXException { if (CocoonMarkupLanguage.this.getURI().equals(uri)) { this.localPrefix = prefix; } super.startPrefixMapping(prefix, uri); } public void startElement (String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (isRootElem) { if (!CocoonMarkupLanguage.this.getURI().equals(namespaceURI) || !CocoonMarkupLanguage.this.getRootElement().equals(localName)) { throw new SAXException("This page is not valid page of this markup langugage." + " Root element is: " + namespaceURI + ":" + localName + ", must be: " + CocoonMarkupLanguage.this.getURI() + ":" + CocoonMarkupLanguage.this.getRootElement()); } isRootElem=false; // Store path and file name int pos = this.filename.lastIndexOf(File.separatorChar); String name = this.filename.substring(pos + 1); String path = this.filename.substring(0, pos).replace(File.separatorChar, '/'); // update the attributes AttributesImpl newAtts = new AttributesImpl(atts); newAtts.addAttribute("", "file-name", "file-name", "CDATA", name); newAtts.addAttribute("", "file-path", "file-path", "CDATA", path); newAtts.addAttribute("", "creation-date", "creation-date", "CDATA", String.valueOf(System.currentTimeMillis())); // forward element with the modified attribute super.startElement(namespaceURI, localName, qName, newAtts); } else { super.startElement(namespaceURI, localName, qName, atts); } } } /** * This filter builds on the fly a chain of transformers. It extends the * <code>AbstractMarkupLanguage.TransformerChainBuilderFilter</code> so * it can add common markup language features such as: * <ul> * <li>Looking for <?xml-logisheet href="..."?;> PI and * <xsp:xml-logisheet location="..."> elements to register * user defined logicsheets;</li> * <li>Adding all the dependencies related to the pages as * <xsp:dependency;>...</xsp:dependency;></li> * </ul> * * @see org.xml.sax.ContentHandler */ public class CocoonTransformerChainBuilderFilter extends TransformerChainBuilderFilter implements Loggable { protected Logger log; private List startPrefix; private Object[] rootElement; private StringBuffer rootChars; private boolean isRootElem; private boolean insideRootElement; private boolean finished; private String localPrefix; /** * @param logicsheetMarkupGenerator the code generator * @param resolver the entity resolver */ public CocoonTransformerChainBuilderFilter( LogicsheetCodeGenerator logicsheetMarkupGenerator, SourceResolver resolver) { super(logicsheetMarkupGenerator, resolver); } public void setLogger(Logger logger) { if (this.log == null) { this.log = logger; } } public void processingInstruction(String target, String data) throws SAXException { // Retrieve logicsheets declared by processing-instruction if ("xml-logicsheet".equals(target)) { int start = data.indexOf("href"); if (start >= 0) { // add 6, for lenght of 'href', plus '=' char, plus '"' char start += 6; // get the quote char. Can be " or ' char quote = data.charAt(start-1); int end = data.indexOf(quote, start); String href = data.substring(start, end); try { CocoonMarkupLanguage.this.addLogicsheetToList( language, href, this.resolver); } catch (ProcessingException pe) { log.warn("ProcessingException in SitemapMarkupLanguage", pe); throw new SAXException (pe); } catch (IOException ioe) { log.warn("CocoonMarkupLanguage.processingInstruction", ioe); throw new SAXException (ioe); } } // Do not forward the PI event. return; } // Call super when this is not a logicsheet related PI super.processingInstruction(target,data); } public void startDocument () throws SAXException { isRootElem=true; insideRootElement=false; finished=false; startPrefix = new ArrayList(); rootChars = new StringBuffer(); } public void startElement (String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (finished) { // Call super method super.startElement(namespaceURI, localName, qName, atts); } else { // Need more work if(isRootElem) { localPrefix = ""; if (qName.indexOf(':') != -1) localPrefix = qName.substring(0, qName.indexOf(':')); isRootElem = false; // Cache the root element and resend the SAX event when // we've finished dealing with <xsp:logicsheet > elements rootElement = new Object[4]; rootElement[0]=namespaceURI; rootElement[1]=localName; rootElement[2]=qName; rootElement[3]=atts; } else { insideRootElement = true; // Retrieve logicsheets declared by top-level elements <xsp:logicsheet ...> // And do not forward the startElement event if (CocoonMarkupLanguage.this.getURI().equals(namespaceURI) && "logicsheet".equals(localName)) { String href = atts.getValue("location"); try { CocoonMarkupLanguage.this.addLogicsheetToList( language, href, this.resolver); } catch (ProcessingException pe) { log.warn("DEfautlMarkupLanguage.startElement", pe); throw new SAXException (pe); } catch (IOException ioe) { log.warn("DEfautlMarkupLanguage.startElement", ioe); throw new SAXException (ioe); } } else { // This element is not a <xsp:logicsheet> element, so finish // by: // * setting the 'fisnished' flag to true ; // * refiring all the cached events ; // * firing all the necessary event dealing with file dependencies finished = true; // Send SAX events 'startDocument' super.startDocument(); // Send all prefix namespace String [] prefixArray; for (int i=0; i<startPrefix.size(); i++) { prefixArray = (String []) startPrefix.get(i); super.startPrefixMapping(prefixArray[0], prefixArray[1]); } // Send cached RootElement event super.startElement( (String) rootElement[0], (String) rootElement[1], (String) rootElement[2], (Attributes) rootElement[3] ); // Send cached characters char[] ch = rootChars.toString().toCharArray(); super.characters( ch, 0, ch.length); // Send the events dealing with dependencies. // If some dependencies exist, then creates // <xsp:dependency> elements char[] locationChars; Iterator iter = CocoonMarkupLanguage.this.dependencies.iterator(); while(iter.hasNext()) { super.startElement( namespaceURI, "dependency", localPrefix + ":dependency", new AttributesImpl() ); locationChars = ((String) iter.next()).toCharArray(); super.characters(locationChars, 0 , locationChars.length); super.endElement(namespaceURI, "dependency", localPrefix + ":dependency"); } // And finally forward current Element. super.startElement(namespaceURI, localName, qName, atts); } } } } public void endElement (String namespaceURI, String localName, String qName) throws SAXException { if (finished) { // Forward the events super.endElement(namespaceURI, localName, qName); } } public void characters(char[] ch, int start, int length) throws SAXException { if (finished) { super.characters(ch, start, length); } else if(!insideRootElement) { // Caching the PCDATA for the root element rootChars.append(ch, start, length); } } public void startPrefixMapping(String prefix, String uri) throws SAXException { if(finished) { super.startPrefixMapping(prefix, uri); } else { String[] prefixArray = new String [2]; prefixArray[0]= prefix; prefixArray[1]= uri; startPrefix.add(prefixArray); } } } } 1.8 +6 -425 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/sitemap/SitemapMarkupLanguage.java Index: SitemapMarkupLanguage.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/sitemap/SitemapMarkupLanguage.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SitemapMarkupLanguage.java 4 Feb 2002 12:22:22 -0000 1.7 +++ SitemapMarkupLanguage.java 6 Feb 2002 04:40:28 -0000 1.8 @@ -59,8 +59,8 @@ import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.components.language.markup.AbstractMarkupLanguage; import org.apache.cocoon.components.language.markup.LogicsheetCodeGenerator; +import org.apache.cocoon.components.language.markup.CocoonMarkupLanguage; import org.apache.cocoon.components.language.programming.ProgrammingLanguage; import org.apache.cocoon.environment.SourceResolver; import org.apache.log.Logger; @@ -79,431 +79,12 @@ * This class implements <code>MarkupLanguage</code> for Cocoon's * <a href="http://xml.apache.org/cocoon2/userdocs/concepts/sitemap.html">Sitemap</a>. * - * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Id: SitemapMarkupLanguage.java,v 1.7 2002/02/04 12:22:22 cziegeler Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @version CVS $Id: SitemapMarkupLanguage.java,v 1.8 2002/02/06 04:40:28 vgritsenko Exp $ */ -public class SitemapMarkupLanguage extends AbstractMarkupLanguage { +public class SitemapMarkupLanguage extends CocoonMarkupLanguage { - /** - * The dependencies' list - */ - private Set dependencies; - - /** - * The default constructor. - */ - public SitemapMarkupLanguage() throws SAXException, IOException { - super(); - dependencies = new HashSet(); - } - - public void recycle() - { - super.recycle(); - this.dependencies.clear(); - } - - - /** - * Return the Sitemap language name: <i>map</i> :-) - * - * @return The <i>map</i> constant - */ - public String getName() { - return "map"; - } - - /** - * FIXME (SSA) : See interface. For now returns null. - * - * Return the document-declared encoding or <code>null</code> if it's the - * platform's default encoding - * - * @return The document-declared encoding - */ - public String getEncoding() { - return null; - } - - /** - * Prepare the input source for logicsheet processing and code generation - * with a preprocess filter. - * The return <code>XMLFilter</code> object is the first filter on the - * transformer chain. - * - * The Sitemap preprocess filter adds information on the root element such as - * creation-date, file-name and file-path, plus it use the the passed - * programming language to quote <code>Strings</code> on PCDATA node. - * - * @param filename The source filename - * @param language The target programming language - * @return The preprocess filter - * - * @see SitemapMarkupLanguage.PreProcessFilter - * - */ - protected XMLFilter getPreprocessFilter( String filename, ProgrammingLanguage language ) - { - return new PreProcessFilter(filename, language); - } - - /** - * Add a dependency on an external file to the document for inclusion in - * generated code. This is used to populate a list of <code>File</code>'s - * tested for change on each invocation; this information is used to assert - * whether regeneration is necessary. - * - * @param location The file path of the dependent file - * @see <code>AbstractMarkupLanguage</code>, <code>ServerPagesGenerator</code> - * and <code>AbstractServerPage</code> - */ - protected void addDependency(String location) { - dependencies.add(location); - } - - // This is required here to avoid IllegalAccessError when - // SitemapTransformerChainBuilderFilter invokes the method. - protected void addLogicsheetToList(LanguageDescriptor language, - String logicsheetLocation, - SourceResolver resolver) - throws IOException, SAXException, ProcessingException - { - super.addLogicsheetToList(language, logicsheetLocation, resolver); - } - - /** - * Returns a filter that chain on the fly the requested transformers - * for source code generation. This method scans the input SAX events for - * <?xml-logicsheet?> processing instructions and top-level - * <map:logicsheet> elements. Logicsheet declarations are removed from - * the input document. - * - * @param logicsheetMarkupGenerator the logicsheet markup generator - * @param language the language descriptor - * @param resolver the entity resolver - * @return XMLFilter the filter that build on the fly the transformer chain - */ - protected TransformerChainBuilderFilter getTransformerChainBuilder ( - LogicsheetCodeGenerator logicsheetMarkupGenerator, - SourceResolver resolver) - { - SitemapTransformerChainBuilderFilter filter = - new SitemapTransformerChainBuilderFilter( - logicsheetMarkupGenerator, resolver - ); - filter.setLogger(getLogger()); - return filter; - } - - -// -// Inner classes -// - - /** - * Preprocess filter for Sitemap Markup language. - * It looks for PI event other that <?xml-logisheet href="..."> - * for quoting them; - * It adds creation-date, file-name and file-path attributes to the root - * Element; - * And it quotes the PCDATA based by calling the quote method of the - * programming language. - * - */ - protected class PreProcessFilter extends XMLFilterImpl { - protected Logger log; - - private String filename; - - private boolean isRootElem; - - private ProgrammingLanguage language; - - public PreProcessFilter (String filename, ProgrammingLanguage language) { - super (); - this.filename = filename; - this.language = language; - } - - public void setParent(XMLReader reader) { - reader.setContentHandler(this); - super.setParent(reader); - } - - public void setLogger(Logger logger) { - if (this.log == null) { - this.log = logger; - } - } - - public void startDocument() throws SAXException { - super.startDocument(); - isRootElem = true; - } - - public void processingInstruction(String target, String data) throws SAXException { - if (!"xml-logicsheet".equals(target)) { - data = this.language.quoteString(data); - } - super.processingInstruction(target, data); - } - - public void startElement (String namespaceURI, String localName, - String qName, Attributes atts) throws SAXException { - if (isRootElem) { - isRootElem=false; - // Store path and file name - int pos = this.filename.lastIndexOf(File.separatorChar); - String name = this.filename.substring(pos + 1); - String path = - this.filename.substring(0, pos).replace(File.separatorChar, '/'); - // update the attributes - AttributesImpl newAtts = new AttributesImpl(); - - // FIXME (SSA) workaround a bug in SAX2 that goes in infinite loop - // when atts.getLength() == 0 - if (atts.getLength()>0) - newAtts.setAttributes(atts); - - newAtts.addAttribute("", "file-name", "file-name", "CDATA", name); - newAtts.addAttribute("", "file-path", "file-path", "CDATA", path); - newAtts.addAttribute("", "creation-date", "creation-date", - "CDATA", String.valueOf(System.currentTimeMillis()) - ); - // forward element with the modified attribute - super.startElement(namespaceURI, localName, qName, newAtts); - } else { - super.startElement(namespaceURI, localName, qName, atts); - } - } - } - - /** - * This filter builds on the fly a chain of transformers. It extends the - * <code>AbstractMArkupLanguage.TransformerChainBuilderFilter</code> so - * it can adds XSP specific feature such as : - * looking for <?xml-logisheet href="..."?;> PI and - * <map:xml-logisheet location="..."> elements to register - * user defined logicsheets ; - * adding all the dependencies related to the Sitemap as - * <map:dependency;>...</map:dependency;> - * - */ - protected class SitemapTransformerChainBuilderFilter extends TransformerChainBuilderFilter implements Loggable { - protected Logger log; - - private Object[] rootElement; - - private List startPrefix; - - private List endPrefix; - - private StringBuffer rootChars; - - private boolean isRootElem; - - private boolean insideRootElement; - - private boolean finished; - - public void setLogger(Logger logger) { - if (this.log == null) { - this.log = logger; - } - } - - /** - * default constructor - * - * @param logicsheetMarkupGenerator the code generator - * @param resolver the entity resolver - */ - protected SitemapTransformerChainBuilderFilter ( - LogicsheetCodeGenerator logicsheetMarkupGenerator, - SourceResolver resolver - ) { - super(logicsheetMarkupGenerator, resolver); - } - - /** - * @see org.xml.sax.ContentHandler - */ - public void startDocument () throws SAXException { - isRootElem=true; - insideRootElement=false; - finished=false; - startPrefix = new ArrayList(); - rootChars = new StringBuffer(); - } - - /** - * @see org.xml.sax.ContentHandler - */ - public void processingInstruction(String target, String data) throws SAXException { - // Retrieve logicsheets declared by processing-instruction - if ("xml-logicsheet".equals(target)) { - int start = data.indexOf("href"); - if (start >=0) { - // add 6, for lenght of 'href', plus '=' char, plus '"' char - start += 6; - // get the quote char. Can be " or ' - char quote = data.charAt(start-1); - String href = data.substring(start); - int end = href.indexOf(quote); - href = href.substring(0, end); - try { - SitemapMarkupLanguage.this.addLogicsheetToList( - language, href, this.resolver - ); - } catch (ProcessingException pe) { - log.warn("ProcessingException in SitemapMarkupLanguage", pe); - throw new SAXException (pe); - } catch (IOException ioe) { - log.warn("IOException in SitemapMarkupLanguage", ioe); - throw new SAXException (ioe); - } - } - // Do not forward the PI event. - return; - } - // Call super when this is not a logicsheet related PI - super.processingInstruction(target,data); - } - - /** - * @see org.xml.sax.ContentHandler - */ - public void startElement (String namespaceURI, String localName, - String qName, Attributes atts) throws SAXException { - - if (finished) { - // Call super method - super.startElement(namespaceURI, localName, qName, atts); - } else { - // Need more work - if(isRootElem) { - isRootElem = false; - // cache the root element so that we resend the SAX event when - // we've finished dealing with <map:logicsheet > elements - rootElement = new Object[4]; - rootElement[0]=namespaceURI; - rootElement[1]=localName; - rootElement[2]=qName; - rootElement[3]=atts; - } else { - insideRootElement = true; - // Retrieve logicsheets declared by top-level elements <map:logicsheet ...> - // And do not forward the startElement event - if ("map:logicsheet".equals(qName)) { - String location = atts.getValue("location"); - try { - SitemapMarkupLanguage.this.addLogicsheetToList( - language, location,this.resolver - ); - } catch (ProcessingException pe) { - log.warn("ProcessingException in SitemapMarkupLanguage", pe); - throw new SAXException (pe); - } catch (IOException ioe) { - log.warn("IOException in SitemapMarkupLanguage", ioe); - throw new SAXException (ioe); - } - } else { - // This element is not a <map:logicsheet element, so finish - // by : - // * setting the 'fisnished' flag to true ; - // * refiring all the cached events ; - // * firing all the necessary event dealing with file dependencies - finished=true; - - // send SAX events 'startDocument' - super.startDocument(); - - // send all prefix namespace - String [] prefixArray; - Iterator i = startPrefix.iterator(); - while (i.hasNext()) { - prefixArray = (String []) i.next(); - super.startPrefixMapping( - prefixArray[0], - prefixArray[1] - ); - } - - // send cached RootElement event - super.startElement( - (String) rootElement[0], - (String) rootElement[1], - (String) rootElement[2], - (Attributes) rootElement[3] - ); - - // send cached characters - char[] ch = rootChars.toString().toCharArray(); - super.characters( ch, 0, ch.length); - - // send the events dealing with dependencies. - // If some dependencies exist, then create <map:dependency elements - char[] locationChars; - Iterator iter = SitemapMarkupLanguage.this.dependencies.iterator(); - while(iter.hasNext()) { - super.startElement(namespaceURI, - "dependency", "map:dependency", - new AttributesImpl() - ); - locationChars = ((String) iter.next()).toCharArray(); - super.characters(locationChars, 0 , - locationChars.length - ); - super.endElement(namespaceURI, - "dependency", "map:dependency" - ); - } - - // And finally forward current Element. - super.startElement(namespaceURI, localName, qName, atts); - } - } - } - } - - /** - * @see org.xml.sax.ContentHandler - */ - public void endElement (String namespaceURI, String localName, - String qName) throws SAXException { - if (finished) { - // Forward the events - super.endElement(namespaceURI, localName, qName); - } - } - - - /** - * @see org.xml.sax.ContentHandler - */ - public void characters(char[] ch, int start, int length) throws SAXException { - if (finished) { - super.characters(ch, start, length); - } else { - if(!insideRootElement) { - // caching the PCDATA for the root element - rootChars.append(ch, start, length); - } - } - } - - /** - * @see org.xml.sax.ContentHandler - */ - public void startPrefixMapping(String prefix, String uri) throws SAXException { - if(finished) { - super.startPrefixMapping(prefix, uri); - } else { - String[] prefixArray = new String [2]; - prefixArray[0]= prefix; - prefixArray[1]= uri; - startPrefix.add(prefixArray); - } - } + public String getRootElement() { + return "sitemap"; } } 1.10 +17 -379 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPMarkupLanguage.java Index: XSPMarkupLanguage.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPMarkupLanguage.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XSPMarkupLanguage.java 5 Feb 2002 14:46:59 -0000 1.9 +++ XSPMarkupLanguage.java 6 Feb 2002 04:40:28 -0000 1.10 @@ -59,8 +59,8 @@ import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.components.language.markup.AbstractMarkupLanguage; import org.apache.cocoon.components.language.markup.LogicsheetCodeGenerator; +import org.apache.cocoon.components.language.markup.CocoonMarkupLanguage; import org.apache.cocoon.components.language.programming.ProgrammingLanguage; import org.apache.cocoon.environment.SourceResolver; @@ -86,51 +86,16 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Sahuc</a> - * @version CVS $Id: XSPMarkupLanguage.java,v 1.9 2002/02/05 14:46:59 vgritsenko Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @version CVS $Id: XSPMarkupLanguage.java,v 1.10 2002/02/06 04:40:28 vgritsenko Exp $ */ -public class XSPMarkupLanguage extends AbstractMarkupLanguage { +public class XSPMarkupLanguage extends CocoonMarkupLanguage { /** - * store the dependencies. - * - * FIXME (SSA) Should not be shared between different calls. - * Should be passed as argument of method getPreprocessFilter ? - */ - private Set dependencies; - - /** - * The default constructor. - */ - public XSPMarkupLanguage() throws SAXException, IOException { - super(); - dependencies = new HashSet(); - } - - public void recycle() { - super.recycle(); - this.dependencies.clear(); - } - - - /** - * Return the XSP language name: <i>xsp</i> :-) - * - * @return The <i>xsp</i> constant + * Returns the root element for a valid XSP page: page element! */ - public String getName() { - return "xsp"; - } - - /** - * FIXME (SSA) : See interface. For now returns null. - * - * Return the document-declared encoding or <code>null</code> if it's the - * platform's default encoding - * - * @return The document-declared encoding - */ - public String getEncoding() { - return null; + public String getRootElement() { + return "page"; } /** @@ -139,9 +104,7 @@ * The return <code>XMLFilter</code> object is the first filter on the * transformer chain. * - * The XSP preprocess filter adds information on the root element such as - * creation-date, file-name and file-path, plus it use the the passed - * programming language to quote <code>Strings</code> on PCDATA node. + * Wraps PCDATA nodes with xsp:text nodes. * * @param filename The source filename * @param language The target programming language @@ -156,146 +119,35 @@ return filter; } - /** - * Add a dependency on an external file to the document for inclusion in - * generated code. This is used to populate a list of <code>File</code>'s - * tested for change on each invocation; this information is used to assert - * whether regeneration is necessary. XSP uses <xsp:dependency> - * elements for this purpose. - * - * @param location The file path of the dependent file - * @see <code>AbstractMarkupLanguage</code>, <code>ServerPagesGenerator</code> - * and <code>AbstractServerPage</code> - */ - protected void addDependency(String location) { - dependencies.add(location); - } - - // This is required here to avoid IllegalAccessError when - // XSPTransformerChainBuilderFilter invokes the method. - protected void addLogicsheetToList(LanguageDescriptor language, - String logicsheetLocation, - SourceResolver resolver) - throws IOException, SAXException, ProcessingException - { - super.addLogicsheetToList(language, logicsheetLocation, resolver); - } - - /** - * Returns a filter that chain on the fly the requested transformers for source - * code generation. This method scans the input SAX events for - * <?xml-logicsheet?> processing instructions and top-level - * <xsp:logicsheet> elements. Logicsheet declarations are removed from - * the input document. - * - * @param logicsheetMarkupGenerator the logicsheet markup generator - * @param language the language descriptor - * @param resolver the entity resolver - * @return XMLFilter the filter that build on the fly the transformer chain - */ - protected TransformerChainBuilderFilter getTransformerChainBuilder( - LogicsheetCodeGenerator logicsheetMarkupGenerator, - SourceResolver resolver) - { - XSPTransformerChainBuilderFilter filter = - new XSPTransformerChainBuilderFilter( - logicsheetMarkupGenerator, resolver); - filter.setLogger(getLogger()); - return filter; - } - // // Inner classes // /** - * Preprocess filter for XSP Markup language. - * It looks for PI event other that <?xml-logisheet href="..."> - * for quoting them; - * It adds creation-date, file-name and file-path attributes to the root - * Element; - * And it quotes the PCDATA based by calling the quote method of the - * programming language. - * + * This preprocessor wraps the PCDATA into xsp:text elements. * @see org.xml.sax.ContentHandler */ - protected class PreProcessFilter extends XMLFilterImpl implements Loggable { - protected Logger log; + protected class PreProcessFilter extends CocoonMarkupLanguage.PreProcessFilter { private Stack stack; - private String filename; - - private boolean isRootElem; - - private ProgrammingLanguage language; - - private String localPrefix; - - /** - * @param filename the filename - * @param the programming language - */ public PreProcessFilter (String filename, ProgrammingLanguage language) { - super (); - this.filename = filename; - this.language = language; - } - - public void setLogger(Logger logger) { - if (this.log == null) { - this.log = logger; - } + super(filename, language); } public void startDocument() throws SAXException { super.startDocument(); - isRootElem = true; stack = new Stack(); } - public void processingInstruction(String target, String data) throws SAXException { - if (!"xml-logicsheet".equals(target)) { - data = this.language.quoteString(data); - } - super.processingInstruction(target, data); - } - public void startElement (String namespaceURI, String localName, - String qName, Attributes atts) throws SAXException { - if (isRootElem) { - if (!XSPMarkupLanguage.this.getURI().equals(namespaceURI) - || !"page".equals(localName)) { - throw new SAXException("This page is not valid XSP page." - + " Root element is: " + qName); - } - localPrefix = ""; - if (qName.indexOf(':') != -1) - localPrefix = qName.substring(0, qName.indexOf(':')); - - stack.push(new String[] { namespaceURI, localName, qName} ); - isRootElem=false; - // Store path and file name - int pos = this.filename.lastIndexOf(File.separatorChar); - String name = this.filename.substring(pos + 1); - String path = this.filename.substring(0, pos).replace(File.separatorChar, '/'); - // update the attributes - AttributesImpl newAtts = new AttributesImpl(atts); - newAtts.addAttribute("", "file-name", "file-name", "CDATA", name); - newAtts.addAttribute("", "file-path", "file-path", "CDATA", path); - newAtts.addAttribute("", "creation-date", "creation-date", "CDATA", - String.valueOf(System.currentTimeMillis()) - ); - // forward element with the modified attribute - super.startElement(namespaceURI, localName, qName, newAtts); - } else { - stack.push(new String[] { namespaceURI, localName, qName} ); - super.startElement(namespaceURI, localName, qName, atts); - } + String qName, Attributes atts) throws SAXException { + stack.push(new String[] { namespaceURI, localName, qName} ); + super.startElement(namespaceURI, localName, qName, atts); } public void endElement (String namespaceURI, String localName, - String qName) throws SAXException { + String qName) throws SAXException { stack.pop(); super.endElement(namespaceURI, localName, qName); } @@ -310,227 +162,13 @@ super.characters(ch, start, length); } else { // Quote the string depending on the programming language - String value = this.language.quoteString(String.valueOf(ch, start, length)); - // Create a new element <xsp:text that wrap the quoted PCDATA + String value = String.valueOf(ch, start, length); + // Create a new element <xsp:text> that wrap the quoted PCDATA super.startElement(XSPMarkupLanguage.this.getURI(), "text", localPrefix + ":text", new AttributesImpl()); super.characters(value.toCharArray(), 0, value.length()); super.endElement(XSPMarkupLanguage.this.getURI(), "text", localPrefix + ":text"); - } - } - } - - public String getURI() { - return super.uri; - } - - public String getPrefix() { - return super.prefix; - } - - /** - * This filter builds on the fly a chain of transformers. It extends the - * <code>AbstractMarkupLanguage.TransformerChainBuilderFilter</code> so - * it can add XSP specific features such as: - * <ul> - * <li>Looking for <?xml-logisheet href="..."?;> PI and - * <xsp:xml-logisheet location="..."> elements to register - * user defined logicsheets;</li> - * <li>Adding all the dependencies related to the XSP pages as - * <xsp:dependency;>...</xsp:dependency;></li> - * </ul> - * - * @see org.xml.sax.ContentHandler - */ - protected class XSPTransformerChainBuilderFilter extends TransformerChainBuilderFilter implements Loggable { - - protected Logger log; - - private List startPrefix; - - private Object[] rootElement; - - private StringBuffer rootChars; - - private boolean isRootElem; - - private boolean insideRootElement; - - private boolean finished; - - private String localPrefix; - - /** - * @param logicsheetMarkupGenerator the code generator - * @param resolver the entity resolver - */ - protected XSPTransformerChainBuilderFilter( - LogicsheetCodeGenerator logicsheetMarkupGenerator, - SourceResolver resolver) - { - super(logicsheetMarkupGenerator, resolver); - } - - public void setLogger(Logger logger) { - if (this.log == null) { - this.log = logger; - } - } - - public void processingInstruction(String target, String data) throws SAXException { - // Retrieve logicsheets declared by processing-instruction - if ("xml-logicsheet".equals(target)) { - int start = data.indexOf("href"); - if (start >= 0) { - // add 6, for lenght of 'href', plus '=' char, plus '"' char - start += 6; - // get the quote char. Can be " or ' - char quote = data.charAt(start-1); - int end = data.indexOf(quote, start); - String href = data.substring(start, end); - - try { - XSPMarkupLanguage.this.addLogicsheetToList( - language, href, this.resolver - ); - } catch (ProcessingException pe) { - log.warn("ProcessingException in SitemapMarkupLanguage", pe); - throw new SAXException (pe); - } catch (IOException ioe) { - log.warn("XSPMarkupLanguage.processingInstruction", ioe); - throw new SAXException (ioe); - } - } - // Do not forward the PI event. - return; - } - - // Call super when this is not a logicsheet related PI - super.processingInstruction(target,data); - } - - public void startDocument () throws SAXException { - isRootElem=true; - insideRootElement=false; - finished=false; - startPrefix = new ArrayList(); - rootChars = new StringBuffer(); - } - - public void startElement (String namespaceURI, String localName, - String qName, Attributes atts) throws SAXException { - if (finished) { - // Call super method - super.startElement(namespaceURI, localName, qName, atts); - } else { - // Need more work - if(isRootElem) { - localPrefix = ""; - if (qName.indexOf(':') != -1) - localPrefix = qName.substring(0, qName.indexOf(':')); - - isRootElem = false; - // Cache the root element and resend the SAX event when - // we've finished dealing with <xsp:logicsheet > elements - rootElement = new Object[4]; - rootElement[0]=namespaceURI; - rootElement[1]=localName; - rootElement[2]=qName; - rootElement[3]=atts; - } else { - insideRootElement = true; - // Retrieve logicsheets declared by top-level elements <xsp:logicsheet ...> - // And do not forward the startElement event - if (XSPMarkupLanguage.this.getURI().equals(namespaceURI) && "logicsheet".equals(localName)) { - String href = atts.getValue("location"); - try { - XSPMarkupLanguage.this.addLogicsheetToList( - language, href, this.resolver - ); - } catch (ProcessingException pe) { - log.warn("XSPMarkupLanguage.startElement", pe); - throw new SAXException (pe); - } catch (IOException ioe) { - log.warn("XSPMarkupLanguage.startElement", ioe); - throw new SAXException (ioe); - } - } else { - // This element is not a <xsp:logicsheet> element, so finish - // by: - // * setting the 'fisnished' flag to true ; - // * refiring all the cached events ; - // * firing all the necessary event dealing with file dependencies - finished = true; - - // Send SAX events 'startDocument' - super.startDocument(); - - // Send all prefix namespace - String [] prefixArray; - for (int i=0; i<startPrefix.size(); i++) { - prefixArray = (String []) startPrefix.get(i); - super.startPrefixMapping(prefixArray[0], prefixArray[1]); - } - - // Send cached RootElement event - super.startElement( - (String) rootElement[0], - (String) rootElement[1], - (String) rootElement[2], - (Attributes) rootElement[3] - ); - - // Send cached characters - char[] ch = rootChars.toString().toCharArray(); - super.characters( ch, 0, ch.length); - - // Send the events dealing with dependencies. - // If some dependencies exist, then creates - // <xsp:dependency> elements - char[] locationChars; - Iterator iter = XSPMarkupLanguage.this.dependencies.iterator(); - while(iter.hasNext()) { - super.startElement( - namespaceURI, "dependency", localPrefix + ":dependency", new AttributesImpl() - ); - locationChars = ((String) iter.next()).toCharArray(); - super.characters(locationChars, 0 , locationChars.length); - super.endElement(namespaceURI, "dependency", localPrefix + ":dependency"); - } - - // And finally forward current Element. - super.startElement(namespaceURI, localName, qName, atts); - } - } - } - } - - public void endElement (String namespaceURI, String localName, - String qName) throws SAXException { - if (finished) { - // Forward the events - super.endElement(namespaceURI, localName, qName); - } - } - - public void characters(char[] ch, int start, int length) throws SAXException { - if (finished) { - super.characters(ch, start, length); - } else if(!insideRootElement) { - // Caching the PCDATA for the root element - rootChars.append(ch, start, length); - } - } - - public void startPrefixMapping(String prefix, String uri) throws SAXException { - if(finished) { - super.startPrefixMapping(prefix, uri); - } else { - String[] prefixArray = new String [2]; - prefixArray[0]= prefix; - prefixArray[1]= uri; - startPrefix.add(prefixArray); } } } 1.3 +5 -6 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/cookie.xsl Index: cookie.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/cookie.xsl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- cookie.xsl 26 Jan 2002 17:13:33 -0000 1.2 +++ cookie.xsl 6 Feb 2002 04:40:28 -0000 1.3 @@ -14,15 +14,14 @@ cookies @author ? - @version CVS $Revision: 1.2 $ $Date: 2002/01/26 17:13:33 $ + @version CVS $Revision: 1.3 $ $Date: 2002/02/06 04:40:28 $ --> <!-- XSP Cookie logicsheet for the Java language --> -<xsl:stylesheet - version="1.0" - xmlns:xsp="http://apache.org/xsp" - xmlns:xsp-cookie="http://apache.org/xsp/cookie/2.0" - xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:stylesheet version="1.0" + xmlns:xsp="http://apache.org/xsp" + xmlns:xsp-cookie="http://apache.org/xsp/cookie/2.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="xsp:page"> <xsp:page> 1.6 +0 -11 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/session.xsl Index: session.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/session.xsl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- session.xsl 5 Feb 2002 15:08:32 -0000 1.5 +++ session.xsl 6 Feb 2002 04:40:28 -0000 1.6 @@ -56,17 +56,6 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsp="http://apache.org/xsp" xmlns:xsp-session="http://apache.org/xsp/session/2.0"> - <!-- *** ServletSession Templates *** --> - - <xsl:template match="xsp:page"> - <xsl:copy> - <xsl:copy-of select="@*"/> - <xsp:structure> - <xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPSessionHelper</xsp:include> - </xsp:structure> - <xsl:apply-templates/> - </xsl:copy> - </xsl:template> <!-- *** ServletSession Templates *** --> 1.2 +5 -5 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl Index: xscript-lib.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- xscript-lib.xsl 3 Jan 2002 12:31:11 -0000 1.1 +++ xscript-lib.xsl 6 Feb 2002 04:40:28 -0000 1.2 @@ -246,9 +246,9 @@ <xsl:choose> <xsl:when test="$scope = 'global'">""</xsl:when> <!-- for the page scope use the context-path as context --> - <xsl:when test="$scope = 'page'">(XSPRequestHelper.getContextPath(objectModel))</xsl:when> - <xsl:when test="$scope = 'session'">(XSPRequestHelper.getSessionId(objectModel))</xsl:when> - <xsl:otherwise>(XSPRequestHelper.getSessionId(objectModel)), (XSPRequestHelper.getContextPath(objectModel))</xsl:otherwise> + <xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when> + <xsl:when test="$scope = 'session'">(XSPSessionHelper.getSessionId(objectModel))</xsl:when> + <xsl:otherwise>(XSPSessionHelper.getSessionId(objectModel)), (request.getContextPath())</xsl:otherwise> </xsl:choose> </xsl:template> @@ -261,8 +261,8 @@ <xsl:choose> <xsl:when test="$scope = 'global'">""</xsl:when> <!-- for the page scope use the context-path as context --> - <xsl:when test="$scope = 'page'">(XSPRequestHelper.getContextPath(objectModel))</xsl:when> - <xsl:otherwise>(XSPRequestHelper.getSessionId(objectModel))</xsl:otherwise> + <xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when> + <xsl:otherwise>(XSPSessionHelper.getSessionId(objectModel))</xsl:otherwise> </xsl:choose> </xsl:template> 1.3 +20 -6 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl Index: xsp.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xsp.xsl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- xsp.xsl 3 Feb 2002 18:49:33 -0000 1.2 +++ xsp.xsl 6 Feb 2002 04:40:28 -0000 1.3 @@ -12,17 +12,30 @@ <!-- * @author <a href="mailto:[EMAIL PROTECTED]>Ricardo Rocha</a> * @author <a href="[EMAIL PROTECTED]">Sylvain Wallez</a> - * @version CVS $Revision: 1.2 $ $Date: 2002/02/03 18:49:33 $ + * @version CVS $Revision: 1.3 $ $Date: 2002/02/06 04:40:28 $ --> <!-- XSP Core logicsheet for the Java language --> <xsl:stylesheet version="1.0" xmlns:xsp="http://apache.org/xsp" - xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:XSLTExtension="org.apache.cocoon.components.language.markup.xsp.java.XSLTExtension"> <xsl:output method="text"/> <xsl:variable name="xsp-uri" select="'http://apache.org/xsp'"/> + <!-- + this variable holds the instance of extension class to properly + escape text into Java strings + + ovidiu: use the class name as the namespace to identify the + class. This is supposedly portable across XSLT implementations. + --> + <xsl:variable + name="extension" + select="XSLTExtension:new()" + xmlns:XSLTExtension="org.apache.cocoon.components.language.markup.xsp.java.XSLTExtension"/> + <xsl:template match="/"> <code xml:space="preserve"> <xsl:apply-templates select="xsp:page"/> @@ -64,6 +77,7 @@ import org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper; import org.apache.cocoon.components.language.markup.xsp.XSPRequestHelper; import org.apache.cocoon.components.language.markup.xsp.XSPResponseHelper; + import org.apache.cocoon.components.language.markup.xsp.XSPSessionHelper; /* User Imports */ <xsl:for-each select="xsp:structure/xsp:include"> @@ -93,9 +107,9 @@ /* User Class Declarations */ <xsl:apply-templates select="xsp:logic"/> - /** - * Generate XML data. - */ + /** + * Generate XML data. + */ public void generate() throws SAXException, IOException, ProcessingException { <!-- Do any user-defined necessary initializations --> <xsl:value-of select="xsp:init-page"/> @@ -438,7 +452,7 @@ <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> - this.characters("<xsl:value-of select="."/>"); + this.characters("<xsl:value-of select="XSLTExtension:escape($extension, .)"/>"); </xsl:otherwise> </xsl:choose> </xsl:template> 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/XSLTExtension.java Index: XSLTExtension.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache Cocoon" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.cocoon.components.language.markup.xsp.java; /** * This class is used as a XSLT extension class. It is used by the XSP * generation stylesheet to escape XML characters to make a valid Java strings. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @version CVS $Id: XSLTExtension.java,v 1.1 2002/02/06 04:40:28 vgritsenko Exp $ */ public class XSLTExtension { /** * Escapes '"' and '\' characters in a String (add a '\' before them) so that it can * be inserted in java source. */ public String escape(String string) { char chr[] = string.toCharArray(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < chr.length; i++) { switch (chr[i]) { case '\t': buffer.append("\\t"); break; case '\r': buffer.append("\\r"); break; case '\n': buffer.append("\\n"); break; case '"': case '\\': buffer.append('\\'); // Fall through default: buffer.append(chr[i]); break; } } return buffer.toString(); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]