Author: alexsmirnov
Date: 2009-11-18 20:34:17 -0500 (Wed, 18 Nov 2009)
New Revision: 15927
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
Log:
https://jira.jboss.org/jira/browse/RF-7732
Revrite Renderer generator to avoid static context variables.
Create renderer template in the integration test.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -21,12 +21,14 @@
*/
package org.richfaces.builder.model;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
*
*/
public interface MethodBodyStatement {
- public String getCode();
+ public String getCode(FreeMarkerRenderer renderer);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -21,6 +21,8 @@
*/
package org.richfaces.builder.model;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
*
@@ -35,7 +37,7 @@
}
@Override
- public String getCode() {
+ public String getCode(FreeMarkerRenderer renderer) {
return code;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -63,10 +65,10 @@
* @see org.richfaces.builder.model.MethodBodyStatement#getCode()
*/
@Override
- public String getCode() {
+ public String getCode(FreeMarkerRenderer renderer) {
StringBuilder sb = new StringBuilder();
for (MethodBodyStatement statement: statements) {
- sb.append(statement.getCode());
+ sb.append(statement.getCode(renderer));
sb.append('\n');
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -181,7 +181,8 @@
setComponentDescription(componentElement, component);
processFacets(componentElement, component);
- // TODO - process Events attribute.
+ // process Events.
+ setEvents(componentElement, component);
// TODO - process renderers ( @Renderer and @RendererTemplate attribute.
// TODO - process @Test annotations.
// Process attributes.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -27,6 +27,8 @@
import org.richfaces.cdk.CdkContext;
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
import freemarker.template.Configuration;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModel;
@@ -52,18 +54,7 @@
setObjectWrapper(new LibraryModelWrapper());
// Add context variables
- this.setSharedVariable("context", new TemplateHashModel() {
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
-
- // TODO - define context parameters that could be exposed to template.
- return null;
- }
- @Override
- public boolean isEmpty() throws TemplateModelException {
- return false;
- }
- });
+ this.setSharedVariable("context", new BeanModel(context,new
BeansWrapper()));
}
/**
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -37,8 +37,8 @@
}
@Override
- public String getCode() {
- return RenderingContext.renderSnippet(templateName, this);
+ public String getCode(FreeMarkerRenderer renderer) {
+ return renderer.renderSnippet(templateName, this);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -37,8 +37,8 @@
}
@Override
- public String getCode() {
- return RenderingContext.renderSnippet(templateName, this);
+ public String getCode(FreeMarkerRenderer renderer) {
+ return renderer.renderSnippet(templateName, this);
}
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -0,0 +1,15 @@
+package org.richfaces.cdk.templatecompiler;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import freemarker.template.TemplateException;
+
+public interface FreeMarkerRenderer {
+
+ public void writeSnippet(String templateName, Object object, Writer writer)
+ throws IOException, TemplateException;
+
+ public String renderSnippet(String templateName, Object object);
+
+}
\ No newline at end of file
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -0,0 +1,115 @@
+/*
+ * $Id: JavaClassConfiguration.java 15790 2009-11-01 16:21:55Z Alex.Kolonitsky $
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.templatecompiler;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.richfaces.cdk.CdkContext;
+
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateHashModel;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JavaClassConfiguration extends Configuration implements FreeMarkerRenderer
{
+ private static final String TEMPLATES = "/META-INF/templates/java";
+ private final CdkContext context;
+
+ public JavaClassConfiguration(CdkContext context) {
+ super();
+ this.context = context;
+
+ // TODO set proper template loader.
+ setClassForTemplateLoading(context.getClass(), TEMPLATES);
+
+ // TODO create an object wrapper for library model.
+ setObjectWrapper(new JavaClassModelWrapper(this));
+
+ // Add context variables
+ this.setSharedVariable("context", new BeanModel(context,new
BeansWrapper()));
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the context
+ */
+ public CdkContext getContext() {
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String,
java.lang.Object, java.io.Writer)
+ */
+ public void writeSnippet(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
+ Template t = getTemplate(templateName + ".ftl");
+ Map<String, Object> rootMap = new HashMap<String, Object>();
+ rootMap.put("modelItem", object);
+
+ rootMap.put("facesContextVariable",
RendererClassVisitor.FACES_CONTEXT_VARIABLE);
+ rootMap.put("componentVariable",
RendererClassVisitor.COMPONENT_VARIABLE);
+ rootMap.put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
+
+ t.process(rootMap, writer);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String,
java.lang.Object)
+ */
+ public String renderSnippet(String templateName, Object object) {
+ StringWriter writer = new StringWriter();
+ try {
+ writeSnippet(templateName, object, writer);
+
+ return writer.toString();
+ } catch (IOException e) {
+ // TODO: handle exception
+ return e.getMessage();
+ } catch (TemplateException e) {
+ // TODO: handle exception
+ return e.getMessage();
+ } finally {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ //do nothing
+ }
+ }
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -0,0 +1,43 @@
+package org.richfaces.cdk.templatecompiler;
+
+import org.richfaces.builder.model.MethodBodyStatement;
+import org.richfaces.cdk.freemarker.ComponentTemplateModel;
+import org.richfaces.cdk.freemarker.PropertyModel;
+import org.richfaces.cdk.model.Component;
+import org.richfaces.cdk.model.Property;
+
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.ObjectWrapper;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+public class JavaClassModelWrapper extends BeansWrapper implements ObjectWrapper {
+
+ private final JavaClassConfiguration configuration;
+
+ public JavaClassModelWrapper(JavaClassConfiguration configuration) {
+ this.configuration = configuration;
+ }
+ @Override
+ public TemplateModel wrap(Object obj) throws TemplateModelException {
+
+ // TODO wrap specified model classes.
+ TemplateModel templateModel;
+
+ if (obj instanceof MethodBodyStatement) {
+ templateModel = new MethodBodyTemplateModel((MethodBodyStatement) obj,
this);
+ } else {
+ templateModel = super.wrap(obj);
+ }
+
+ return templateModel;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the configuration
+ */
+ public JavaClassConfiguration getConfiguration() {
+ return configuration;
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -0,0 +1,63 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler;
+
+import org.richfaces.builder.model.MethodBodyStatement;
+import org.richfaces.cdk.freemarker.LibraryModelWrapper;
+
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class MethodBodyTemplateModel extends BeanModel implements TemplateModel {
+
+ private final MethodBodyStatement statement;
+ private final JavaClassModelWrapper modelWrapper;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param statement
+ * @param javaClassModelWrapper
+ */
+ public MethodBodyTemplateModel(MethodBodyStatement statement, JavaClassModelWrapper
javaClassModelWrapper) {
+ super(statement, javaClassModelWrapper);
+ this.statement = statement;
+ this.modelWrapper = javaClassModelWrapper;
+ }
+
+ @Override
+ public TemplateModel get(String key) throws TemplateModelException {
+ if("code".equals(key)){
+ statement.getCode(modelWrapper.getConfiguration());
+ }
+ return super.get(key);
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -32,7 +32,6 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
import org.richfaces.cdk.StandardOutputs;
-import org.richfaces.cdk.freemarker.CdkConfiguration;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.RenderKit;
import org.richfaces.cdk.model.Renderer;
@@ -91,15 +90,13 @@
try {
outputWriter = new PrintWriter(outFile);
- CdkConfiguration cdkConfiguration = new
CdkConfiguration(context);
- RenderingContext.setCdkConfiguration(cdkConfiguration);
- RenderingContext.writeSnippet("class", javaClass,
outputWriter);
+ JavaClassConfiguration cdkConfiguration = new
JavaClassConfiguration(context);
+ cdkConfiguration.writeSnippet("class", javaClass,
outputWriter);
} catch (IOException e) {
throw new CdkException(e);
} catch (TemplateException e) {
throw new CdkException(e);
} finally {
- RenderingContext.setCdkConfiguration(null);
if (outputWriter != null) {
outputWriter.close();
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -103,7 +103,7 @@
try {
// TODO read default attributes values
- // TODO detect URI attributes
+ // TODO detect URI and boolean attributes
ObjectInputStream ois = new ObjectInputStream(serializedAttributesStream);
@SuppressWarnings("unchecked")
@@ -314,7 +314,6 @@
}
}
- // TODO Auto-generated method stub
}
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java 2009-11-19
01:34:04 UTC (rev 15926)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java 2009-11-19
01:34:17 UTC (rev 15927)
@@ -1,80 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.templatecompiler;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.richfaces.cdk.freemarker.CdkConfiguration;
-
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-class RenderingContext {
-
- private static ThreadLocal<CdkConfiguration> cdkConfigurationHolder = new
ThreadLocal<CdkConfiguration>();
-
- static void setCdkConfiguration(CdkConfiguration cdkConfiguration) {
- cdkConfigurationHolder.set(cdkConfiguration);
- }
-
- static void writeSnippet(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
- Template t = cdkConfigurationHolder.get().getTemplate("java/" + templateName
+ ".ftl");
- Map<String, Object> rootMap = new HashMap<String, Object>();
- rootMap.put("modelItem", object);
-
- rootMap.put("facesContextVariable",
RendererClassVisitor.FACES_CONTEXT_VARIABLE);
- rootMap.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE);
- rootMap.put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
-
- t.process(rootMap, writer);
- }
-
- static String renderSnippet(String templateName, Object object) {
- StringWriter writer = new StringWriter();
- try {
- writeSnippet(templateName, object, writer);
-
- return writer.toString();
- } catch (IOException e) {
- // TODO: handle exception
- return e.getMessage();
- } catch (TemplateException e) {
- // TODO: handle exception
- return e.getMessage();
- } finally {
- try {
- writer.close();
- } catch (IOException e) {
- //do nothing
- }
- }
- }
-
-}