cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: rev 36290 - in cocoon/branches/BRANCH_2_1_X: . src/java/org/apache/cocoon/transformation
Date Thu, 12 Aug 2004 16:01:24 GMT
Author: vgritsenko
Date: Thu Aug 12 09:01:23 2004
New Revision: 36290

Modified:
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Sync with 2.2: Added support for stripping root elements in the CIncludeTransformer.


Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
Thu Aug 12 09:01:23 2004
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -15,11 +15,11 @@
  */
 package org.apache.cocoon.transformation;
 
-import org.apache.excalibur.xml.xpath.XPathProcessor;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.components.sax.XMLDeserializer;
@@ -31,11 +31,14 @@
 import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.XMLUtils;
+
+import org.apache.commons.lang.StringUtils;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceParameters;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.xml.dom.DOMParser;
+import org.apache.excalibur.xml.xpath.XPathProcessor;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 import org.xml.sax.Attributes;
@@ -76,14 +79,14 @@
  *         <!-- more can follow -->
  *     </cinclude:parameters>
  * </cinclude:includexml>
- * 
+ *
  *
  * This transformer also supports caching of the included content.
  * Therefore it triggers for the element <code>cached-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.
- * First, it works like the usual include command. But it can be 
+ * First, it works like the usual include command. But it can be
  * configured with various parameters:
  * The most important one is the <code>expires</code> parameter.
  * If (and only if) this is set to a value greater than zero,
@@ -102,18 +105,18 @@
  * in a series.
  * With the optional parameter <code>preemptive</code> set to <code>true</code>
  * a pre-emptive caching is activated. When a resource is requested with
- * pre-emptive caching, this transformer always attempts to get the 
+ * pre-emptive caching, this transformer always attempts to get the
  * content from the cache. If the content is not in the cache, it is
  * of course retrieved from the original source and cached.
  * If the cached resource has expired, it is still provided. The cache
  * is updated by a background task. This task has to be started
  * beforehand.
- * 
+ *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * @author <a href="mailto:acoliver@apache.org">Andrew C. Oliver</a>
- * @version CVS $Id: CIncludeTransformer.java,v 1.10 2004/03/17 11:50:21 cziegeler Exp $
+ * @version CVS $Id$
  */
-public class CIncludeTransformer 
+public class CIncludeTransformer
 extends AbstractSAXTransformer
 implements Disposable, CacheableProcessingComponent {
 
@@ -124,6 +127,7 @@
     public static final String CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE = "select";
     public static final String CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE = "ns";
     public static final String CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE = "prefix";
+    public static final String CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE = "strip-root";
 
     public static final String CINCLUDE_INCLUDEXML_ELEMENT    = "includexml";
     public static final String CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE = "ignoreErrors";
@@ -142,30 +146,30 @@
 
     /** The configuration of includexml */
     protected Parameters configurationParameters;
-    
+
     /** The parameters for includexml */
     protected SourceParameters resourceParameters;
-    
+
     /** The current state: STATE_ */
     protected int state;
-    
+
     protected IncludeCacheManager cacheManager;
 
     protected IncludeCacheManagerSession cachingSession;
 
     protected boolean compiling;
-    
+
     protected IncludeXMLConsumer filter;
-    
+
     protected XMLSerializer recorder;
-    
+
     protected AttributesImpl srcAttributes = new AttributesImpl();
-    
+
     protected boolean supportCaching;
-    
+
     /** Remember the start time of the request for profiling */
     protected long startTime;
-    
+
    /**
      * Constructor
      * Set the namespace
@@ -173,7 +177,7 @@
     public CIncludeTransformer() {
         this.namespaceURI = CINCLUDE_NAMESPACE_URI;
     }
-    
+
     /**
      * Setup the component.
      */
@@ -187,8 +191,8 @@
         }
         this.compiling = false;
         this.supportCaching = parameters.getParameterAsBoolean("support-caching", false);
-        if (this.getLogger().isErrorEnabled()) {
-            this.getLogger().debug("Starting CIncludeTransformer with session " + this.cachingSession);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Starting, session " + this.cachingSession);
             this.startTime = System.currentTimeMillis();
         }
     }
