cziegeler 2003/02/26 07:02:40
Modified: src/java/org/apache/cocoon/components/source SourceUtil.java src/deprecated/java/org/apache/cocoon/components/source AbstractSAXSource.java AbstractStreamSource.java SitemapSource.java DelayedRefreshSourceWrapper.java src/java/org/apache/cocoon/components/source/impl CocoonToAvalonSource.java src/java/org/apache/cocoon/environment AbstractEnvironment.java src/java/org/apache/cocoon/xml XMLUtils.java src/deprecated/java/org/apache/cocoon/environment Source.java src/java/org/apache/cocoon/components/language/markup/xsp XSPObjectHelper.java src/blocks/xmldb/java/org/apache/cocoon/components/source XMLDBSource.java src/java/org/apache/cocoon/generation SessionAttributeGenerator.java src/deprecated/java/org/apache/cocoon/xml XMLizable.java Added: src/deprecated/java/org/apache/cocoon/components/source/impl CocoonSourceFactory.java FileSourceFactory.java AvalonToCocoonSource.java SourceFactoryWrapper.java FileSource.java URLFactoryWrapper.java Removed: src/scratchpad/src/org/apache/cocoon/components/source FileSource.java CocoonSourceFactory.java FileSourceFactory.java src/scratchpad/src/org/apache/cocoon/components/source/impl SourceFactoryWrapper.java URLFactoryWrapper.java src/java/org/apache/cocoon/components/source/impl AvalonToCocoonSource.java Log: Updating code; removing dependencies on deprecated code (and moving code into correct dirs...) Revision Changes Path 1.22 +4 -5 xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java Index: SourceUtil.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- SourceUtil.java 6 Feb 2003 12:19:44 -0000 1.21 +++ SourceUtil.java 26 Feb 2003 15:02:33 -0000 1.22 @@ -71,6 +71,7 @@ import org.apache.excalibur.source.SourceNotFoundException; import org.apache.excalibur.source.SourceParameters; import org.apache.excalibur.source.SourceResolver; +import org.apache.excalibur.xml.sax.XMLizable; import org.apache.excalibur.xmlizer.XMLizer; import org.apache.regexp.RE; import org.apache.regexp.RECompiler; @@ -134,10 +135,8 @@ ContentHandler handler, ComponentManager manager ) throws SAXException, IOException, ProcessingException { - if ( source instanceof org.apache.excalibur.xml.sax.XMLizable ) { - ((org.apache.excalibur.xml.sax.XMLizable)source).toSAX( handler ); - } else if ( source instanceof org.apache.cocoon.xml.XMLizable ) { - ((org.apache.cocoon.xml.XMLizable)source).toSAX( handler ); + if ( source instanceof XMLizable ) { + ((XMLizable)source).toSAX( handler ); } else { String mimeType = source.getMimeType(); if ( null == mimeType) mimeType = mimeTypeHint; 1.3 +2 -4 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/AbstractSAXSource.java Index: AbstractSAXSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/AbstractSAXSource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractSAXSource.java 31 Jan 2003 22:50:23 -0000 1.2 +++ AbstractSAXSource.java 26 Feb 2003 15:02:34 -0000 1.3 @@ -126,8 +126,6 @@ return new ByteArrayInputStream(os.toByteArray()); } catch (ComponentException cme) { throw new ProcessingException("could not lookup pipeline components", cme); - } catch (ProcessingException e) { - throw e; } catch (Exception e) { throw new ProcessingException("Exception during processing of " + this.getSystemId(), e); } finally { @@ -155,7 +153,7 @@ */ public abstract void toSAX(ContentHandler handler) - throws SAXException, ProcessingException; + throws SAXException; /** * Implement this method to set the unique identifier. 1.4 +3 -6 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/AbstractStreamSource.java Index: AbstractStreamSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/AbstractStreamSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractStreamSource.java 22 Jan 2003 05:19:16 -0000 1.3 +++ AbstractStreamSource.java 26 Feb 2003 15:02:34 -0000 1.4 @@ -191,7 +191,7 @@ * HTTP location does not exist. * @throws SAXException if failed to parse source document. */ - public void toSAX(ContentHandler handler) throws SAXException, ProcessingException { + public void toSAX(ContentHandler handler) throws SAXException { SAXParser parser = null; try { parser = (SAXParser)this.manager.lookup(SAXParser.ROLE); @@ -200,11 +200,8 @@ } catch (SAXException e) { // Preserve original exception throw e; - } catch (ProcessingException e){ - // Preserve original exception - throw e; } catch (Exception e){ - throw new ProcessingException("Exception during processing of " + throw new SAXException("Exception during processing of " + this.getSystemId(), e); } finally { if (parser != null) this.manager.release( (Component)parser); 1.3 +9 -9 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java Index: SitemapSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SitemapSource.java 31 Jan 2003 22:50:23 -0000 1.2 +++ SitemapSource.java 26 Feb 2003 15:02:34 -0000 1.3 @@ -121,7 +121,7 @@ private org.apache.excalibur.source.Source redirectSource; /** The <code>SAXException</code> if unable to get resource */ - private ProcessingException exception; + private SAXException exception; /** Do I need a refresh ? */ private boolean needsRefresh; @@ -226,7 +226,7 @@ } // VG: Why exception is not thrown in constructor? if (this.exception != null) { - throw this.exception; + throw new ProcessingException(this.exception); } if (this.redirectSource != null) { @@ -287,12 +287,12 @@ this.redirectSource = this.environment.resolveURI(redirectURL); this.lastModificationDate = this.redirectSource.getLastModified(); } - } catch (ProcessingException e) { + } catch (SAXException e) { reset(); this.exception = e; } catch (Exception e) { reset(); - this.exception = new ProcessingException("Could not get sitemap source " + this.exception = new SAXException("Could not get sitemap source " + this.systemId, e); } this.needsRefresh = false; @@ -312,12 +312,12 @@ * Stream content to the content handler */ public void toSAX(ContentHandler contentHandler) - throws SAXException, ProcessingException + throws SAXException { if (this.needsRefresh) { this.refresh(); } - if (this.exception != null) { + if (this.exception != null) { throw this.exception; } try { @@ -354,11 +354,11 @@ this.manager.release(xmld); } } - } catch (ProcessingException e) { + } catch (SAXException e) { // Preserve original exception throw e; } catch (Exception e) { - throw new ProcessingException("Exception during processing of " + throw new SAXException("Exception during processing of " + this.systemId, e); } finally { reset(); 1.3 +2 -2 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/DelayedRefreshSourceWrapper.java Index: DelayedRefreshSourceWrapper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/DelayedRefreshSourceWrapper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DelayedRefreshSourceWrapper.java 31 Jan 2003 22:50:23 -0000 1.2 +++ DelayedRefreshSourceWrapper.java 26 Feb 2003 15:02:34 -0000 1.3 @@ -153,7 +153,7 @@ this.source.recycle(); } - public final void toSAX(ContentHandler handler) throws SAXException, ProcessingException { + public final void toSAX(ContentHandler handler) throws SAXException { this.source.toSAX(handler); } } 1.9 +16 -31 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java Index: CocoonToAvalonSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CocoonToAvalonSource.java 31 Jan 2003 22:51:34 -0000 1.8 +++ CocoonToAvalonSource.java 26 Feb 2003 15:02:34 -0000 1.9 @@ -73,18 +73,19 @@ public final class CocoonToAvalonSource implements Source, XMLizable, Recyclable { - + /** The real source */ protected org.apache.cocoon.environment.Source source; /** The protocol */ protected String protocol; - + /** * Constructor */ - public CocoonToAvalonSource( String location, - org.apache.cocoon.environment.Source source ) { + public CocoonToAvalonSource( + String location, + org.apache.cocoon.environment.Source source) { this.source = source; int pos = location.indexOf(':'); this.protocol = location.substring(0, pos); @@ -108,12 +109,11 @@ return false; } } - + /** * Return an <code>InputStream</code> object to read from the source. */ - public InputStream getInputStream() - throws IOException, SourceException { + public InputStream getInputStream() throws IOException, SourceException { try { return this.source.getInputStream(); } catch (ResourceNotFoundException rnfe) { @@ -126,8 +126,7 @@ /** * Return the unique identifer for this source */ - public String getURI() - { + public String getURI() { return this.source.getSystemId(); } @@ -148,10 +147,9 @@ * Refresh this object and update the last modified date * and content length. */ - public void refresh() - { + public void refresh() { if (this.source instanceof ModifiableSource) { - ((ModifiableSource)this.source).refresh(); + ((ModifiableSource) this.source).refresh(); } } @@ -160,22 +158,15 @@ * If the source is not able to determine the mime-type by itself * this can be null. */ - public String getMimeType() - { + public String getMimeType() { return null; } /** * Stream content to the content handler */ - public void toSAX(ContentHandler contentHandler) - throws SAXException - { - try { - this.source.toSAX( contentHandler ); - } catch (ProcessingException pe) { - throw new SAXException(pe); - } + public void toSAX(ContentHandler contentHandler) throws SAXException { + this.source.toSAX(contentHandler); } /** @@ -189,8 +180,7 @@ * Return the content length of the content or -1 if the length is * unknown */ - public long getContentLength() - { + public long getContentLength() { return this.source.getContentLength(); } @@ -198,8 +188,7 @@ * Get the last modification date of the source or 0 if it * is not possible to determine the date. */ - public long getLastModified() - { + public long getLastModified() { return this.source.getLastModified(); } @@ -230,8 +219,4 @@ return java.util.Collections.EMPTY_LIST.iterator(); } - } - - - 1.42 +4 -5 xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java Index: AbstractEnvironment.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- AbstractEnvironment.java 26 Feb 2003 13:28:19 -0000 1.41 +++ AbstractEnvironment.java 26 Feb 2003 15:02:34 -0000 1.42 @@ -60,6 +60,7 @@ import org.apache.cocoon.util.BufferedOutputStream; import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.xml.sax.XMLizable; import org.apache.excalibur.xmlizer.XMLizer; import org.xml.sax.ContentHandler; @@ -534,10 +535,8 @@ } try { - if (source instanceof org.apache.excalibur.xml.sax.XMLizable) { - ((org.apache.excalibur.xml.sax.XMLizable)source).toSAX( handler ); - } else if ( source instanceof org.apache.cocoon.xml.XMLizable ) { - ((org.apache.cocoon.xml.XMLizable)source).toSAX( handler ); + if (source instanceof XMLizable) { + ((XMLizable)source).toSAX( handler ); } else { try { xmlizer.toSAX( source.getInputStream(), 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/CocoonSourceFactory.java Index: CocoonSourceFactory.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Source; import org.apache.cocoon.Processor; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; /** * This class implements the cocoon: protocol. * It cannot be configured like the other source factories * as it needs the current <code>Sitemap</code> as input. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: CocoonSourceFactory.java,v 1.1 2003/02/26 15:02:35 cziegeler Exp $ */ public final class CocoonSourceFactory extends AbstractLogEnabled implements SourceFactory { /** The component manager */ private ComponentManager manager; public CocoonSourceFactory(Processor processor, ComponentManager manager) { this.manager = manager; } /** * Resolve the source */ public Source getSource(Environment environment, String location) throws ProcessingException, IOException, MalformedURLException { if (environment == null) throw new ProcessingException("CocoonSourceFactory: environment is required."); return new SitemapSource(this.manager, location, this.getLogger()); } /** * Resolve the source */ public Source getSource(Environment environment, URL base, String location) throws ProcessingException, IOException, MalformedURLException { if (environment == null) throw new ProcessingException("CocoonSourceFactory: environment is required."); return this.getSource(environment, base.toExternalForm() + location); } } 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/FileSourceFactory.java Index: FileSourceFactory.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.source; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.source.SourceFactory; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Source; import org.apache.cocoon.ProcessingException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; /** * A factory for 'file:' sources. * * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> * @version $Id: FileSourceFactory.java,v 1.1 2003/02/26 15:02:35 cziegeler Exp $ * @deprecated Use the new avalon source resolving instead */ public class FileSourceFactory extends AbstractLogEnabled implements SourceFactory, Composable, ThreadSafe { private ComponentManager manager; public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; } public Source getSource(Environment environment, String location) throws ProcessingException, MalformedURLException, IOException { Source result = new FileSource(location, this.manager); setupLogger(result); return result; } public Source getSource(Environment environment, URL base, String location) throws ProcessingException, MalformedURLException, IOException { return getSource(environment, new URL(base, location).toExternalForm()); } } 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/AvalonToCocoonSource.java Index: AvalonToCocoonSource.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source.impl; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.ModifiableSource; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceResolver; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; /** * This source objects wraps an Avalon Excalibur Source to get * an obsolete Cocoon Source object for the use of the deprecated * [EMAIL PROTECTED] org.apache.cocoon.environment.SourceResolver#resolve(String)} * method. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Revision: 1.1 $ $Date: 2003/02/26 15:02:35 $ */ public final class AvalonToCocoonSource implements ModifiableSource { /** The real source */ protected Source source; /** The source resolver */ protected SourceResolver resolver; /** The environment */ protected Environment environment; /** * Constructor */ public AvalonToCocoonSource(Source source, SourceResolver resolver, Environment environment) { this.source = source; this.resolver = resolver; this.environment = environment; } /** * Get the last modification date of the source or 0 if it * is not possible to determine the date. */ public long getLastModified() { return this.source.getLastModified(); } /** * Get the content length of the source or -1 if it * is not possible to determine the length. */ public long getContentLength() { return this.source.getContentLength(); } /** * Return an <code>InputStream</code> object to read from the source. */ public InputStream getInputStream() throws ProcessingException, IOException { try { return this.source.getInputStream(); } catch (SourceException e) { throw SourceUtil.handle(e); } } /** * Return an <code>InputSource</code> object to read the XML * content. * * @return an <code>InputSource</code> value * @exception ProcessingException if an error occurs * @exception IOException if an error occurs */ public InputSource getInputSource() throws ProcessingException, IOException { try { InputSource newObject = new InputSource(this.source.getInputStream()); newObject.setSystemId(this.getSystemId()); return newObject; } catch (SourceException se) { throw SourceUtil.handle(se); } } /** * Return the unique identifer for this source */ public String getSystemId() { return this.source.getURI(); } public void recycle() { this.resolver.release(this.source); this.source = null; this.environment = null; } public void refresh() { this.source.refresh(); } /** * Stream content to a content handler or to an XMLConsumer. * * @throws ResourceNotFoundException if file not found or * HTTP location does not exist. * @throws SAXException if failed to parse source document. */ public void toSAX(ContentHandler handler) throws SAXException { try { this.environment.toSAX(this.source, handler); } catch (ProcessingException pe) { throw new SAXException("ProcessingException during streaming.", pe); } catch (IOException ioe) { throw new SAXException("IOException during streaming.", ioe); } } } 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/SourceFactoryWrapper.java Index: SourceFactoryWrapper.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source.impl; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.CascadingIOException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.util.ClassUtils; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceFactory; import java.io.IOException; import java.net.MalformedURLException; import java.util.Map; /** * This class wraps a Cocoon SourceFactory and makes it * usable within the Avalon Excalibur source resolving architecure. * The main purpose is to avoid recoding existing factories. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: SourceFactoryWrapper.java,v 1.1 2003/02/26 15:02:35 cziegeler Exp $ */ public final class SourceFactoryWrapper extends AbstractLogEnabled implements SourceFactory, ThreadSafe, Configurable, Disposable, Composable, Contextualizable { /** The <code>ComponentManager</code> */ private ComponentManager manager; /** The special Source factories */ private org.apache.cocoon.components.source.SourceFactory sourceFactory; /** The context */ private Context context; /** * Configure the SourceFactories */ public void configure(final Configuration conf) throws ConfigurationException { try { final Configuration factoryConf = conf.getChild("source-factory"); final String className = factoryConf.getAttribute("class"); if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Getting the SourceFactory " + className); } this.sourceFactory = (org.apache.cocoon.components.source.SourceFactory) ClassUtils.newInstance(className); this.init(this.sourceFactory, factoryConf); } catch (ConfigurationException e) { throw e; } catch (Exception e) { throw new ConfigurationException("Could not get parameters because: " + e.getMessage(), e); } } /** * Get the context */ public void contextualize(Context context) throws ContextException { this.context = context; } /** * Set the current <code>ComponentManager</code> instance used by this * <code>Composable</code>. */ public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; } /** * Dispose */ public void dispose() { if (this.sourceFactory != null) { this.deinit(this.sourceFactory); } this.sourceFactory = null; } /** * Get a <code>Source</code> object. * @param parameters This is optional. */ public Source getSource( String location, Map parameters ) throws MalformedURLException, IOException { if( getLogger().isDebugEnabled() ) { getLogger().debug( "Creating source object for " + location ); } final Environment currentEnv = CocoonComponentManager.getCurrentEnvironment(); org.apache.cocoon.environment.Source source; try { source = this.sourceFactory.getSource(currentEnv, location); } catch (ProcessingException pe) { throw new CascadingIOException("ProcessingException: " + pe.getMessage(), pe); } return new CocoonToAvalonSource( location, source ); } /** * Init a source factory */ private void init(org.apache.cocoon.components.source.SourceFactory factory, Configuration config) throws ContextException, ComponentException, ConfigurationException { if (factory instanceof LogEnabled) { ((LogEnabled) factory).enableLogging(getLogger()); } if (factory instanceof Contextualizable) { ((Contextualizable) factory).contextualize (this.context); } if (factory instanceof Composable) { ((Composable) factory).compose(this.manager); } if (config != null && factory instanceof Configurable) { ((Configurable) factory).configure(config); } } /** * Deinit a source factory */ private void deinit(org.apache.cocoon.components.source.SourceFactory factory) { if (factory instanceof Disposable) { ((Disposable) factory).dispose(); } } /** * Release a [EMAIL PROTECTED] Source} object. */ public void release( Source source ) { if ( null != source ) { if ( this.getLogger().isDebugEnabled() ) { this.getLogger().debug("Releasing source " + source.getURI()); } ((Recyclable)source).recycle(); } } } 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/FileSource.java Index: FileSource.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.source; import org.apache.avalon.framework.component.ComponentManager; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import java.io.*; import java.net.MalformedURLException; import java.util.ConcurrentModificationException; /** * A <code>org.apache.cocoon.environment.WriteableSource</code> for 'file:/' system IDs. * * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> * @version $Id: FileSource.java,v 1.1 2003/02/26 15:02:35 cziegeler Exp $ * @deprecated Use the new avalon source resolving instead */ public class FileSource extends AbstractStreamWriteableSource implements org.apache.cocoon.environment.WriteableSource { /** The underlying file. */ private File file; /** The system ID for this source (lazily created by getSystemId()) */ private String systemId = null; /** Is this an html file ? */ private boolean isHTMLContent; /** * Create a file source from a 'file:' url and a component manager. */ public FileSource(String url, ComponentManager manager) { super(manager); if (!url.startsWith("file:")) { throw new IllegalArgumentException("Malformed url for a file source : " + url); } if (url.endsWith(".htm") || url.endsWith(".html")) { this.isHTMLContent = true; } this.file = new File(url.substring(5)); // 5 == "file:".length() } public boolean exists() { return this.file.exists(); } /** * Returns <code>true</code> if the file name ends with ".htm" or ".html". */ protected boolean isHTMLContent() { return this.isHTMLContent; } /** * Return the unique identifer for this source */ public String getSystemId() { if (this.systemId == null) { try { this.systemId = this.file.toURL().toExternalForm(); } catch(MalformedURLException mue) { // Can this really happen ? this.systemId = "file:" + this.file.getPath(); } } return this.systemId; } /** * Get the input stream for this source. */ public InputStream getInputStream() throws IOException, ProcessingException { try { return new FileInputStream(this.file); } catch (FileNotFoundException e) { throw new ResourceNotFoundException("Resource not found " + getSystemId(), e); } } public long getLastModified() { return this.file.lastModified(); } public long getContentLength() { return this.file.length(); } /** * Get an output stream to write to this source. The output stream returned * actually writes to a temp file that replaces the real one on close. This * temp file is used as lock to forbid multiple simultaneous writes. The * real file is updated atomically when the output stream is closed. * * @throws ConcurrentModificationException if another thread is currently * writing to this file. */ public OutputStream getOutputStream() throws IOException, ProcessingException { // Create a temp file. It will replace the right one when writing terminates, // and serve as a lock to prevent concurrent writes. File tmpFile = new File(this.file.getPath() + ".tmp"); // Ensure the directory exists tmpFile.getParentFile().mkdirs(); // Can we write the file ? if (this.file.exists() && !this.file.canWrite()) { throw new IOException("Cannot write to file " + this.file.getPath()); } // Check if it temp file already exists, meaning someone else currently writing if (!tmpFile.createNewFile()) { throw new ConcurrentModificationException("File " + this.file.getPath() + " is already being written by another thread"); } // Return a stream that will rename the temp file on close. return new FileSourceOutputStream(tmpFile); } /** * Always return <code>false</code>. To be redefined by implementations that support * <code>cancel()</code>. */ public boolean canCancel(OutputStream stream) { if (stream instanceof FileSourceOutputStream) { FileSourceOutputStream fsos = (FileSourceOutputStream)stream; if (fsos.getSource() == this) { return fsos.canCancel(); } } // Not a valid stream for this source throw new IllegalArgumentException("The stream is not associated to this source"); } /** * Cancels the output stream. */ public void cancel(OutputStream stream) throws Exception { if (stream instanceof FileSourceOutputStream) { FileSourceOutputStream fsos = (FileSourceOutputStream)stream; if (fsos.getSource() == this) { fsos.cancel(); return; } } // Not a valid stream for this source throw new IllegalArgumentException("The stream is not associated to this source"); } /** * A file outputStream that will rename the temp file to the destination file upon close() * and discard the temp file upon cancel(). */ private class FileSourceOutputStream extends FileOutputStream { private File tmpFile; private boolean isClosed = false; public FileSourceOutputStream(File tmpFile) throws IOException { super(tmpFile); this.tmpFile = tmpFile; } public FileSource getSource() { return FileSource.this; } public void close() throws IOException { super.close(); try { // Delete destination file if (FileSource.this.file.exists()) { FileSource.this.file.delete(); } // Rename temp file to destination file tmpFile.renameTo(FileSource.this.file); } finally { // Ensure temp file is deleted, ie lock is released. // If there was a failure above, written data is lost. if (tmpFile.exists()) { tmpFile.delete(); } this.isClosed = true; } } public boolean canCancel() { return !this.isClosed; } public void cancel() throws Exception { if (this.isClosed) { throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); } this.isClosed = true; super.close(); this.tmpFile.delete(); } public void finalize() { if (!this.isClosed && tmpFile.exists()) { // Something wrong happened while writing : delete temp file tmpFile.delete(); } } } } 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/URLFactoryWrapper.java Index: URLFactoryWrapper.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source.impl; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.url.URLFactory; import org.apache.cocoon.util.ClassUtils; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceFactory; import org.apache.excalibur.source.impl.URLSource; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; /** * This class wraps a Cocoon URLFactory and makes it * usable within the Avalon Excalibur source resolving architecure. * The main purpose is to avoid recoding existing factories. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: URLFactoryWrapper.java,v 1.1 2003/02/26 15:02:35 cziegeler Exp $ */ public final class URLFactoryWrapper extends AbstractLogEnabled implements SourceFactory, ThreadSafe, Configurable, Disposable, Composable, Contextualizable { /** The <code>ComponentManager</code> */ private ComponentManager manager; /** The special Source factories */ private URLFactory urlFactory; /** The context */ private Context context; /** * Configure the SourceFactories */ public void configure(final Configuration conf) throws ConfigurationException { try { final Configuration factoryConf = conf.getChild("url-factory"); final String className = factoryConf.getAttribute("class"); if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Getting the URLFactory " + className); } this.urlFactory = (URLFactory)ClassUtils.newInstance(className); this.init(this.urlFactory, factoryConf); } catch (ConfigurationException e) { throw e; } catch (Exception e) { throw new ConfigurationException("Could not get parameters because: " + e.getMessage(), e); } } /** * Get the context */ public void contextualize(Context context) throws ContextException { this.context = context; } /** * Set the current <code>ComponentManager</code> instance used by this * <code>Composable</code>. */ public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; } /** * Dispose */ public void dispose() { if (this.urlFactory != null) { this.deinit(this.urlFactory); } this.urlFactory = null; } /** * Get a <code>Source</code> object. * @param parameters This is optional. */ public Source getSource( String location, Map parameters ) throws MalformedURLException, IOException { if( this.getLogger().isDebugEnabled() ) { this.getLogger().debug( "Creating source object for " + location ); } final int protocolPos = location.indexOf("://"); final URL url = this.urlFactory.getURL(location.substring(protocolPos+3)); final URLSource source = new org.apache.excalibur.source.impl.URLSource(); source.init(url, parameters); return source; } /** * Init a url factory */ private void init(URLFactory factory, Configuration config) throws ContextException, ComponentException, ConfigurationException { if (factory instanceof LogEnabled) { ((LogEnabled) factory).enableLogging(getLogger()); } if (factory instanceof Contextualizable) { ((Contextualizable) factory).contextualize (this.context); } if (factory instanceof Composable) { ((Composable) factory).compose(this.manager); } if (config != null && factory instanceof Configurable) { ((Configurable) factory).configure(config); } } /** * Deinit a url factory */ private void deinit(URLFactory factory) { if (factory instanceof Disposable) { ((Disposable) factory).dispose(); } } /** * Release a [EMAIL PROTECTED] Source} object. */ public void release( Source source ) { if ( null != source ) { if ( this.getLogger().isDebugEnabled() ) { this.getLogger().debug("Releasing source " + source.getURI()); } // do simply nothing } } } 1.14 +2 -6 xml-cocoon2/src/java/org/apache/cocoon/xml/XMLUtils.java Index: XMLUtils.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/xml/XMLUtils.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- XMLUtils.java 31 Jan 2003 22:51:59 -0000 1.13 +++ XMLUtils.java 26 Feb 2003 15:02:39 -0000 1.14 @@ -278,11 +278,7 @@ public static void valueOf(ContentHandler contentHandler, XMLizable v) throws SAXException { if (v != null) { - try { - v.toSAX(contentHandler); - } catch(ProcessingException e) { - throw new SAXException(e); - } + v.toSAX(contentHandler); } } 1.3 +2 -2 xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/Source.java Index: Source.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/Source.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Source.java 31 Jan 2003 22:50:24 -0000 1.2 +++ Source.java 26 Feb 2003 15:02:39 -0000 1.3 @@ -52,7 +52,7 @@ import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.xml.XMLizable; +import org.apache.excalibur.xml.sax.XMLizable; import org.xml.sax.InputSource; import java.io.IOException; 1.9 +357 -368 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java Index: XSPObjectHelper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XSPObjectHelper.java 31 Jan 2003 22:51:26 -0000 1.8 +++ XSPObjectHelper.java 26 Feb 2003 15:02:39 -0000 1.9 @@ -50,17 +50,16 @@ */ package org.apache.cocoon.components.language.markup.xsp; -import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.xml.XMLizable; +import java.util.Collection; +import java.util.Iterator; + import org.apache.cocoon.xml.dom.DOMStreamer; +import org.apache.excalibur.xml.sax.XMLizable; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import java.util.Collection; -import java.util.Iterator; - /** * Base class for XSP's object model manipulation logicsheets * @@ -70,366 +69,356 @@ * @version CVS $Id$ */ public class XSPObjectHelper { - /** - * Empty attributes used for contentHandler.startElement() - */ - protected static final AttributesImpl emptyAttr = new AttributesImpl(); - - /** - * Output an element containing text only and no attributes - * - * @param contentHandler The SAX content handler - * @param name The element name - * @param data The data contained by the element - */ - protected static void elementData(String uri, String prefix, - ContentHandler contentHandler, - String name, - String data - ) - throws SAXException - { - start(uri, prefix, contentHandler, name); - data(contentHandler, data); - end(uri, prefix, contentHandler, name); - } - - /** - * Output an element containing text only and attributes - * - * @param contentHandler The SAX content handler - * @param name The element name - * @param data The data contained by the element - * @param attr The element attributes - */ - protected static void elementData(String uri, String prefix, - ContentHandler contentHandler, - String name, - String data, - AttributesImpl attr - ) - throws SAXException - { - start(uri, prefix, contentHandler, name, attr); - data(contentHandler, data); - end(uri, prefix, contentHandler, name); - } - - /** - * Start an element with the proper object's uri and prefix and no - * attributes - * - * @param contentHandler The SAX content handler - * @param name The element name - */ - protected static void start(String uri, String prefix, - ContentHandler contentHandler, - String name - ) - throws SAXException - { - contentHandler.startElement(uri, name, new StringBuffer(prefix).append(":").append(name).toString(), emptyAttr); - } - - /** - * Start an element with the proper object's uri and prefix and with - * attributes - * - * @param contentHandler The SAX content handler - * @param name The element name - * @param attr The element attributes - */ - protected static void start(String uri, String prefix, - ContentHandler contentHandler, - String name, - AttributesImpl attr - ) - throws SAXException - { - contentHandler.startElement(uri, name, new StringBuffer(prefix).append(":").append(name).toString(), attr); - } - - /** - * End an element with the proper object's uri and prefix - * - * @param contentHandler The SAX content handler - * @param name The element name - */ - protected static void end(String uri, String prefix, - ContentHandler contentHandler, - String name - ) - throws SAXException - { - contentHandler.endElement(uri, name, new StringBuffer(prefix).append(":").append(name).toString()); - } - - /** - * Add an attribute - * - * @param attr The attribute list - * @param name The attribute name - * @param value The attribute value - */ - protected static void addAttribute( - AttributesImpl attr, - String name, - String value - ) - throws SAXException - { - attr.addAttribute("", name, name, "CDATA", value); - } - - /** - * Add string data - * - * @param contentHandler The SAX content handler - * @param data The string data - */ - protected static void data( - ContentHandler contentHandler, - String data - ) - throws SAXException - { - contentHandler.characters(data.toCharArray(), 0, data.length()); - } - - // <xsp:expr> methods - - /** - * Implementation of <xsp:expr> for <code>char</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, char v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>byte</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, byte v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>boolean</code> : - * outputs characters representing the value (true / false). - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, boolean v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>int</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, int v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>long</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, long v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>long</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, float v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>double</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, double v) throws SAXException - { - data(contentHandler, String.valueOf(v)); - } - - /** - * Implementation of <xsp:expr> for <code>String</code> : - * outputs characters representing the value. - * - * @param contentHandler the SAX content handler - * @param text the value - */ - public static void xspExpr(ContentHandler contentHandler, String text) throws SAXException - { - if (text != null) - { - data(contentHandler, text); - } - } - -// Now handled by XMLizable -// /** -// * Implementation of <xsp:expr> for <code>XMLFragment</code> : -// * outputs the value by calling <code>v.toSax(contentHandler)</code>. -// * -// * @param contentHandler the SAX content handler -// * @param v the XML fragment -// */ -// public static void xspExpr(ContentHandler contentHandler, XMLFragment v) throws SAXException -// { -// if (v != null) -// { -// v.toSAX(contentHandler); -// } -// } - - /** - * Implementation of <xsp:expr> for <code>XMLizable</code> : - * outputs the value by calling <code>v.toSax(contentHandler)</code>. - * - * @param contentHandler the SAX content handler - * @param v the XML fragment - */ - public static void xspExpr(ContentHandler contentHandler, XMLizable v) throws SAXException - { - if (v != null) - { - try{ - v.toSAX(contentHandler); - }catch(ProcessingException e){ - throw new SAXException(e); - } - } - } - - /** - * Implementation of <xsp:expr> for <code>org.w3c.dom.Node</code> : - * converts the Node to a SAX event stream. - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, Node v) throws SAXException - { - if (v != null) - { - DOMStreamer streamer = new DOMStreamer(contentHandler); - streamer.stream(v); - } - } - - /** - * Implementation of <xsp:expr> for <code>java.util.Collection</code> : - * outputs the value by calling <code>xspExpr()</code> on each element of the - * collection. - * - * @param contentHandler the SAX content handler - * @param v the XML fragment - */ - public static void xspExpr(ContentHandler contentHandler, Collection v) throws SAXException - { - if (v != null) - { - Iterator iterator = v.iterator(); - while (iterator.hasNext()) - { - xspExpr(contentHandler, iterator.next()); - } - } - } - - /** - * Implementation of <xsp:expr> for <code>Object</code> depending on its class : - * <ul> - * <li>if it's an array, call <code>xspExpr()</code> on all its elements,</li> - * <li>if it's class has a specific <code>xspExpr()</code>implementation, use it,</li> - * <li>else, output it's string representation.</li> - * </ul> - * - * @param contentHandler the SAX content handler - * @param v the value - */ - public static void xspExpr(ContentHandler contentHandler, Object v) throws SAXException - { - if (v == null) - { - return; - } - - // Array: recurse over each element - if (v.getClass().isArray()) - { - Object[] elements = (Object[]) v; - - for (int i = 0; i < elements.length; i++) - { - xspExpr(contentHandler, elements[i]); - } - return; - } - - // Check handled object types in case they were not typed in the XSP - - // XMLizable - if (v instanceof XMLizable) - { - xspExpr(contentHandler, (XMLizable)v); - return; - } - -// Now handled by XMLizable -// // XMLFragment -// if (v instanceof XMLFragment) -// { -// xspExpr(contentHandler, (XMLFragment)v); -// return; -// } - - // Node - if (v instanceof Node) - { - xspExpr(contentHandler, (Node)v); - return; - } - - // Collection - if (v instanceof Collection) - { - xspExpr(contentHandler, (Collection)v); - return; - } - - // Give up: hope it's a string or has a meaningful string representation - data(contentHandler, String.valueOf(v)); - } + /** + * Empty attributes used for contentHandler.startElement() + */ + protected static final AttributesImpl emptyAttr = new AttributesImpl(); + + /** + * Output an element containing text only and no attributes + * + * @param contentHandler The SAX content handler + * @param name The element name + * @param data The data contained by the element + */ + protected static void elementData( + String uri, + String prefix, + ContentHandler contentHandler, + String name, + String data) + throws SAXException { + start(uri, prefix, contentHandler, name); + data(contentHandler, data); + end(uri, prefix, contentHandler, name); + } + + /** + * Output an element containing text only and attributes + * + * @param contentHandler The SAX content handler + * @param name The element name + * @param data The data contained by the element + * @param attr The element attributes + */ + protected static void elementData( + String uri, + String prefix, + ContentHandler contentHandler, + String name, + String data, + AttributesImpl attr) + throws SAXException { + start(uri, prefix, contentHandler, name, attr); + data(contentHandler, data); + end(uri, prefix, contentHandler, name); + } + + /** + * Start an element with the proper object's uri and prefix and no + * attributes + * + * @param contentHandler The SAX content handler + * @param name The element name + */ + protected static void start( + String uri, + String prefix, + ContentHandler contentHandler, + String name) + throws SAXException { + contentHandler.startElement( + uri, + name, + new StringBuffer(prefix).append(":").append(name).toString(), + emptyAttr); + } + + /** + * Start an element with the proper object's uri and prefix and with + * attributes + * + * @param contentHandler The SAX content handler + * @param name The element name + * @param attr The element attributes + */ + protected static void start( + String uri, + String prefix, + ContentHandler contentHandler, + String name, + AttributesImpl attr) + throws SAXException { + contentHandler.startElement( + uri, + name, + new StringBuffer(prefix).append(":").append(name).toString(), + attr); + } + + /** + * End an element with the proper object's uri and prefix + * + * @param contentHandler The SAX content handler + * @param name The element name + */ + protected static void end( + String uri, + String prefix, + ContentHandler contentHandler, + String name) + throws SAXException { + contentHandler.endElement( + uri, + name, + new StringBuffer(prefix).append(":").append(name).toString()); + } + + /** + * Add an attribute + * + * @param attr The attribute list + * @param name The attribute name + * @param value The attribute value + */ + protected static void addAttribute( + AttributesImpl attr, + String name, + String value) + throws SAXException { + attr.addAttribute("", name, name, "CDATA", value); + } + + /** + * Add string data + * + * @param contentHandler The SAX content handler + * @param data The string data + */ + protected static void data(ContentHandler contentHandler, String data) + throws SAXException { + contentHandler.characters(data.toCharArray(), 0, data.length()); + } + + // <xsp:expr> methods + + /** + * Implementation of <xsp:expr> for <code>char</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, char v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>byte</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, byte v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>boolean</code> : + * outputs characters representing the value (true / false). + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, boolean v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>int</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, int v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>long</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, long v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>long</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, float v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>double</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, double v) + throws SAXException { + data(contentHandler, String.valueOf(v)); + } + + /** + * Implementation of <xsp:expr> for <code>String</code> : + * outputs characters representing the value. + * + * @param contentHandler the SAX content handler + * @param text the value + */ + public static void xspExpr(ContentHandler contentHandler, String text) + throws SAXException { + if (text != null) { + data(contentHandler, text); + } + } + + // Now handled by XMLizable + // /** + // * Implementation of <xsp:expr> for <code>XMLFragment</code> : + // * outputs the value by calling <code>v.toSax(contentHandler)</code>. + // * + // * @param contentHandler the SAX content handler + // * @param v the XML fragment + // */ + // public static void xspExpr(ContentHandler contentHandler, XMLFragment v) throws SAXException + // { + // if (v != null) + // { + // v.toSAX(contentHandler); + // } + // } + + /** + * Implementation of <xsp:expr> for <code>XMLizable</code> : + * outputs the value by calling <code>v.toSax(contentHandler)</code>. + * + * @param contentHandler the SAX content handler + * @param v the XML fragment + */ + public static void xspExpr(ContentHandler contentHandler, XMLizable v) + throws SAXException { + if (v != null) { + v.toSAX(contentHandler); + } + } + + /** + * Implementation of <xsp:expr> for <code>org.w3c.dom.Node</code> : + * converts the Node to a SAX event stream. + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, Node v) + throws SAXException { + if (v != null) { + DOMStreamer streamer = new DOMStreamer(contentHandler); + streamer.stream(v); + } + } + + /** + * Implementation of <xsp:expr> for <code>java.util.Collection</code> : + * outputs the value by calling <code>xspExpr()</code> on each element of the + * collection. + * + * @param contentHandler the SAX content handler + * @param v the XML fragment + */ + public static void xspExpr(ContentHandler contentHandler, Collection v) + throws SAXException { + if (v != null) { + Iterator iterator = v.iterator(); + while (iterator.hasNext()) { + xspExpr(contentHandler, iterator.next()); + } + } + } + + /** + * Implementation of <xsp:expr> for <code>Object</code> depending on its class : + * <ul> + * <li>if it's an array, call <code>xspExpr()</code> on all its elements,</li> + * <li>if it's class has a specific <code>xspExpr()</code>implementation, use it,</li> + * <li>else, output it's string representation.</li> + * </ul> + * + * @param contentHandler the SAX content handler + * @param v the value + */ + public static void xspExpr(ContentHandler contentHandler, Object v) + throws SAXException { + if (v == null) { + return; + } + + // Array: recurse over each element + if (v.getClass().isArray()) { + Object[] elements = (Object[]) v; + + for (int i = 0; i < elements.length; i++) { + xspExpr(contentHandler, elements[i]); + } + return; + } + + // Check handled object types in case they were not typed in the XSP + + // XMLizable + if (v instanceof XMLizable) { + xspExpr(contentHandler, (XMLizable) v); + return; + } + + // Now handled by XMLizable + // // XMLFragment + // if (v instanceof XMLFragment) + // { + // xspExpr(contentHandler, (XMLFragment)v); + // return; + // } + + // Node + if (v instanceof Node) { + xspExpr(contentHandler, (Node) v); + return; + } + + // Collection + if (v instanceof Collection) { + xspExpr(contentHandler, (Collection) v); + return; + } + + // Give up: hope it's a string or has a meaningful string representation + data(contentHandler, String.valueOf(v)); + } } 1.2 +12 -8 xml-cocoon2/src/blocks/xmldb/java/org/apache/cocoon/components/source/XMLDBSource.java Index: XMLDBSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/xmldb/java/org/apache/cocoon/components/source/XMLDBSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XMLDBSource.java 21 Feb 2003 14:45:58 -0000 1.1 +++ XMLDBSource.java 26 Feb 2003 15:02:39 -0000 1.2 @@ -205,15 +205,19 @@ * resource is a collection, build an XML view of it. * */ - public void toSAX(ContentHandler handler) throws SAXException, ProcessingException { + public void toSAX(ContentHandler handler) throws SAXException { - if (!connected) { - this.connect(); + try { + if (!connected) { + this.connect(); + } + if (url.endsWith("/")) + this.collectionToSAX(handler); + else + this.resourceToSAX(handler); + } catch (ProcessingException pe) { + throw new SAXException("ProcessingException", pe); } - if (url.endsWith("/")) - this.collectionToSAX(handler); - else - this.resourceToSAX(handler); } 1.7 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java Index: SessionAttributeGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SessionAttributeGenerator.java 31 Jan 2003 22:51:46 -0000 1.6 +++ SessionAttributeGenerator.java 26 Feb 2003 15:02:39 -0000 1.7 @@ -57,7 +57,7 @@ import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.xml.XMLUtils; -import org.apache.cocoon.xml.XMLizable; +import org.apache.excalibur.xml.sax.XMLizable; import org.w3c.dom.Node; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; 1.4 +2 -12 xml-cocoon2/src/deprecated/java/org/apache/cocoon/xml/XMLizable.java Index: XMLizable.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/xml/XMLizable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XMLizable.java 31 Jan 2003 22:50:24 -0000 1.3 +++ XMLizable.java 26 Feb 2003 15:02:40 -0000 1.4 @@ -50,9 +50,6 @@ */ package org.apache.cocoon.xml; -import org.apache.cocoon.ProcessingException; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; /** * This interface can be implemented by classes willing to provide an XML representation @@ -64,13 +61,6 @@ * @version CVS $Id$ */ -public interface XMLizable { - /** - * Generates SAX events representing the object's state.<br/> - * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken - * that <code>handler</code> can actually be a [EMAIL PROTECTED] org.apache.cocoon.xml.XMLConsumer} that accepts such - * events. - */ - void toSAX(ContentHandler handler) throws SAXException, ProcessingException; +public interface XMLizable extends org.apache.excalibur.xml.sax.XMLizable { }