package edu.mayo.trilliumbridge.core.xslt;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;

import java.io.File;
import java.net.MalformedURLException;

/**
 */
public class XsltDirectoryResourceFactory {

    public static final String TBT_HOME_PROP = "TBT_HOME";

    public static final String TBT_CONF_DIR = "conf";

    private String envXsltDirOverride;

    private static XsltDirectoryResourceFactory instance;

    private XsltDirectoryResourceFactory() {
        String prop = System.getProperty(TBT_HOME_PROP);
        if (prop != null) {
            this.envXsltDirOverride = prop + File.separator + TBT_CONF_DIR;
        }
    }

    protected Resource getResource(String path) {
        if(path.startsWith("http:")) {
            try {
                return new UrlResource(path);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        } else if (this.envXsltDirOverride != null) {
            return new FileSystemResource(this.envXsltDirOverride + File.separator + path);
        } else {
            return new ClassPathResource(path);
        }
    }

    protected static synchronized XsltDirectoryResourceFactory instance() {
        if(instance == null) {
            instance = new XsltDirectoryResourceFactory();
        }

        return instance;
    }
}

@@ -76,235 +76,224 @@
 .io.
-ClassPathResource;%0Aimport org.springframework.core.io.FileSystemResource;%0Aimport org.springframework.core.io.Resource;%0Aimport org.springframework.core.io.UrlResource;%0A%0Aimport java.io.File;%0Aimport java.net.MalformedURLException;
+*;%0A%0Aimport java.io.File;%0Aimport java.net.MalformedURLException;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A%0Aimport com.memetix.mst.language.Language;%0Aimport com.memetix.mst.translate.Translate;%0A
 %0A%0A/*
@@ -454,24 +454,162 @@
  = %22conf%22;%0A%0A
+%09public static final Pattern xlatere = Pattern.compile(%22http://trilliumbridge.org/from/(%5C%5Cp%7BAlpha%7D%7B2%7D)/to/(%5C%5Cp%7BAlpha%7D%7B2%7D)%5C%5C?text=(.*)%22);%0A%0A
     private 
@@ -910,32 +910,401 @@
        %7D%0A    %7D%0A%0A
+%09%7B%0A%09%09Translate.setClientId(%22TBXform%22);%0A%09%09Translate.setClientSecret(%22uIBJDNcc5K21BCsK/w2DBQNE4ezCebif0oyiIWAep0Y=%22);%0A%09%7D%0A%0A%09protected String translate(String text, String from_language, String to_language) %7B%0A%0A%09%09try %7B%0A%09%09%09return Translate.execute(text, Language.fromString(from_language), Language.fromString(to_language));%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09return text;%0A%09%09%7D%0A%09%7D%0A%0A
     protected Re
@@ -1333,24 +1333,25 @@
 ing path) %7B%0A
+%0A
         if(p
@@ -1373,24 +1373,239 @@
 %22http:%22)) %7B%0A
+%09%09%09System.out.println(path);%0A%09%09%09Matcher m = xlatere.matcher(path);%0A%09%09%09if(m.matches()) %7B%0A%09%09%09%09return new ByteArrayResource( (%22%3Cstring%3E%22 + translate(m.group(3), m.group(1), m.group(2)) + %22%3C/string%3E%22).getBytes());%0A%09%09%09%7D%0A
             
@@ -1811,32 +1811,104 @@
 ride != null) %7B%0A
+%09%09%09System.out.println(this.envXsltDirOverride + File.separator + path);%0A
             retu

Put local bing translator hook in