diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2013-06-09 17:35:48 -0700 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2013-06-09 17:35:48 -0700 | 
| commit | 69e2512750dd75fce43a21226979996c3cd7da1d (patch) | |
| tree | 691dca375161583393ce32bb0869cb7449255118 | |
| parent | f4c2eb2dafbca580319a9f50ef4f5dd68d658702 (diff) | |
Configuration Changes
Fixing a bug in the config class and updating all templates and pages to
use the dynamicRoot and staticRoot config values to prefix URLs.
| -rw-r--r-- | build.xml | 2 | ||||
| -rw-r--r-- | src/com/p4square/grow/config/Config.java | 8 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/GrowFrontend.java | 12 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/LoginPageResource.java | 2 | ||||
| -rw-r--r-- | src/com/p4square/grow/frontend/SurveyPageResource.java | 8 | ||||
| -rw-r--r-- | src/grow.properties (renamed from devfiles/dev-config-override.properties) | 0 | ||||
| -rw-r--r-- | src/templates/macros/common-page.ftl | 6 | ||||
| -rw-r--r-- | src/templates/macros/noticebox.ftl | 2 | ||||
| -rw-r--r-- | src/templates/pages/about.html.ftl | 2 | ||||
| -rw-r--r-- | src/templates/pages/index.html.ftl | 2 | ||||
| -rw-r--r-- | src/templates/pages/login.html.ftl | 2 | ||||
| -rw-r--r-- | src/templates/templates/footer.ftl | 6 | ||||
| -rw-r--r-- | src/templates/templates/nav.ftl | 12 | ||||
| -rw-r--r-- | src/templates/templates/question-image.ftl | 4 | ||||
| -rw-r--r-- | src/templates/templates/survey.ftl | 6 | ||||
| -rw-r--r-- | web/META-INF/context.xml | 4 | ||||
| -rw-r--r-- | web/WEB-INF/restlet.xml | 18 | ||||
| -rw-r--r-- | web/WEB-INF/web.xml | 21 | 
18 files changed, 75 insertions, 42 deletions
@@ -14,7 +14,7 @@          <java classname="com.p4square.grow.frontend.GrowFrontend"              classpathref="classpath.run" fork="true"> -            <arg file="devfiles/dev-config-override.properties" /> +            <arg file="build/WEB-INF/classes/grow.properties" />          </java>      </target> diff --git a/src/com/p4square/grow/config/Config.java b/src/com/p4square/grow/config/Config.java index f5ebe3c..20d6ff5 100644 --- a/src/com/p4square/grow/config/Config.java +++ b/src/com/p4square/grow/config/Config.java @@ -49,6 +49,7 @@ public class Config {       * @param domain The new domain.       */      public void setDomain(String domain) { +        cLog.info("Setting Config domain to " + domain);          mDomain = domain;      } @@ -99,17 +100,20 @@ public class Config {          String result;          final String domainKey = mDomain + "." + key; -        result = mProperties.getProperty(domainKey, defaultValue); +        result = mProperties.getProperty(domainKey);          if (result != null) { +            cLog.debug("Reading config for key = { " + key + " }. Got result = { " + result + " }");              return result;          }          final String globalKey = "*." + key; -        result = mProperties.getProperty(globalKey, defaultValue); +        result = mProperties.getProperty(globalKey);          if (result != null) { +            cLog.debug("Reading config for key = { " + key + " }. Got result = { " + result + " }");              return result;          } +        cLog.debug("Reading config for key = { " + key + " }. Got default value = { " + defaultValue + " }");          return defaultValue;      } diff --git a/src/com/p4square/grow/frontend/GrowFrontend.java b/src/com/p4square/grow/frontend/GrowFrontend.java index e3662d5..226929d 100644 --- a/src/com/p4square/grow/frontend/GrowFrontend.java +++ b/src/com/p4square/grow/frontend/GrowFrontend.java @@ -41,13 +41,15 @@ public class GrowFrontend extends FMFacade {          super.start();          final String configDomain = -            getContext().getParameters().getFirstValue("config-domain"); +            getContext().getParameters().getFirstValue("configDomain");          if (configDomain != null) {              mConfig.setDomain(configDomain);          } +        mConfig.updateConfig(this.getClass().getResourceAsStream("/grow.properties")); +          final String configFilename = -            getContext().getParameters().getFirstValue("config-file"); +            getContext().getParameters().getFirstValue("configFile");          if (configFilename != null) {              mConfig.updateConfig(configFilename); @@ -58,8 +60,10 @@ public class GrowFrontend extends FMFacade {      protected Router createRouter() {          Router router = new Router(getContext()); +        final String loginPage = getConfig().getString("dynamicRoot", "") + "/login.html"; +          final LoginAuthenticator defaultGuard = -            new LoginAuthenticator(getContext(), true, "login.html"); +            new LoginAuthenticator(getContext(), true, loginPage);          defaultGuard.setNext(FreeMarkerPageResource.class);          router.attachDefault(defaultGuard);          router.attach("/login.html", LoginPageResource.class); @@ -69,7 +73,7 @@ public class GrowFrontend extends FMFacade {          accountRouter.attach("/assessment", SurveyPageResource.class);          final LoginAuthenticator accountGuard = -            new LoginAuthenticator(getContext(), false, "login.html"); +            new LoginAuthenticator(getContext(), false, loginPage);          accountGuard.setNext(accountRouter);          router.attach("/account", accountGuard); diff --git a/src/com/p4square/grow/frontend/LoginPageResource.java b/src/com/p4square/grow/frontend/LoginPageResource.java index ac9f651..70caa3e 100644 --- a/src/com/p4square/grow/frontend/LoginPageResource.java +++ b/src/com/p4square/grow/frontend/LoginPageResource.java @@ -91,7 +91,7 @@ public class LoginPageResource extends FreeMarkerPageResource {          if (authenticated) {              // TODO: Better return url. -            getResponse().redirectSeeOther("/index.html"); +            getResponse().redirectSeeOther(mGrowFrontend.getConfig().getString("dynamicRoot", "") + "/index.html");              return null;          } else { diff --git a/src/com/p4square/grow/frontend/SurveyPageResource.java b/src/com/p4square/grow/frontend/SurveyPageResource.java index e7fcd07..280184b 100644 --- a/src/com/p4square/grow/frontend/SurveyPageResource.java +++ b/src/com/p4square/grow/frontend/SurveyPageResource.java @@ -152,13 +152,13 @@ public class SurveyPageResource extends FreeMarkerPageResource {              }              // Find the next question or finish the assessment. -            String nextPage; +            String nextPage = mConfig.getString("dynamicRoot", "");              {                  String nextQuestionId = (String) questionData.get("nextQuestion");                  if (nextQuestionId == null) { -                    nextPage = "/account/assessment/results"; +                    nextPage += "/account/assessment/results";                  } else { -                    nextPage = "/account/assessment/question/" + nextQuestionId; +                    nextPage += "/account/assessment/question/" + nextQuestionId;                  }              } @@ -176,7 +176,7 @@ public class SurveyPageResource extends FreeMarkerPageResource {       * @return The backend endpoint URI       */      private String getBackendEndpoint() { -        return mConfig.getString("backendUri", "http://localhost:9095"); +        return mConfig.getString("backendUri", "riap://component/backend");      }      /** diff --git a/devfiles/dev-config-override.properties b/src/grow.properties index b1bd989..b1bd989 100644 --- a/devfiles/dev-config-override.properties +++ b/src/grow.properties diff --git a/src/templates/macros/common-page.ftl b/src/templates/macros/common-page.ftl index 1a5c3d3..5fa2740 100644 --- a/src/templates/macros/common-page.ftl +++ b/src/templates/macros/common-page.ftl @@ -4,9 +4,9 @@      <head>          <title>Grow Process</title> -        <link rel="stylesheet" href="${contentroot}/style.css" /> -        <script src="${contentroot}/scripts/jquery.min.js"></script> -        <script src="${contentroot}/scripts/growth.js"></script> +        <link rel="stylesheet" href="${staticRoot}/style.css" /> +        <script src="${staticRoot}/scripts/jquery.min.js"></script> +        <script src="${staticRoot}/scripts/growth.js"></script>      </head>      <body>      <div id="notfooter"> diff --git a/src/templates/macros/noticebox.ftl b/src/templates/macros/noticebox.ftl index 43c36c3..eca1428 100644 --- a/src/templates/macros/noticebox.ftl +++ b/src/templates/macros/noticebox.ftl @@ -1,7 +1,7 @@  <#macro noticebox>      <div id="middlebar">          <div id="noticebox"> -            <img class="icon" src="${contentroot}/images/noticeicon.png"> +            <img class="icon" src="${staticRoot}/images/noticeicon.png">              <p>                  <#nested>              </p> diff --git a/src/templates/pages/about.html.ftl b/src/templates/pages/about.html.ftl index 65a1f1d..3ab2bc0 100644 --- a/src/templates/pages/about.html.ftl +++ b/src/templates/pages/about.html.ftl @@ -9,8 +9,6 @@      </@noticebox>      <@content> -        <img src="images/buckets.png" /> -          <h1>About</h1>          <p>              Curabitur mattis molestie ligula, ac vestibulum Curabitur diff --git a/src/templates/pages/index.html.ftl b/src/templates/pages/index.html.ftl index 44f9dce..4e6ea73 100644 --- a/src/templates/pages/index.html.ftl +++ b/src/templates/pages/index.html.ftl @@ -11,7 +11,7 @@      </@noticebox>      <@content> -        <img src="images/buckets.png" /> +        <img src="${staticRoot}/images/buckets.png" />          <h1>Grow "Buckets"</h1>          <p> diff --git a/src/templates/pages/login.html.ftl b/src/templates/pages/login.html.ftl index 29e30e9..590649c 100644 --- a/src/templates/pages/login.html.ftl +++ b/src/templates/pages/login.html.ftl @@ -12,7 +12,7 @@      <@content>          <p>Welcome! You will need to login with your Foursquare Church InFellowship login.</p> -        <form action="login.html" method="post"> +        <form action="${dynamicRoot}/login.html" method="post">          <p><label for="emailField">Email:</label> <input id="emailField" type="text" name="email" /></p>          <p><label for="passwordField">Password:</label> <input id="passwordField" type="password" name="password" /></p>          <p><input type="submit" value="Login" /></p> diff --git a/src/templates/templates/footer.ftl b/src/templates/templates/footer.ftl index c7f6ca6..64d6d47 100644 --- a/src/templates/templates/footer.ftl +++ b/src/templates/templates/footer.ftl @@ -1,9 +1,9 @@  <footer>      <div class="left">          ©2012 Grow Process -        <a href="index.html">Home</a> -        <a href="about.html">About</a> -        <a href="contact.html">Contact</a> +        <a href="${dynamicRoot}/index.html">Home</a> +        <a href="${dynamicRoot}/about.html">About</a> +        <a href="${dynamicRoot}/contact.html">Contact</a>      </div>      <div class="right"> diff --git a/src/templates/templates/nav.ftl b/src/templates/templates/nav.ftl index cf2562c..cef283e 100644 --- a/src/templates/templates/nav.ftl +++ b/src/templates/templates/nav.ftl @@ -7,17 +7,17 @@  </#macro>  <header> -    <h1><img src="${contentroot}/images/logo.png"> Grow Process</h1> +    <h1><img src="${staticRoot}/images/logo.png"> Grow Process</h1>      <nav class="primary">          <ul> -            <@navLink href="/index.html">Home</@navLink> -            <@navLink href="/about.html">About</@navLink> -            <@navLink href="/contact.html">Contact</@navLink> +            <@navLink href="${dynamicRoot}/index.html">Home</@navLink> +            <@navLink href="${dynamicRoot}/about.html">About</@navLink> +            <@navLink href="${dynamicRoot}/contact.html">Contact</@navLink>              <#if user??> -                <@navLink href="/account/assessment">Take Assessment</@navLink> +                <@navLink href="${dynamicRoot}/account/assessment">Take Assessment</@navLink>              <#else> -                <@navLink href="/login.html">Login / Sign Up</@navLink> +                <@navLink href="${dynamicRoot}/login.html">Login / Sign Up</@navLink>              </#if>          </ul>      </nav> diff --git a/src/templates/templates/question-image.ftl b/src/templates/templates/question-image.ftl index 63f0616..f117256 100644 --- a/src/templates/templates/question-image.ftl +++ b/src/templates/templates/question-image.ftl @@ -1,9 +1,9 @@  <div class="imageQuestion question">      <#list question.answers?keys as answerid>          <#if selectedAnswerId?? && answerid == selectedAnswerId> -            <a href="#" class="answer" id="${answerid}" onclick="selectAnswer(this)" class="selected"><img src="images/${question.id}-${answerid}.png" alt="${question.answers[answerid]!}" /></a> +            <a href="#" class="answer" id="${answerid}" onclick="selectAnswer(this)" class="selected"><img src="${staticRoot}/images/${question.id}-${answerid}.png" alt="${question.answers[answerid]!}" /></a>          <#else> -            <a href="#" class="answer" id="${answerid}" onclick="selectAnswer(this)" class="answer"><img src="images/${question.id}-${answerid}.png" alt="${question.answers[answerid]!}" /></a> +            <a href="#" class="answer" id="${answerid}" onclick="selectAnswer(this)" class="answer"><img src="${staticRoot}/images/${question.id}-${answerid}.png" alt="${question.answers[answerid]!}" /></a>          </#if>      </#list>  </div> diff --git a/src/templates/templates/survey.ftl b/src/templates/templates/survey.ftl index a1eb18d..9ea47d5 100644 --- a/src/templates/templates/survey.ftl +++ b/src/templates/templates/survey.ftl @@ -13,16 +13,16 @@      </div>      <div id="content"> -        <form id="questionForm" action="/account/assessment/question/${question.id}" method="post"> +        <form id="questionForm" action="${dynamicRoot}/account/assessment/question/${question.id}" method="post">          <input id="answerField" type="hidden" name="answer" value="${selectedAnswerId!}" />          <div id="previous">              <a href="#" onclick="previousQuestion();return false;"> -                <img src="${contentroot}/images/previous.png" alt="Previous Question" /> +                <img src="${staticRoot}/images/previous.png" alt="Previous Question" />              </a>          </div>          <div id="next">              <a href="#" onclick="nextQuestion();return false;"> -                <img src="${contentroot}/images/next.png" alt="Next Question" /> +                <img src="${staticRoot}/images/next.png" alt="Next Question" />              </a>          </div>          <article> diff --git a/web/META-INF/context.xml b/web/META-INF/context.xml new file mode 100644 index 0000000..24744f5 --- /dev/null +++ b/web/META-INF/context.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Context> +    <Parameter name="configFile" value="grow.properties" override="false"/> +</Context> diff --git a/web/WEB-INF/restlet.xml b/web/WEB-INF/restlet.xml new file mode 100644 index 0000000..d77fb2e --- /dev/null +++ b/web/WEB-INF/restlet.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<component xmlns="http://www.restlet.org/schemas/2.0/Component"> +    <client protocol="FILE" /> +    <client protocols="HTTP HTTPS" /> +    <server protocols="HTTP HTTPS" /> +  +    <defaultHost> +        <attach uripattern="/images" targetDescriptor="war:///images" /> +        <attach uripattern="/scripts" targetDescriptor="war:///scripts" /> +        <attach uripattern="/style.css" targetDescriptor="war:///style.css" /> +        <attach uriPattern="" targetClass="com.p4square.grow.frontend.GrowFrontend" /> +    </defaultHost> + +    <internalRouter> +        <attach uriPattern="/backend" +                targetClass="com.p4square.grow.backend.GrowBackend" /> +    </internalRouter> +</component> diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 235f33d..be1e4cf 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -7,13 +7,6 @@      <display-name>grow-frontend</display-name> -    <!-- Application class name --> -    <context-param> -        <param-name>org.restlet.application</param-name> -        <param-value> -            net.jesterpm.fmfacade.FMFacade -        </param-value> -    </context-param>      <!-- Restlet adapter -->      <servlet> @@ -25,7 +18,19 @@      <!-- Catch all requests -->      <servlet-mapping> +        <servlet-name>default</servlet-name> +        <url-pattern>/style.css</url-pattern> +    </servlet-mapping> +    <servlet-mapping> +        <servlet-name>default</servlet-name> +        <url-pattern>/images/*</url-pattern> +    </servlet-mapping> +    <servlet-mapping> +        <servlet-name>default</servlet-name> +        <url-pattern>/scripts/*</url-pattern> +    </servlet-mapping> +    <servlet-mapping>          <servlet-name>RestletServlet</servlet-name> -        <url-pattern>/p/*</url-pattern> +        <url-pattern>/*</url-pattern>      </servlet-mapping>  </web-app>  | 
