3 (:use clj-stacktrace.repl)
4 (:require clojure.contrib.string)
5 (:require clojure.contrib.http.agent)
6 (:require clojure-http.resourcefully))
9 " Replacing these characters http encoded ones
19 (clojure.contrib.string/replace-str " " "%20"
20 (clojure.contrib.string/replace-str "'" "%27"
21 (clojure.contrib.string/replace-str ";" "%3B"
22 (clojure.contrib.string/replace-str "[" "%5B"
23 (clojure.contrib.string/replace-str "@" "%40"
24 (clojure.contrib.string/replace-str "=" "%3D"
25 (clojure.contrib.string/replace-str "]" "%5D" text
30 (defn filterSpacesFromXML [text]
32 (clojure.contrib.string/replace-str "< " "<"
33 (clojure.contrib.string/replace-str " : " ":"
34 (clojure.contrib.string/replace-str " / >" " />"
35 (clojure.contrib.string/replace-str "< /" "</"
36 (clojure.contrib.string/replace-str "</ " "</"
37 (clojure.contrib.string/replace-str " / " "/"
38 (clojure.contrib.string/replace-re #"=\"\s" "=\""
39 (clojure.contrib.string/replace-re #"\s\"" "\""
40 (clojure.contrib.string/replace-str " = " "="
46 ;; set get base URL ...TODO - put in config
47 (def db-base-URL "http://localhost:8080/exist/rest/")
50 ;; set root/system dir fragment ...TODO - put in config
51 (def db-system-DIR "rootDir/system.main.system/")
53 ;; working directory lookup ...TODO - put these lookups into config
54 (defn working-dir-lookup [token]
56 ;;(println "DEBUG > 'working-dir-lookup' CALLED > ["(keyword token)"]" )
57 ( { :group "aauthentication.main.authentication/groups.aauth.groups"
58 :user "aauthentication.main.authentication/users.aauth.users"
59 :users "aauthentication.main.authentication/users.aauth.users"
60 :account "groups.main.groups"
61 :journal "groups.main.groups"
62 :entry "groups.main.groups"
63 :entries "groups.main.groups"
64 :debit "groups.main.groups"
65 :credit "groups.main.groups"
66 :bookkeeping "groups.main.groups"
72 (defn namespace-lookup
75 ;;(println "DEBUG > 'namespace-lookup' CALLED > ["token"]" )
76 ( { "group" "com/interrupt/bookkeeping/users"
77 "user" "com/interrupt/bookkeeping/users"
78 "account" "com/interrupt/bookkeeping/account"
79 "journal" "com/interrupt/bookkeeping/journal"
80 "entry" "com/interrupt/bookkeeping/journal"
81 "entries" "com/interrupt/bookkeeping/journal"
82 "debit" "com/interrupt/bookkeeping/account"
83 "credit" "com/interrupt/bookkeeping/account"
89 (defn execute-http-call [ full-URL http-method header-hash xml-content ]
91 ;; from DB, get 'token' for 'option' args & value
92 (println "DEBUG > FINAL http query[" full-URL "] > http-method[" http-method "] > header-hash[" header-hash "] > xml-content[" xml-content "]")
95 (. "GET" equals http-method)
96 (let [agt (clojure.contrib.http.agent/http-agent
98 ;; TODO - parse results, check for i) null or ii) multiple results
104 (if (clojure.contrib.http.agent/error? agt)
105 (str "<error method='GET' query='" full-URL "' errors='" (agent-errors agt) "' />")
106 (clojure.contrib.http.agent/string agt))
109 (. "PUT" equals http-method)
110 (clojure-http.resourcefully/put full-URL header-hash xml-content)