cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r595785 - in /cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal: ./ components/ coplet/adapter/impl/ impl/ layout/renderer/aspect/impl/ services/
Date Fri, 16 Nov 2007 19:21:24 GMT
Author: cziegeler
Date: Fri Nov 16 11:21:23 2007
New Revision: 595785

URL: http://svn.apache.org/viewvc?rev=595785&view=rev
Log:
Add new variable resolver service to remove dependencies to tree processor.

Added:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
  (with props)
Removed:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/components/
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/PortalService.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/XSLTAspect.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/PortalService.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/PortalService.java?rev=595785&r1=595784&r2=595785&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/PortalService.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/PortalService.java
Fri Nov 16 11:21:23 2007
@@ -28,6 +28,7 @@
 import org.apache.cocoon.portal.services.LinkService;
 import org.apache.cocoon.portal.services.PortalManager;
 import org.apache.cocoon.portal.services.UserService;
+import org.apache.cocoon.portal.services.VariableResolver;
 import org.apache.cocoon.processing.ProcessInfoProvider;
 
 /**
@@ -141,4 +142,10 @@
      * Get the user service.
      */
     UserService getUserService();
+
+    /**
+     * Get the variable resolver
+     * @since 2.2
+     */
+    VariableResolver getVariableResolver();
 }

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java?rev=595785&r1=595784&r2=595785&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
Fri Nov 16 11:21:23 2007
@@ -17,13 +17,15 @@
 package org.apache.cocoon.portal.coplet.adapter.impl;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.source.SourceUtil;
+import javax.xml.transform.sax.SAXResult;
+
+import org.apache.cocoon.core.xml.SAXParser;
 import org.apache.cocoon.portal.om.CopletInstance;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 /**
@@ -34,11 +36,10 @@
 public class URICopletAdapter
     extends AbstractCopletAdapter {
 
-    /** The source resolver */
-    protected SourceResolver resolver;
+    protected SAXParser parser;
 
