3 (:use clj-stacktrace.repl)
4 (:require clojure.contrib.string)
5 (:require clojure.contrib.http.agent)
6 (:require clojure-http.resourcefully)
7 (:require clojure.pprint))
10 " Replacing these characters http encoded ones
20 (clojure.contrib.string/replace-str " " "%20"
21 (clojure.contrib.string/replace-str "'" "%27"
22 (clojure.contrib.string/replace-str ";" "%3B"
23 (clojure.contrib.string/replace-str "[" "%5B"
24 (clojure.contrib.string/replace-str "@" "%40"
25 (clojure.contrib.string/replace-str "=" "%3D"
26 (clojure.contrib.string/replace-str "]" "%5D" text
30 (defn url-encode-spaces
31 " Replacing just spaces
35 (clojure.contrib.string/replace-str " " "%20" text )
38 (defn filterSpacesFromXML [text]
40 (clojure.contrib.string/replace-str "< " "<"
41 (clojure.contrib.string/replace-str " : " ":"
42 (clojure.contrib.string/replace-str " / >" " />"
43 (clojure.contrib.string/replace-str "< /" "</"
44 (clojure.contrib.string/replace-str "</ " "</"
45 (clojure.contrib.string/replace-str " / " "/"
46 (clojure.contrib.string/replace-re #"=\"\s" "=\""
47 (clojure.contrib.string/replace-re #"\s\"" "\""
48 (clojure.contrib.string/replace-str " = " "="
54 ;; set get base URL ...TODO - put in config
55 ;; TODO - replace URL with a config value
56 (def db-base-URL "http://localhost:8080/exist/rest/")
59 ;; set root/system dir fragment ...TODO - put in config
60 (def db-system-DIR "rootDir/system.main.system/")
62 ;; working directory lookup ...TODO - put these lookups into config
63 (defn working-dir-lookup [token]
65 ;;(println "DEBUG > 'working-dir-lookup' CALLED > ["(keyword token)"]" )
66 ( { :group "aauthentication.main.authentication/groups.aauth.groups"
67 :user "aauthentication.main.authentication/users.aauth.users"
68 :users "aauthentication.main.authentication/users.aauth.users"
69 :account "groups.main.groups"
70 :journal "groups.main.groups"
71 :entry "groups.main.groups"
72 :entries "groups.main.groups"
73 :debit "groups.main.groups"
74 :credit "groups.main.groups"
75 :bookkeeping "groups.main.groups"
81 (defn namespace-lookup
84 ;;(println "DEBUG > 'namespace-lookup' CALLED > ["token"]" )
85 ( { "group" "com/interrupt/bookkeeping/users"
86 "user" "com/interrupt/bookkeeping/users"
87 "users" "com/interrupt/bookkeeping/users"
88 "account" "com/interrupt/bookkeeping/account"
89 "journal" "com/interrupt/bookkeeping/journal"
90 "entry" "com/interrupt/bookkeeping/journal"
91 "entries" "com/interrupt/bookkeeping/journal"
92 "debit" "com/interrupt/bookkeeping/account"
93 "credit" "com/interrupt/bookkeeping/account"
99 (defn execute-http-call [ full-URL http-method header-hash xml-content ]
101 ;; from DB, get 'token' for 'option' args & value
102 (println "DEBUG > FINAL http query[" full-URL "] > http-method[" http-method "] > header-hash[" header-hash "] > xml-content[" xml-content "]")
105 (. "GET" equals http-method)
107 (clojure-http.resourcefully/get full-URL header-hash xml-content)
108 (catch Exception e { :msg "Error" :code 500 :dmsg (. e getMessage ) } )
111 (. "PUT" equals http-method)
113 (clojure-http.resourcefully/put full-URL header-hash xml-content)
114 (catch Exception e { :msg "Error" :code 500 :dmsg (. e getMessage ) } )