summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-11-12 12:50:58 +0100
committerDavid A. Madore <david+git@madore.org>2011-11-12 12:50:58 +0100
commit71dc0d53fcefea70ce978d305fba653cc2180a3b (patch)
treeaaa383e6d1561b081fe8cbc60539a718aa24c5f4
parent2b55a35cf1188e0b7215ebf65c593ff45971e184 (diff)
downloaddamlengine-71dc0d53fcefea70ce978d305fba653cc2180a3b.tar.gz
damlengine-71dc0d53fcefea70ce978d305fba653cc2180a3b.tar.bz2
damlengine-71dc0d53fcefea70ce978d305fba653cc2180a3b.zip
Allow selecting a single entry.
-rw-r--r--org/madore/damlengine/Context.java8
-rw-r--r--org/madore/damlengine/DamlEngine.java10
-rw-r--r--org/madore/damlengine/TodoElement.java2
-rw-r--r--org/madore/damlengine/TodoWeblogSelectionElement.java67
-rw-r--r--org/madore/damlengine/WeblogSelect.java4
-rw-r--r--org/madore/damlengine/weblog-single-template.daml45
6 files changed, 128 insertions, 8 deletions
diff --git a/org/madore/damlengine/Context.java b/org/madore/damlengine/Context.java
index ca521fa..6674c76 100644
--- a/org/madore/damlengine/Context.java
+++ b/org/madore/damlengine/Context.java
@@ -58,6 +58,14 @@ public class Context implements Cloneable {
}
}
+ public static class WeblogSingleSelectionContext
+ extends WeblogSelectionContext {
+ public int number;
+ public WeblogSingleSelectionContext(int number) {
+ this.number = number;
+ }
+ }
+
public WeblogSelectionContext wsc;
public static class EntryContext {
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index c24ea33..77fbf7f 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -198,6 +198,16 @@ public final class DamlEngine {
: System.out;
WeblogSelect.fullProcess(new Context.WeblogRecentSelectionContext(count),
out);
+ } else if ( (matcher=Pattern.compile("process-weblog-single\\s+(\\d+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) {
+ int number = Integer.parseInt(matcher.group(1));
+ String outf = matcher.group(2);
+ OutputStream out = (outf != null)
+ ? new FileOutputStream(outf)
+ : System.out;
+ WeblogSelect.fullProcess(new Context.WeblogSingleSelectionContext(number),
+ out);
+ if ( out != System.out )
+ out.close();
} else if ( (matcher=Pattern.compile("process-weblog-index(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) {
String outf = matcher.group(1);
OutputStream out = (outf != null)
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index 4f15afa..5f4fe3c 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -68,6 +68,8 @@ public abstract class TodoElement extends TodoItem {
damlFactories.put("weblog-selection-month-month", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.MONTH_MONTH));
damlFactories.put("weblog-selection-cat-code", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_CODE));
damlFactories.put("weblog-selection-cat-name", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.CATEGORY_NAME));
+ damlFactories.put("weblog-selection-single-number", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_NUMBER));
+ damlFactories.put("weblog-selection-single-title", new TodoWeblogSelectionElement.Factory(TodoWeblogSelectionElement.Type.SINGLE_TITLE));
}
protected final static Factory killAFactory
diff --git a/org/madore/damlengine/TodoWeblogSelectionElement.java b/org/madore/damlengine/TodoWeblogSelectionElement.java
index df9c75e..ec87d17 100644
--- a/org/madore/damlengine/TodoWeblogSelectionElement.java
+++ b/org/madore/damlengine/TodoWeblogSelectionElement.java
@@ -1,8 +1,12 @@
package org.madore.damlengine;
+import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import org.w3c.dom.*;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSParser;
+import org.w3c.dom.ls.LSInput;
public final class TodoWeblogSelectionElement extends TodoDefaultElement {
@@ -11,7 +15,9 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement {
MONTH_YEAR,
MONTH_MONTH,
CATEGORY_NAME,
- CATEGORY_CODE;
+ CATEGORY_CODE,
+ SINGLE_NUMBER,
+ SINGLE_TITLE;
}
public static class Factory extends TodoElement.Factory {
@@ -93,37 +99,82 @@ public final class TodoWeblogSelectionElement extends TodoDefaultElement {
throw new IllegalStateException("weblog-selection element encountered with no weblog selection state");
// String lang = LangHelper.getLangRec(node);
String str;
+ Node newNode;
switch ( t ) {
case RECENT_COUNT:
if ( ! ( ctx.wsc instanceof Context.WeblogRecentSelectionContext ) )
throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog recent selection state");
- str = String.format("%d", ((Context.WeblogRecentSelectionContext)(ctx.wsc)).count );
+ str = String.format("%d", ((Context.WeblogRecentSelectionContext)(ctx.wsc)).count);
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
break;
case MONTH_YEAR:
if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) )
- throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog month selection state");
+ throw new IllegalStateException("weblog-selection-month-year element encountered while not in weblog month selection state");
str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).year;
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
break;
case MONTH_MONTH:
if ( ! ( ctx.wsc instanceof Context.WeblogMonthSelectionContext ) )
- throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog month selection state");
+ throw new IllegalStateException("weblog-selection-month-month element encountered while not in weblog month selection state");
str = ((Context.WeblogMonthSelectionContext)(ctx.wsc)).month;
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
break;
case CATEGORY_CODE:
if ( ! ( ctx.wsc instanceof Context.WeblogCategorySelectionContext ) )
- throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog category selection state");
+ throw new IllegalStateException("weblog-selection-cat-code element encountered while not in weblog category selection state");
str = ((Context.WeblogCategorySelectionContext)(ctx.wsc)).code;
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
break;
case CATEGORY_NAME:
if ( ! ( ctx.wsc instanceof Context.WeblogCategorySelectionContext ) )
- throw new IllegalStateException("weblog-selection-recent-count element encountered while not in weblog category selection state");
+ throw new IllegalStateException("weblog-selection-cat-name element encountered while not in weblog category selection state");
str = categoryName(((Context.WeblogCategorySelectionContext)(ctx.wsc)).code, LangHelper.getLangRec(node));
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
+ break;
+ case SINGLE_NUMBER:
+ if ( ! ( ctx.wsc instanceof Context.WeblogSingleSelectionContext ) )
+ throw new IllegalStateException("weblog-selection-single-number element encountered while not in weblog single entry selection state");
+ str = String.format("%04d", ((Context.WeblogSingleSelectionContext)(ctx.wsc)).number);
+ newNode = ctx.doc.createTextNode(str);
+ node.getParentNode().replaceChild(newNode, node);
+ break;
+ case SINGLE_TITLE:
+ if ( ! ( ctx.wsc instanceof Context.WeblogSingleSelectionContext ) )
+ throw new IllegalStateException("weblog-selection-single-title element encountered while not in weblog single entry selection state");
+ WeblogSummary wsum = WeblogSummary.getSummary();
+ if ( wsum == null || wsum.entries == null )
+ throw new IllegalStateException("failed to obtain weblog summary for weblog-selection-single-title");
+ WeblogSummary.EntrySummary esum
+ = wsum.entries.get(new Integer(((Context.WeblogSingleSelectionContext)(ctx.wsc)).number));
+ if ( esum == null )
+ throw new IllegalStateException("tried weblog-selection-single-title on inexistent entry");
+ {
+ Element span = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span");
+ node.getParentNode().replaceChild(span, node);
+ LangHelper.setLangRec(span, esum.lang);
+ DOMImplementationLS domi
+ = (DOMImplementationLS)ctx.doc.getImplementation();
+ LSParser par = domi.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
+ LSInput input = domi.createLSInput();
+ input.setStringData(esum.titleXml);
+ Document temp = par.parse(input);
+ Node titleNode = ctx.doc.adoptNode(temp.getDocumentElement());
+ String explicitLang = LangHelper.getLangNorec(titleNode);
+ if ( explicitLang != null )
+ LangHelper.setLangNorec(span, explicitLang);
+ ArrayList<Node> childList = getChildList(titleNode);
+ for ( Node child : childList )
+ span.appendChild(child);
+ }
break;
default:
throw new AssertionError("unknown type");
}
- Node txt = ctx.doc.createTextNode(str);
- node.getParentNode().replaceChild(txt, node);
}
}
diff --git a/org/madore/damlengine/WeblogSelect.java b/org/madore/damlengine/WeblogSelect.java
index 9e1c6a2..8ebdaf4 100644
--- a/org/madore/damlengine/WeblogSelect.java
+++ b/org/madore/damlengine/WeblogSelect.java
@@ -33,6 +33,10 @@ public final class WeblogSelect {
templateResourceName = "weblog-recent-template.daml";
selSt = conn.prepareStatement("SELECT id , content FROM entries ORDER BY id DESC LIMIT ?");
selSt.setInt(1,((Context.WeblogRecentSelectionContext)wsc).count);
+ } else if ( wsc instanceof Context.WeblogSingleSelectionContext ) {
+ templateResourceName = "weblog-single-template.daml";
+ selSt = conn.prepareStatement("SELECT id , content FROM entries WHERE id=?");
+ selSt.setInt(1,((Context.WeblogSingleSelectionContext)wsc).number);
} else
throw new IllegalArgumentException("don't know how to perform this selection");
diff --git a/org/madore/damlengine/weblog-single-template.daml b/org/madore/damlengine/weblog-single-template.daml
new file mode 100644
index 0000000..673ee32
--- /dev/null
+++ b/org/madore/damlengine/weblog-single-template.daml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE d:daml [
+ <!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
+ %HTMLlat1;
+ <!ENTITY % HTMLspecial PUBLIC "-//W3C//ENTITIES Special for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent">
+ %HTMLspecial;
+ <!ENTITY % HTMLsymbol PUBLIC "-//W3C//ENTITIES Symbols for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent">
+ %HTMLsymbol;
+ <!ENTITY uri-to-top "../">
+ <!ENTITY file.language "en">
+ <!ENTITY my-email "<d:email-despammed xmlns:d='http://www.madore.org/~david/NS/daml/'>david+www<d:email-at />madore<d:email-dot />org</d:email-despammed>">
+]>
+
+<d:daml xml:lang="&file.language;" uri-to-top="&uri-to-top;" xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.madore.org/~david/NS/daml/">
+
+<d:title>David Madore's WebLog: <d:weblog-selection-single-title /></d:title>
+
+<d:meta-description>David Alexander Madore's WebLog / Diary</d:meta-description>
+
+<d:meta-keywords>David Alexander Madore, WebLog, diary</d:meta-keywords>
+
+<link rel="alternate" type="application/rss+xml" title="RSS" href="weblog.rss" />
+
+<d:body>
+
+<p><a href="weblog-index.html#index">Index of all entries —
+<span xml:lang="fr">Index de toutes les entrées</span></a> — <a
+href="weblog.rss" rel="alternate" type="application/rss+xml"
+title="RSS"><img src="&uri-to-top;images/xml.gif" alt="XML" width="36"
+height="14" /></a> (<abbr>RSS</abbr> 1.0) — <a
+href="http://www.madore.org/cgi-bin/comment.pl/lscomments">Recent
+comments — <span xml:lang="fr">Commentaires
+récents</span></a></p>
+
+<p>Entry #<d:weblog-selection-single-number />
+/ <span xml:lang="fr">Entrée #<d:weblog-selection-single-number /></span>:</p>
+
+<d:weblog-select />
+
+<hr />
+
+</d:body>
+
+</d:daml>