├── deps.edn ├── .gitignore ├── .github └── workflows │ ├── snapshot.yml │ ├── doc-build.yml │ ├── release.yml │ └── test.yml ├── CONTRIBUTING.md ├── script └── test ├── pom.xml ├── project.clj ├── README.md ├── src ├── main │ ├── clojure │ │ └── clojure │ │ │ └── data │ │ │ ├── zip │ │ │ └── xml.clj │ │ │ └── zip.clj │ └── clojurescript │ │ └── clojure │ │ └── data │ │ ├── zip │ │ └── xml.cljs │ │ └── zip.cljs └── test │ ├── clojure │ └── clojure │ │ └── data │ │ └── zip │ │ └── xml_test.clj │ └── clojurescript │ └── clojure │ └── data │ └── zip │ └── xml_test.cljs ├── LICENSE └── epl.html /deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src/main/clojure"]} 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | resources 3 | .idea/ 4 | *.iml 5 | .cpcache/ 6 | -------------------------------------------------------------------------------- /.github/workflows/snapshot.yml: -------------------------------------------------------------------------------- 1 | name: Snapshot on demand 2 | 3 | on: [workflow_dispatch] 4 | 5 | jobs: 6 | call-snapshot: 7 | uses: clojure/build.ci/.github/workflows/snapshot.yml@master 8 | secrets: inherit 9 | -------------------------------------------------------------------------------- /.github/workflows/doc-build.yml: -------------------------------------------------------------------------------- 1 | name: Build API Docs 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | call-doc-build-workflow: 8 | uses: clojure/build.ci/.github/workflows/doc-build.yml@master 9 | with: 10 | project: clojure/data.zip 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | This is a [Clojure contrib] project. 2 | 3 | Under the Clojure contrib [guidelines], this project cannot accept 4 | pull requests. All patches must be submitted via [JIRA]. 5 | 6 | See [Contributing] on the Clojure website for 7 | more information on how to contribute. 8 | 9 | [Clojure contrib]: https://clojure.org/community/contrib_libs 10 | [Contributing]: https://clojure.org/community/contributing 11 | [JIRA]: https://clojure.atlassian.net/browse/DZIP 12 | [guidelines]: https://clojure.org/community/contrib_howto 13 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release on demand 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | releaseVersion: 7 | description: "Version to release" 8 | required: true 9 | snapshotVersion: 10 | description: "Snapshot version after release" 11 | required: true 12 | 13 | jobs: 14 | call-release: 15 | uses: clojure/build.ci/.github/workflows/release.yml@master 16 | with: 17 | releaseVersion: ${{ github.event.inputs.releaseVersion }} 18 | snapshotVersion: ${{ github.event.inputs.snapshotVersion }} 19 | secrets: inherit -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push] 4 | 5 | jobs: 6 | test: 7 | strategy: 8 | matrix: 9 | os: [ubuntu-latest] # macOS-latest, windows-latest] 10 | java-version: ["8", "11", "17"] 11 | clojure-version: ["1.10.3", "1.11.1"] 12 | runs-on: ${{ matrix.os }} 13 | steps: 14 | - uses: actions/checkout@v3 15 | - name: Set up Java 16 | uses: actions/setup-java@v3 17 | with: 18 | java-version: ${{ matrix.java-version }} 19 | distribution: 'temurin' 20 | cache: 'maven' 21 | - name: Build with Maven 22 | run: mvn -ntp -B -Dclojure.version=${{ matrix.clojure-version }} clean test 23 | -------------------------------------------------------------------------------- /script/test: -------------------------------------------------------------------------------- 1 | rm -rf resources 2 | mkdir -p resources 3 | 4 | lein cljsbuild once adv 5 | 6 | if [ "$V8_HOME" == "" ]; then 7 | echo "V8_HOME not set, skipping V8 tests" 8 | else 9 | echo "Testing with V8" 10 | ${V8_HOME}/d8 resources/tests.js 11 | fi 12 | 13 | if [ "$SPIDERMONKEY_HOME" == "" ]; then 14 | echo "SPIDERMONKEY_HOME not set, skipping SpiderMonkey tests" 15 | else 16 | echo "Testing with SpiderMonkey" 17 | ${SPIDERMONKEY_HOME}/js resources/tests.js 18 | fi 19 | 20 | if [ "$JSC_HOME" == "" ]; then 21 | echo "JSC_HOME not set, skipping JavaScriptCore tests" 22 | else 23 | echo "Testing with JavaScriptCore" 24 | ${JSC_HOME}/jsc resources/tests.js 25 | fi 26 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | data.zip 4 | 1.1.1-SNAPSHOT 5 | data.zip 6 | Utilities for clojure.zip. 7 | 8 | 9 | org.clojure 10 | pom.contrib 11 | 1.3.0 12 | 13 | 14 | 15 | 16 | Chris Houser 17 | 18 | 19 | 20 | 21 | scm:git:git@github.com:clojure/data.zip.git 22 | scm:git:git@github.com:clojure/data.zip.git 23 | git@github.com:clojure/data.zip.git 24 | HEAD 25 | 26 | 27 | 28 | 29 | 30 | src/main/clojurescript 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject org.clojure/data.zip "1.1.0-SNAPSHOT" 2 | :description "System for filtering trees, and XML trees in particular" 3 | :parent [org.clojure/pom.contrib "1.2.0"] 4 | 5 | :source-paths ["src/main/clojure" "src/main/clojurescript"] 6 | :test-paths ["src/test/clojure" "src/test/clojurescript"] 7 | 8 | :dependencies [[org.clojure/clojure "1.9.0"] 9 | [org.clojure/clojurescript "0.0-3211"]] 10 | 11 | :plugins [[lein-cljsbuild "1.0.6"]] 12 | 13 | :clean-targets ^{:protect false} ["resources/tests.js" "resources/out"] 14 | 15 | :cljsbuild 16 | {:builds 17 | [{:id "dev" 18 | :source-paths ["src/main/clojurescript" "src/test/clojurescript"] 19 | :compiler {:optimizations :none 20 | :output-to "resources/tests.js" 21 | :output-dir "resources/out-dev" 22 | :source-map true 23 | :verbose true 24 | :compiler-stats true}} 25 | {:id "simp" 26 | :source-paths ["src/main/clojurescript" "src/test/clojurescript"] 27 | :compiler {:optimizations :simple 28 | :static-fns true 29 | :output-to "resources/tests.js" 30 | :output-dir "resources/out-simp" 31 | :verbose true 32 | :compiler-stats true}} 33 | {:id "adv" 34 | :source-paths ["src/main/clojurescript" "src/test/clojurescript"] 35 | :compiler {:optimizations :advanced 36 | :output-to "resources/tests.js" 37 | :output-dir "resources/out-adv" 38 | :verbose true 39 | :compiler-stats true}}]}) 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | clojure.data.zip 2 | ======================================== 3 | 4 | System for filtering trees, and XML trees in particular. 5 | 6 | Formerly known as clojure.contrib.zip-filter. 7 | 8 | Releases and Dependency Information 9 | ======================================== 10 | 11 | This project follows the version scheme MAJOR.MINOR.PATCH where each component provides some relative indication of the size of the change, but does not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). 12 | 13 | Latest stable release: 1.1.0 14 | 15 | * [All Released Versions](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22data.zip%22) 16 | * [Development Snapshot Versions](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~data.zip~~~) 17 | 18 | deps.edn dependency information: 19 | ```clojure 20 | org.clojure/data.zip {:mvn/version "1.1.0"} 21 | ``` 22 | 23 | [Leiningen](https://github.com/technomancy/leiningen) dependency information: 24 | ```clojure 25 | [org.clojure/data.zip "1.1.0"] 26 | ``` 27 | [Maven](https://maven.apache.org/) dependency information: 28 | ```xml 29 | 30 | org.clojure 31 | data.zip 32 | 1.1.0 33 | 34 | ``` 35 | 36 | Example Usage 37 | ======================================== 38 | 39 | For more detail see the [generated documentation on github](https://clojure.github.io/data.zip/). 40 | 41 | Developer Information 42 | ======================================== 43 | 44 | * [GitHub project](https://github.com/clojure/data.zip) 45 | * [Bug Tracker](https://clojure.atlassian.net/browse/DZIP) 46 | * [Continuous Integration](https://github.com/clojure/data.zip/actions/workflows/test.yml) 47 | 48 | Change Log 49 | ==================== 50 | 51 | * Release 1.1.0 on 2024-02-19 52 | * Update parent pom 53 | * Release 1.0.0 on 2020-02-18 54 | * [DZIP-9](https://clojure.atlassian.net/browse/DZIP-9) - Fix invalid and inappropriate private metadata 55 | * Release 0.1.3 on 2019-03-07 56 | * [DZIP-8](https://clojure.atlassian.net/browse/DZIP-8) - Use unicode char for non-breaking space in regex pattern 57 | * Release 0.1.2 on 2016-04-28 58 | * [DZIP-3](https://clojure.atlassian.net/browse/DZIP-3) - Not returning expected result for tag= 59 | * [DZIP-5](https://clojure.atlassian.net/browse/DZIP-5) - Add ClojureScript support 60 | * Release 0.1.1 on 2012-03-30 61 | * Release 0.1.0 on 2011-08-24 62 | 63 | Copyright and License 64 | ======================================== 65 | 66 | Copyright (c) Aaron Bedra and Rich Hickey. All rights reserved. The use and 67 | distribution terms for this software are covered by the Eclipse Public 68 | License 1.0 (https://opensource.org/license/epl-1-0/) which can 69 | be found in the file epl-v10.html at the root of this distribution. 70 | By using this software in any fashion, you are agreeing to be bound by 71 | the terms of this license. You must not remove this notice, or any 72 | other, from this software. 73 | -------------------------------------------------------------------------------- /src/main/clojure/clojure/data/zip/xml.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Chris Houser, April 2008. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; Specialization of zip-filter for xml trees. 9 | 10 | (ns clojure.data.zip.xml 11 | (:require [clojure.string :as string] 12 | [clojure.data.zip :as zf] 13 | [clojure.zip :as zip])) 14 | 15 | (declare xml->) 16 | 17 | (defn attr 18 | "Returns the xml attribute named attrname, of the xml node at location loc." 19 | ([attrname] (fn [loc] (attr loc attrname))) 20 | ([loc attrname] (when (zip/branch? loc) (-> loc zip/node :attrs attrname)))) 21 | 22 | (defn attr= 23 | "Returns a query predicate that matches a node when it has an 24 | attribute named attrname whose value is attrval." 25 | [attrname attrval] (fn [loc] (= attrval (attr loc attrname)))) 26 | 27 | (defn tag= 28 | "Returns a query predicate that matches a node when its is a tag 29 | named tagname." 30 | [tagname] 31 | (fn [loc] 32 | (or (= tagname (:tag (zip/node loc))) 33 | (filter #(and (zip/branch? %) (= tagname (:tag (zip/node %)))) 34 | (zf/children-auto loc))))) 35 | 36 | (defn text 37 | "Returns the textual contents of the given location, similar to 38 | xpaths's value-of" 39 | [loc] 40 | (string/replace (apply str (xml-> loc zf/descendants zip/node string?)) 41 | (re-pattern (str "[\\s\u00A0]+")) 42 | " ")) 43 | 44 | (defn text= 45 | "Returns a query predicate that matches a node when its textual 46 | content equals s." 47 | [s] (fn [loc] (= (text loc) s))) 48 | 49 | (defn seq-test 50 | "Returns a query predicate that matches a node when its xml content 51 | 52 | matches the query expresions given." 53 | ^{:private true} 54 | [preds] (fn [loc] (and (seq (apply xml-> loc preds)) (list loc)))) 55 | 56 | (defn xml-> 57 | "The loc is passed to the first predicate. If the predicate returns 58 | a collection, each value of the collection is passed to the next 59 | predicate. If it returns a location, the location is passed to the 60 | next predicate. If it returns true, the input location is passed to 61 | the next predicate. If it returns false or nil, the next predicate 62 | is not called. 63 | 64 | This process is repeated, passing the processed results of each 65 | predicate to the next predicate. xml-> returns the final sequence. 66 | The entire chain is evaluated lazily. 67 | 68 | There are also special predicates: keywords are converted to tag=, 69 | strings to text=, and vectors to sub-queries that return true if 70 | they match. 71 | 72 | See xml_test.clj for examples." 73 | [loc & preds] 74 | (zf/mapcat-chain loc preds 75 | #(cond (keyword? %) (tag= %) 76 | (string? %) (text= %) 77 | (vector? %) (seq-test %)))) 78 | 79 | (defn xml1-> 80 | "Returns the first item from loc based on the query predicates 81 | given. See xml->" 82 | [loc & preds] (first (apply xml-> loc preds))) 83 | -------------------------------------------------------------------------------- /src/main/clojurescript/clojure/data/zip/xml.cljs: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Chris Houser, April 2008. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; Specialization of zip-filter for xml trees. 9 | 10 | (ns clojure.data.zip.xml 11 | (:require [clojure.string :as string] 12 | [clojure.data.zip :as zf] 13 | [clojure.zip :as zip])) 14 | 15 | (declare xml->) 16 | 17 | (defn attr 18 | "Returns the xml attribute named attrname, of the xml node at location loc." 19 | ([attrname] (fn [loc] (attr loc attrname))) 20 | ([loc attrname] (when (zip/branch? loc) (-> loc zip/node :attrs attrname)))) 21 | 22 | (defn attr= 23 | "Returns a query predicate that matches a node when it has an 24 | attribute named attrname whose value is attrval." 25 | [attrname attrval] (fn [loc] (= attrval (attr loc attrname)))) 26 | 27 | (defn tag= 28 | "Returns a query predicate that matches a node when its is a tag 29 | named tagname." 30 | [tagname] 31 | (fn [loc] 32 | (or (= tagname (:tag (zip/node loc))) 33 | (filter #(and (zip/branch? %) (= tagname (:tag (zip/node %)))) 34 | (zf/children-auto loc))))) 35 | 36 | (defn text 37 | "Returns the textual contents of the given location, similar to 38 | xpaths's value-of" 39 | [loc] 40 | (string/replace (apply str (xml-> loc zf/descendants zip/node string?)) 41 | (re-pattern (str "[\\s\u00A0]+")) 42 | " ")) 43 | 44 | (defn text= 45 | "Returns a query predicate that matches a node when its textual 46 | content equals s." 47 | [s] (fn [loc] (= (text loc) s))) 48 | 49 | (defn seq-test 50 | "Returns a query predicate that matches a node when its xml content 51 | matches the query expresions given." 52 | ^{:private true} 53 | [preds] (fn [loc] (and (seq (apply xml-> loc preds)) (list loc)))) 54 | 55 | (defn xml-> 56 | "The loc is passed to the first predicate. If the predicate returns 57 | a collection, each value of the collection is passed to the next 58 | predicate. If it returns a location, the location is passed to the 59 | next predicate. If it returns true, the input location is passed to 60 | the next predicate. If it returns false or nil, the next predicate 61 | is not called. 62 | 63 | This process is repeated, passing the processed results of each 64 | predicate to the next predicate. xml-> returns the final sequence. 65 | The entire chain is evaluated lazily. 66 | 67 | There are also special predicates: keywords are converted to tag=, 68 | strings to text=, and vectors to sub-queries that return true if 69 | they match. 70 | 71 | See the footer of zip-query.clj for examples." 72 | [loc & preds] 73 | (zf/mapcat-chain loc preds 74 | #(cond (keyword? %) (tag= %) 75 | (string? %) (text= %) 76 | (vector? %) (seq-test %)))) 77 | 78 | (defn xml1-> 79 | "Returns the first item from loc based on the query predicates 80 | given. See xml->" 81 | [loc & preds] (first (apply xml-> loc preds))) 82 | -------------------------------------------------------------------------------- /src/test/clojure/clojure/data/zip/xml_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.data.zip.xml-test 2 | (:use [clojure.test] 3 | [clojure.data.zip.xml]) 4 | (:require [clojure.xml :as xml] 5 | [clojure.zip :as zip])) 6 | 7 | 8 | (defn parse-str [s] 9 | (zip/xml-zip (xml/parse (new org.xml.sax.InputSource 10 | (new java.io.StringReader s))))) 11 | 12 | (def atom1 (parse-str " 13 | 14 | tag:blogger.com,1999:blog-28403206 15 | 2008-02-14T08:00:58.567-08:00 16 | n01senet 17 | 18 | 19 | 1 20 | 2008-02-13 21 | clojure is the best lisp yet 22 | Chouser 23 | 24 | 25 | 2 26 | 2008-02-07 27 | experimenting with vnc 28 | agriffis 29 | 30 | 31 | ")) 32 | 33 | (deftest test-simple-single-function filter 34 | (is (= (xml-> atom1 #(:tag (zip/node %))) 35 | '(:feed)))) 36 | 37 | (deftest test-two-stage-filter 38 | (testing "using helpful query prediates" 39 | (is (= (xml-> atom1 (tag= :title) text) 40 | '("n01senet")))) 41 | (testing "keyword shortcut" 42 | (is (= (xml-> atom1 :title text) 43 | '("n01senet"))))) 44 | 45 | (deftest test-multi-stage-filter 46 | (testing "basic functionality" 47 | (is (= (xml-> atom1 :entry :author :name text) 48 | '("Chouser" "agriffis")))) 49 | (testing "subquery specified using a vector" 50 | (is (= (xml-> atom1 :entry [:author :name (text= "agriffis")] 51 | :id text) 52 | '("2")))) 53 | (testing "with string shortcut" 54 | (is (= (xml-> atom1 :entry [:author :name "agriffis"] :id text) 55 | '("2"))))) 56 | 57 | (deftest test-xml1-> 58 | (is (= (xml1-> atom1 :entry :author :name text) 59 | "Chouser"))) 60 | 61 | (deftest test-attribute-access 62 | (is (= (xml-> atom1 :title (attr :type)) 63 | '("text")))) 64 | 65 | (deftest test-attribute-filtering 66 | (is (= (xml-> atom1 :link [(attr= :rel "alternate")] (attr :type)) 67 | '("text/html")))) 68 | 69 | ;; This was in the original code under a comment, but is fails 70 | #_(deftest test-ancestors 71 | (testing "basic function" 72 | (is (= (xml-> atom1 descendants :id "2" ancestors zip/node #(:tag %)) 73 | '(:id :entry :feed)))) 74 | (testing "with non-auto tag= (:entry), followed by auto tag= (:id)" 75 | (is (= (xml-> atom1 descendants :name "Chouser" ancestors 76 | :entry :id text) 77 | '("1"))))) 78 | 79 | (defrecord Node [tag attrs content]) 80 | 81 | (def record 82 | (zip/xml-zip 83 | (Node. :root {} 84 | [(Node. :entry {} [(Node. :id {} ["1"]) 85 | (Node. :author {:type "text"} ["John"])]) 86 | (Node. :entry {} [(Node. :id {} ["2"]) 87 | (Node. :author {:type "text"} ["Jane"])])]))) 88 | 89 | (deftest test-records 90 | (is (= (xml-> record :entry :author text) 91 | '("John" "Jane")))) 92 | 93 | (def atom2 (parse-str " 94 | bar")) 95 | 96 | (deftest dzip-3-first-node 97 | (is (not= (xml-> atom2 :feed ) '()))) 98 | 99 | (deftest dzip-3-second-node 100 | (is (= (xml-> atom2 :foo text) '("bar")))) 101 | -------------------------------------------------------------------------------- /src/main/clojure/clojure/data/zip.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Chris Houser, April 2008. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; System for filtering trees and nodes generated by zip.clj in 9 | ; general, and xml trees in particular. 10 | 11 | (ns ^{:author "Chris Houser", 12 | :doc "System for filtering trees and nodes generated by zip.clj in 13 | general, and xml trees in particular."} 14 | clojure.data.zip 15 | (:refer-clojure :exclude (descendants ancestors)) 16 | (:require [clojure.zip :as zip])) 17 | 18 | ; This uses the negative form (no-auto) so that the result from any 19 | ; naive function, including user functions, defaults to "auto". 20 | (defn auto 21 | [v x] (with-meta x ((if v dissoc assoc) (meta x) :zip-filter/no-auto? true))) 22 | 23 | (defn auto? 24 | [x] (not (:zip-filter/no-auto? (meta x)))) 25 | 26 | (defn right-locs 27 | "Returns a lazy sequence of locations to the right of loc, starting with loc." 28 | [loc] (lazy-seq (when loc (cons (auto false loc) (right-locs (zip/right loc)))))) 29 | 30 | (defn left-locs 31 | "Returns a lazy sequence of locations to the left of loc, starting with loc." 32 | [loc] (lazy-seq (when loc (cons (auto false loc) (left-locs (zip/left loc)))))) 33 | 34 | (defn leftmost? 35 | "Returns true if there are no more nodes to the left of location loc." 36 | [loc] (nil? (zip/left loc))) 37 | 38 | (defn rightmost? 39 | "Returns true if there are no more nodes to the right of location loc." 40 | [loc] (nil? (zip/right loc))) 41 | 42 | (defn children 43 | "Returns a lazy sequence of all immediate children of location loc, 44 | left-to-right." 45 | [loc] 46 | (when (zip/branch? loc) 47 | (map #(auto false %) (right-locs (zip/down loc))))) 48 | 49 | (defn children-auto 50 | "Returns a lazy sequence of all immediate children of location loc, 51 | left-to-right, marked so that a following tag= predicate will auto-descend." 52 | [loc] 53 | (when (zip/branch? loc) 54 | (map #(auto true %) (right-locs (zip/down loc))))) 55 | 56 | (defn descendants 57 | "Returns a lazy sequence of all descendants of location loc, in 58 | depth-first order, left-to-right, starting with loc." 59 | [loc] (lazy-seq (cons (auto false loc) (mapcat descendants (children loc))))) 60 | 61 | (defn ancestors 62 | "Returns a lazy sequence of all ancestors of location loc, starting 63 | with loc and proceeding to loc's parent node and on through to the 64 | root of the tree." 65 | [loc] (lazy-seq (when loc (cons (auto false loc) (ancestors (zip/up loc)))))) 66 | 67 | (defn- fixup-apply 68 | "Calls (pred loc), and then converts the result to the 'appropriate' 69 | sequence." 70 | [pred loc] 71 | (let [rtn (pred loc)] 72 | (cond (and (map? (meta rtn)) (:zip-filter/is-node? (meta rtn))) (list rtn) 73 | (= rtn true) (list loc) 74 | (= rtn false) nil 75 | (nil? rtn) nil 76 | (sequential? rtn) rtn 77 | :else (list rtn)))) 78 | 79 | (defn mapcat-chain 80 | [loc preds mkpred] 81 | (reduce (fn [prevseq expr] 82 | (mapcat #(fixup-apply (or (mkpred expr) expr) %) prevseq)) 83 | (list (with-meta loc (assoc (meta loc) :zip-filter/is-node? true))) 84 | preds)) 85 | -------------------------------------------------------------------------------- /src/main/clojurescript/clojure/data/zip.cljs: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Chris Houser, April 2008. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; System for filtering trees and nodes generated by zip.clj in 9 | ; general, and xml trees in particular. 10 | 11 | (ns ^{:author "Chris Houser", 12 | :doc "System for filtering trees and nodes generated by zip.clj in 13 | general, and xml trees in particular."} 14 | clojure.data.zip 15 | (:refer-clojure :exclude (descendants ancestors)) 16 | (:require [clojure.zip :as zip])) 17 | 18 | ; This uses the negative form (no-auto) so that the result from any 19 | ; naive function, including user functions, defaults to "auto". 20 | (defn auto 21 | [v x] (with-meta x ((if v dissoc assoc) (meta x) :zip-filter/no-auto? true))) 22 | 23 | (defn auto? 24 | [x] (not (:zip-filter/no-auto? (meta x)))) 25 | 26 | (defn right-locs 27 | "Returns a lazy sequence of locations to the right of loc, starting with loc." 28 | [loc] (lazy-seq (when loc (cons (auto false loc) (right-locs (zip/right loc)))))) 29 | 30 | (defn left-locs 31 | "Returns a lazy sequence of locations to the left of loc, starting with loc." 32 | [loc] (lazy-seq (when loc (cons (auto false loc) (left-locs (zip/left loc)))))) 33 | 34 | (defn leftmost? 35 | "Returns true if there are no more nodes to the left of location loc." 36 | [loc] (nil? (zip/left loc))) 37 | 38 | (defn rightmost? 39 | "Returns true if there are no more nodes to the right of location loc." 40 | [loc] (nil? (zip/right loc))) 41 | 42 | (defn children 43 | "Returns a lazy sequence of all immediate children of location loc, 44 | left-to-right." 45 | [loc] 46 | (when (zip/branch? loc) 47 | (map #(auto false %) (right-locs (zip/down loc))))) 48 | 49 | (defn children-auto 50 | "Returns a lazy sequence of all immediate children of location loc, 51 | left-to-right, marked so that a following tag= predicate will auto-descend." 52 | [loc] 53 | (when (zip/branch? loc) 54 | (map #(auto true %) (right-locs (zip/down loc))))) 55 | 56 | (defn descendants 57 | "Returns a lazy sequence of all descendants of location loc, in 58 | depth-first order, left-to-right, starting with loc." 59 | [loc] (lazy-seq (cons (auto false loc) (mapcat descendants (children loc))))) 60 | 61 | (defn ancestors 62 | "Returns a lazy sequence of all ancestors of location loc, starting 63 | with loc and proceeding to loc's parent node and on through to the 64 | root of the tree." 65 | [loc] (lazy-seq (when loc (cons (auto false loc) (ancestors (zip/up loc)))))) 66 | 67 | (defn- fixup-apply 68 | "Calls (pred loc), and then converts the result to the 'appropriate' 69 | sequence." 70 | [pred loc] 71 | (let [rtn (pred loc)] 72 | (cond (and (map? (meta rtn)) (:zip-filter/is-node? (meta rtn))) (list rtn) 73 | (= rtn true) (list loc) 74 | (= rtn false) nil 75 | (nil? rtn) nil 76 | (sequential? rtn) rtn 77 | :else (list rtn)))) 78 | 79 | (defn mapcat-chain 80 | [loc preds mkpred] 81 | (reduce (fn [prevseq expr] 82 | (mapcat #(fixup-apply (or (mkpred expr) expr) %) prevseq)) 83 | (list (with-meta loc (assoc (meta loc) :zip-filter/is-node? true))) 84 | preds)) 85 | -------------------------------------------------------------------------------- /src/test/clojurescript/clojure/data/zip/xml_test.cljs: -------------------------------------------------------------------------------- 1 | (ns clojure.data.zip.xml-test 2 | (:require [clojure.zip :as zip] 3 | [clojure.data.zip.xml :refer [xml-> xml1-> attr attr= text text= tag=]] 4 | [cljs.test :refer-macros [deftest is testing run-tests]])) 5 | 6 | 7 | (def atom1 8 | (zip/xml-zip {:tag :feed 9 | :attrs {:xmlns "http://www.w3.org/2005/Atom"} 10 | :content [{:tag :id 11 | :attrs {} 12 | :content ["tag:blogger.com1999:blog-28403206"]} 13 | {:tag :updated 14 | :attrs {} 15 | :content ["2008-02-14T08:00:58.567-08:00"]} 16 | {:tag :title 17 | :attrs {:type "text"} 18 | :content ["n01senet"]} 19 | {:tag :link 20 | :attrs {:rel "alternate" 21 | :type "text/html" 22 | :href "http://n01senet.blogspot.com/"} 23 | :content []} 24 | {:tag :entry 25 | :attrs {} 26 | :content [{:tag :id 27 | :attrs {} 28 | :content ["1"]} 29 | {:tag :published 30 | :attrs {} 31 | :content ["2008-02-13"]} 32 | {:tag :title 33 | :attrs {:type text} 34 | :content ["clojure is the best lisp yet"]} 35 | {:tag :author 36 | :attrs {} 37 | :content [{:tag :name 38 | :attrs {} 39 | :content ["Chouser"]}]}]} 40 | {:tag :entry 41 | :attrs {} 42 | :content [{:tag :id 43 | :attrs {} 44 | :content ["2"]} 45 | {:tag :published 46 | :attrs {} 47 | :content ["2008-02-07"]} 48 | {:tag :title 49 | :attrs {:type "text"} 50 | :content ["experimenting with vnc"]} 51 | {:tag :author 52 | :attrs {} 53 | :content [{:tag :name 54 | :attrs {} 55 | :content ["agriffis"]}]}]}]})) 56 | 57 | (deftest test-simple-single-function filter 58 | (is (= (xml-> atom1 #(:tag (zip/node %))) 59 | '(:feed)))) 60 | 61 | (deftest test-two-stage-filter 62 | (testing "using helpful query prediates" 63 | (is (= (xml-> atom1 (tag= :title) text) 64 | '("n01senet")))) 65 | (testing "keyword shortcut" 66 | (is (= (xml-> atom1 :title text) 67 | '("n01senet"))))) 68 | 69 | (deftest test-multi-stage-filter 70 | (testing "basic functionality" 71 | (is (= (xml-> atom1 :entry :author :name text) 72 | '("Chouser" "agriffis")))) 73 | (testing "subquery specified using a vector" 74 | (is (= (xml-> atom1 :entry [:author :name (text= "agriffis")] 75 | :id text) 76 | '("2")))) 77 | (testing "with string shortcut" 78 | (is (= (xml-> atom1 :entry [:author :name "agriffis"] :id text) 79 | '("2"))))) 80 | 81 | (deftest test-xml1-> 82 | (is (= (xml1-> atom1 :entry :author :name text) 83 | "Chouser"))) 84 | 85 | (deftest test-attribute-access 86 | (is (= (xml-> atom1 :title (attr :type)) 87 | '("text")))) 88 | 89 | (deftest test-attribute-filtering 90 | (is (= (xml-> atom1 :link [(attr= :rel "alternate")] (attr :type)) 91 | '("text/html")))) 92 | 93 | ;; This was in the original code under a comment, but is fails 94 | #_(deftest test-ancestors 95 | (testing "basic function" 96 | (is (= (xml-> atom1 descendants :id "2" ancestors zip/node #(:tag %)) 97 | '(:id :entry :feed)))) 98 | (testing "with non-auto tag= (:entry), followed by auto tag= (:id)" 99 | (is (= (xml-> atom1 descendants :name "Chouser" ancestors 100 | :entry :id text) 101 | '("1"))))) 102 | 103 | (defrecord Node [tag attrs content]) 104 | 105 | (def record 106 | (zip/xml-zip 107 | (Node. :root {} 108 | [(Node. :entry {} [(Node. :id {} ["1"]) 109 | (Node. :author {:type "text"} ["John"])]) 110 | (Node. :entry {} [(Node. :id {} ["2"]) 111 | (Node. :author {:type "text"} ["Jane"])])]))) 112 | 113 | (deftest test-records 114 | (is (= (xml-> record :entry :author text) 115 | '("John" "Jane")))) 116 | 117 | (def atom2 118 | (zip/xml-zip 119 | {:tag :feed 120 | :content [{:tag :foo 121 | :content "bar"}]})) 122 | 123 | (deftest dzip-3-first-node 124 | (is (not= (xml-> atom2 :feed) '()))) 125 | 126 | (deftest dzip-3-second-node 127 | (is (= (xml-> atom2 :foo text) '("bar")))) 128 | 129 | (defn js-print [& args] 130 | (if (exists? js/console) 131 | (.log js/console (apply str args)) 132 | (js/print (apply str args)))) 133 | 134 | (set! *print-fn* js-print) 135 | 136 | (run-tests) 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 1.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 4 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 5 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial code and documentation 12 | distributed under this Agreement, and 13 | b) in the case of each subsequent Contributor: 14 | i) changes to the Program, and 15 | ii) additions to the Program; 16 | 17 | where such changes and/or additions to the Program originate from and are 18 | distributed by that particular Contributor. A Contribution 'originates' 19 | from a Contributor if it was added to the Program by such Contributor 20 | itself or anyone acting on such Contributor's behalf. Contributions do not 21 | include additions to the Program which: (i) are separate modules of 22 | software distributed in conjunction with the Program under their own 23 | license agreement, and (ii) are not derivative works of the Program. 24 | 25 | "Contributor" means any person or entity that distributes the Program. 26 | 27 | "Licensed Patents" mean patent claims licensable by a Contributor which are 28 | necessarily infringed by the use or sale of its Contribution alone or when 29 | combined with the Program. 30 | 31 | "Program" means the Contributions distributed in accordance with this 32 | Agreement. 33 | 34 | "Recipient" means anyone who receives the Program under this Agreement, 35 | including all Contributors. 36 | 37 | 2. GRANT OF RIGHTS 38 | a) Subject to the terms of this Agreement, each Contributor hereby grants 39 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 40 | reproduce, prepare derivative works of, publicly display, publicly 41 | perform, distribute and sublicense the Contribution of such Contributor, 42 | if any, and such derivative works, in source code and object code form. 43 | b) Subject to the terms of this Agreement, each Contributor hereby grants 44 | Recipient a non-exclusive, worldwide, royalty-free patent license under 45 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 46 | transfer the Contribution of such Contributor, if any, in source code and 47 | object code form. This patent license shall apply to the combination of 48 | the Contribution and the Program if, at the time the Contribution is 49 | added by the Contributor, such addition of the Contribution causes such 50 | combination to be covered by the Licensed Patents. The patent license 51 | shall not apply to any other combinations which include the Contribution. 52 | No hardware per se is licensed hereunder. 53 | c) Recipient understands that although each Contributor grants the licenses 54 | to its Contributions set forth herein, no assurances are provided by any 55 | Contributor that the Program does not infringe the patent or other 56 | intellectual property rights of any other entity. Each Contributor 57 | disclaims any liability to Recipient for claims brought by any other 58 | entity based on infringement of intellectual property rights or 59 | otherwise. As a condition to exercising the rights and licenses granted 60 | hereunder, each Recipient hereby assumes sole responsibility to secure 61 | any other intellectual property rights needed, if any. For example, if a 62 | third party patent license is required to allow Recipient to distribute 63 | the Program, it is Recipient's responsibility to acquire that license 64 | before distributing the Program. 65 | d) Each Contributor represents that to its knowledge it has sufficient 66 | copyright rights in its Contribution, if any, to grant the copyright 67 | license set forth in this Agreement. 68 | 69 | 3. REQUIREMENTS 70 | 71 | A Contributor may choose to distribute the Program in object code form under 72 | its own license agreement, provided that: 73 | 74 | a) it complies with the terms and conditions of this Agreement; and 75 | b) its license agreement: 76 | i) effectively disclaims on behalf of all Contributors all warranties 77 | and conditions, express and implied, including warranties or 78 | conditions of title and non-infringement, and implied warranties or 79 | conditions of merchantability and fitness for a particular purpose; 80 | ii) effectively excludes on behalf of all Contributors all liability for 81 | damages, including direct, indirect, special, incidental and 82 | consequential damages, such as lost profits; 83 | iii) states that any provisions which differ from this Agreement are 84 | offered by that Contributor alone and not by any other party; and 85 | iv) states that source code for the Program is available from such 86 | Contributor, and informs licensees how to obtain it in a reasonable 87 | manner on or through a medium customarily used for software exchange. 88 | 89 | When the Program is made available in source code form: 90 | 91 | a) it must be made available under this Agreement; and 92 | b) a copy of this Agreement must be included with each copy of the Program. 93 | Contributors may not remove or alter any copyright notices contained 94 | within the Program. 95 | 96 | Each Contributor must identify itself as the originator of its Contribution, 97 | if 98 | any, in a manner that reasonably allows subsequent Recipients to identify the 99 | originator of the Contribution. 100 | 101 | 4. COMMERCIAL DISTRIBUTION 102 | 103 | Commercial distributors of software may accept certain responsibilities with 104 | respect to end users, business partners and the like. While this license is 105 | intended to facilitate the commercial use of the Program, the Contributor who 106 | includes the Program in a commercial product offering should do so in a manner 107 | which does not create potential liability for other Contributors. Therefore, 108 | if a Contributor includes the Program in a commercial product offering, such 109 | Contributor ("Commercial Contributor") hereby agrees to defend and indemnify 110 | every other Contributor ("Indemnified Contributor") against any losses, 111 | damages and costs (collectively "Losses") arising from claims, lawsuits and 112 | other legal actions brought by a third party against the Indemnified 113 | Contributor to the extent caused by the acts or omissions of such Commercial 114 | Contributor in connection with its distribution of the Program in a commercial 115 | product offering. The obligations in this section do not apply to any claims 116 | or Losses relating to any actual or alleged intellectual property 117 | infringement. In order to qualify, an Indemnified Contributor must: 118 | a) promptly notify the Commercial Contributor in writing of such claim, and 119 | b) allow the Commercial Contributor to control, and cooperate with the 120 | Commercial Contributor in, the defense and any related settlement 121 | negotiations. The Indemnified Contributor may participate in any such claim at 122 | its own expense. 123 | 124 | For example, a Contributor might include the Program in a commercial product 125 | offering, Product X. That Contributor is then a Commercial Contributor. If 126 | that Commercial Contributor then makes performance claims, or offers 127 | warranties related to Product X, those performance claims and warranties are 128 | such Commercial Contributor's responsibility alone. Under this section, the 129 | Commercial Contributor would have to defend claims against the other 130 | Contributors related to those performance claims and warranties, and if a 131 | court requires any other Contributor to pay any damages as a result, the 132 | Commercial Contributor must pay those damages. 133 | 134 | 5. NO WARRANTY 135 | 136 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN 137 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 138 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each 140 | Recipient is solely responsible for determining the appropriateness of using 141 | and distributing the Program and assumes all risks associated with its 142 | exercise of rights under this Agreement , including but not limited to the 143 | risks and costs of program errors, compliance with applicable laws, damage to 144 | or loss of data, programs or equipment, and unavailability or interruption of 145 | operations. 146 | 147 | 6. DISCLAIMER OF LIABILITY 148 | 149 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 150 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 151 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 152 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 153 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 154 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 155 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 156 | OF SUCH DAMAGES. 157 | 158 | 7. GENERAL 159 | 160 | If any provision of this Agreement is invalid or unenforceable under 161 | applicable law, it shall not affect the validity or enforceability of the 162 | remainder of the terms of this Agreement, and without further action by the 163 | parties hereto, such provision shall be reformed to the minimum extent 164 | necessary to make such provision valid and enforceable. 165 | 166 | If Recipient institutes patent litigation against any entity (including a 167 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 168 | (excluding combinations of the Program with other software or hardware) 169 | infringes such Recipient's patent(s), then such Recipient's rights granted 170 | under Section 2(b) shall terminate as of the date such litigation is filed. 171 | 172 | All Recipient's rights under this Agreement shall terminate if it fails to 173 | comply with any of the material terms or conditions of this Agreement and does 174 | not cure such failure in a reasonable period of time after becoming aware of 175 | such noncompliance. If all Recipient's rights under this Agreement terminate, 176 | Recipient agrees to cease use and distribution of the Program as soon as 177 | reasonably practicable. However, Recipient's obligations under this Agreement 178 | and any licenses granted by Recipient relating to the Program shall continue 179 | and survive. 180 | 181 | Everyone is permitted to copy and distribute copies of this Agreement, but in 182 | order to avoid inconsistency the Agreement is copyrighted and may only be 183 | modified in the following manner. The Agreement Steward reserves the right to 184 | publish new versions (including revisions) of this Agreement from time to 185 | time. No one other than the Agreement Steward has the right to modify this 186 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 187 | Eclipse Foundation may assign the responsibility to serve as the Agreement 188 | Steward to a suitable separate entity. Each new version of the Agreement will 189 | be given a distinguishing version number. The Program (including 190 | Contributions) may always be distributed subject to the version of the 191 | Agreement under which it was received. In addition, after a new version of the 192 | Agreement is published, Contributor may elect to distribute the Program 193 | (including its Contributions) under the new version. Except as expressly 194 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 195 | licenses to the intellectual property of any Contributor under this Agreement, 196 | whether expressly, by implication, estoppel or otherwise. All rights in the 197 | Program not expressly granted under this Agreement are reserved. 198 | 199 | This Agreement is governed by the laws of the State of New York and the 200 | intellectual property laws of the United States of America. No party to this 201 | Agreement will bring a legal action under this Agreement more than one year 202 | after the cause of action arose. Each party waives its rights to a jury trial in 203 | any resulting litigation. 204 | 205 | 206 | -------------------------------------------------------------------------------- /epl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Eclipse Public License - Version 1.0 8 | 25 | 26 | 27 | 28 | 29 | 30 |

