Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r26 - trunk/src: main/java/com/artilekt/modules/console main/java/com/artilekt/modules/utils/io test/java/com/artilekt/modules/template test/java/com/artilekt/modules/template/freemarker test/java/com/artilekt/modules/template/velocity test/java/com/artilekt/modules/utils/io

jetmailer
Discussion topic

Back to topic list

svn commit: r26 - trunk/src: main/java/com/artilekt/modules/console main/java/com/artilekt/modules/utils/io test/java/com/artilekt/modules/template test/java/com/artilekt/modules/template/freemarker test/java/com/artilekt/modules/template/velocity test/java/com/artilekt/modules/utils/io

Reply

Author volenin
Full name Vladimir Olenin
Date 2006-08-31 16:05:44 PDT
Message Author: volenin
Date: 2006-08-31 16:05:44-0700
New Revision: 26

Removed:
   trunk/src/main/java/​com/artilekt/modules​/utils/io/RecursiveD​irectoryLister.java
Modified:
   trunk/src/main/java/​com/artilekt/modules​/console/ConsoleAppl​.java
   trunk/src/main/java/​com/artilekt/modules​/utils/io/ResourceLo​cator.java
   trunk/src/test/java/​com/artilekt/modules​/template/AbstractTe​mplateServiceTest.ja​va
   trunk/src/test/java/​com/artilekt/modules​/template/freemarker​/TemplateServiceTest​.java
   trunk/src/test/java/​com/artilekt/modules​/template/velocity/T​emplateServiceTest.j​ava
   trunk/src/test/java/​com/artilekt/modules​/utils/io/ResourceLo​catorTest.java

Log:
TemplateServiceTest fixed and updated

Modified: trunk/src/main/java/​com/artilekt/modules​/console/ConsoleAppl​.java
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/main/java/com/arti​lekt/modules/console​/ConsoleAppl.java?vi​ew=diff&rev=26​&p1=trunk/src/main​/java/com/artilekt/m​odules/console/Conso​leAppl.java&p2=t​runk/src/main/java/c​om/artilekt/modules/​console/ConsoleAppl.​java&r1=25&r​2=26
====================​====================​====================​==================
--- trunk/src/main/java/​com/artilekt/modules​/console/ConsoleAppl​.java (original)
+++ trunk/src/main/java/​com/artilekt/modules​/console/ConsoleAppl​.java 2006-08-31 16:05:44-0700
@@ -23,6 +23,7 @@
 import org.springframework.​beans.factory.access​.BeanFactoryLocator;​
 import org.springframework.​beans.factory.access​.SingletonBeanFactor​yLocator;
 import org.springframework.​beans.factory.access​.BeanFactoryReferenc​e;
