Author: bbrossaud Date: 2010-05-28 16:43:51 +0200 (Fri, 28 May 2010) New Revision: 41 Url: http://chorem.org/repositories/revision/bow/41 Log: add bow url in properties file Added: trunk/src/main/java/org/chorem/bow/AliasServlet.java trunk/src/main/resources/bow.properties Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/home.jsp trunk/src/main/webapp/login.jsp trunk/src/main/webapp/openSearchResult.jsp trunk/src/main/webapp/register.jsp trunk/src/main/webapp/search.jsp Added: trunk/src/main/java/org/chorem/bow/AliasServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/AliasServlet.java (rev 0) +++ trunk/src/main/java/org/chorem/bow/AliasServlet.java 2010-05-28 14:43:51 UTC (rev 41) @@ -0,0 +1,74 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.chorem.bow; + +import com.sun.tools.javac.resources.version; +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; +import org.nuiton.wikitty.Criteria; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.search.Search; + +/** + * + * @author bbrossaud + */ +public class AliasServlet extends HttpServlet { + + private static final Log log = LogFactory.getLog(AliasServlet.class); + protected Model model = new Model(); + protected String bowUrl = ""; + + public AliasServlet() throws ArgumentsParserException { + ApplicationConfig config = new ApplicationConfig(); + config.setConfigFileName("bow.properties"); + config.parse(new String[]{}); + bowUrl = config.getOption("bow.url"); + } + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + this.doPost(request, response); + } + + /* @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet error occurs + */ + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + try { + String url = request.getRequestURL().toString(); + int index = url.indexOf("alias"); + index += 5; + String alias = url.substring(index); + if (alias != null && !alias.isEmpty()) { + alias = alias.substring(1); + WikittyProxy proxy = model.getProxy(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_ALIAS, alias).criteria(); + Bookmark bookmark = proxy.findByCriteria(Bookmark.class, criteria); + if (bookmark != null) { + String redirect = bookmark.getLink(); + response.sendRedirect(redirect); + } else { + response.sendRedirect(bowUrl); + } + } else { + response.sendRedirect(bowUrl); + } + } catch (Exception eee) { + request.getRequestDispatcher("error.jsp").forward(request, response); + } + } +} Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-28 14:43:51 UTC (rev 41) @@ -47,12 +47,20 @@ private static final Log log = LogFactory.getLog(ControllerServlet.class); protected Model model = new Model(); protected String version = ""; + protected String url = ""; - public ControllerServlet() throws ArgumentsParserException { + public ControllerServlet() throws ArgumentsParserException, Exception { ApplicationConfig config = new ApplicationConfig(); config.setConfigFileName("bow.properties"); config.parse(new String[]{}); version = config.getOption("application.version"); + url = config.getOption("bow.url"); + if (url == null) { + throw new Exception("No bow.url=\"SERVER URL\" in bow.properties"); + } + if (url.charAt(url.length() - 1) != '/') { + url += '/'; + } } @Override @@ -70,6 +78,7 @@ throws IOException, ServletException { try { request.setAttribute("version", version); + request.setAttribute("bowUrl", url); HttpSession session = request.getSession(true); User user = (User) session.getAttribute("user"); String token = request.getParameter("token"); // token or not Added: trunk/src/main/resources/bow.properties =================================================================== --- trunk/src/main/resources/bow.properties (rev 0) +++ trunk/src/main/resources/bow.properties 2010-05-28 14:43:51 UTC (rev 41) @@ -0,0 +1,2 @@ +application.version=${project.version} +bow.url=http://localhost:8080/bow/ Modified: trunk/src/main/webapp/home.jsp =================================================================== --- trunk/src/main/webapp/home.jsp 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/webapp/home.jsp 2010-05-28 14:43:51 UTC (rev 41) @@ -16,9 +16,7 @@ if (tokenActions != null && bookmarkActions != null) { String temporaryToken = tokenActions.getTemporaryToken(); String permanentToken = tokenActions.getPermanentToken(); - String url = request.getRequestURL().toString(); - int index = url.indexOf("home.jsp"); - url = url.substring(0, index); + String url = (String) request.getAttribute("bowUrl"); String version = (String) request.getAttribute("version"); %> Modified: trunk/src/main/webapp/login.jsp =================================================================== --- trunk/src/main/webapp/login.jsp 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/webapp/login.jsp 2010-05-28 14:43:51 UTC (rev 41) @@ -1,7 +1,7 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String error = (String) request.getAttribute("msgError"); - String url = request.getRequestURL().toString(); + String url = (String) request.getAttribute("bowUrl"); String version = (String) request.getAttribute("version"); %> Modified: trunk/src/main/webapp/openSearchResult.jsp =================================================================== --- trunk/src/main/webapp/openSearchResult.jsp 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/webapp/openSearchResult.jsp 2010-05-28 14:43:51 UTC (rev 41) @@ -16,9 +16,7 @@ if (bookmarkActions != null) { searchLine = bookmarkActions.getSearchLine(); } - String url = request.getRequestURL().toString(); - int index = url.indexOf("openSearchResult.jsp"); - url = url.substring(0, index); + String url = (String) request.getAttribute("bowUrl"); %> <html> Modified: trunk/src/main/webapp/register.jsp =================================================================== --- trunk/src/main/webapp/register.jsp 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/webapp/register.jsp 2010-05-28 14:43:51 UTC (rev 41) @@ -1,9 +1,7 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String error = (String) request.getAttribute("msgError"); - String url = request.getRequestURL().toString(); - int index = url.indexOf("register.jsp"); - url = url.substring(0, index); + String url = (String) request.getAttribute("bowUrl"); String version = (String) request.getAttribute("version"); %> <html> Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-28 14:12:51 UTC (rev 40) +++ trunk/src/main/webapp/search.jsp 2010-05-28 14:43:51 UTC (rev 41) @@ -17,9 +17,7 @@ String temporaryToken = tokenActions.getTemporaryToken(); String permanentToken = tokenActions.getPermanentToken(); String searchLine = bookmarkActions.getSearchLine(); - String url = request.getRequestURL().toString(); - int index = url.indexOf("search.jsp"); - url = url.substring(0, index); + String url = (String) request.getAttribute("bowUrl"); String version = (String) request.getAttribute("version"); %>