@@ -198,10 +202,11 @@
      */
     public void service(ServiceManager manager) throws ServiceException {
         super.service(manager);
-        if ( this.manager.hasService( IncludeCacheManager.ROLE )) {
-            this.cacheManager = (IncludeCacheManager) this.manager.lookup( IncludeCacheManager.ROLE
);
+        if (this.manager.hasService(IncludeCacheManager.ROLE)) {
+            this.cacheManager = (IncludeCacheManager) this.manager.lookup(IncludeCacheManager.ROLE);
         } else {
-            this.getLogger().warn("The cinclude transformer cannot find the IncludeCacheManager.
Therefore caching is turned off for the include transformer.");
+            getLogger().warn("The cinclude transformer cannot find the IncludeCacheManager.
" +
+                             "Therefore caching is turned off for the include transformer.");
         }
     }
 
@@ -230,8 +235,9 @@
         super.recycle();
         this.configurationParameters = null;
         this.resourceParameters = null;
-        if (this.getLogger().isErrorEnabled()) {
-            this.getLogger().debug("Finishing CachingCIncludeTransformer, time: " + (System.currentTimeMillis()
- this.startTime));
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Finishing, time: " +
+                              (System.currentTimeMillis() - this.startTime));
             this.startTime = 0;
         }
         this.filter = null;
@@ -239,17 +245,21 @@
 
     public void startTransformingElement(String uri, String name, String raw, Attributes
attr)
     throws ProcessingException ,IOException, SAXException {
+        // Element: include
         if (name.equals(CINCLUDE_INCLUDE_ELEMENT)) {
+            String stripRootValue = attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE);
+            boolean stripRoot = StringUtils.equals(stripRootValue, "true");
 
-            this.processCIncludeElement(attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE),
-                                        attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE),
-                                        attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE),
-                                        attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE),
-                                        attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE),
-                                        false);
+            processCIncludeElement(attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE),
+                                   attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE),
+                                   attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE),
+                                   attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE),
+                                   attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE),
+                                   stripRoot,
+                                   false);
 
-        // Element: include
-        } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT) 
+        // Element: includexml
+        } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT)
                    && this.state == STATE_OUTSIDE) {
             this.state = STATE_INCLUDE;
             String ignoreErrors = attr.getValue("", CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE);
@@ -264,26 +274,26 @@
             this.ignoreWhitespaces = true;
 
         // target
-        } else if (name.equals(CINCLUDE_SRC_ELEMENT) 
+        } else if (name.equals(CINCLUDE_SRC_ELEMENT)
                    && this.state == STATE_INCLUDE) {
             this.startTextRecording();
 
         // configparameters
-        } else if (name.equals(CINCLUDE_CONFIGURATION_ELEMENT) 
+        } else if (name.equals(CINCLUDE_CONFIGURATION_ELEMENT)
                    && this.state == STATE_INCLUDE) {
             stack.push("end");
 
         // parameters
-        } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT) 
+        } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT)
                    && this.state == STATE_INCLUDE) {
             stack.push("end");
 
         // parameter
-        } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT) 
+        } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT)
                    && this.state == STATE_INCLUDE) {
 
         // parameter name
-        } else if (name.equals(CINCLUDE_NAME_ELEMENT) 
+        } else if (name.equals(CINCLUDE_NAME_ELEMENT)
                    && this.state == STATE_INCLUDE) {
             this.startTextRecording();
 
@@ -294,55 +304,56 @@
 
        } else if (name.equals(CINCLUDE_CACHED_INCLUDE_ELEMENT)) {
 
-           String src = this.processCIncludeElement(attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE),
-                                                    null,
-                                                    null,
-                                                    null,
-                                                    null,
-                                                    this.cacheManager != null);
+           String src = processCIncludeElement(attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE),
+                                               null,
+                                               null,
+                                               null,
+                                               null,
+                                               false,
+                                               this.cacheManager != null);
            if (this.compiling) {
                this.srcAttributes.addAttribute("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE,
CINCLUDE_SRC_ELEMENT, "CDATA", src);
-               super.startTransformingElement(uri, 
-                                              CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT,

-                                              raw+"p", 
+               super.startTransformingElement(uri,
+                                              CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT,
+                                              raw + "p",
                                               this.srcAttributes);
-               this.srcAttributes.clear();                                              

+               this.srcAttributes.clear();
            }
         } else {
             super.startTransformingElement(uri, name, raw, attr);
         }
     }
 
-    public void endTransformingElement(String uri, String name, String raw) 
+    public void endTransformingElement(String uri, String name, String raw)
     throws ProcessingException, IOException, SAXException {
         if (name.equals(CINCLUDE_INCLUDE_ELEMENT)) {
             // do nothing
             return;
 
-       // Element: includexml
         } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT)
                    && this.state == STATE_INCLUDE) {
-                    
+            // Element: includexml
+
             this.state = STATE_OUTSIDE;
 
             final String resource = (String)stack.pop();
 
-            final boolean ignoreErrors = ((String)stack.pop()).equals("true");
+            final boolean ignoreErrors = stack.pop().equals("true");
 
-            if (this.getLogger().isDebugEnabled()) {
-                getLogger().debug("Processing CIncludexml element: src=" + resource
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Processing includexml element: src=" + resource
                               + ", ignoreErrors=" + ignoreErrors
                               + ", configuration=" + this.configurationParameters
                               + ", parameters=" + this.resourceParameters);
             }
             Source source = null;
-            
+
             try {
-                source = SourceUtil.getSource(resource, 
-                                              this.configurationParameters, 
+                source = SourceUtil.getSource(resource,
+                                              this.configurationParameters,
                                               this.resourceParameters,
                                               this.resolver);
-                                              
+
                 XMLSerializer serializer = null;
                 XMLDeserializer deserializer = null;
                 try {
@@ -361,7 +372,7 @@
                 } finally {
                     this.manager.release( serializer );
                     this.manager.release( deserializer );
-                }               
+                }
             } catch (SourceException se) {
                 if (!ignoreErrors) throw SourceUtil.handle(se);
             } catch (SAXException se) {
@@ -379,7 +390,7 @@
         // src element
         } else if (name.equals(CINCLUDE_SRC_ELEMENT)
                    && this.state == STATE_INCLUDE) {
-                   
+
             this.stack.push(this.endTextRecording());
 
         } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT)
@@ -420,7 +431,7 @@
 
         } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT) == true
                    && this.state == STATE_INCLUDE) {
-            
+
         } else if (name.equals(CINCLUDE_NAME_ELEMENT) == true
                    && this.state == STATE_INCLUDE) {
             stack.push(this.endTextRecording());
@@ -434,9 +445,9 @@
 
         } else if (name.equals(CINCLUDE_CACHED_INCLUDE_ELEMENT)) {
             if (this.compiling) {
-               super.endTransformingElement(uri, 
+               super.endTransformingElement(uri,
                                             CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT,
-                                            raw+"p");
+                                            raw + "p");
             }
             // do nothing else
         } else {
@@ -444,8 +455,9 @@
         }
     }
 
-    protected String processCIncludeElement(String src, String element, 
+    protected String processCIncludeElement(String src, String element,
                                             String select, String ns, String prefix,
+                                            boolean stripRoot,
                                             boolean cache)
     throws SAXException, IOException {
 
@@ -458,13 +470,14 @@
         if (ns == null) ns="";
         if (prefix == null) prefix="";
 
-        if (this.getLogger().isDebugEnabled()) {
-            getLogger().debug("Processing CInclude element: src=" + src
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Processing include element: src=" + src
                           + ", element=" + element
                           + ", select=" + select
                           + ", ns=" + ns
                           + ", prefix=" + prefix
-                          + ", caching="+cache);
+                          + ", stripRoot=" + stripRoot
+                          + ", caching=" + cache);
         }
 
         if (cache) {
@@ -478,7 +491,7 @@
             } else {
                 this.cacheManager.stream(src, this.cachingSession, this.filter);
             }
-        
+
             return src;
         }
 
@@ -500,10 +513,10 @@
 
             if (!"".equals(select)) {
 
-                
+
                 DOMParser parser = null;
                 XPathProcessor processor = null;
-                
+
                 try {
                     parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                     processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
@@ -515,7 +528,7 @@
                     int length = list.getLength();
                     for (int i=0; i<length; i++) {
                           IncludeXMLConsumer.includeNode(list.item(i),
-                                               this,  
+                                               this,
                                                this);
                     }
                 } finally {
@@ -524,17 +537,17 @@
                 }
             } else {
                 String mimeType = null;
-                if ( null != this.configurationParameters ) {
-                    mimeType = this.configurationParameters.getParameter("mime-type", mimeType);
                   
+                if (null != this.configurationParameters) {
+                    mimeType = this.configurationParameters.getParameter("mime-type", mimeType);
                 }
-                if ( this.compiling ) {
+                if (this.compiling) {
                     SourceUtil.toSAX(source, mimeType, new IncludeXMLConsumer(this.contentHandler,
this.lexicalHandler));
                 } else {
+                    this.filter.setIgnoreRootElement(stripRoot);
                     SourceUtil.toSAX(source, mimeType, this.filter);
                 }
             }
 
-
         } catch (SourceException se) {
             throw new SAXException("Exception in CIncludeTransformer",se);
         } catch (IOException e) {
@@ -555,7 +568,7 @@
         }
         return src;
     }