Eclipse Public License - v 1.0

31 | 32 |

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 33 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR 34 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS 35 | AGREEMENT.

36 | 37 |

1. DEFINITIONS

38 | 39 |

"Contribution" means:

40 | 41 |

a) in the case of the initial Contributor, the initial 42 | code and documentation distributed under this Agreement, and

43 |

b) in the case of each subsequent Contributor:

44 |

i) changes to the Program, and

45 |

ii) additions to the Program;

46 |

where such changes and/or additions to the Program 47 | originate from and are distributed by that particular Contributor. A 48 | Contribution 'originates' from a Contributor if it was added to the 49 | Program by such Contributor itself or anyone acting on such 50 | Contributor's behalf. Contributions do not include additions to the 51 | Program which: (i) are separate modules of software distributed in 52 | conjunction with the Program under their own license agreement, and (ii) 53 | are not derivative works of the Program.

54 | 55 |

"Contributor" means any person or entity that distributes 56 | the Program.

57 | 58 |

"Licensed Patents" mean patent claims licensable by a 59 | Contributor which are necessarily infringed by the use or sale of its 60 | Contribution alone or when combined with the Program.

61 | 62 |

"Program" means the Contributions distributed in accordance 63 | with this Agreement.

64 | 65 |

"Recipient" means anyone who receives the Program under 66 | this Agreement, including all Contributors.

