Skip to content

Commit

Permalink
completed tasklist example
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthalloway committed Jan 28, 2009
1 parent 2669ac6 commit a3c829f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions bin/reader-tasklist.bat
@@ -0,0 +1 @@
java -cp classes;lib/clojure.jar;lib/clojure-contrib.jar reader.tasklist %1 %2 %3 %4 %5 %6 %7 %8 %9
1 change: 1 addition & 0 deletions bin/reader-tasklist.sh
@@ -0,0 +1 @@
java -cp classes:lib/clojure.jar:lib/clojure-contrib.jar reader.tasklist $@
26 changes: 17 additions & 9 deletions examples/tasklist.clj
@@ -1,29 +1,37 @@
(ns examples.tasklist
(:gen-class
:extends org.xml.sax.helpers.DefaultHandler
:init init
:state state)
(:use [clojure.contrib.duck-streams :only (reader)])
(:import [java.io File]
[org.xml.sax InputSource]
[org.xml.sax.helpers DefaultHandler]
[javax.xml.parsers SAXParserFactory])
(:gen-class
:extends org.xml.sax.helpers.DefaultHandler
:init init
:state state))
[javax.xml.parsers SAXParserFactory]))

; START: task-list
(defn task-list [arg]
(let [handler (new examples.tasklist)]
(let [handler (new examples.tasklist)] ; <label id="code.tasklist.classname"/>
(.. SAXParserFactory newInstance newSAXParser
(parse (InputSource. (reader (File. arg)))
handler))
@(.state handler)))
@(.state handler))) ; <label id="code.tasklist.statename"/>
; END: task-list

; START: init
(defn -init []
[[] (atom [])])
; END: init

; START: startElement
(defn -startElement
[this uri local qname atts]
(when (= qname "target")
(swap! (.state this) conj (.getValue atts "name"))))
(swap! (.state this) conj (.getValue atts "name")))) ; <label id="code.tasklist.update"/>
; END: startElement

; START: main
(defn -main [& args]
(doseq [arg args]
(println (task-list arg))))
(println (task-list arg))))
; END: main
10 changes: 10 additions & 0 deletions reader/tasklist.clj
@@ -0,0 +1,10 @@
(ns reader.tasklist
(:gen-class ; <label id="code.tasklist.genclass"/>
:extends org.xml.sax.helpers.DefaultHandler ; <label id="code.tasklist.extends"/>
:state state ; <label id="code.tasklist.state"/>
:init init) ; <label id="code.tasklist.init"/>
(:use [clojure.contrib.duck-streams :only (reader)])
(:import [java.io File]
[org.xml.sax InputSource]
[org.xml.sax.helpers DefaultHandler]
[javax.xml.parsers SAXParserFactory]))
18 changes: 3 additions & 15 deletions snippets/example-build.xml
Expand Up @@ -17,9 +17,11 @@
<tstamp/>
<mkdir dir="${build}"/>
</target>


<!-- START: target -->
<target name="compile-java" depends="init"
description="Compile Java sources.">
<!-- END: target -->
<javac srcdir="${jsrc}" destdir="${build}" includeJavaRuntime="yes"
debug="true" target="1.5"/>
</target>
Expand Down Expand Up @@ -49,20 +51,6 @@
</jar>
</target>

<target name="clojure-slim" depends="compile-java"
description="Create clojure-slim jar file (omits compiled Clojure code)">
<jar jarfile="${slim_jar}">
<fileset dir="${build}" includes="clojure/asm/**"/>
<fileset dir="${build}" includes="clojure/lang/**"/>
<fileset dir="${build}" includes="clojure/main.class"/>
<fileset dir="${cljsrc}" includes="**/*.clj"/>
<manifest>
<attribute name="Main-Class" value="clojure.main"/>
<attribute name="Class-Path" value="."/>
</manifest>
</jar>
</target>

<target name="jar" depends="clojure"/>

<target name="all" depends="clojure,clojure-slim"/>
Expand Down

0 comments on commit a3c829f

Please sign in to comment.