woproject/projects/wolips/plugins/org.objectstyle.wolips.templateengine/java/org/objectstyle/wolips/templateengine TemplateEngine.java,1.3,1.4 AbstractEngine.java,1.3,1.4

[email protected] Thu, 16 Feb 2006 06:08:03 -0800 (PST)
Newsgroups gmane.comp.web.webobjects.woproject.cvs
Message-ID <[email protected]>
Update of /cvsroot/woproject/woproject/projects/wolips/plugins/org.objectstyle.wolips.templateengine/java/org/objectstyle/wolips/templateengine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13502/java/org/objectstyle/wolips/templateengine

Modified Files:
	TemplateEngine.java AbstractEngine.java 
Log Message:
1) Incorporated Sebastien's patch from WOL-209 so Template engine always makes parent folders (and accidentally did a reformat code ... really hard to break that muscle memory :) )
2) Modified WOComponentCreationWizard specifically to create package subfolders (for people who don't have autorefresh enabled) for WOL-209
3) Added compile targets to WOApplication and WOFramework templates
4) Cleaned up a couple strict Eclipse warnings in wizards

Index: TemplateEngine.java
===================================================================
RCS file: /cvsroot/woproject/woproject/projects/wolips/plugins/org.objectstyle.wolips.templateengine/java/org/objectstyle/wolips/templateengine/TemplateEngine.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- TemplateEngine.java	3 Jan 2005 15:38:46 -0000	1.3
+++ TemplateEngine.java	16 Feb 2006 14:07:12 -0000	1.4
@@ -54,6 +54,7 @@
  *
  */
 package org.objectstyle.wolips.templateengine;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.lang.reflect.InvocationTargetException;
@@ -73,6 +74,7 @@
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.jdom.Document;
 import org.jdom.input.SAXBuilder;
+
 /**
  * @author ulrich
  * 
@@ -80,142 +82,153 @@
  * Window>Preferences>Java>Code Generation>Code and Comments
  */
 public class TemplateEngine implements IRunnableWithProgress {
-	private VelocityContext context = null;
-	private ArrayList templates = null;
-	private VelocityEngine velocityEngine = null;
-	private WOLipsContext wolipsContext;
-	/**
-	 * @throws Exception
-	 */
-	public void init() throws Exception {
-		/*
-		 * create a new instance of the engine
-		 */
-		this.velocityEngine = new VelocityEngine();
-		/*
-		 * configure the engine. In this case, we are using ourselves as a
-		 * logger (see logging examples..)
-		 */
-		this.velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,
-				this);
-		/*
-		 * initialize the engine
-		 */
-		String userHomeWOLipsPath = System.getProperty("user.home")
-				+ File.separator + "Library" + File.separator + "WOLips";
-		URL url = null;
-		url = Platform.resolve(TemplateEnginePlugin.baseURL());
-		String templatePaths = userHomeWOLipsPath + ", ";
-		Path path = new Path(url.getPath());
-		templatePaths = templatePaths + path.append("templates").toOSString();
-		this.velocityEngine.setProperty("file.resource.loader.path",
-				templatePaths);
-		this.velocityEngine.init();
-		this.context = new VelocityContext();
-		this.templates = new ArrayList();
-		this.wolipsContext = new WOLipsContext();
-		this.setPropertyForKey(this.wolipsContext, WOLipsContext.Key);
-		SAXBuilder builder;
-		Document myContext = null;
-		try {
-			builder = new SAXBuilder();
-			myContext = builder.build(userHomeWOLipsPath + File.separator
-					+ "MyContext.xml");
-		} catch (Exception ee) {
-			//We can ignore this exception, it`s thrown if the xml document is
-			// not found.
-			//Per default there is no such file
-			builder = null;
-			myContext = null;
-		}
-		if (myContext != null) {
-			this.setPropertyForKey(myContext, "MyContext");
-		}
-	}
-	/**
-	 * @param template
-	 */
-	public void addTemplate(TemplateDefinition template) {
-		this.templates.add(template);
-	}
-	/**
-	 * @param templateDefinitions
-	 */
-	public void addTemplates(TemplateDefinition[] templateDefinitions) {
-		if (this.templates == null) {
-			return;
-		}
-		for (int i = 0; i < templateDefinitions.length; i++) {
-			TemplateDefinition templateDefinition = templateDefinitions[i];
-			this.templates.add(templateDefinition);
-		}
-	}
-	/**
-	 * @param property
-	 * @param key
-	 */
-	public void setPropertyForKey(Object property, String key) {
-		this.context.put(key, property);
-	}
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void run(IProgressMonitor monitor) throws InvocationTargetException {
-		setDateInContext();
-		try {
-			for (int i = 0; i < this.templates.size(); i++) {
-				TemplateDefinition templateDefinition = (TemplateDefinition) this.templates
-						.get(i);
-				this.run(templateDefinition);
-			}
-		} catch (Exception e) {
-			throw new InvocationTargetException(e);
-		}
-	}
+  private VelocityContext context = null;
+  private ArrayList templates = null;
+  private VelocityEngine velocityEngine = null;
+  private WOLipsContext wolipsContext;
 
