Commits

Stephen McKamey committed 7a08804

tweak to allow staticapps config as resource

Comments (0)

Files changed (3)

duel-staticapps-maven-plugin/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-staticapps-maven-plugin</artifactId>
-	<version>0.8.5</version>
+	<version>0.8.6</version>
 	<packaging>maven-plugin</packaging>
 
 	<name>DUEL Static Apps Maven Plugin</name>

duel-staticapps/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-staticapps</artifactId>
-	<version>0.8.5</version>
+	<version>0.8.6</version>
 	<packaging>jar</packaging>
 
 	<name>DUEL Static Apps</name>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
-		<duel.version>0.8.2</duel.version>
+		<duel.version>0.8.3</duel.version>
 		<jackson.version>1.9.6</jackson.version>
 		<codec.version>1.6</codec.version>
 		<slf4j.version>1.6.4</slf4j.version>
 			<version>${slf4j.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-jdk14</artifactId>
+			<groupId>com.pseudocode</groupId>
+			<artifactId>slf4j-compact</artifactId>
 			<version>${slf4j.version}</version>
 			<scope>test</scope>
 		</dependency>

duel-staticapps/src/main/java/org/duelengine/duel/staticapps/RoutingServlet.java

 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URISyntaxException;
 import java.util.Locale;
 import java.util.ResourceBundle;
 
 		super.init(servletConfig);
 
+		String configPath = null;
 		try {
 			// load from config file
-			String configPath = servletConfig.getInitParameter("config-path");
-			File configFile = new File(configPath);
-			config = new ObjectMapper().reader(SiteConfig.class).readValue(configFile);
+			configPath = servletConfig.getInitParameter("config-path");
+			if (configPath == null || configPath.isEmpty()) {
+				config = null;
+
+			} else {
+				File configFile = new File(configPath);
+				if (configFile.exists()) {
+					log.info("Loading config from file path: "+configFile.getPath());
+					config = new ObjectMapper().reader(SiteConfig.class).readValue(configFile);
+				}
+			}
 
 		} catch (Exception ex) {
-			log.error("Error loading staticapp config", ex);
-			config = new SiteConfig();
+			log.error("Error loading staticapp config from 'config-path' param in WEB-INF/web.xml: "+configPath, ex);
+			config = null;
+		}
+
+		if (config == null) {
+			try {
+				configPath = servletConfig.getInitParameter("config-resource");
+				log.info("Loading config from resource: "+configPath);
+				InputStream stream = getServletContext().getResourceAsStream(configPath);
+				config = new ObjectMapper().reader(SiteConfig.class).readValue(stream);
+
+			} catch (Exception ex) {
+				log.error("Error loading staticapp config from 'config-resource' param in WEB-INF/web.xml: "+configPath, ex);
+				config = new SiteConfig();
+			}
 		}
 
 		String devModeOverride = servletConfig.getInitParameter("dev-mode-override");
 		// TODO: expand routing capabilities beyond exact match and default doc
 		
 		SiteViewPage page = config.views().get(servletPath.substring(1));
-		if (page == null) {
-			if (servletPath.endsWith("/")) {
-				// continue to attempt to resolve with default document
-				return route(servletPath+DEFAULT_DOC);
-			}
-			return null;
+		if (page == null && servletPath.endsWith("/")) {
+			// continue to attempt to resolve with default document
+			log.info("routing: "+servletPath+DEFAULT_DOC);
+			page = config.views().get(servletPath.substring(1)+DEFAULT_DOC);
 		}
 
 		return page;