-    
+
     /**
      * Start recording of compiled xml.
      * The incomming SAX events are recorded and a compiled representation
@@ -570,9 +583,9 @@
 
         try {
             this.recorder = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
-            
+
             this.addRecorder(recorder);
-  
+
         } catch (ServiceException ce) {
             throw new SAXException("Unable to lookup xml serializer for compiling xml.",
ce);
         }
@@ -592,7 +605,7 @@
         }
 
         XMLSerializer recorder = (XMLSerializer)this.removeRecorder();
-        Object text = (byte[])recorder.getSAXFragment();
+        Object text = recorder.getSAXFragment();
 
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("END endCompiledXMLRecording text="+text);
@@ -607,7 +620,7 @@
         this.filter = new MyFilter(this.xmlConsumer, this);
         super.startDocument();
     }
-    
+
     /**
      * @see org.xml.sax.ContentHandler#endDocument()
      */
@@ -632,8 +645,8 @@
      * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
      */
     public Serializable getKey() {
-        if (this.supportCaching 
-            && null != this.cacheManager 
+        if (this.supportCaching
+            && null != this.cacheManager
             && this.cachingSession.getExpires() > 0) {
             return "1";
         }
@@ -644,7 +657,7 @@
      * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
      */
     public SourceValidity getValidity() {
-        if (this.supportCaching 
+        if (this.supportCaching
             && null != this.cacheManager
             && this.cachingSession.getExpires() > 0
             && !this.cachingSession.isPurging()) {
@@ -652,13 +665,13 @@
         }
         return null;
     }
-    
+
 }
 
 final class MyFilter extends IncludeXMLConsumer {
 
     private CIncludeTransformer transformer;
-    
+
     /**
      * This filter class post-processes the parallel fetching
      * @param consumer
@@ -667,17 +680,17 @@
         super(consumer);
         this.transformer = transformer;
     }
-    
-    
+
+
     public void endElement(String uri, String local, String qName)
     throws SAXException {
-        if (uri != null 
+        if (uri != null
             && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
             && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT))
{
             // this is the placeholder element: do nothing
         } else {
             super.endElement(uri, local, qName);
-        }        
+        }
     }
 
     public void startElement(String uri,
@@ -685,7 +698,7 @@
                                 String qName,
                                 Attributes attr)
     throws SAXException {
-        if (uri != null 
+        if (uri != null
             && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
             && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT))
{
             // this is a placeholder
@@ -697,7 +710,7 @@
             }
         } else {
             super.startElement(uri, local, qName, attr);
-        }        
+        }
     }
 
 }

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml	Thu Aug 12 09:01:23 2004
@@ -206,9 +206,16 @@
    <action dev="AG" type="update">
      Updated Apache Ant to 1.6.2.
    </action>
-    <action dev="CZ" type="fix">
+   <action dev="CZ" type="fix">
      Mail block: The mail transformer ignored configured toAddresses from a pipeline parameter.
This is fixed now.
    </action>
+   <action dev="TC" type="add" fixes-bug="29935" due-to="Leszek Gawron" due-to-email="ouzo@wlkp.org">
+     Added support for stripping root elements in the CIncludeTransformer.
+   </action>
+   <action dev="VG" type="add">
+     Portal block: Added ManagedCocoonPortlet, to be used together with
+     CocoonServlet or CocoonPortlet.
+   </action>
    <action dev="VG" type="update">
      Portal: CocoonPortlet has new configuration parameter,
      default-session-scope.
@@ -226,7 +233,7 @@
      Portal: Fix problem with bookmarks and CachingURICoplet
    </action>
  </release>
-<release version="2.1.5.1" date="July 9 2004">
+ <release version="2.1.5.1" date="July 9 2004">
    <action dev="CZ" type="update">
      The store/caching system now uses JCS instead of Jisp.
    </action>

Mime
View raw message