67 | 68 |

2. GRANT OF RIGHTS

69 | 70 |

a) Subject to the terms of this Agreement, each 71 | Contributor hereby grants Recipient a non-exclusive, worldwide, 72 | royalty-free copyright license to reproduce, prepare derivative works 73 | of, publicly display, publicly perform, distribute and sublicense the 74 | Contribution of such Contributor, if any, and such derivative works, in 75 | source code and object code form.

76 | 77 |

b) Subject to the terms of this Agreement, each 78 | Contributor hereby grants Recipient a non-exclusive, worldwide, 79 | royalty-free patent license under Licensed Patents to make, use, sell, 80 | offer to sell, import and otherwise transfer the Contribution of such 81 | Contributor, if any, in source code and object code form. This patent 82 | license shall apply to the combination of the Contribution and the 83 | Program if, at the time the Contribution is added by the Contributor, 84 | such addition of the Contribution causes such combination to be covered 85 | by the Licensed Patents. The patent license shall not apply to any other 86 | combinations which include the Contribution. No hardware per se is 87 | licensed hereunder.

88 | 89 |

c) Recipient understands that although each Contributor 90 | grants the licenses to its Contributions set forth herein, no assurances 91 | are provided by any Contributor that the Program does not infringe the 92 | patent or other intellectual property rights of any other entity. Each 93 | Contributor disclaims any liability to Recipient for claims brought by 94 | any other entity based on infringement of intellectual property rights 95 | or otherwise. As a condition to exercising the rights and licenses 96 | granted hereunder, each Recipient hereby assumes sole responsibility to 97 | secure any other intellectual property rights needed, if any. For 98 | example, if a third party patent license is required to allow Recipient 99 | to distribute the Program, it is Recipient's responsibility to acquire 100 | that license before distributing the Program.

