cziegeler 2003/02/26 07:46:51
Modified: . build.xml src/java/org/apache/cocoon/xml XMLUtils.java XMLFragment.java Added: src/deprecated/java/org/apache/cocoon/components/source/impl CocoonToAvalonSource.java src/deprecated/java/org/apache/cocoon/transformation CachingCIncludeTransformer.java Removed: src/java/org/apache/cocoon/transformation CachingCIncludeTransformer.java src/java/org/apache/cocoon/components/source/impl CocoonToAvalonSource.java Log: Updating code; removing dependencies on deprecated code Revision Changes Path 1.336 +2 -2 xml-cocoon2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/build.xml,v retrieving revision 1.335 retrieving revision 1.336 diff -u -r1.335 -r1.336 --- build.xml 26 Feb 2003 15:25:58 -0000 1.335 +++ build.xml 26 Feb 2003 15:46:44 -0000 1.336 @@ -190,7 +190,7 @@ classpathref="classpath"> <src> <!-- [FIXME] THE DEPENDENCY ON DEPRECATED SHOULD GO AWAY!!!! --> - <path location="${deprecated.src}"/> + <path location="${deprecated.src}"/> <path location="${build.src}"/> <path location="${java}"/> </src> 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java Index: CocoonToAvalonSource.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 java.io.IOException; import java.io.InputStream; import java.util.Iterator; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.excalibur.source.*; import org.apache.excalibur.source.impl.validity.TimeStampValidity; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.environment.ModifiableSource; import org.apache.excalibur.xml.sax.XMLizable; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; /** * This source objects wraps an obsolete Cocoon Source object * to avoid recoding existing source objects. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Revision: 1.1 $ $Date: 2003/02/26 15:46:45 $ */ 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) { this.source = source; int pos = location.indexOf(':'); this.protocol = location.substring(0, pos); } /** * Return the protocol identifier. */ public String getScheme() { return this.protocol; } /** * @see org.apache.excalibur.source.Source#exists() */ public boolean exists() { try { this.getInputStream(); return true; } catch (Exception local) { return false; } } /** * Return an <code>InputStream</code> object to read from the source. */ public InputStream getInputStream() throws IOException, SourceException { try { return this.source.getInputStream(); } catch (ResourceNotFoundException rnfe) { throw new SourceNotFoundException("Source not found.", rnfe); } catch (ProcessingException pe) { throw new SourceException("ProcessingException", pe); } } /** * Return the unique identifer for this source */ public String getURI() { return this.source.getSystemId(); } /** * Get the Validity object. This can either wrap the last modification * date or the expires information or... * If it is currently not possible to calculate such an information * <code>null</code> is returned. */ public SourceValidity getValidity() { if (this.source.getLastModified() > 0) { return new TimeStampValidity(this.source.getLastModified()); } return null; } /** * Refresh this object and update the last modified date * and content length. */ public void refresh() { if (this.source instanceof ModifiableSource) { ((ModifiableSource) this.source).refresh(); } } /** * The mime-type of the content described by this object. * If the source is not able to determine the mime-type by itself * this can be null. */ public String getMimeType() { return null; } /** * Stream content to the content handler */ public void toSAX(ContentHandler contentHandler) throws SAXException { this.source.toSAX(contentHandler); } /** * Recyclable */ public void recycle() { this.source.recycle(); } /** * Return the content length of the content or -1 if the length is * unknown */ public long getContentLength() { return this.source.getContentLength(); } /** * 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 value of a parameter. * Using this it is possible to get custom information provided by the * source implementation, like an expires date, HTTP headers etc. */ public String getParameter(String name) { return null; } /** * Get the value of a parameter. * Using this it is possible to get custom information provided by the * source implementation, like an expires date, HTTP headers etc. */ public long getParameterAsLong(String name) { return 0; } /** * Get parameter names * Using this it is possible to get custom information provided by the * source implementation, like an expires date, HTTP headers etc. */ public Iterator getParameterNames() { return java.util.Collections.EMPTY_LIST.iterator(); } } 1.16 +1 -20 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- XMLUtils.java 26 Feb 2003 15:20:45 -0000 1.15 +++ XMLUtils.java 26 Feb 2003 15:46:50 -0000 1.16 @@ -269,20 +269,6 @@ * @param contentHandler the SAX content handler * @param v the XML fragment */ - public static void valueOf(ContentHandler contentHandler, XMLizable 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 valueOf(ContentHandler contentHandler, org.apache.excalibur.xml.sax.XMLizable v) throws SAXException { @@ -358,11 +344,6 @@ // Check handled object types in case they were not typed in the XSP // XMLizable - if (v instanceof XMLizable) { - valueOf(contentHandler, (XMLizable)v); - return; - } - if (v instanceof org.apache.excalibur.xml.sax.XMLizable) { valueOf(contentHandler, (org.apache.excalibur.xml.sax.XMLizable)v); } 1.6 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/xml/XMLFragment.java Index: XMLFragment.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/xml/XMLFragment.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XMLFragment.java 31 Jan 2003 22:51:59 -0000 1.5 +++ XMLFragment.java 26 Feb 2003 15:46:50 -0000 1.6 @@ -67,7 +67,7 @@ * @version CVS $Id$ */ -public interface XMLFragment extends XMLizable { +public interface XMLFragment extends org.apache.excalibur.xml.sax.XMLizable { // Now inherited from XMLizable // /** // * Generates SAX events representing the object's state 1.1 xml-cocoon2/src/deprecated/java/org/apache/cocoon/transformation/CachingCIncludeTransformer.java Index: CachingCIncludeTransformer.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.transformation; 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.parameters.Parameters; import org.apache.excalibur.source.Source; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.CacheValidity; import org.apache.cocoon.caching.Cacheable; import org.apache.cocoon.caching.IncludeCacheValidity; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.xml.IncludeXMLConsumer; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; import java.util.Map; /** * <p>This transformer triggers for the element <code>include</code> in the * namespace "http://apache.org/cocoon/include/1.0". * The <code>src</code> attribute contains the url which points to * an xml resource which is include instead of the element. * With the attributes <code>element</code>, <code>ns</code> and * <code>prefix</code> it is possible to specify an element * which surrounds the included content.</p> * * <p>Validity of cached pipelines is calculated not by comparing old and new * IncludeCacheValidity objects (as in AggregatedCacheValidity) but by comparing * timestamps. Validity object of cached pipeline contain two lists: source urls * and timestamps. When it comes to checking validity of cached pipeline we know * that generation/transformation steps before CIncludeTransformer are valid (otherwise * we would have had discarded cached pipeline already) so source url list * of new validity will be the same as of old one. Only timestamps have to be * recalculated and compared.</p> * * @author <a href="mailto:[EMAIL PROTECTED]">Maciek Kaminski</a> * @deprecated This transformer violates the avalon/cocoon design principles * @version CVS $Id: CachingCIncludeTransformer.java,v 1.1 2003/02/26 15:46:51 cziegeler Exp $ */ public class CachingCIncludeTransformer extends AbstractTransformer implements Composable, Cacheable { public static final String CINCLUDE_NAMESPACE_URI = "http://apache.org/cocoon/include/1.0"; public static final String CINCLUDE_INCLUDE_ELEMENT = "include"; public static final String CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE = "src"; public static final String CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE = "element"; public static final String CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE = "ns"; public static final String CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE = "prefix"; /** The <code>SourceResolver</code> */ protected SourceResolver sourceResolver; /** The current <code>ComponentManager</code>. */ protected ComponentManager manager = null; /** The current <code>IncludeCacheValidity</code>. */ protected IncludeCacheValidity currentCacheValidity; /** The current <code>IncludeXMLConsumer</code> that ommits start and endDocument events. */ protected IncludeXMLConsumer consumer; /** * Setup the component. */ public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException { this.sourceResolver = resolver; } /** * Composable Interface */ public final void compose(final ComponentManager manager) throws ComponentException { this.manager = manager; } /** * Recycle the component */ public void recycle() { super.recycle(); this.sourceResolver = null; this.currentCacheValidity = null; } public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException { if (uri != null && name != null && uri.equals(CINCLUDE_NAMESPACE_URI) && name.equals(CINCLUDE_INCLUDE_ELEMENT)) { this.processCIncludeElement(attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE), attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE), attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE), attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE)); } else { super.startElement(uri, name, raw, attr); } } public void endElement(String uri, String name, String raw) throws SAXException { if (uri != null && name != null && uri.equals(CINCLUDE_NAMESPACE_URI) && name.equals(CINCLUDE_INCLUDE_ELEMENT)) { return; } super.endElement(uri, name, raw); } public void endDocument() throws SAXException { super.endDocument(); if(currentCacheValidity != null) { currentCacheValidity.setIsNew2False(); } } protected void processCIncludeElement(String src, String element, String ns, String prefix) throws SAXException { if (element == null) element=""; if (ns == null) ns=""; if (prefix == null) prefix=""; if (this.getLogger().isDebugEnabled()) { getLogger().debug("Processing CInclude element: src=" + src + ", element=" + element + ", ns=" + ns + ", prefix=" + prefix); } // complete validity information if(currentCacheValidity != null ) { Source temp = null; try { temp = sourceResolver.resolveURI(src); currentCacheValidity.add(src, temp.getLastModified()); if (this.getLogger().isDebugEnabled()) { getLogger().debug("currentCacheValidity: " + currentCacheValidity); } } catch (Exception e) { throw new SAXException("CachingCIncludeTransformer could not resolve resource", e); } finally { sourceResolver.release(temp); } } if (!"".equals(element)) { AttributesImpl attrs = new AttributesImpl(); if (!ns.equals("")) { super.startPrefixMapping(prefix, ns); } super.startElement(ns, element, (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element), attrs); } Source source = null; try { source = this.sourceResolver.resolveURI(src); this.sourceResolver.toSAX(source, getConsumer()); } catch (Exception e) { throw new SAXException("CachingCIncludeTransformer could not read resource", e); } finally { sourceResolver.release(source); } if (!"".equals(element)) { super.endElement(ns, element, (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element)); if (!ns.equals("")) { super.endPrefixMapping(prefix); } } } /** * Generate the unique key. * This key must be unique inside the space of this component. * CachingCIncludeTransformer always generates the same key since which documents * are included depends only on former generation/transformation stages. * * @return The generated key hashes the src */ public long generateKey() { return 1; } /** * Generate the validity object. * CachingCIncludeTransformer generates "empty" IncludeCacheValidity * and completes it with validity data during transformation. * See processCIncludeElement method. * * @return The generated validity object or <code>null</code> if the * component is currently not cacheable. */ public CacheValidity generateValidity() { try { currentCacheValidity = new IncludeCacheValidity(sourceResolver); return currentCacheValidity; } catch (RuntimeException e) { getLogger().warn("CachingCIncludeTransformer: could not generateKey", e); return null; } } protected IncludeXMLConsumer getConsumer() { if(consumer == null) { consumer = new IncludeXMLConsumer(this); } return consumer; } }