Permalink
Browse files

IDE-859

  • Loading branch information...
1 parent 93526b7 commit e595272c22c8f67a43a1663c3a70dcd3c21bb2b7 @cinnndy9 cinnndy9 committed with gamerson Mar 18, 2013
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/freemarker.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/"/>
- <classpathentry exported="true" kind="lib" path="lib/velocity-1.6.4.jar"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
@@ -11,31 +11,6 @@ Require-Bundle: org.eclipse.core.runtime,
com.liferay.ide.core
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
-Export-Package: com.liferay.ide.templates.core,
- org.apache.velocity,
- org.apache.velocity.anakia,
- org.apache.velocity.app,
- org.apache.velocity.app.event,
- org.apache.velocity.app.event.implement,
- org.apache.velocity.app.tools,
- org.apache.velocity.context,
- org.apache.velocity.convert,
- org.apache.velocity.exception,
- org.apache.velocity.io,
- org.apache.velocity.runtime,
- org.apache.velocity.runtime.directive,
- org.apache.velocity.runtime.log,
- org.apache.velocity.runtime.parser,
- org.apache.velocity.runtime.parser.node,
- org.apache.velocity.runtime.resource,
- org.apache.velocity.runtime.resource.loader,
- org.apache.velocity.runtime.resource.util,
- org.apache.velocity.runtime.visitor,
- org.apache.velocity.servlet,
- org.apache.velocity.texen,
- org.apache.velocity.texen.ant,
- org.apache.velocity.texen.util,
- org.apache.velocity.util,
- org.apache.velocity.util.introspection
+Export-Package: com.liferay.ide.templates.core
Bundle-ClassPath: .,
- lib/velocity-1.6.4.jar
+ lib/freemarker.jar
@@ -5,5 +5,5 @@ bin.includes = META-INF/,\
lib/,\
schema/,\
plugin.xml,\
- lib/velocity-1.6.4.jar,\
- OSGI-INF/
+ OSGI-INF/,\
+ lib/freemarker.jar
@@ -14,26 +14,34 @@
package com.liferay.ide.templates.core;
-import org.apache.velocity.VelocityContext;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author Cindy Li
*/
-public class TemplateContext extends VelocityContext implements ITemplateContext
+public class TemplateContext implements ITemplateContext
{
- TemplateContext()
+ protected Map<String, Object> context = new HashMap<String, Object>();
+
+ public TemplateContext()
{
- super();
}
public boolean containsKey( String key )
{
- return super.containsKey( key );
+ return context.containsKey( key );
}
public Object put( String key, Object value )
{
- return super.put( key, value );
+ return context.put( key, value );
+ }
+
+ public Map<String, Object> getMap()
+ {
+ return context;
}
}
@@ -19,48 +19,49 @@
import com.liferay.ide.core.util.CoreUtil;
+import freemarker.template.Configuration;
+
import java.util.ArrayList;
import java.util.List;
-import org.apache.velocity.app.VelocityEngine;
-
/**
* @author Gregory Amerson
+ * @author Cindy Li
*/
public class TemplateModel
{
protected String bundleId;
+ protected Configuration config;
protected String id;
protected String name;
protected String resource;
protected String templateFolder;
- protected VelocityEngine engine;
private TemplateVariable[] vars;
public TemplateModel(
- String bundleId, String id, String name, String resource, String templateFolder, VelocityEngine velocityEngine,
+ String bundleId, Configuration config, String id, String name, String resource, String templateFolder,
TemplateVariable[] vars )
{
super();
this.bundleId = bundleId;
+ this.config = config;
this.id = id;
this.name = name;
this.resource = resource;
this.templateFolder = templateFolder;
- this.engine = velocityEngine;
this.vars = vars;
}
- public VelocityEngine getEngine()
+ public Configuration getConfig()
{
- return engine;
+ return config;
}
- public void setEngine( VelocityEngine engine )
+ public void setConfig( Configuration config )
{
- this.engine = engine;
+ this.config = config;
}
public String getId()
@@ -19,16 +19,17 @@
import com.liferay.ide.core.util.CoreUtil;
+import freemarker.template.Template;
+
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
-import org.apache.velocity.Template;
-import org.apache.velocity.context.Context;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Gregory Amerson
+ * @author Cindy Li
*/
public class TemplateOperation implements ITemplateOperation
{
@@ -85,7 +86,8 @@ public void execute( IProgressMonitor monitor ) throws Exception
}
StringWriter writer = new StringWriter();
- getTemplate().merge( (Context) getContext(), writer );
+ TemplateContext templateContext = (TemplateContext)getContext();
+ getTemplate().process( templateContext.getMap(), writer );
String result = writer.toString();
if( this.outputFile != null )
@@ -142,7 +144,7 @@ protected Template getTemplate() throws Exception
if( template == null )
{
- template = this.model.getEngine().getTemplate( this.model.getResource() );
+ template = this.model.getConfig().getTemplate( this.model.getResource() );
}
return template;
@@ -1,13 +1,17 @@
package com.liferay.ide.templates.core;
+import freemarker.template.Configuration;
+import freemarker.template.ObjectWrapper;
+
+import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.velocity.app.VelocityEngine;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IStatus;
@@ -109,11 +113,10 @@ private static TemplateModel createPluginModel( IConfigurationElement element, S
}
}
- VelocityEngine velocityEngine = new VelocityEngine();
+ Configuration config = new Configuration();
templateModel =
new TemplateModel(
- pluginName, id, name, resource, templateFolder, velocityEngine,
- paramList.toArray( new TemplateVariable[0] ) );
+ pluginName, config, id, name, resource, templateFolder, paramList.toArray( new TemplateVariable[0] ) );
}
catch( Exception e )
{
@@ -203,17 +206,14 @@ private static IConfigurationElement getTplDefinitionElement( String templateId
private static void initializeModel( TemplateModel templateModel ) throws Exception
{
- VelocityEngine engine = templateModel.getEngine();
+ Configuration config = templateModel.getConfig();
- engine.setProperty( "resource.loader", "url" ); //$NON-NLS-1$ //$NON-NLS-2$
- engine.setProperty(
- "url.resource.loader.class", "org.apache.velocity.runtime.resource.loader.URLResourceLoader" ); //$NON-NLS-1$ //$NON-NLS-2$
URL loaderRoot = Platform.getBundle( templateModel.bundleId ).getEntry( templateModel.templateFolder );
- engine.setProperty( "url.resource.loader.root", loaderRoot.toURI().toASCIIString() ); //$NON-NLS-1$
- engine.setProperty( "url.resource.loader.cache", true ); //$NON-NLS-1$
- // properties.put("url.resource.loader.modificationCheckInterval", 10);
+ URL fileUrl = FileLocator.toFileURL( loaderRoot );
+ config.setDirectoryForTemplateLoading( new File( fileUrl.getFile().toString() ) );
+ config.setObjectWrapper( ObjectWrapper.BEANS_WRAPPER );
- templateModel.getEngine().init();
+ templateModel.setConfig( config );
}
/**
@@ -29,7 +29,7 @@
<template
id="layouttpl.tpl"
name="Default Layout Template"
- resource="layouttpl.vm">
+ resource="layouttpl.ftl">
</template>
<templatesFolder
path="templates/">
@@ -0,0 +1,30 @@
+<#if (root.getRows().size() > 0)>
+<div class="${templateName}" id="${root.id}" role="${root.role}">
+<#list root.getRows() as row>
+<#if row.getColumns().size() == 1>
+<#assign columnOnly = row.getColumns().get(0)>
+ <div class="${row.className}">
+ <div class="portlet-column portlet-column-only" id="column-${columnOnly.numId}">
+ $processor.processColumn("column-${columnOnly.numId}", "portlet-column-content portlet-column-content-only")
+ </div>
+ </div>
+<#elseif (row.getColumns().size() > 1)>
+ <div class="${row.className}">
+<#list row.getColumns() as col>
+<#if col.isFirst()>
+ <div class="aui-w${col.getWeight()} portlet-column portlet-column-first" id="column-${col.numId}">
+ $processor.processColumn("column-${col.numId}", "portlet-column-content portlet-column-content-first")
+<#elseif col.isLast()>
+ <div class="aui-w${col.getWeight()} portlet-column portlet-column-last" id="column-${col.numId}">
+ $processor.processColumn("column-${col.numId}", "portlet-column-content portlet-column-content-last")
+<#else>
+ <div class="aui-w${col.getWeight()} portlet-column" id="column-${col.numId}">
+ $processor.processColumn("column-${col.numId}", "portlet-column-content")
+</#if>
+ </div>
+</#list>
+ </div>
+</#if>
+</#list>
+</div>
+</#if>
@@ -1,32 +0,0 @@
-#set( $esc1 = '#' )
-#set( $esc2 = '$' )
-#if ( $root.getRows().size() > 0)
-<div class="$templateName" id="$root.id" role="$root.role">
-#foreach( $row in $root.getRows() )
-#if ( $row.getColumns().size() == 1)
-#set( $columnOnly = $row.getColumns().get(0) )
- <div class="$row.className">
- <div class="portlet-column portlet-column-only" id="column-$columnOnly.numId">
- ${esc2}processor.processColumn("column-$columnOnly.numId", "portlet-column-content portlet-column-content-only")
- </div>
- </div>
-#elseif ( $row.getColumns().size() > 1)
- <div class="$row.className">
-#foreach ( $col in $row.getColumns() )
-#if ( $col.isFirst() )
- <div class="aui-w$col.getWeight() portlet-column portlet-column-first" id="column-$col.numId">
- ${esc2}processor.processColumn("column-$col.numId", "portlet-column-content portlet-column-content-first")
-#elseif ( $col.isLast() )
- <div class="aui-w$col.getWeight() portlet-column portlet-column-last" id="column-$col.numId">
- ${esc2}processor.processColumn("column-$col.numId", "portlet-column-content portlet-column-content-last")
-#else
- <div class="aui-w$col.getWeight() portlet-column" id="column-$col.numId">
- ${esc2}processor.processColumn("column-$col.numId", "portlet-column-content")
-#end
- </div>
-#end
- </div>
-#end
-#end
-</div>
-#end

0 comments on commit e595272

Please sign in to comment.