101 | 102 |

d) Each Contributor represents that to its knowledge it 103 | has sufficient copyright rights in its Contribution, if any, to grant 104 | the copyright license set forth in this Agreement.

105 | 106 |

3. REQUIREMENTS

107 | 108 |

A Contributor may choose to distribute the Program in object code 109 | form under its own license agreement, provided that:

110 | 111 |

a) it complies with the terms and conditions of this 112 | Agreement; and

113 | 114 |

b) its license agreement:

115 | 116 |

i) effectively disclaims on behalf of all Contributors 117 | all warranties and conditions, express and implied, including warranties 118 | or conditions of title and non-infringement, and implied warranties or 119 | conditions of merchantability and fitness for a particular purpose;

120 | 121 |

ii) effectively excludes on behalf of all Contributors 122 | all liability for damages, including direct, indirect, special, 123 | incidental and consequential damages, such as lost profits;

124 | 125 |

iii) states that any provisions which differ from this 126 | Agreement are offered by that Contributor alone and not by any other 127 | party; and

128 | 129 |

iv) states that source code for the Program is available 130 | from such Contributor, and informs licensees how to obtain it in a 131 | reasonable manner on or through a medium customarily used for software 132 | exchange.

133 | 134 |

When the Program is made available in source code form:

135 | 136 |

a) it must be made available under this Agreement; and

137 | 138 |

b) a copy of this Agreement must be included with each 139 | copy of the Program.

140 | 141 |

Contributors may not remove or alter any copyright notices contained 142 | within the Program.

143 | 144 |

Each Contributor must identify itself as the originator of its 145 | Contribution, if any, in a manner that reasonably allows subsequent 146 | Recipients to identify the originator of the Contribution.

147 | 148 |

4. COMMERCIAL DISTRIBUTION

149 | 150 |

Commercial distributors of software may accept certain 151 | responsibilities with respect to end users, business partners and the 152 | like. While this license is intended to facilitate the commercial use of 153 | the Program, the Contributor who includes the Program in a commercial 154 | product offering should do so in a manner which does not create 155 | potential liability for other Contributors. Therefore, if a Contributor 156 | includes the Program in a commercial product offering, such Contributor 157 | ("Commercial Contributor") hereby agrees to defend and 158 | indemnify every other Contributor ("Indemnified Contributor") 159 | against any losses, damages and costs (collectively "Losses") 160 | arising from claims, lawsuits and other legal actions brought by a third 161 | party against the Indemnified Contributor to the extent caused by the 162 | acts or omissions of such Commercial Contributor in connection with its 163 | distribution of the Program in a commercial product offering. The 164 | obligations in this section do not apply to any claims or Losses 165 | relating to any actual or alleged intellectual property infringement. In 166 | order to qualify, an Indemnified Contributor must: a) promptly notify 167 | the Commercial Contributor in writing of such claim, and b) allow the 168 | Commercial Contributor to control, and cooperate with the Commercial 169 | Contributor in, the defense and any related settlement negotiations. The 170 | Indemnified Contributor may participate in any such claim at its own 171 | expense.

