+ <li>New class <tt>broadcast-handler</tt> as a generalization
[cxml/s11.git] / klacks / tap-source.lisp
blobd92f98c35ba169d2a6bd753fd0f0d5321ba82a0c
1 ;;; -*- Mode: Lisp; readtable: runes; -*-
2 ;;; (c) copyright 2007 David Lichteblau
4 ;;; This library is free software; you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Library General Public
6 ;;; License as published by the Free Software Foundation; either
7 ;;; version 2 of the License, or (at your option) any later version.
8 ;;;
9 ;;; This library is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Library General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU Library General Public
15 ;;; License along with this library; if not, write to the
16 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 ;;; Boston, MA 02111-1307 USA.
19 (in-package :cxml)
21 (defun klacks:make-tapping-source (upstream-source &optional sax-handler)
22 (make-instance 'klacks:tapping-source
23 :upstream-source upstream-source
24 :dribble-handler sax-handler))
26 (defclass klacks:tapping-source (klacks:source)
27 ((upstream-source :initarg :upstream-source :accessor upstream-source)
28 (dribble-handler :initarg :dribble-handler :accessor dribble-handler)
29 (seen-event-p :initform nil :accessor seen-event-p)))
31 (defmethod initialize-instance :after ((instance klacks:tapping-source) &key)
32 (let ((s-p (make-instance 'klacksax :source (upstream-source instance))))
33 (sax:register-sax-parser (dribble-handler instance) s-p)))
36 ;;; event dribbling
38 (defun maybe-dribble (source)
39 (unless (seen-event-p source)
40 (klacks:serialize-event (upstream-source source)
41 (dribble-handler source)
42 :consume nil)
43 (setf (seen-event-p source) t)))
45 (defmethod klacks:peek ((source klacks:tapping-source))
46 (multiple-value-prog1
47 (klacks:peek (upstream-source source))
48 (maybe-dribble source)))
50 (defmethod klacks:peek-value ((source klacks:tapping-source))
51 (multiple-value-prog1
52 (klacks:peek-value (upstream-source source))
53 (maybe-dribble source)))
55 (defmethod klacks:peek-next ((source klacks:tapping-source))
56 (setf (seen-event-p source) nil)
57 (multiple-value-prog1
58 (klacks:peek-next (upstream-source source))
59 (maybe-dribble source)))
61 (defmethod klacks:consume ((source klacks:tapping-source))
62 (maybe-dribble source)
63 (multiple-value-prog1
64 (klacks:consume (upstream-source source))
65 (setf (seen-event-p source) nil)))
68 ;;; loop through
70 (defmethod klacks:close-source ((source klacks:tapping-source))
71 (klacks:close-source (upstream-source source)))
73 (defmethod klacks:map-attributes (fn (source klacks:tapping-source))
74 (klacks:map-attributes fn (upstream-source source)))
76 (defmethod klacks:map-current-namespace-declarations
77 (fn (source klacks:tapping-source))
78 (klacks:map-current-namespace-declarations fn (upstream-source source)))
80 (defmethod klacks:list-attributes ((source klacks:tapping-source))
81 (klacks:list-attributes (upstream-source source)))
83 (defmethod klacks:current-line-number ((source klacks:tapping-source))
84 (klacks:current-line-number (upstream-source source)))
86 (defmethod klacks:current-column-number ((source klacks:tapping-source))
87 (klacks:current-column-number (upstream-source source)))
89 (defmethod klacks:current-system-id ((source klacks:tapping-source))
90 (klacks:current-system-id (upstream-source source)))
92 (defmethod klacks:current-xml-base ((source klacks:tapping-source))
93 (klacks:current-xml-base (upstream-source source)))
95 (defmethod klacks:current-cdata-section-p ((source klacks:tapping-source))
96 (klacks:current-cdata-section-p (upstream-source source)))
98 (defmethod klacks:find-namespace-binding
99 (prefix (source klacks:tapping-source))
100 (klacks:find-namespace-binding prefix (upstream-source source)))
102 (defmethod klacks:decode-qname (qname (source klacks:tapping-source))
103 (klacks:decode-qname qname (upstream-source source)))