From 01e7ed9dcdbffc2f0d24d03ba83f7313d785620b Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 10 Oct 2014 22:16:11 +0200 Subject: Permalinks in servlet system. --- org/madore/damlengine/WeblogLink.java | 12 ++++-------- org/madore/damlengine/WeblogServlet.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/org/madore/damlengine/WeblogLink.java b/org/madore/damlengine/WeblogLink.java index f29c69e..9762e49 100644 --- a/org/madore/damlengine/WeblogLink.java +++ b/org/madore/damlengine/WeblogLink.java @@ -39,10 +39,7 @@ public final class WeblogLink { public void setTypeSingle() { this.t = Type.SINGLE; } public void setTypeStandard() { - if ( singlePage == null ) - this.t = Type.MONTH; - else - this.t = Type.SINGLE; + this.t = Type.SINGLE; } public String getFragment() { @@ -59,10 +56,9 @@ public final class WeblogLink { case CAT: return baseDir + cat + ".html"; case SINGLE: - if ( singlePage == null ) - throw new IllegalArgumentException("can't have single page link to non single-page entry"); - return baseDir + yearStr + "-" + monthStr + "-" + dayStr - + "-" + singlePage + ".html"; + return baseDir + "d." + yearStr + "-" + monthStr + "-" + dayStr + + "." + numberStr + + (singlePage==null ? "" : "." + singlePage) + ".html"; default: throw new AssertionError("unknown type"); } diff --git a/org/madore/damlengine/WeblogServlet.java b/org/madore/damlengine/WeblogServlet.java index b68f114..648c12f 100644 --- a/org/madore/damlengine/WeblogServlet.java +++ b/org/madore/damlengine/WeblogServlet.java @@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletResponse; public class WeblogServlet extends HttpServlet { - private static final long serialVersionUID = 2014100902L; + private static final long serialVersionUID = 2014101001L; @Override public void init(ServletConfig cfg) @@ -65,27 +65,32 @@ public class WeblogServlet extends HttpServlet { Matcher matcher; if ( pathInfo == null ) return new NoSuchPath(); - if ( (matcher=Pattern.compile("/d\\.(\\d{4}-\\d{2}-\\d{2})\\.(\\d{4})\\.html").matcher(pathInfo)).matches() ) { + if ( (matcher=Pattern.compile("/d\\.(\\d{4}-\\d{2}-\\d{2})\\.(\\d{4})(?:\\.([\\p{Alnum}\\-]*))?\\.html").matcher(pathInfo)).matches() ) { final String date; final int number; + final String extra; try { date = matcher.group(1); number = Integer.parseInt(matcher.group(2)); + extra = matcher.group(3); } catch (NumberFormatException e) { return new NoSuchPath(); } try { final Connection conn = WeblogDatabaseConnection.getConnection(); final PreparedStatement selSt - = conn.prepareStatement("SELECT id , extract(epoch from mdate) FROM entries WHERE edate=? AND id=?"); + = conn.prepareStatement("SELECT id , extract(epoch from mdate) , do_single_page FROM entries WHERE edate=? AND id=?"); selSt.setString(1,date); selSt.setInt(2,number); final ResultSet selRes = selSt.executeQuery(); if ( selRes.next() ) { int id = selRes.getInt(1); double mdate = selRes.getDouble(2); + String doSinglePage = selRes.getString(3); if ( id != number ) throw new ServletException("this cannot happen"); + if ( extra != null && ! extra.equals(doSinglePage) ) + return new NoSuchPath(); long lastModified = (long)(mdate*1000); long thisLastModified; try { -- cgit v1.2.3