cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r683394 - in /cocoon/whiteboard/corona/trunk: corona-pipeline/src/main/java/cc/ corona-pipeline/src/main/java/cc/cerebro/ corona-pipeline/src/main/java/cc/cerebro/client/ corona-pipeline/src/main/java/cc/cerebro/client/web/ corona-pipeline/...
Date Wed, 06 Aug 2008 20:27:17 GMT
Author: reinhard
Date: Wed Aug  6 13:27:16 2008
New Revision: 683394

URL: http://svn.apache.org/viewvc?rev=683394&view=rev
Log:
add stringtemplate generator

Added:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
  (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/   (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml   (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
  (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/org/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/org/apache/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/org/apache/cocoon/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/org/apache/cocoon/corona/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/org/apache/cocoon/corona/stringtemplate/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
  (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
  (with props)
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/test/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/test/java/
    cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/test/resources/

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java?rev=683394&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
Wed Aug  6 13:27:16 2008
@@ -0,0 +1,59 @@
+package cc.cerebro.client.web.generator;
+
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.caching.CacheKey;
+
+/**
+ * A {@link CacheKey} that contains a {@link Map} of parameters.
+ */
+public class ParameterCacheKey implements CacheKey {
+
+    private final Map<String, Object> parameters;
+
+    public ParameterCacheKey(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof ParameterCacheKey)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return ParameterCacheKey.class.hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.caching.CacheKey#isValid(org.apache.cocoon.corona.pipeline.caching.CacheKey)
+     */
+    public boolean isValid(CacheKey cacheKey) {
+        if (!this.equals(cacheKey)) {
+            return false;
+        }
+
+        ParameterCacheKey other = (ParameterCacheKey) cacheKey;
+        return this.parameters.equals(other.parameters);
+    }
+
+    public long getLastModifed() {
+        return -1;
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/cc/cerebro/client/web/generator/ParameterCacheKey.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Aug  6 13:27:16 2008
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project

Added: cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml?rev=683394&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml (added)
+++ cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml Wed Aug  6 13:27:16 2008
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+ -->
+<!-- $Id$ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>jar</packaging>
+
+  <parent>
+    <groupId>org.apache.cocoon.corona</groupId>
+    <artifactId>corona-parent</artifactId>
+    <version>1-SNAPSHOT</version>
+    <relativePath>../parent/pom.xml</relativePath>
+  </parent>
+
+  <artifactId>corona-stringtemplate</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <name>Cocoon Corona: String Templates [jar]</name>
+  <description>String-Template support for Corona.</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cocoon.corona</groupId>
+      <artifactId>corona-servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.antlr</groupId>
+      <artifactId>stringtemplate</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+        
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java?rev=683394&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
Wed Aug  6 13:27:16 2008
@@ -0,0 +1,109 @@
+package cc.cerebro.client.web.generator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.apache.cocoon.corona.pipeline.caching.CacheKey;
+import org.apache.cocoon.corona.pipeline.caching.CompoundCacheKey;
+import org.apache.cocoon.corona.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.corona.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.corona.pipeline.component.Starter;
+import org.apache.cocoon.corona.pipeline.component.sax.AbstractXMLProducer;
+import org.apache.cocoon.corona.servlet.controller.ControllerContextHelper;
+import org.apache.commons.io.IOUtils;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+public class StringTemplateGenerator extends AbstractXMLProducer implements Starter, CachingPipelineComponent
{
+
+    private URL source;
+    private Map<String, Object> parameters = new HashMap<String, Object>();
+
+    public StringTemplateGenerator() {
+        super();
+    }
+
+    public StringTemplateGenerator(URL source) {
+        super();
+        this.source = source;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.CachingPipelineComponent#constructCacheKey()
+     */
+    public CacheKey constructCacheKey() {
+        CompoundCacheKey cacheKey = new CompoundCacheKey();
+
+        try {
+            cacheKey.addCacheKey(new TimestampCacheKey(this.source, this.source.openConnection().getLastModified()));
+            cacheKey.addCacheKey(new ParameterCacheKey(this.parameters));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return cacheKey;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.Starter#execute()
+     */
+    public void execute() {
+        if (this.source == null) {
+            throw new IllegalArgumentException("StringTemplateGenerator has no source.");
+        }
+
+        try {
+            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+
+            xmlReader.setContentHandler(this.getXMLConsumer());
+            xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this.getXMLConsumer());
+
+            InputStream inputStream = this.source.openStream();
+            try {
+                StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(inputStream,
"UTF-8"));
+
+                Map<String, Object> controllerContext = ControllerContextHelper.getContext(this.parameters);
+                for (Entry<String, Object> eachEntry : controllerContext.entrySet())
{
+                    stringTemplate.setAttribute(eachEntry.getKey(), eachEntry.getValue());
+                }
+
+                xmlReader.parse(new InputSource(new StringReader(stringTemplate.toString())));
+            } finally {
+                IOUtils.closeQuietly(inputStream);
+
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.AbstractXMLProducer#setConfiguration(java.util.Map)
+     */
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> parameters) {
+        this.setSource((URL) parameters.get("source"));
+    }
+
+    @Override
+    public void setup(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+
+    public void setSource(URL source) {
+        this.source = source;
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/java/cc/cerebro/client/web/generator/StringTemplateGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml?rev=683394&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
(added)
+++ cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
Wed Aug  6 13:27:16 2008
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="
+  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+  <bean name="generator:string-template" class="cc.cerebro.client.web.generator.StringTemplateGenerator"
scope="prototype" />
+
+</beans>

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/META-INF/cocoon/spring/corona-stringtemplate-sitemap-components.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd?rev=683394&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
(added)
+++ cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
Wed Aug  6 13:27:16 2008
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- $Id$ -->
+<xsd:schema targetNamespace="http://apache.org/cocoon/corona/controller" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns="http://apache.org/cocoon/corona/controller" xmlns:map="http://apache.org/cocoon/corona/sitemap"
+  elementFormDefault="qualified">
+
+  <xsd:import namespace="http://apache.org/cocoon/corona/sitemap" />
+
+  <xsd:element name="call">
+    <xsd:annotation>
+      <xsd:documentation>Activate a controller instance.</xsd:documentation>
+    </xsd:annotation>
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element ref="map:parameter" minOccurs="0" maxOccurs="unbounded" />
+      </xsd:sequence>
+      <xsd:attribute name="controller" type="xsd:string">
+        <xsd:annotation>
+          <xsd:documentation>The type of the controller.</xsd:documentation>
+        </xsd:annotation>
+      </xsd:attribute>
+      <xsd:attribute name="select" type="xsd:string">
+        <xsd:annotation>
+          <xsd:documentation>A parameter that is passed to the invoked controller instance.</xsd:documentation>
+        </xsd:annotation>
+      </xsd:attribute>
+      <xsd:attribute name="wrapper-type" type="xsd:string" use="optional">
+        <xsd:annotation>
+          <xsd:documentation>
+            The pipeline component that is used to lookup the controller type implementation.
+          </xsd:documentation>
+        </xsd:annotation>
+      </xsd:attribute>
+    </xsd:complexType>
+  </xsd:element>
+
+</xsd:schema>

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-stringtemplate/src/main/resources/corona-controller-1.0.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message