172 | 173 |

For example, a Contributor might include the Program in a commercial 174 | product offering, Product X. That Contributor is then a Commercial 175 | Contributor. If that Commercial Contributor then makes performance 176 | claims, or offers warranties related to Product X, those performance 177 | claims and warranties are such Commercial Contributor's responsibility 178 | alone. Under this section, the Commercial Contributor would have to 179 | defend claims against the other Contributors related to those 180 | performance claims and warranties, and if a court requires any other 181 | Contributor to pay any damages as a result, the Commercial Contributor 182 | must pay those damages.

183 | 184 |

5. NO WARRANTY

185 | 186 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS 187 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 188 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 189 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY 190 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely 191 | responsible for determining the appropriateness of using and 192 | distributing the Program and assumes all risks associated with its 193 | exercise of rights under this Agreement , including but not limited to 194 | the risks and costs of program errors, compliance with applicable laws, 195 | damage to or loss of data, programs or equipment, and unavailability or 196 | interruption of operations.

197 | 198 |

6. DISCLAIMER OF LIABILITY

199 | 200 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT 201 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 202 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 203 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 204 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 205 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 206 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 207 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

208 | 209 |

7. GENERAL

210 | 211 |

If any provision of this Agreement is invalid or unenforceable under 212 | applicable law, it shall not affect the validity or enforceability of 213 | the remainder of the terms of this Agreement, and without further action 214 | by the parties hereto, such provision shall be reformed to the minimum 215 | extent necessary to make such provision valid and enforceable.

