Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 60020 invoked from network); 13 Aug 2004 11:20:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 Aug 2004 11:20:05 -0000 Received: (qmail 86294 invoked by uid 500); 13 Aug 2004 11:20:02 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 86131 invoked by uid 500); 13 Aug 2004 11:20:01 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 86120 invoked by uid 99); 13 Aug 2004 11:20:01 -0000 X-ASF-Spam-Status: No, hits=-2.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME,URIBL_SBL X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Fri, 13 Aug 2004 04:20:00 -0700 Received: (qmail 59868 invoked by uid 65534); 13 Aug 2004 11:20:00 -0000 Date: 13 Aug 2004 11:20:00 -0000 Message-ID: <20040813112000.59865.qmail@minotaur.apache.org> From: unico@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 36337 - in cocoon/branches/BRANCH_2_1_X/src: blocks/scratchpad/java/org/apache/cocoon/transformation java/org/apache/cocoon/components/source/impl X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: unico Date: Fri Aug 13 04:19:59 2004 New Revision: 36337 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java - copied, changed from rev 36290, cocoon/branches/BRANCH_2_1_X/src/blocks/repository/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java Log: sync with 2.2: move MultiSourceValidity to the core and add simple caching Source IncludeTransformer to the scratchpad (see bug 30356) Added: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java Fri Aug 13 04:19:59 2004 @@ -0,0 +1,131 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.transformation; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Map; + +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.caching.CacheableProcessingComponent; +import org.apache.cocoon.components.source.SourceUtil; +import org.apache.cocoon.components.source.impl.MultiSourceValidity; +import org.apache.cocoon.environment.SourceResolver; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceValidity; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Simple Source include transformer. + * + *

+ * Triggers for the element include in the + * namespace http://apache.org/cocoon/include/1.0. + * Use <include src="scheme://path"/> + *

+ * + * @cocoon.sitemap.component.name include + * @cocoon.sitemap.component.logger sitemap.transformer.include + * + * @cocoon.sitemap.component.pooling.min 2 + * @cocoon.sitemap.component.pooling.max 16 + * @cocoon.sitemap.component.pooling.grow 2 + */ +public class IncludeTransformer extends AbstractTransformer +implements Serviceable, Transformer, CacheableProcessingComponent { + + private static final String NS_URI = "http://apache.org/cocoon/include/1.0"; + private static final String INCLUDE_ELEMENT = "include"; + private static final String SRC_ATTRIBUTE = "src"; + + private SourceResolver m_resolver; + private ServiceManager m_manager; + private MultiSourceValidity m_validity; + + public IncludeTransformer() { + super(); + } + + public void service(ServiceManager manager) throws ServiceException { + m_manager = manager; + } + + public void setup(SourceResolver resolver, Map om, String src, Parameters parameters) + throws ProcessingException, SAXException, IOException { + m_resolver = resolver; + m_validity = null; + } + + public void startElement(String uri, String localName, String qName, Attributes atts) + throws SAXException { + if (NS_URI.equals(uri)) { + if (INCLUDE_ELEMENT.equals(localName)) { + String src = atts.getValue(SRC_ATTRIBUTE); + Source source = null; + try { + source = m_resolver.resolveURI(src); + if (m_validity != null) { + m_validity.addSource(source); + } + SourceUtil.toSAX(m_manager, source, "text/xml", super.contentHandler); + } + catch (IOException e) { + throw new SAXException(e); + } + catch (ProcessingException e) { + throw new SAXException(e); + } + finally { + if (source != null) { + m_resolver.release(source); + } + } + } + } + else { + super.startElement(uri, localName, qName, atts); + } + } + + public void recycle() { + super.recycle(); + m_resolver = null; + m_validity = null; + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + if (!NS_URI.equals(uri)) { + super.endElement(uri, localName, qName); + } + } + + public Serializable getKey() { + return "IncludeTransformer"; + } + + public SourceValidity getValidity() { + if (m_validity == null) { + m_validity = new MultiSourceValidity(m_resolver, -1); + } + return m_validity; + } + +} Copied: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java (from rev 36290, cocoon/branches/BRANCH_2_1_X/src/blocks/repository/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java) ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/repository/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java Fri Aug 13 04:19:59 2004 @@ -28,7 +28,7 @@ * An aggregated validity for multiple sources. * * @author Sylvain Wallez - * @version CVS $Id: MultiSourceValidity.java,v 1.3 2004/03/05 13:02:21 bdelacretaz Exp $ + * @version CVS $Id$ */ public class MultiSourceValidity extends AbstractAggregatedValidity implements SourceValidity {