You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2007/03/09 01:28:40 UTC
svn commit: r516239 - in /incubator/roller/trunk/sandbox/scripting/groovy:
./ bin/ bin/logs/ src/org/apache/roller/scripting/
src/org/apache/roller/util/
Author: snoopdave
Date: Thu Mar 8 16:28:39 2007
New Revision: 516239
URL: http://svn.apache.org/viewvc?view=rev&rev=516239
Log:
Groovy renderer plugin
Added:
incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/
incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/README.txt
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRenderer.java
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRendererFactory.java
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRollerBinding.java
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRunner.java
- copied, changed from r516136, incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/util/GroovyRunner.java
Removed:
incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/util/GroovyRunner.java
Modified:
incubator/roller/trunk/sandbox/scripting/groovy/ant.properties
incubator/roller/trunk/sandbox/scripting/groovy/bin/groovy
incubator/roller/trunk/sandbox/scripting/groovy/bin/listusers.gy
incubator/roller/trunk/sandbox/scripting/groovy/build.xml
Modified: incubator/roller/trunk/sandbox/scripting/groovy/ant.properties
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/ant.properties?view=diff&rev=516239&r1=516238&r2=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/ant.properties (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/ant.properties Thu Mar 8 16:28:39 2007
@@ -1,2 +1,2 @@
-rollersrc.dir=/Users/dave/roller_trunk
+rollersrc.dir=../../..
groovy.home=/Applications/Java/groovy
Modified: incubator/roller/trunk/sandbox/scripting/groovy/bin/groovy
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/bin/groovy?view=diff&rev=516239&r1=516238&r2=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/bin/groovy (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/bin/groovy Thu Mar 8 16:28:39 2007
@@ -6,7 +6,7 @@
export GROOVY_HOME=/Applications/Java/groovy
# Directory of Roller webapp context
-export WEBAPP_DIR=/Users/dave/src/roller-svn/roller/trunk/build/webapp
+export WEBAPP_DIR=../../../../../trunk/build/webapp
# Directory of additional jars
export JARS_DIR=/Applications/Java/jakarta-tomcat-5.5.9/common/lib
Modified: incubator/roller/trunk/sandbox/scripting/groovy/bin/listusers.gy
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/bin/listusers.gy?view=diff&rev=516239&r1=516238&r2=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/bin/listusers.gy (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/bin/listusers.gy Thu Mar 8 16:28:39 2007
@@ -16,13 +16,17 @@
* directory of this distribution.
*/
-roller = org.apache.roller.business.RollerFactory.getRoller();
-users = roller.getUserManager().getUsers(null, null, null, null, 0, -1);
+try {
+ roller = org.apache.roller.business.RollerFactory.getRoller();
+ users = roller.getUserManager().getUsers(null, null, null, null, 0, -1);
+ for (u in users) {
+ println " User [${u.userName}] has password [${u.password}]";
+ weblogs = roller.getUserManager().getWebsites(u, null, null, null, null, 0, Integer.MAX_VALUE);
+ for (w in weblogs) {
+ println " Belongs to weblog [${w.handle}]";
+ }
+ }
+} catch (Exception e) {
+ e.printStackTrace();
+}
-for (u in users) {
- println " User [${u.userName}] has password [${u.password}]";
- weblogs = roller.getUserManager().getWebsites(u, null, null, null, null, 0, Integer.MAX_VALUE);
- for (w in weblogs) {
- println " Belongs to weblog [${w.handle}]";
- }
-}
Added: incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/README.txt
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/README.txt?view=auto&rev=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/README.txt (added)
+++ incubator/roller/trunk/sandbox/scripting/groovy/bin/logs/README.txt Thu Mar 8 16:28:39 2007
@@ -0,0 +1 @@
+Groovy-Roller logs should end up here.
Modified: incubator/roller/trunk/sandbox/scripting/groovy/build.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/build.xml?view=diff&rev=516239&r1=516238&r2=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/build.xml (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/build.xml Thu Mar 8 16:28:39 2007
@@ -1,12 +1,14 @@
<project name="scripting" default="build" basedir=".">
- <description>Build scripting tools for Roller</description>
+ <description>Build Roller-Groovy integration classes</description>
<property file="./ant.properties" />
<path id="scripting.path">
- <fileset dir="${rollersrc.dir}/build/webapp/WEB-INF/lib">
+ <fileset dir="${rollersrc.dir}/build/webapp/WEB-INF/lib">
+ <include name="roller-web.jar"/>
<include name="roller-business.jar"/>
+ <include name="commons-logging.jar"/>
</fileset>
<fileset dir="${groovy.home}/lib">
<include name="groovy-1.0.jar"/>
@@ -21,6 +23,8 @@
<path refid="scripting.path"/>
</classpath>
</javac>
+ <mkdir dir="./build/lib" />
+ <jar basedir="build/classes" jarfile="./build/lib/roller-groovy.jar" />
</target>
<target name="clean">
Added: incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRenderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRenderer.java?view=auto&rev=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRenderer.java (added)
+++ incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRenderer.java Thu Mar 8 16:28:39 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.scripting;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyShell;
+import java.io.Writer;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.pojos.Template;
+import org.apache.roller.ui.rendering.Renderer;
+import org.apache.roller.ui.rendering.RenderingException;
+
+/**
+ * Renderer that evaluates template as Groovy script.
+ */
+public class GroovyRenderer implements Renderer {
+ private static Log log = LogFactory.getLog(GroovyRenderer.class);
+ private Template template = null;
+
+ public GroovyRenderer(Template template) {
+ this.template = template;
+ }
+
+ public void render(Map model, Writer writer) throws RenderingException {
+ try {
+ Binding binding = new GroovyRollerBinding(model, writer);
+ GroovyShell shell = new GroovyShell(binding);
+
+ long startTime = System.currentTimeMillis();
+
+ shell.evaluate(template.getContents());
+
+ long endTime = System.currentTimeMillis();
+ long renderTime = (endTime - startTime)/1000;
+ log.debug("Rendered ["+template.getId()+"] in "+renderTime+" secs");
+
+ } catch (Exception ex) {
+ throw new RenderingException("Error during rendering", ex);
+ }
+ }
+}
+
+
Added: incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRendererFactory.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRendererFactory.java?view=auto&rev=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRendererFactory.java (added)
+++ incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRendererFactory.java Thu Mar 8 16:28:39 2007
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.scripting;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.pojos.Template;
+import org.apache.roller.ui.rendering.Renderer;
+import org.apache.roller.ui.rendering.RendererFactory;
+
+/**
+ * Renderer for "groovy" templates.
+ */
+public class GroovyRendererFactory implements RendererFactory {
+ private static Log log = LogFactory.getLog(GroovyRendererFactory.class);
+
+ public Renderer getRenderer(Template template) {
+ Renderer renderer = null;
+ if(template.getTemplateLanguage() == null || template.getId() == null) {
+ return null;
+ }
+ if("groovy".equals(template.getTemplateLanguage())) {
+ try {
+ renderer = new GroovyRenderer(template);
+ } catch(Exception ex) {
+ return null;
+ }
+ }
+ return renderer;
+ }
+
+}
Added: incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRollerBinding.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRollerBinding.java?view=auto&rev=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRollerBinding.java (added)
+++ incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRollerBinding.java Thu Mar 8 16:28:39 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.scripting;
+
+import groovy.lang.Binding;
+import groovy.xml.MarkupBuilder;
+import java.io.Writer;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.ui.rendering.model.UtilitiesModel;
+
+/**
+ * Binds Roller model objects to Groovy context.
+ */
+public class GroovyRollerBinding extends Binding {
+ private static Log log = LogFactory.getLog(GroovyRollerBinding.class);
+ private Binding binding;
+ private MarkupBuilder html;
+ private Writer writer;
+
+ public GroovyRollerBinding(Map model, Writer writer) {
+ binding = new Binding(model);
+ binding.setVariable("out", writer);
+ binding.setVariable("utils", new UtilitiesModel());
+ }
+
+ public void setVariable(String name, Object value) {
+ if (name == null) {
+ throw new IllegalArgumentException("Can't bind variable to null key.");
+ }
+ if (name.length() == 0) {
+ throw new IllegalArgumentException("Can't bind variable to blank key name. [length=0]");
+ }
+ if ("out".equals(name)) {
+ throw new IllegalArgumentException("Can't bind variable to key named '" + name + "'.");
+ }
+ if ("html".equals(name)) {
+ throw new IllegalArgumentException("Can't bind variable to key named '" + name + "'.");
+ }
+ binding.setVariable(name, value);
+ }
+
+ public Map getVariables() {
+ return binding.getVariables();
+ }
+
+ public Object getVariable(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("No variable with null key name.");
+ }
+ if (name.length() == 0) {
+ throw new IllegalArgumentException("No variable with blank key name. [length=0]");
+ }
+ try {
+ if ("out".equals(name)) {
+ return writer;
+ }
+ if ("html".equals(name)) {
+ if (html == null) {
+ html = new MarkupBuilder(writer);
+ }
+ return html;
+ }
+ } catch (Exception e) {
+ String message = "Failed to get writer or output stream from response.";
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+
+ return binding.getVariable(name);
+ }
+}
Copied: incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRunner.java (from r516136, incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/util/GroovyRunner.java)
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRunner.java?view=diff&rev=516239&p1=incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/util/GroovyRunner.java&r1=516136&p2=incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRunner.java&r2=516239
==============================================================================
--- incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/util/GroovyRunner.java (original)
+++ incubator/roller/trunk/sandbox/scripting/groovy/src/org/apache/roller/scripting/GroovyRunner.java Thu Mar 8 16:28:39 2007
@@ -19,7 +19,7 @@
* Created on October 20, 2006, 10:54 PM
*/
-package org.apache.roller.util;
+package org.apache.roller.scripting;
import java.io.File;
import groovy.lang.*;
@@ -90,5 +90,5 @@
java \
-Droller.custom.config=roller-custom.properties \
-Dcatalina.base=. \
--cp ${RGPATH} org.apache.roller.util.GroovyRunner $WEBAPP_DIR $JARS_DIR $1
+-cp ${RGPATH} org.apache.roller.scripting.GroovyRunner $WEBAPP_DIR $JARS_DIR $1
*/
Re: svn commit: r516239 - in /incubator/roller/trunk/sandbox/scripting/groovy: ./ bin/ bin/logs/ src/org/apache/roller/scripting/ src/org/apache/roller/util/
Posted by Dave <sn...@gmail.com>.
On 3/9/07, Anil Gangolli <an...@busybuddha.org> wrote:
> Missed the proposal for this (probably my fault).
I don't have a proposal for this scripting work yet -- I'm trying to
figure out what to do. I'm doing the work in the sandbox so that
others can see it and offer suggestions.
> I would have suggested using BSF (Bean Scripting Framework
> http://jakarta.apache.org/bsf/) so as to accommodate any of the languages
> that work with BSF (including Groovy and several others)
Yes, BSF is a good way to support multiple scripting languages and I
have now gotten BSF to work for Groovy and JavaScript, but not JRuby
because it has a conflict with a Hibernate dependency (Hibernate uses
an older ASM lib).
> I'm not sure if that would work in this particular setting or not. Did you
> already consider this?
BSF works fine for basic scripting needs, but doesn't allow for
Groovlet and GSP style pages because they require that special
Groovy-specific objects are put into context (i.e. the "html"
MarkupBuilder). Check the README's in the groovy and bsf directories
for sample examples.
- Dave
Re: svn commit: r516239 - in /incubator/roller/trunk/sandbox/scripting/groovy: ./ bin/ bin/logs/ src/org/apache/roller/scripting/ src/org/apache/roller/util/
Posted by Anil Gangolli <an...@busybuddha.org>.
Dave:
Missed the proposal for this (probably my fault).
I would have suggested using BSF (Bean Scripting Framework
http://jakarta.apache.org/bsf/) so as to accommodate any of the languages
that work with BSF (including Groovy and several others)
I'm not sure if that would work in this particular setting or not. Did you
already consider this?
--a.