summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/DamlEngine.java
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine/DamlEngine.java')
-rw-r--r--org/madore/damlengine/DamlEngine.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index 77fbf7f..f708d81 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -3,6 +3,7 @@ package org.madore.damlengine;
import java.util.MissingResourceException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
+import java.util.Properties;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
@@ -11,6 +12,7 @@ import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.PrintStream;
+import java.io.FileNotFoundException;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import org.w3c.dom.*;
@@ -148,9 +150,47 @@ public final class DamlEngine {
fullProcess(in, out, null);
}
+ public static Properties appProps;
+ public static String basePath;
+ public static String templatePath;
+
public static void main(String[] args)
throws Exception {
+ appProps = new Properties();
+ String appPropsFile = null;
+ if ( System.getenv("DAMLENGINE_PROPERTIES_PATH") != null )
+ appPropsFile = System.getenv("DAMLENGINE_PROPERTIES_PATH");
+ if ( appPropsFile == null ) {
+ if ( System.getProperty("user.home") != null )
+ appPropsFile = System.getProperty("user.home") + "/damlengine.properties";
+ else
+ appPropsFile = "damlengine.properties";
+ }
+ try {
+ appProps.load(new FileInputStream(appPropsFile));
+ } catch (FileNotFoundException e) { }
+
+ basePath = null;
+ if ( System.getenv("DAMLENGINE_BASE_PATH") != null )
+ basePath = System.getenv("DAMLENGINE_BASE_PATH");
+ if ( basePath == null )
+ basePath = appProps.getProperty("base_path");
+ if ( basePath == null ) {
+ basePath = ".";
+ System.err.println("warning: using working directory as base path");
+ }
+
+ templatePath = null;
+ if ( System.getenv("DAMLENGINE_TEMPLATE_PATH") != null )
+ templatePath = System.getenv("DAMLENGINE_TEMPLATE_PATH");
+ if ( templatePath == null )
+ templatePath = appProps.getProperty("template_path");
+ if ( templatePath == null ) {
+ templatePath = basePath + "/templates";
+ System.err.println("warning: using "+templatePath+" as template path");
+ }
+
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
String line;
Matcher matcher;
@@ -162,7 +202,7 @@ public final class DamlEngine {
if ( (matcher=Pattern.compile("process\\s+(\\S+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) {
String inf = matcher.group(1);
String outf = matcher.group(2);
- InputStream in = new FileInputStream(inf);
+ InputStream in = new FileInputStream((inf.charAt(0)=='/'?"":basePath+"/")+inf);
OutputStream out = (outf != null)
? new FileOutputStream(outf)
: System.out;
@@ -226,7 +266,7 @@ public final class DamlEngine {
out.close();
} else if ( (matcher=Pattern.compile("populate-weblog\\s+(\\S+)\\s*").matcher(line)).matches() ) {
String inf = matcher.group(1);
- InputStream in = new FileInputStream(inf);
+ InputStream in = new FileInputStream((inf.charAt(0)=='/'?"":basePath+"/")+inf);
WeblogPopulate.populate(in);
} else if ( (matcher=Pattern.compile("echo\\s+(\\S+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) {
String str = matcher.group(1);