-	private void run(TemplateDefinition templateDefinition) {
-		FileWriter writer = null;
-		try {
-			/*
-			 * make a writer, and merge the template 'against' the context
-			 */
-			String templateName = templateDefinition.getTemplateName();
-			Template template = this.velocityEngine.getTemplate(templateName);
-			writer = new FileWriter(templateDefinition.getDestinationPath());
-			template.merge(this.context, writer);
-		} catch (Exception e) {
-			System.out.println("Exception : " + e);
-		} finally {
-			if (writer != null) {
-				try {
-					writer.flush();
-					writer.close();
-				} catch (Exception ee) {
-					System.out.println("Exception : " + ee);
-				}
-			}
-		}
-	}
-	/**
-	 * @return Returns the wolipsContext.
-	 */
-	public WOLipsContext getWolipsContext() {
-		return this.wolipsContext;
-	}
-	
+  /**
+   * @throws Exception
+   */
+  public void init() throws Exception {
+    /*
+     * create a new instance of the engine
+     */
+    this.velocityEngine = new VelocityEngine();
+    /*
+     * configure the engine. In this case, we are using ourselves as a
+     * logger (see logging examples..)
+     */
+    this.velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, this);
+    /*
+     * initialize the engine
+     */
+    String userHomeWOLipsPath = System.getProperty("user.home") + File.separator + "Library" + File.separator + "WOLips";
+    URL url = null;
+    url = Platform.resolve(TemplateEnginePlugin.baseURL());
+    String templatePaths = userHomeWOLipsPath + ", ";
+    Path path = new Path(url.getPath());
+    templatePaths = templatePaths + path.append("templates").toOSString();
+    this.velocityEngine.setProperty("file.resource.loader.path", templatePaths);
+    this.velocityEngine.init();
+    this.context = new VelocityContext();
+    this.templates = new ArrayList();
+    this.wolipsContext = new WOLipsContext();
+    this.setPropertyForKey(this.wolipsContext, WOLipsContext.Key);
+    SAXBuilder builder;
+    Document myContext = null;
+    try {
+      builder = new SAXBuilder();
+      myContext = builder.build(userHomeWOLipsPath + File.separator + "MyContext.xml");
+    }
+    catch (Exception ee) {
+      //We can ignore this exception, it`s thrown if the xml document is
+      // not found.
+      //Per default there is no such file
+      builder = null;
+      myContext = null;
+    }
+    if (myContext != null) {
+      this.setPropertyForKey(myContext, "MyContext");
+    }
+  }
 
-	
-	/**
-	 * sets the date in the context
-	 */
-	private void setDateInContext() {
-		DateFormat dateFormat = DateFormat.getDateInstance();
-		DateFormat timeFormat = DateFormat.getTimeInstance();
-		Date currentDate = Calendar.getInstance().getTime();
-		String date = dateFormat.format(currentDate) + " " + timeFormat.format(currentDate);
-		this.setPropertyForKey(date, "Date");
-		
-	}
+  /**
+   * @param template
+   */
+  public void addTemplate(TemplateDefinition template) {
+    this.templates.add(template);
+  }
+
+  /**
+   * @param templateDefinitions
+   */
+  public void addTemplates(TemplateDefinition[] templateDefinitions) {
+    if (this.templates == null) {
+      return;
+    }
+    for (int i = 0; i < templateDefinitions.length; i++) {
+      TemplateDefinition templateDefinition = templateDefinitions[i];
+      this.templates.add(templateDefinition);
+    }
+  }
+
+  /**
+   * @param property
+   * @param key
+   */
+  public void setPropertyForKey(Object property, String key) {
+    this.context.put(key, property);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+   */
+  public void run(IProgressMonitor monitor) throws InvocationTargetException {
+    setDateInContext();
+    try {
+      for (int i = 0; i < this.templates.size(); i++) {
+        TemplateDefinition templateDefinition = (TemplateDefinition) this.templates.get(i);
+        this.run(templateDefinition);
+      }
+    }
+    catch (Exception e) {
+      throw new InvocationTargetException(e);
+    }
+  }
+
+  private void run(TemplateDefinition templateDefinition) {
+    FileWriter writer = null;
+    File file = null;
+    try {
+      /*
+       * make a writer, and merge the template 'against' the context
+       */
+      String templateName = templateDefinition.getTemplateName();
+      Template template = this.velocityEngine.getTemplate(templateName);
+      writer = new FileWriter(templateDefinition.getDestinationPath());
+      file = new File(templateDefinition.getDestinationPath());
+      File parentDir = file.getParentFile();
+      if (!parentDir.exists()) {
+        parentDir.mkdirs();
+      }
+      writer = new FileWriter(file);
+      template.merge(this.context, writer);
+    }
+    catch (Exception e) {
+      System.out.println("Exception : " + e);
+    }
+    finally {
+      if (writer != null) {
+        try {
+          writer.flush();
+          writer.close();
+        }
+        catch (Exception ee) {
+          System.out.println("Exception : " + ee);
+        }
+      }
+    }
+  }
+
+  /**
+   * @return Returns the wolipsContext.
+   */
+  public WOLipsContext getWolipsContext() {
+    return this.wolipsContext;
+  }
+
+  /**
+   * sets the date in the context
+   */
+  private void setDateInContext() {
+    DateFormat dateFormat = DateFormat.getDateInstance();
+    DateFormat timeFormat = DateFormat.getTimeInstance();
+    Date currentDate = Calendar.getInstance().getTime();
+    String date = dateFormat.format(currentDate) + " " + timeFormat.format(currentDate);
+    this.setPropertyForKey(date, "Date");
+
+  }
 }
\ No newline at end of file

Index: AbstractEngine.java
===================================================================
RCS file: /cvsroot/woproject/woproject/projects/wolips/plugins/org.objectstyle.wolips.templateengine/java/org/objectstyle/wolips/templateengine/AbstractEngine.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- AbstractEngine.java	3 Jan 2005 15:38:46 -0000	1.3
+++ AbstractEngine.java	16 Feb 2006 14:07:12 -0000	1.4
@@ -55,6 +55,7 @@
  */
 
 package org.objectstyle.wolips.templateengine;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.lang.reflect.InvocationTargetException;
@@ -74,6 +75,7 @@
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.jdom.Document;
 import org.jdom.input.SAXBuilder;