+import org.springframework.​core.io.Resource;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
@@ -60,7 +61,7 @@
   public final static class Main {
     public static void main(String[] args) throws Exception {
       String log4j = System.getProperty("​LOG_CONFIG", "log4j.xml");
- ResourceLocator log4jLocator = new ResourceLocator(log4j);
+ Resource log4jLocator = new ResourceLocator().ge​tResource(log4j);
       DOMConfigurator.conf​igure(log4jLocator.g​etURL());
 
       BeanFactoryLocator bfl = SingletonBeanFactory​Locator.getInstance(​"classpath*:com/arti​lekt/**/beanRefFacto​ry.xml");

Removed: trunk/src/main/java/​com/artilekt/modules​/utils/io/RecursiveD​irectoryLister.java
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/main/java/com/arti​lekt/modules/utils/i​o/RecursiveDirectory​Lister.java?view=aut​o&rev=25

Modified: trunk/src/main/java/​com/artilekt/modules​/utils/io/ResourceLo​cator.java
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/main/java/com/arti​lekt/modules/utils/i​o/ResourceLocator.ja​va?view=diff&rev​=26&p1=trunk/src​/main/java/com/artil​ekt/modules/utils/io​/ResourceLocator.jav​a&p2=trunk/src/m​ain/java/com/artilek​t/modules/utils/io/R​esourceLocator.java​&r1=25&r2=26
====================​====================​====================​==================
--- trunk/src/main/java/​com/artilekt/modules​/utils/io/ResourceLo​cator.java (original)
+++ trunk/src/main/java/​com/artilekt/modules​/utils/io/ResourceLo​cator.java 2006-08-31 16:05:44-0700
@@ -30,77 +30,37 @@
  * Date: 16-Oct-2005
  * Time: 14:39:25
  */
-public class ResourceLocator extends AbstractResource {
- String path;
- Resource res;
-
- public ResourceLocator(String path) {
- this.path = path;
- init();
- }
+public class ResourceLocator implements ResourceLoader {
 
- private void init() {
- res = null;
+ public Resource getResource(final String location) {
+ Resource res;
     // Try ClassPathResource first
- res = new ClassPathResource(path);
- if (res.exists()) return;
+ res = new ClassPathResource(location);
+ if (res.exists()) return res;
 
     // if that fails, try FileSystemResource
- res = new FileSystemResource(path);
- if (res.exists()) return;
+ res = new FileSystemResource(location);
+ if (res.exists()) return res;
 
     // if that fails, try UrlResource
     try {
- res = new UrlResource(path);
- if (res.exists()) return;
+ res = new UrlResource(location);
+ if (res.exists()) return res;
     }
- catch (RuntimeException Re) { throw Re; }
- catch (Exception e) { throw new InitializationException(e); }
+ catch (RuntimeException Re) { }
+ catch (Exception e) { }
+ return new AbstractResource() {
+ public boolean exists() { return false; }
+ public String getDescription() {
+ return "location ["+location+"]";
+ }
+ public InputStream getInputStream() throws IOException {
+ throw new IOException("Can't open input stream for: "+getDescription());
+ }
+ };
   }
 
- public boolean exists() {
- return (res != null && res.exists());
- }
 
- public URL getURL() throws IOException {
- checkResource();
- return res.getURL();
- }
-
- public File getFile() throws IOException {
- checkResource();
- return res.getFile();
- }
-
- public String getFilename() {
- return res.getFilename();
- }
-
- public boolean isOpen() {
- return res.isOpen();
- }
 
- public Resource createRelative(String relativePath) throws IOException {
- return res.createRelative(r​elativePath);
- }
-
- public String getDescription() {
- checkResource();
- return res.toString();
- }
-
- public InputStream getInputStream() throws IOException {
- checkResource();
- if (!(res instanceof InputStreamSource)) throw new IOException("Can not open InputStream to ["+path+"] resource."+
- "Resource '"+res+"' does not implement '"+
- InputStreamSource.class+"' interface");
- InputStreamSource inSource = (InputStreamSource)res;
- return inSource.getInputStream();
- }
-
-
- private void checkResource() {
- if (!res.exists()) throw new InitializationExcept​ion("Resource ["+path+"] could not be located.");
- }
 }
 

Modified: trunk/src/test/java/​com/artilekt/modules​/template/AbstractTe​mplateServiceTest.ja​va
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/test/java/com/arti​lekt/modules/templat​e/AbstractTemplateSe​rviceTest.java?view=​diff&rev=26&​p1=trunk/src/test/ja​va/com/artilekt/modu​les/template/Abstrac​tTemplateServiceTest​.java&p2=trunk/s​rc/test/java/com/art​ilekt/modules/templa​te/AbstractTemplateS​erviceTest.java&​r1=25&r2=26
====================​====================​====================​==================
--- trunk/src/test/java/​com/artilekt/modules​/template/AbstractTe​mplateServiceTest.ja​va (original)
+++ trunk/src/test/java/​com/artilekt/modules​/template/AbstractTe​mplateServiceTest.ja​va 2006-08-31 16:05:44-0700
@@ -23,6 +23,7 @@
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -41,7 +42,10 @@
     PackageResource res = new PackageResource(Abst​ractTemplateServiceT​est.class, "templateServiceTest.xml");
     StreamUtils.reader2writer(new BufferedReader(new InputStreamReader(re​s.getInputStream()))​, System.out);
 
- InputStream in = getTemplateService()​.merge(values, res.getFile().getPath());
+ String path = res.getFile().getPath();
+// path = path.replace('\\', '/');
+// path = path.substring(12, path.length());
+ InputStream in = getTemplateService()​.merge(values, path);
     StreamUtils.reader2writer(new BufferedReader(new InputStreamReader(in)), System.out);
   }
 

Modified: trunk/src/test/java/​com/artilekt/modules​/template/freemarker​/TemplateServiceTest​.java
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/test/java/com/arti​lekt/modules/templat​e/freemarker/Templat​eServiceTest.java?vi​ew=diff&rev=26​&p1=trunk/src/test​/java/com/artilekt/m​odules/template/free​marker/TemplateServi​ceTest.java&p2=t​runk/src/test/java/c​om/artilekt/modules/​template/freemarker/​TemplateServiceTest.​java&r1=25&r​2=26
====================​====================​====================​==================
--- trunk/src/test/java/​com/artilekt/modules​/template/freemarker​/TemplateServiceTest​.java (original)
+++ trunk/src/test/java/​com/artilekt/modules​/template/freemarker​/TemplateServiceTest​.java 2006-08-31 16:05:44-0700
@@ -2,6 +2,10 @@
 
 import com.artilekt.modules​.template.AbstractTe​mplateServiceTest;
 import com.artilekt.modules​.template.TemplateSe​rvice;
+import com.artilekt.modules​.utils.io.ResourceLo​cator;
+import org.springframework.​web.servlet.view.fre​emarker.FreeMarkerCo​nfigurer;
+import org.springframework.​ui.freemarker.FreeMa​rkerConfigurationFac​tory;
+import freemarker.template.​Configuration;
 
 /**
  * Author: Vladimir Olenin
@@ -12,12 +16,15 @@
 
   protected TemplateService templateService;
   protected TemplateService getTemplateService() throws Exception {
- if (templateService != null) return templateService;
+ if (templateService != null) return templateService;
 
- ConfigurationFactory cfgFactory = new ConfigurationFactory();
- cfgFactory.setTemplatePath("");
+ FreeMarkerConfigurationFactory fmCfgFactory = new FreeMarkerConfigurat​ionFactory();
+ fmCfgFactory.setPref​erFileSystemAccess(f​alse);
+ fmCfgFactory.setReso​urceLoader(new ResourceLocator());
+ fmCfgFactory.setTemp​lateLoaderPath("");
+ Configuration cfg = fmCfgFactory.createC​onfiguration();
     FreemarkerEngineImpl fmEngine = new FreemarkerEngineImpl();
- fmEngine.setConfigur​ation(cfgFactory.cre​ateInstance());
+ fmEngine.setConfiguration(cfg);
     templateService = fmEngine;
 
     return templateService;

Modified: trunk/src/test/java/​com/artilekt/modules​/template/velocity/T​emplateServiceTest.j​ava
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/test/java/com/arti​lekt/modules/templat​e/velocity/TemplateS​erviceTest.java?view​=diff&rev=26​&p1=trunk/src/test/j​ava/com/artilekt/mod​ules/template/veloci​ty/TemplateServiceTe​st.java&p2=trunk​/src/test/java/com/a​rtilekt/modules/temp​late/velocity/Templa​teServiceTest.java​&r1=25&r2=26
====================​====================​====================​==================
--- trunk/src/test/java/​com/artilekt/modules​/template/velocity/T​emplateServiceTest.j​ava (original)
+++ trunk/src/test/java/​com/artilekt/modules​/template/velocity/T​emplateServiceTest.j​ava 2006-08-31 16:05:44-0700
@@ -2,7 +2,9 @@
 
 import com.artilekt.modules​.template.AbstractTe​mplateServiceTest;
 import com.artilekt.modules​.template.TemplateSe​rvice;
+import com.artilekt.modules​.utils.io.ResourceLo​cator;
 import org.apache.velocity.​app.VelocityEngine;
+import org.springframework.​ui.velocity.Velocity​EngineFactory;
 
 /**
  * Author: Vladimir Olenin
@@ -15,11 +17,13 @@
   protected TemplateService getTemplateService() throws Exception {
     if (templateService != null) return templateService;
 
+ VelocityEngineFactory veFactory = new VelocityEngineFactory();
+ veFactory.setPreferF​ileSystemAccess(fals​e);
+ veFactory.setResourceLoader(new ResourceLocator());
+ veFactory.setResourc​eLoaderPath("");
+
     VelocityEngineImpl tmplService = new VelocityEngineImpl();
- VelocityEngine engine = new VelocityEngine();
- engine.setProperty(V​elocityEngine.RUNTIM​E_LOG_LOGSYSTEM, this);
- engine.setProperty(V​elocityEngine.FILE_R​ESOURCE_LOADER_PATH,​ "");
- engine.init();
+ VelocityEngine engine = veFactory.createVelo​cityEngine();
     tmplService.setEngine(engine);
     this.templateService = tmplService;
 

Modified: trunk/src/test/java/​com/artilekt/modules​/utils/io/ResourceLo​catorTest.java
Url: http://jetmailer.tig​ris.org/source/brows​e/jetmailer/trunk/sr​c/test/java/com/arti​lekt/modules/utils/i​o/ResourceLocatorTes​t.java?view=diff​&rev=26&p1=trunk​/src/test/java/com/a​rtilekt/modules/util​s/io/ResourceLocator​Test.java&p2=tru​nk/src/test/java/com​/artilekt/modules/ut​ils/io/ResourceLocat​orTest.java&r1=2​5&r2=26
====================​====================​====================​==================
--- trunk/src/test/java/​com/artilekt/modules​/utils/io/ResourceLo​catorTest.java (original)
+++ trunk/src/test/java/​com/artilekt/modules​/utils/io/ResourceLo​catorTest.java 2006-08-31 16:05:44-0700
@@ -17,6 +17,7 @@
 package com.artilekt.modules.utils.io;
 
 import junit.framework.TestCase;
+import org.springframework.​core.io.Resource;
 
 /**
  * Author: Vladimir Olenin
@@ -27,14 +28,14 @@
 
   public void test() throws Exception {
     String path = getClass().getResour​ce(getClass().getSim​pleName()+".class").​toString();
- ResourceLocator resLocator = new ResourceLocator(path);
+ Resource res = new ResourceLocator().ge​tResource(path);
 
     System.out.println("Resource '"+path+"':");
- System.out.println(" toString(): "+resLocator);
- System.out.println(" exists(): "+resLocator.exists());
- System.out.println(" getFile(): "+resLocator.getFile());
- System.out.println(" getURL(): "+resLocator.getURL());
+ System.out.println(" toString(): "+res);
+ System.out.println(" exists(): "+res.exists());
+ System.out.println(" getFile(): "+res.getFile());
+ System.out.println(" getURL(): "+res.getURL());
 
- assertTrue(resLocato​r.exists());
+ assertTrue(res.exists());
   }
 }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r26 - trunk/src: main/java/com/artilekt/modules/console main/java/com/artilekt/modules/utils/io test/java/com/artilekt/modules/template test/java/com/artilekt/modules/template/freemarker t... volenin Vladimir Olenin 2006-08-31 16:05:44 PDT
Messages per page: