summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2014-10-10 22:16:11 +0200
committerDavid A. Madore <david+git@madore.org>2014-10-10 22:16:11 +0200
commit01e7ed9dcdbffc2f0d24d03ba83f7313d785620b (patch)
treecca79510f30527149c7bdb60fd093e6bdac541b4
parenteaa29f26c5aa1ff9cfc306dc23c6bcfae0c0c68d (diff)
downloaddamlengine-01e7ed9dcdbffc2f0d24d03ba83f7313d785620b.tar.gz
damlengine-01e7ed9dcdbffc2f0d24d03ba83f7313d785620b.tar.bz2
damlengine-01e7ed9dcdbffc2f0d24d03ba83f7313d785620b.zip
Permalinks in servlet system.
-rw-r--r--org/madore/damlengine/WeblogLink.java12
-rw-r--r--org/madore/damlengine/WeblogServlet.java11
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 {