+
 /**
  * @author ulrich
  * 
@@ -81,151 +83,167 @@
  * Window>Preferences>Java>Code Generation>Code and Comments
  */
 public abstract class AbstractEngine implements IRunnableWithProgress {
-	private String projectName;
-	private VelocityContext context = null;
-	private ArrayList templates = null;
-	private VelocityEngine velocityEngine = null;
-	/**
-	 * @throws Exception
-	 */
-	public void init() throws Exception {
-		/*
-		 * create a new instance of the engine
-		 */
-		this.velocityEngine = new VelocityEngine();
-		/*
-		 * configure the engine. In this case, we are using ourselves as a
-		 * logger (see logging examples..)
-		 */
-		this.velocityEngine
-				.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, this);
-		/*
-		 * initialize the engine
-		 */
-		String userHomeWOLipsPath = System.getProperty("user.home")
-				+ File.separator + "Library" + File.separator + "WOLips";
-		URL url = null;
-		url = Platform.resolve(TemplateEnginePlugin.baseURL());
-		String templatePaths = userHomeWOLipsPath + ", ";
-		Path path = new Path(url.getPath());
-		templatePaths = templatePaths + path.append("templates").toOSString();
-		this.velocityEngine.setProperty("file.resource.loader.path", templatePaths);
-		this.velocityEngine.init();
-		this.context = new VelocityContext();
-		this.templates = new ArrayList();
-		this.setPropertyForKey(this, WOLipsContext.Key);
-		SAXBuilder builder;
-		Document myContext = null;
-		try {
-			builder = new SAXBuilder();
-			myContext = builder.build(userHomeWOLipsPath + File.separator
-					+ "MyContext.xml");
-		} catch (Exception ee) {
-			//We can ignore this exception, it`s thrown if the xml document is
-			// not found.
-			//Per default there is no such file
-			builder = null;
-			myContext = null;
-		}
-		if (myContext != null) {
-			this.setPropertyForKey(myContext, "MyContext");
-		}
-	}
-	/**
-	 * @param template
-	 */
-	public void addTemplate(TemplateDefinition template) {
-		this.templates.add(template);
-	}
-	/**
-	 * @param templateDefinitions
-	 */
-	public void addTemplates(TemplateDefinition[] templateDefinitions) {
-		if (this.templates == null) {
-			return;
-		}
-		for (int i = 0; i < templateDefinitions.length; i++) {
-			TemplateDefinition templateDefinition = templateDefinitions[i];
-			this.templates.add(templateDefinition);
-		}
-	}
-	/**
-	 * @param property
-	 * @param key
-	 */
-	public void setPropertyForKey(Object property, String key) {
-		this.context.put(key, property);
-	}
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void run(IProgressMonitor monitor) throws InvocationTargetException {
-		try {
-			for (int i = 0; i < this.templates.size(); i++) {
-				TemplateDefinition templateDefinition = (TemplateDefinition) this.templates
-						.get(i);
-				this.run(templateDefinition);
-			}
-		} catch (Exception e) {
-			throw new InvocationTargetException(e);
-		}
-	}
-	private void run(TemplateDefinition templateDefinition) {
-		FileWriter writer = null;
-		try {
-			/*
-			 * make a writer, and merge the template 'against' the context
-			 */
-			String templateName = templateDefinition.getTemplateName();
-			Template template = this.velocityEngine.getTemplate(templateName);
-			writer = new FileWriter(templateDefinition.getDestinationPath());
-			template.merge(this.context, writer);
-		} catch (Exception e) {
-			System.out.println("Exception : " + e);
-		} finally {
-			if (writer != null) {
-				try {
-					writer.flush();
-					writer.close();
-				} catch (Exception ee) {
-					System.out.println("Exception : " + ee);
-				}
-			}
-			this.setPropertyForKey(null, WOLipsContext.Key);
-		}
-	}
-	/**
-	 * @return Returns the projectName.
-	 */
-	public String getProjectName() {
-		return this.projectName;
-	}
-	/**
-	 * @param projectName
-	 *            The projectName to set.
-	 */
-	public void setProjectName(String projectName) {
-		this.projectName = projectName;
-	}
+  private String projectName;
+  private VelocityContext context = null;
+  private ArrayList templates = null;
+  private VelocityEngine velocityEngine = null;
 
-	/**
-	 * @return Returns the plugin name.
-	 */
-	public String getPluginName() {
-		return TemplateEnginePlugin.getPluginId();
-	}
-	
-	/**
-	 * sets the date in the context
-	 */
-	public void setDateInContext() {
-		DateFormat dateFormat = DateFormat.getDateInstance();
-		DateFormat timeFormat = DateFormat.getTimeInstance();
-		Date currentDate = Calendar.getInstance().getTime();
-		String date = dateFormat.format(currentDate) + " " + timeFormat.format(currentDate);
-		this.setPropertyForKey(date, "Date");
-		
-	}
+  /**
+   * @throws Exception
+   */
+  public void init() throws Exception {
+    /*
+     * create a new instance of the engine
+     */
+    this.velocityEngine = new VelocityEngine();
+    /*
+     * configure the engine. In this case, we are using ourselves as a
+     * logger (see logging examples..)
+     */
+    this.velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, this);
+    /*
+     * initialize the engine
+     */
+    String userHomeWOLipsPath = System.getProperty("user.home") + File.separator + "Library" + File.separator + "WOLips";
+    URL url = null;
+    url = Platform.resolve(TemplateEnginePlugin.baseURL());
+    String templatePaths = userHomeWOLipsPath + ", ";
+    Path path = new Path(url.getPath());
+    templatePaths = templatePaths + path.append("templates").toOSString();
+    this.velocityEngine.setProperty("file.resource.loader.path", templatePaths);
+    this.velocityEngine.init();
+    this.context = new VelocityContext();
+    this.templates = new ArrayList();
+    this.setPropertyForKey(this, WOLipsContext.Key);
+    SAXBuilder builder;
+    Document myContext = null;
+    try {
+      builder = new SAXBuilder();
+      myContext = builder.build(userHomeWOLipsPath + File.separator + "MyContext.xml");
+    }
+    catch (Exception ee) {
+      //We can ignore this exception, it`s thrown if the xml document is
+      // not found.
+      //Per default there is no such file
+      builder = null;
+      myContext = null;
+    }
+    if (myContext != null) {
+      this.setPropertyForKey(myContext, "MyContext");
+    }
+  }
+
+  /**
+   * @param template
+   */
+  public void addTemplate(TemplateDefinition template) {
+    this.templates.add(template);
+  }
+
+  /**
+   * @param templateDefinitions
+   */
+  public void addTemplates(TemplateDefinition[] templateDefinitions) {
+    if (this.templates == null) {
+      return;
+    }
+    for (int i = 0; i < templateDefinitions.length; i++) {
+      TemplateDefinition templateDefinition = templateDefinitions[i];
+      this.templates.add(templateDefinition);
+    }
+  }
+
+  /**
+   * @param property
+   * @param key
+   */
+  public void setPropertyForKey(Object property, String key) {
+    this.context.put(key, property);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+   */
+  public void run(IProgressMonitor monitor) throws InvocationTargetException {
+    try {
+      for (int i = 0; i < this.templates.size(); i++) {
+        TemplateDefinition templateDefinition = (TemplateDefinition) this.templates.get(i);
+        this.run(templateDefinition);
+      }
+    }
+    catch (Exception e) {
+      throw new InvocationTargetException(e);
+    }
+  }
+
+  private void run(TemplateDefinition templateDefinition) {
+    FileWriter writer = null;
+    File file = null;
+    try {
+      /*
+       * make a writer, and merge the template 'against' the context
+       */
+      String templateName = templateDefinition.getTemplateName();
+      Template template = this.velocityEngine.getTemplate(templateName);
+      writer = new FileWriter(templateDefinition.getDestinationPath());
+      file = new File(templateDefinition.getDestinationPath());
+      File parentDir = file.getParentFile();
+      if (!parentDir.exists()) {
+        parentDir.mkdirs();
+      }
+      writer = new FileWriter(file);
+      template.merge(this.context, writer);
+    }
+    catch (Exception e) {
+      System.out.println("Exception : " + e);
+    }
+    finally {
+      if (writer != null) {
+        try {
+          writer.flush();
+          writer.close();
+        }
+        catch (Exception ee) {
+          System.out.println("Exception : " + ee);
+        }
+      }
+      this.setPropertyForKey(null, WOLipsContext.Key);
+    }
+  }
+
+  /**
+   * @return Returns the projectName.
+   */
+  public String getProjectName() {
+    return this.projectName;
+  }
+
+  /**
+   * @param projectName
+   *            The projectName to set.
+   */
+  public void setProjectName(String projectName) {
+    this.projectName = projectName;
+  }
+
+  /**
+   * @return Returns the plugin name.
+   */
+  public String getPluginName() {
+    return TemplateEnginePlugin.getPluginId();
+  }
+
+  /**
+   * sets the date in the context
+   */
+  public void setDateInContext() {
+    DateFormat dateFormat = DateFormat.getDateInstance();
+    DateFormat timeFormat = DateFormat.getTimeInstance();
+    Date currentDate = Calendar.getInstance().getTime();
+    String date = dateFormat.format(currentDate) + " " + timeFormat.format(currentDate);
+    this.setPropertyForKey(date, "Date");
+
+  }
 }
\ No newline at end of file



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642