216 | 217 |

If Recipient institutes patent litigation against any entity 218 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 219 | Program itself (excluding combinations of the Program with other 220 | software or hardware) infringes such Recipient's patent(s), then such 221 | Recipient's rights granted under Section 2(b) shall terminate as of the 222 | date such litigation is filed.

223 | 224 |

All Recipient's rights under this Agreement shall terminate if it 225 | fails to comply with any of the material terms or conditions of this 226 | Agreement and does not cure such failure in a reasonable period of time 227 | after becoming aware of such noncompliance. If all Recipient's rights 228 | under this Agreement terminate, Recipient agrees to cease use and 229 | distribution of the Program as soon as reasonably practicable. However, 230 | Recipient's obligations under this Agreement and any licenses granted by 231 | Recipient relating to the Program shall continue and survive.

232 | 233 |

Everyone is permitted to copy and distribute copies of this 234 | Agreement, but in order to avoid inconsistency the Agreement is 235 | copyrighted and may only be modified in the following manner. The 236 | Agreement Steward reserves the right to publish new versions (including 237 | revisions) of this Agreement from time to time. No one other than the 238 | Agreement Steward has the right to modify this Agreement. The Eclipse 239 | Foundation is the initial Agreement Steward. The Eclipse Foundation may 240 | assign the responsibility to serve as the Agreement Steward to a 241 | suitable separate entity. Each new version of the Agreement will be 242 | given a distinguishing version number. The Program (including 243 | Contributions) may always be distributed subject to the version of the 244 | Agreement under which it was received. In addition, after a new version 245 | of the Agreement is published, Contributor may elect to distribute the 246 | Program (including its Contributions) under the new version. Except as 247 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no 248 | rights or licenses to the intellectual property of any Contributor under 249 | this Agreement, whether expressly, by implication, estoppel or 250 | otherwise. All rights in the Program not expressly granted under this 251 | Agreement are reserved.

252 | 253 |

This Agreement is governed by the laws of the State of New York and 254 | the intellectual property laws of the United States of America. No party 255 | to this Agreement will bring a legal action under this Agreement more 256 | than one year after the cause of action arose. Each party waives its 257 | rights to a jury trial in any resulting litigation.

258 | 259 | 260 | 261 | 262 | --------------------------------------------------------------------------------