-    public void setSourceResolver(SourceResolver resolver) {
-        this.resolver = resolver;
+    public void setSAXParser(final SAXParser p) {
+        this.parser = p;
     }
 
     /**
@@ -48,7 +49,7 @@
     throws SAXException {
         final String uri = (String)coplet.getCopletDefinition().getAttribute("uri");
         if ( uri == null ) {
-            throw new SAXException("No URI for coplet definition "+coplet.getCopletDefinition().getId()+"
found.");
+            throw new SAXException("No URI for coplet definition " + coplet.getCopletDefinition().getId()+"
found.");
         }
         this.streamContent( coplet, uri, contentHandler);
     }
@@ -60,16 +61,18 @@
         if ( this.getLogger().isDebugEnabled() ) {
             this.getLogger().debug("Streaming coplet instance + " + coplet + " using uri:
" + uri);
         }
-		Source copletSource = null;
 		try {
-			copletSource = this.resolver.resolveURI(uri);
-			SourceUtil.toSAX(copletSource, contentHandler);
+	        final URL url = new URL(uri);
+	        final Object content = url.getContent(new Class[] {SAXResult.class});
+	        if ( content instanceof SAXResult ) {
+	            ((SAXResult)content).setHandler(contentHandler);
+	        } else {
+	            final InputSource source = new InputSource((InputStream)content);
+	            source.setSystemId(url.toExternalForm());
+	            this.parser.parse(source, contentHandler);
+	        }
 		} catch (IOException ioe) {
-			throw new SAXException("IOException", ioe);
-		} catch (ProcessingException pe) {
-			throw new SAXException("ProcessingException", pe);
-		} finally {
-			this.resolver.release(copletSource);
+			throw new SAXException("Unable to stream coplet instance " + coplet + " from uri " + uri,
ioe);
 		}
     }
 

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java?rev=595785&r1=595784&r2=595785&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
Fri Nov 16 11:21:23 2007
@@ -50,6 +50,8 @@
 import org.apache.cocoon.portal.services.LinkService;
 import org.apache.cocoon.portal.services.PortalManager;
 import org.apache.cocoon.portal.services.UserService;
+import org.apache.cocoon.portal.services.VariableResolver;
+import org.apache.cocoon.portal.services.VariableResolver.CompiledExpression;
 import org.apache.cocoon.processing.ProcessInfoProvider;
 import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.excalibur.source.Source;
@@ -417,6 +419,38 @@
         return new RequestContextImpl(this.processInfoProvider);
     }
 
+    /**
+     * TODO Make this a real service
+     * @see org.apache.cocoon.portal.PortalService#getVariableResolver()
+     */
+    public VariableResolver getVariableResolver() {
+        return new VariableResolverImpl();
+    }
+
+    public static final class VariableResolverImpl implements VariableResolver {
+
+        public CompiledExpression compile(String expression) {
+            return new CompiledExpressionImpl(expression);
+        }
+
+        public String resolve(String expression) {
+            return expression;
+        }
+    }
+
+    public static final class CompiledExpressionImpl implements CompiledExpression {
+
+        protected final String expression;
+
+        public CompiledExpressionImpl(String e) {
+            this.expression = e;
+        }
+
+        public String resolve() {
+            return this.expression;
+        }
+
+    }
     public static final class RequestContextImpl implements RequestContext {
 
         protected final ProcessInfoProvider provider;

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/XSLTAspect.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/XSLTAspect.java?rev=595785&r1=595784&r2=595785&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/XSLTAspect.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/XSLTAspect.java
Fri Nov 16 11:21:23 2007
@@ -17,10 +17,8 @@
 package org.apache.cocoon.portal.layout.renderer.aspect.impl;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
@@ -28,16 +26,13 @@
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.sax.TransformerHandler;
 
-import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
-import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
 import org.apache.cocoon.portal.PortalException;
 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
 import org.apache.cocoon.portal.om.Layout;
 import org.apache.cocoon.portal.om.LayoutException;
-import org.apache.cocoon.sitemap.PatternException;
+import org.apache.cocoon.portal.services.VariableResolver;
 import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
@@ -78,16 +73,14 @@
  * <table><tbody>
  * <tr><th>style</th><td></td><td>req</td><td>String</td><td><code>null</code></td></tr>
  * <tr><th>xslt-processor-role</th><td></td><td>req</td><td>String</td><td><code>null</code></td></tr>
- * </tbody></table>  
+ * </tbody></table>
  *
  * TODO - Remove all dependencies to Avalon.
  * @version $Id$
  */
-public class XSLTAspect 
+public class XSLTAspect
     extends AbstractAspect {
 
-    protected List variables = new ArrayList();
-
     /** Additional parameters passed to the stylesheet. */
     protected Map parameters;
 
@@ -101,7 +94,7 @@
     }
 
     public void setSourceResolver(SourceResolver resolver) {
-        this.resolver = resolver;   
+        this.resolver = resolver;
     }
 
     public void setXsltParameters(Map p) {
@@ -124,7 +117,7 @@
             processor = (XSLTProcessor) this.serviceManager.lookup(config.xsltRole);
             TransformerHandler transformer = processor.getTransformerHandler(stylesheet);
             // Pass configured parameters to the stylesheet.
-            if (config.parameters.size() > 0) {                
+            if (config.parameters.size() > 0) {
                 Transformer theTransformer = transformer.getTransformer();
                 Iterator iter = config.parameters.entrySet().iterator();
                 while (iter.hasNext()) {
@@ -163,41 +156,23 @@
         }
 	}
 
-    protected String getStylesheetURI(PreparedConfiguration config, Layout layout) 
+    protected String getStylesheetURI(PreparedConfiguration config, Layout layout)
     throws SAXException {
-        final Map objectModel = this.portalService.getProcessInfoProvider().getObjectModel();
         String stylesheet = layout.getParameter("stylesheet");
         if ( stylesheet != null ) {
-            VariableResolver variableResolver = null;
-            try {
-                variableResolver = VariableResolverFactory.getResolver(stylesheet, this.serviceManager);
-                stylesheet = variableResolver.resolve(objectModel);
-            } catch (PatternException pe) {
-                throw new SAXException("Unknown pattern for stylesheet " + stylesheet, pe);
-            } finally {
-                ContainerUtil.dispose(variableResolver);
-            }            
+            stylesheet = this.portalService.getVariableResolver().resolve(stylesheet);
         } else {
-            try {
-                stylesheet = config.stylesheet.resolve(objectModel);
-            } catch (PatternException pe) {
-                throw new SAXException("Pattern exception during variable resolving.", pe);
           
-            }
+            stylesheet = config.stylesheet.resolve();
         }
         return stylesheet;
     }
 
     protected String getParameterValue(Map.Entry entry) throws SAXException {
-        final Map objectModel = this.portalService.getProcessInfoProvider().getObjectModel();
-        try {
-            return ((VariableResolver)entry.getValue()).resolve(objectModel);
-        } catch (PatternException pe) {
-            throw new SAXException("Unable to get value for parameter " + entry.getKey(),
pe);
-        }
+        return ((VariableResolver.CompiledExpression)entry.getValue()).resolve();
     }
 
     protected static class PreparedConfiguration {
-        public VariableResolver stylesheet;
+        public VariableResolver.CompiledExpression stylesheet;
         public String xsltRole;
         public Map parameters = new HashMap();
 
@@ -216,39 +191,16 @@
         PreparedConfiguration pc = new PreparedConfiguration();
         pc.xsltRole = configuration.getProperty("xslt-processor-role", XSLTProcessor.ROLE);
         String stylesheet = configuration.getProperty("style", null);
-        try {
-            pc.stylesheet = VariableResolverFactory.getResolver(stylesheet, this.serviceManager);
-        } catch (PatternException pe) {
-            throw new PortalException("Unknown pattern for stylesheet " + stylesheet, pe);
-        }
-        this.variables.add(pc.stylesheet);
+        pc.stylesheet = this.portalService.getVariableResolver().compile(stylesheet);
         if (this.parameters != null) {
             final Iterator i = this.parameters.entrySet().iterator();
             while ( i.hasNext() ) {
                 final Map.Entry current = (Map.Entry)i.next();
-                try {
-                    VariableResolver variableResolver =
-                        VariableResolverFactory.getResolver(current.getValue().toString(),
this.serviceManager);
-                    this.variables.add(variableResolver);
-                    pc.parameters.put(current.getKey(), variableResolver);
-                } catch (PatternException e) {
-                    throw new PortalException("Invalid value for parameter " + current.getKey()
+ " : " + current.getValue(), e);
-                }
+                VariableResolver.CompiledExpression compiledExpression =
+                    this.portalService.getVariableResolver().compile(current.getValue().toString());
+                pc.parameters.put(current.getKey(), compiledExpression);
             }
         }
         return pc;
-    }
-
-    /**
-     * Destroy this component.
-     */
-    public void destroy() {
-        if ( this.serviceManager != null ) {
-            Iterator vars = this.variables.iterator();
-            while ( vars.hasNext() ) {
-                ContainerUtil.dispose(vars.next());
-            }
-            this.variables.clear();
-        }
     }
 }

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java?rev=595785&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
Fri Nov 16 11:21:23 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.portal.services;
+
+public interface VariableResolver {
+
+    public interface CompiledExpression {
+
+        String resolve();
+    }
+
+    String resolve(String expression);
+
+    CompiledExpression compile(String expression);
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/VariableResolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message