Generate cah.config.js via a Servlet. Idea from d4472c1238/src/net/socialgamer/cah/servlets/JavascriptConfig.java
This commit is contained in:
parent
68998c3244
commit
3b454c4552
|
@ -6,26 +6,34 @@
|
|||
<welcome-file>index.htm</welcome-file>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
<servlet>
|
||||
<servlet-name>LongPollServlet</servlet-name>
|
||||
<servlet-class>net.socialgamer.cah.servlets.LongPollServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>AjaxServlet</servlet-name>
|
||||
<servlet-class>net.socialgamer.cah.servlets.AjaxServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>JavascriptConfig</servlet-name>
|
||||
<servlet-class>net.socialgamer.cah.servlets.JavascriptConfig</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>LongPollServlet</servlet-name>
|
||||
<servlet-class>net.socialgamer.cah.servlets.LongPollServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>Schema</servlet-name>
|
||||
<servlet-class>net.socialgamer.cah.servlets.Schema</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>LongPollServlet</servlet-name>
|
||||
<url-pattern>/LongPollServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>AjaxServlet</servlet-name>
|
||||
<url-pattern>/AjaxServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>JavascriptConfig</servlet-name>
|
||||
<url-pattern>/js/cah.config.js</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>LongPollServlet</servlet-name>
|
||||
<url-pattern>/LongPollServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Schema</servlet-name>
|
||||
<url-pattern>/Schema</url-pattern>
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Andy Janata
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
* and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration file.
|
||||
*
|
||||
* @author Andy Janata (ajanata@socialgamer.net)
|
||||
*/
|
||||
|
||||
cah.DEBUG = false;
|
||||
cah.SILENT_DEBUG = false;
|
||||
|
||||
cah.AJAX_URI = "/cah/AjaxServlet";
|
||||
cah.LONGPOLL_URI = "/cah/LongPollServlet";
|
|
@ -0,0 +1,48 @@
|
|||
package net.socialgamer.cah.servlets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class JavascriptConfig extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 4287566906479434127L;
|
||||
|
||||
private String configString;
|
||||
|
||||
@Override
|
||||
public void init(final ServletConfig config) throws ServletException {
|
||||
final StringBuilder builder = new StringBuilder(256);
|
||||
//TODO: these should be loadable from the web.xml
|
||||
builder.append("cah.DEBUG = false;\n");
|
||||
builder.append("cah.SILENT_DEBUG = false;\n");
|
||||
|
||||
String contextPath = config.getServletContext().getContextPath();
|
||||
if (!contextPath.endsWith("/")) {
|
||||
contextPath += "/";
|
||||
}
|
||||
builder.append(String.format("cah.AJAX_URI = '%sAjaxServlet';\n", contextPath));
|
||||
builder.append(String.format("cah.LONGPOLL_URI = '%sLongPollServlet';\n", contextPath));
|
||||
|
||||
configString = builder.toString();
|
||||
|
||||
super.init(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
|
||||
resp.setContentType("text/javascript");
|
||||
final PrintWriter out = resp.getWriter();
|
||||
out.println(configString);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue