From 4e7ceb1dde219d03e577c7c038e19f977c9abc29 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 12 Oct 2014 17:59:13 +0200 Subject: Separate the "has_cut" property from "do_single_page". Note: the following SQL should be used to upgrade the database: ALTER TABLE entries ADD COLUMN has_cut boolean NOT NULL DEFAULT FALSE ; UPDATE entries SET has_cut = (array_length(xpath('.//d:cut-here', content, ARRAY[ARRAY['d', 'http://www.madore.org/~david/NS/daml/']]), 1) NOTNULL) ; -- Check that the following returns nothing: SELECT edate , id FROM entries WHERE has_cut != ( do_single_page NOTNULL ) ; --- org/madore/damlengine/TodoCutHere.java | 2 -- org/madore/damlengine/TodoWrefAttr.java | 4 ++-- org/madore/damlengine/WeblogPopulate.java | 20 ++++++++++++-------- org/madore/damlengine/WeblogServlet.java | 2 +- org/madore/damlengine/WeblogSummary.java | 9 ++++++--- org/madore/damlengine/weblog-database.sql | 3 ++- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/org/madore/damlengine/TodoCutHere.java b/org/madore/damlengine/TodoCutHere.java index 898c784..f611adf 100644 --- a/org/madore/damlengine/TodoCutHere.java +++ b/org/madore/damlengine/TodoCutHere.java @@ -23,8 +23,6 @@ public final class TodoCutHere extends TodoDefaultElement { public void handleNodeOnly() { if ( ctx.ent == null ) throw new IllegalStateException("entry context not defined in cut-here element"); - if ( ctx.ent.doSinglePage == null ) - throw new IllegalStateException("cut-here element found in non single-page entry"); String lang = LangHelper.getLangRec(node); String explicitLang = LangHelper.getLangNorec(node); final WeblogLink lk diff --git a/org/madore/damlengine/TodoWrefAttr.java b/org/madore/damlengine/TodoWrefAttr.java index 650297c..a2b67ac 100644 --- a/org/madore/damlengine/TodoWrefAttr.java +++ b/org/madore/damlengine/TodoWrefAttr.java @@ -70,8 +70,8 @@ public class TodoWrefAttr extends TodoAttr { wrefNumberStr, wrefSupplementStr); // Decide whether link target is on this page final boolean onThisPage; - if ( lk.singlePage != null && ! lk.supplementStr.equals("") ) { - // Linking to a _fragment_ of an entry that has a single page. + if ( esum != null && esum.hasCut && ! lk.supplementStr.equals("") ) { + // Linking to a _fragment_ of an entry that has a cut-here element. if ( ctx.wsc != null && ctx.wsc.sel != null && ctx.wsc instanceof Context.WeblogSingleSelectionContext && ((Context.WeblogSingleSelectionContext)ctx.wsc).number == wrefNumber ) diff --git a/org/madore/damlengine/WeblogPopulate.java b/org/madore/damlengine/WeblogPopulate.java index 6593f9f..bb3af48 100644 --- a/org/madore/damlengine/WeblogPopulate.java +++ b/org/madore/damlengine/WeblogPopulate.java @@ -46,13 +46,13 @@ public final class WeblogPopulate { final PreparedStatement checkSt = conn.prepareStatement("SELECT sha1 FROM entries WHERE id=?"); final PreparedStatement insertNSt - = conn.prepareStatement("INSERT INTO entries(id,edate,lang,do_single_page,title,title_xml,content,sha1) VALUES (?,?,?,?,?,?::xml,?::xml,?)"); + = conn.prepareStatement("INSERT INTO entries(id,edate,lang,do_single_page,title,title_xml,content,sha1,has_cut) VALUES (?,?,?,?,?,?::xml,?::xml,?,?)"); final PreparedStatement insertCSt - = conn.prepareStatement("INSERT INTO entries(id,edate,lang,do_single_page,title,title_xml,content,sha1,cdate) VALUES (?,?,?,?,?,?::xml,?::xml,?,?::timestamptz)"); + = conn.prepareStatement("INSERT INTO entries(id,edate,lang,do_single_page,title,title_xml,content,sha1,has_cut,cdate) VALUES (?,?,?,?,?,?::xml,?::xml,?,?,?::timestamptz)"); final PreparedStatement updateNSt - = conn.prepareStatement("UPDATE entries SET (edate,mdate,lang,do_single_page,title,title_xml,content,sha1)=(?,DEFAULT,?,?,?,?::xml,?::xml,?) WHERE id=?"); + = conn.prepareStatement("UPDATE entries SET (edate,mdate,lang,do_single_page,title,title_xml,content,sha1,has_cut)=(?,DEFAULT,?,?,?,?::xml,?::xml,?,?) WHERE id=?"); final PreparedStatement updateCSt - = conn.prepareStatement("UPDATE entries SET (edate,mdate,lang,do_single_page,title,title_xml,content,sha1,cdate)=(?,DEFAULT,?,?,?,?::xml,?::xml,?,?::timestamptz) WHERE id=?"); + = conn.prepareStatement("UPDATE entries SET (edate,mdate,lang,do_single_page,title,title_xml,content,sha1,has_cut,cdate)=(?,DEFAULT,?,?,?,?::xml,?::xml,?,?,?::timestamptz) WHERE id=?"); final PreparedStatement checkDateSt = conn.prepareStatement("SELECT to_char(cdate,'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') FROM entries WHERE id=?"); final PreparedStatement clearCatSt @@ -68,6 +68,7 @@ public final class WeblogPopulate { xp.setNamespaceContext(new DamlEngine.DamlNSMapping()); XPathExpression expr = xp.compile("//d:weblog/d:entry"); XPathExpression texpr = xp.compile("d:title"); + XPathExpression cutexpr = xp.compile(".//d:cut-here"); NodeList entries = (NodeList)(expr.evaluate(doc, XPathConstants.NODESET)); for ( int i=0 ; i catSet; public EntrySummary(int id, String date, String lang, String title, String titleXml, - String doSinglePage) { + String doSinglePage, boolean hasCut) { this.id = id; this.date = date; this.lang = lang; this.title = title; this.titleXml = titleXml; this.doSinglePage = doSinglePage; + this.hasCut = hasCut; this.catSet = null; } } @@ -49,7 +51,7 @@ public final class WeblogSummary { singleton.obtainedTime = System.currentTimeMillis(); final Connection conn = WeblogDatabaseConnection.getConnection(); final PreparedStatement selSt - = conn.prepareStatement("SELECT id , edate , lang , title , title_xml , do_single_page FROM entries"); + = conn.prepareStatement("SELECT id , edate , lang , title , title_xml , do_single_page , has_cut FROM entries"); final ResultSet selRes = selSt.executeQuery(); while ( selRes.next() ) { int id = selRes.getInt(1); @@ -58,7 +60,8 @@ public final class WeblogSummary { String title = selRes.getString(4); String titleXml = selRes.getString(5); String doSinglePage = selRes.getString(6); - singleton.entries.put(id, new EntrySummary(id, date, lang, title, titleXml, doSinglePage)); + boolean hasCut = selRes.getBoolean(7); + singleton.entries.put(id, new EntrySummary(id, date, lang, title, titleXml, doSinglePage, hasCut)); } final PreparedStatement catSt = conn.prepareStatement("SELECT id , code FROM incat"); diff --git a/org/madore/damlengine/weblog-database.sql b/org/madore/damlengine/weblog-database.sql index ebf8e0c..f5ec56d 100644 --- a/org/madore/damlengine/weblog-database.sql +++ b/org/madore/damlengine/weblog-database.sql @@ -9,7 +9,8 @@ CREATE TABLE entries ( title_xml xml , content xml NOT NULL , sha1 text NOT NULL , - do_single_page text + do_single_page text , + has_cut boolean NOT NULL DEFAULT FALSE ) ; CREATE INDEX entries_edate_key ON entries ( edate ) ; CREATE TABLE incat ( -- cgit v1.2.3