diff options
author | David A. Madore <david+git@madore.org> | 2014-10-12 17:59:13 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2014-10-12 17:59:54 +0200 |
commit | 4e7ceb1dde219d03e577c7c038e19f977c9abc29 (patch) | |
tree | a45dfa00055bff48662fef644e4d955f873fc121 /org/madore/damlengine | |
parent | fc921ecbda441f37ff33a1e4b76581434fc3c954 (diff) | |
download | damlengine-4e7ceb1dde219d03e577c7c038e19f977c9abc29.tar.gz damlengine-4e7ceb1dde219d03e577c7c038e19f977c9abc29.tar.bz2 damlengine-4e7ceb1dde219d03e577c7c038e19f977c9abc29.zip |
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 ) ;
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r-- | org/madore/damlengine/TodoCutHere.java | 2 | ||||
-rw-r--r-- | org/madore/damlengine/TodoWrefAttr.java | 4 | ||||
-rw-r--r-- | org/madore/damlengine/WeblogPopulate.java | 20 | ||||
-rw-r--r-- | org/madore/damlengine/WeblogServlet.java | 2 | ||||
-rw-r--r-- | org/madore/damlengine/WeblogSummary.java | 9 | ||||
-rw-r--r-- | 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<entries.getLength() ; i++ ) { Element ent = (Element)(entries.item(i)); @@ -101,6 +102,7 @@ public final class WeblogPopulate { Node titleNode = (Node)(texpr.evaluate(ent, XPathConstants.NODE)); String titleTxt = (titleNode != null) ? titleNode.getTextContent() : null; String titleXml = (titleNode != null) ? ser.writeToString(titleNode) : null; + boolean hasCut = cutexpr.evaluate(ent, XPathConstants.NODE) != null; conn.setAutoCommit(false); if ( exists ) { System.err.println("Updating entry "+id); @@ -116,11 +118,12 @@ public final class WeblogPopulate { updateSt.setString(5, titleXml); updateSt.setString(6, content); updateSt.setString(7, digest); + updateSt.setBoolean(8, hasCut); if ( cdate != null ) { - updateSt.setString(8, cdate); - updateSt.setInt(9, id); + updateSt.setString(9, cdate); + updateSt.setInt(10, id); } else { - updateSt.setInt(8, id); + updateSt.setInt(9, id); } updateSt.executeUpdate(); } else { @@ -138,8 +141,9 @@ public final class WeblogPopulate { insertSt.setString(6, titleXml); insertSt.setString(7, content); insertSt.setString(8, digest); + insertSt.setBoolean(9, hasCut); if ( cdate != null ) - insertSt.setString(9, cdate); + insertSt.setString(10, cdate); insertSt.executeUpdate(); } if ( ! Pattern.matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}\\:\\d{2}(?:\\:\\d{2})?(?:Z|[\\+\\-]\\d{2}\\:\\d{2})$", cdate) ) { diff --git a/org/madore/damlengine/WeblogServlet.java b/org/madore/damlengine/WeblogServlet.java index d9b0958..c5ace1f 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 = 2014101101L; + private static final long serialVersionUID = 2014101201L; @Override public void init(ServletConfig cfg) diff --git a/org/madore/damlengine/WeblogSummary.java b/org/madore/damlengine/WeblogSummary.java index 4819017..662c1d2 100644 --- a/org/madore/damlengine/WeblogSummary.java +++ b/org/madore/damlengine/WeblogSummary.java @@ -15,16 +15,18 @@ public final class WeblogSummary { String lang; String title; String titleXml; String doSinglePage; + boolean hasCut; HashSet<String> 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 ( |