r89 - in trunk/src/main: java/org/chorem/bow resources webapp
Author: bpoussin Date: 2010-07-17 14:55:53 +0200 (Sat, 17 Jul 2010) New Revision: 89 Url: http://chorem.org/repositories/revision/bow/89 Log: add url/servlet path configuration, this permit apache url modification Modified: trunk/src/main/java/org/chorem/bow/AliasServlet.java trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/BowConfig.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/resources/bow.properties trunk/src/main/webapp/bookmark.jsp trunk/src/main/webapp/bookmarkHome.jsp trunk/src/main/webapp/bookmarkSearch.jsp trunk/src/main/webapp/header.jsp Modified: trunk/src/main/java/org/chorem/bow/AliasServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/AliasServlet.java 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/java/org/chorem/bow/AliasServlet.java 2010-07-17 12:55:53 UTC (rev 89) @@ -39,11 +39,11 @@ */ public class AliasServlet extends HttpServlet { - protected String bowUrl = ""; + protected String bowServletUrl = ""; public AliasServlet() throws ArgumentsParserException { BowConfig config = BowConfig.getInstance(); - bowUrl = config.getBowUrl(); + bowServletUrl = config.getBowUrl() + config.getServletBow() ; } @Override @@ -60,11 +60,9 @@ 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); + String alias = request.getPathInfo(); if (alias != null && !alias.isEmpty()) { + // remove first '/' alias = alias.substring(1); WikittyProxy proxy = BowProxy.getInstance(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_ALIAS, alias).criteria(); @@ -73,10 +71,10 @@ String redirect = bookmark.getLink(); response.sendRedirect(redirect); } else { - response.sendRedirect(bowUrl); + response.sendRedirect(bowServletUrl); } } else { - response.sendRedirect(bowUrl); + response.sendRedirect(bowServletUrl); } } catch (Exception eee) { request.getRequestDispatcher("error.jsp").forward(request, response); Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-07-17 12:55:53 UTC (rev 89) @@ -171,7 +171,8 @@ public static void addUrlToBookmark(String url, Bookmark bookmark) { if (url != null && !url.isEmpty()) { String link = url.trim(); - if (!link.contains("http://")) { + // FIXME poussin 20100717 how can add ftp:// in bookmarks ? + if (!link.startsWith("http://") || !link.startsWith("https://")) { link = "http://" + link; } bookmark.setLink(link); Modified: trunk/src/main/java/org/chorem/bow/BowConfig.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BowConfig.java 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/java/org/chorem/bow/BowConfig.java 2010-07-17 12:55:53 UTC (rev 89) @@ -88,9 +88,57 @@ * @return url */ public String getBowUrl() { - return getOption(Option.BOW_URL.key); + String result = getOption(Option.BOW_URL.key); + if (result != null && result.charAt(result.length() - 1) != '/') { + result += '/'; + } + return result; } + /** + * Get alias url as string. + * + * @return url + */ + public String getAliasUrl() { + String result = getOption(Option.ALIAS_URL.key); + if (result != null && result.charAt(result.length() - 1) != '/') { + result += '/'; + } + return result; + } + + /** + * Get bow servlet as string. + * + * @return servlet name + */ + public String getServletBow() { + return getOption(Option.SERVLET_BOW.key); + } + + /** + * Get alias servlet as string. + * + * @return servlet name + */ + public String getServletAlias() { + return getOption(Option.SERVLET_ALIAS.key); + } + + /** + * Get alias servlet url as string. + * + * @return servlet name + */ + public String getServletAliasUrl() { + String result = getAliasUrl() + getServletAlias(); + if (result != null && result.charAt(result.length() - 1) != '/') { + result += '/'; + } + return result; + } + public File getDataDirAsFile() { File option = getOptionAsFile(Option.DATA_DIR.key); return option; @@ -147,6 +195,12 @@ null, String.class, true, true), BOW_URL("bow.url", _("bow.config.bow.url.description"), null, String.class, false, false), + ALIAS_URL("alias.url", _("bow.config.alias.url.description"), + null, String.class, false, false), + SERVLET_BOW("servlet.bow", _("bow.config.servlet.bow.description"), + null, String.class, false, false), + SERVLET_ALIAS("servlet.alias", _("bow.config.servlet.bow.description"), + null, String.class, false, false), BOW_SMTPSERVER("bow.smtpServer", _("bow.config.bow.smtpServer.description"), null, String.class, false, false), BOW_ADDRESSFROM("bow.addressFrom", _("bow.config.bow.addressFrom.description"), Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-07-17 12:55:53 UTC (rev 89) @@ -75,18 +75,16 @@ private static final Log log = LogFactory.getLog(ControllerServlet.class); protected String version = ""; - protected String url = ""; + protected String bowServletUrl = ""; public ControllerServlet() throws ArgumentsParserException, Exception { BowConfig config = BowConfig.getInstance(); version = config.getVersion(); - url = config.getBowUrl(); - if (url == null) { + bowServletUrl = config.getBowUrl(); + if (bowServletUrl == null) { throw new Exception("No bow.url=\"SERVER URL\" in bow.properties"); } - if (url.charAt(url.length() - 1) != '/') { - url += '/'; - } + bowServletUrl += config.getServletBow(); } @Override @@ -104,7 +102,7 @@ throws IOException, ServletException { try { request.setAttribute("version", version); - request.setAttribute("bowUrl", url); + request.setAttribute("bowUrl", bowServletUrl); HttpSession session = request.getSession(true); User user = (User) session.getAttribute("user"); @@ -360,7 +358,7 @@ /* @param request servlet request * @param response servlet response * @throws ServletException if a servlet error occurs - * @description when the user click on the bookmark url, we + * @description when the user click on the bookmark bowServletUrl, we * increment the number of click */ protected void actionAddClick(HttpServletRequest request, HttpServletResponse response) @@ -527,7 +525,7 @@ protected void actionModifyBookmark(HttpServletRequest request, HttpServletResponse response, User user) throws IOException { - String link = request.getParameter("url"); // url of the website + String link = request.getParameter("url"); // bowServletUrl of the website String name = request.getParameter("name"); // website name String alias = request.getParameter("alias"); String tags = request.getParameter("tags"); @@ -558,7 +556,7 @@ } protected void addUrl(HttpServletRequest request, User user) { - String link = request.getParameter("url"); // url of the website + String link = request.getParameter("url"); // bowServletUrl of the website String name = request.getParameter("name"); // website name String alias = request.getParameter("alias"); WikittyProxy proxy = BowProxy.getInstance(); Modified: trunk/src/main/resources/bow.properties =================================================================== --- trunk/src/main/resources/bow.properties 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/resources/bow.properties 2010-07-17 12:55:53 UTC (rev 89) @@ -1,5 +1,8 @@ application.version=${project.version} bow.url=http://localhost:8080/bow/ +alias.url=http://localhost:8080/bow/ +servlet.bow=bow +servlet.alias=alias bow.smtpServer=smtp bow.addressFrom=bow@chorem.org bow.admins=brossa_b@epitech.net Modified: trunk/src/main/webapp/bookmark.jsp =================================================================== --- trunk/src/main/webapp/bookmark.jsp 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/webapp/bookmark.jsp 2010-07-17 12:55:53 UTC (rev 89) @@ -1,3 +1,4 @@ +<%@page import="org.chorem.bow.BowConfig" %> <%@page import="org.chorem.bow.Bookmark" %> <%@page import="java.text.SimpleDateFormat" %> <%@page import="org.chorem.bow.BookmarkActions" %> @@ -8,6 +9,7 @@ BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions"); SimpleDateFormat sdf = (SimpleDateFormat) request.getAttribute("sdf"); String url = (String) request.getAttribute("bowUrl"); + String aliasUrl = BowConfig.getInstance().getServletAliasUrl(); String search = ""; String searchLine = request.getParameter("searchLine"); if (searchLine != null) { @@ -26,7 +28,7 @@ <div class="bookmark"> <div class="bookmarkhead clearfix"> - <a class="alias" href="<%=url + "alias/" + bookmark.getAlias()%>" title="<%=bookmark.getLink()%>" target="_blank"> + <a class="alias" href="<%=aliasUrl + bookmark.getAlias()%>" title="<%=bookmark.getLink()%>" target="_blank"> <%=bookmark.getAlias()%> </a> <p class="date"> (<%=sdf.format(bookmark.getDate())%>)</p> Modified: trunk/src/main/webapp/bookmarkHome.jsp =================================================================== --- trunk/src/main/webapp/bookmarkHome.jsp 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/webapp/bookmarkHome.jsp 2010-07-17 12:55:53 UTC (rev 89) @@ -60,7 +60,7 @@ <div id="headback"> <div id="head"> <div id="headleft"> - <a class="logo" href="<%=url%>bow?action=home">bow</a>(Bookmarks On the Web) + <a class="logo" href="<%=url%>?action=home">bow</a>(Bookmarks On the Web) </div> <div id="headright"> <form action="bow?action=logout"> @@ -134,8 +134,8 @@ <li><a href="bow?action=admin">Admin</a></li> <%}%> <li><a href="bow?action=preferences">Preferences</a></li> - <li><a title="Add this link to your favourites to bookmark others in the future. This link is just available while you are connected on the site!" href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>bow?action=addUrl&token=<%=temporaryToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);}void(0);">Temporary bookmark addition link</a></li> - <li><a title="Add this link to your favourites to bookmark others in the future. This link is always available!" href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>bow?action=addUrl&token=<%=permanentToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);}void(0);">Permanent bookmark addition link</a></li> + <li><a title="Add this link to your favourites to bookmark others in the future. This link is just available while you are connected on the site!" href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>bow?action=addUrl&token=<%=temporaryToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);}void(0);">Bookmark add link (session)</a></li> + <li><a title="Add this link to your favourites to bookmark others in the future. This link is always available!" href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>bow?action=addUrl&token=<%=permanentToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);}void(0);">Bookmark add link (permanent)</a></li> </ul> <div id="nuage"> <jsp:include page="tagsCloud.jsp" flush="true" /> Modified: trunk/src/main/webapp/bookmarkSearch.jsp =================================================================== --- trunk/src/main/webapp/bookmarkSearch.jsp 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/webapp/bookmarkSearch.jsp 2010-07-17 12:55:53 UTC (rev 89) @@ -60,7 +60,7 @@ <div id="headback"> <div id="head"> <div id="headleft"> - <a class="logo" href="<%=url%>bow?action=home">bow</a>(Bookmarks On the Web) + <a class="logo" href="<%=url%>?action=home">bow</a>(Bookmarks On the Web) </div> <div id="headright"> <form action="bow?action=logout"> Modified: trunk/src/main/webapp/header.jsp =================================================================== --- trunk/src/main/webapp/header.jsp 2010-07-16 07:59:52 UTC (rev 88) +++ trunk/src/main/webapp/header.jsp 2010-07-17 12:55:53 UTC (rev 89) @@ -6,8 +6,8 @@ <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Bookmark On the Web" /> <title>Bow</title> - <link rel="search" type="application/opensearchdescription+xml" title="bowTemporarySearchEngine" href="<%=url%>bow?action=temporaryXml" /> - <link rel="search" type="application/opensearchdescription+xml" title="bowPermanentSearchEngine" href="<%=url%>bow?action=permanentXml" /> + <link rel="search" type="application/opensearchdescription+xml" title="bowTemporarySearchEngine" href="<%=url%>?action=temporaryXml" /> + <link rel="search" type="application/opensearchdescription+xml" title="bowPermanentSearchEngine" href="<%=url%>?action=permanentXml" /> <link rel="stylesheet" type="text/css" href="./css/bookmark.css" /> <script type="text/javascript"> <!--
participants (1)
-
bpoussin@users.chorem.org