├── CrunchbaseWrapper ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.apache.ivyde.eclipse.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.ltk.core.refactoring.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ ├── org.eclipse.wst.validation.prefs │ └── org.eclipse.wst.ws.service.policy.prefs ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ └── lib │ │ │ ├── commons-codec-1.6.jar │ │ │ ├── commons-csv-1.0.jar │ │ │ ├── commons-lang3-3.3.2.jar │ │ │ ├── httpclient-4.2.6.jar │ │ │ ├── httpclient-cache-4.2.6.jar │ │ │ ├── httpcore-4.2.5.jar │ │ │ ├── jackson-annotations-2.3.0.jar │ │ │ ├── jackson-core-2.3.3.jar │ │ │ ├── jackson-databind-2.3.3.jar │ │ │ ├── jcl-over-slf4j-1.7.6.jar │ │ │ ├── jena-arq-2.13.0.jar │ │ │ ├── jena-core-2.13.0.jar │ │ │ ├── jena-iri-1.1.2.jar │ │ │ ├── jena-tdb-1.1.2.jar │ │ │ ├── jsonld-java-0.7.0.jar │ │ │ ├── libthrift-0.9.2.jar │ │ │ ├── log4j-1.2.17.jar │ │ │ ├── okhttp-2.5.0.jar │ │ │ ├── okio-1.6.0.jar │ │ │ ├── slf4j-api-1.7.6.jar │ │ │ ├── slf4j-log4j12-1.7.6.jar │ │ │ ├── xercesImpl-2.11.0.jar │ │ │ └── xml-apis-1.4.01.jar │ ├── context.jsonld │ ├── html │ │ ├── authentication.html │ │ ├── facebook.json │ │ ├── facebook.jsonld │ │ └── facebook.nt │ ├── index.html │ ├── ontology.owl │ ├── organization-mappings.nt │ ├── people-mappings.nt │ ├── vocab.rdf │ └── void.ttl ├── build │ └── classes │ │ ├── org │ │ └── json │ │ │ ├── CDL.class │ │ │ ├── Cookie.class │ │ │ ├── CookieList.class │ │ │ ├── HTTP.class │ │ │ ├── HTTPTokener.class │ │ │ ├── JSONArray.class │ │ │ ├── JSONException.class │ │ │ ├── JSONML.class │ │ │ ├── JSONObject$Null.class │ │ │ ├── JSONObject.class │ │ │ ├── JSONString.class │ │ │ ├── JSONStringer.class │ │ │ ├── JSONTokener.class │ │ │ ├── JSONWriter.class │ │ │ ├── Property.class │ │ │ ├── XML.class │ │ │ └── XMLTokener.class │ │ ├── servlets │ │ ├── Authenticate.class │ │ ├── CrunchbaseWrapper.class │ │ └── Listener.class │ │ └── utilities │ │ ├── Authentication.class │ │ ├── JSONHelper.class │ │ ├── JSONLDHelper.class │ │ ├── MappingUtility.class │ │ ├── SPARQLLoader.class │ │ └── URIEncoder.class └── src │ ├── org │ └── json │ │ ├── CDL.java │ │ ├── Cookie.java │ │ ├── CookieList.java │ │ ├── HTTP.java │ │ ├── HTTPTokener.java │ │ ├── JSONArray.java │ │ ├── JSONException.java │ │ ├── JSONML.java │ │ ├── JSONObject.java │ │ ├── JSONString.java │ │ ├── JSONStringer.java │ │ ├── JSONTokener.java │ │ ├── JSONWriter.java │ │ ├── Property.java │ │ ├── XML.java │ │ └── XMLTokener.java │ ├── servlets │ ├── Authenticate.java │ ├── CrunchbaseWrapper.java │ └── Listener.java │ └── utilities │ ├── Authentication.java │ ├── JSONHelper.java │ ├── JSONLDHelper.java │ ├── MappingUtility.java │ ├── SPARQLLoader.java │ └── URIEncoder.java ├── README.md └── crawling └── CsvReader.java /CrunchbaseWrapper/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CrunchbaseWrapper 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.wst.common.project.facet.core.nature 33 | org.eclipse.jdt.core.javanature 34 | org.eclipse.wst.jsdt.core.jsNature 35 | 36 | 37 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.apache.ivyde.eclipse.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.apache.ivyde.eclipse.standaloneretrieve= 3 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 3 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/.settings/org.eclipse.wst.ws.service.policy.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.wst.ws.service.policy.projectEnabled=false 3 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-codec-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-codec-1.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-csv-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-csv-1.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-lang3-3.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/commons-lang3-3.3.2.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/httpclient-4.2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/httpclient-4.2.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/httpclient-cache-4.2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/httpclient-cache-4.2.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/httpcore-4.2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/httpcore-4.2.5.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-annotations-2.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-annotations-2.3.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-core-2.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-core-2.3.3.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-databind-2.3.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jackson-databind-2.3.3.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jcl-over-slf4j-1.7.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jcl-over-slf4j-1.7.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-arq-2.13.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-arq-2.13.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-core-2.13.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-core-2.13.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-iri-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-iri-1.1.2.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-tdb-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jena-tdb-1.1.2.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/jsonld-java-0.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/jsonld-java-0.7.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/libthrift-0.9.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/libthrift-0.9.2.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/log4j-1.2.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/log4j-1.2.17.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/okhttp-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/okhttp-2.5.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/okio-1.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/okio-1.6.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/slf4j-api-1.7.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/slf4j-api-1.7.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/slf4j-log4j12-1.7.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/slf4j-log4j12-1.7.6.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/xercesImpl-2.11.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/xercesImpl-2.11.0.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/WEB-INF/lib/xml-apis-1.4.01.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/WebContent/WEB-INF/lib/xml-apis-1.4.01.jar -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/context.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": 3 | { 4 | "@vocab": "http://ontologycentral.com/2010/05/cb/vocab#", 5 | "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 6 | "owl": "http://www.w3.org/2002/07/owl#", 7 | "cbw": "http://localhost:8080/CrunchbaseWrapper/api-vocab#", 8 | "db": "http://dbpedia.org/resource/", 9 | "foaf": "http://xmlns.com/foaf/0.1/", 10 | "cc:": "http://creativecommons.org/ns#", 11 | "type": { 12 | "@type": "@vocab", 13 | "@id": "rdf:type" 14 | }, 15 | "owl:sameAs": {"@type": "@id"}, 16 | "homepage_url": {"@type": "@id"}, 17 | "url": {"@type": "@id"}, 18 | "api_path": {"@type": "@id"}, 19 | "facebook_url": {"@type": "@id"}, 20 | "linkedin_url": {"@type": "@id"}, 21 | "twitter_url": {"@type": "@id"}, 22 | "profile_image_url": {"@type": "@id"}, 23 | "cbw:next_page_url": {"@type": "@id"}, 24 | "cbw:key_set_url": {"@type": "@id"}, 25 | "cc:license": {"@type": "@id"} 26 | } 27 | } -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/html/authentication.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Authentication required! 6 | 7 | 8 |

Authentication required!

9 |

No or wrong API key given

10 |

This is a wrapper for CrunchBase and every request to this service is redirected to Crunchbase. 11 | As the CrunchBase API access is limited, you have to use an API key to use this service. If you have a key, please provide it in the user field and keep the password field empty.

12 | 13 | 14 |

If you are a researcher, you can apply for a free key here. 15 | Please visit CrunchBase for more information.

16 | 17 |

Linked Crunchbase

18 | 19 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Linked CrunchBase 4 | 5 | 6 | 7 |

Welcome to Linked CrunchBase!

8 | 9 |

10 | A Linked Data API wrapping the REST API of CrunchBase, a database about technology companies and startups. 11 |

12 |

13 | This service maps every request to Crunchbase. There also exist mappings of organizations and mappings of people in Crunchbase to DBpedia. 14 |

15 |

Authentication

16 |

17 | To use our Linked Data API for Crunchbase, you have to authenticate to Crunchbase. 18 | To do so, enter your api key here (put the key in the username field and keep the password field empty). 19 | If you are not authenticated, only triples concerning the mapping to DBpedia are returned due to the licensing model of Crunchbase. 20 |

21 | 22 |

Example Linked Data API Usage

23 | 27 | With curl: 28 |

curl -v -H "Accept:text/turtle" --header "Authorization: Basic {Base64-encoded key}" http://linked-crunchbase.org/api/organizations/facebook#id

29 |

Data Formats

30 | Our Linked Data API supports JSON, JSON-LD, and RDF/N-Triples.
31 |

Crawling RDF Data with the Linked Data API

32 | A detailed description of how to crawl an RDF data set based on our Linked Data API is given on GitHub. 33 | Due to licensing issues, we cannot provide a current RDF data set. An old data set from 2015 is provided online here and licensed partly under Creative Commons Attribution-NonCommercial License 4.0 (CC-BY-NC) and partly under Creative Commons Attribution License 4.0 (CC-BY). 34 | 35 |

Metadata

36 | 41 | 42 |

43 | Please take note of the CrunchBase Terms of Service concerning the licensing of Crunchbase data. 44 |

45 | 46 |

The source-code is available on Github.

47 | 48 |

Changelog

49 | 50 |
51 |
2018-12-10
52 |
initial release
53 |
54 | 55 |
56 | OntologyCentral, 2018. 57 | 58 | 59 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/vocab.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Vocabulary Description for CrunchBase (http://crunchbase.com/). 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/WebContent/void.ttl: -------------------------------------------------------------------------------- 1 | @prefix rdf: . 2 | @prefix rdfs: . 3 | @prefix foaf: . 4 | @prefix dcterms: . 5 | @prefix void: . 6 | @prefix xsd: . 7 | @prefix : <#> . 8 | 9 | :CrunchbaseWrapper 10 | rdf:type void:Dataset ; 11 | foaf:homepage ; 12 | dcterms:title "Linked CrunchBase" ; 13 | dcterms:contributor ; 14 | dcterms:source ; 15 | dcterms:modified "2018-11-11"^^xsd:date ; 16 | dcterms:publisher :Michael_Faerber ; 17 | dcterms:license ; 18 | dcterms:subject ; 19 | void:feature ; 20 | void:triples 346695771 ; 21 | void:entities 14583535 ; 22 | void:linkPredicate owl:sameAs . 23 | 24 | :Michael_Faerber a 25 | foaf:Person ; 26 | rdfs:label "Michael Faerber" ; 27 | foaf:mbox . -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/CDL.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/CDL.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/Cookie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/Cookie.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/CookieList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/CookieList.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/HTTP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/HTTP.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/HTTPTokener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/HTTPTokener.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONArray.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONException.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONML.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONML.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONObject$Null.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONObject$Null.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONObject.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONString.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONString.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONStringer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONStringer.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONTokener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONTokener.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/JSONWriter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/JSONWriter.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/Property.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/Property.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/XML.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/XML.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/org/json/XMLTokener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/org/json/XMLTokener.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/servlets/Authenticate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/servlets/Authenticate.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/servlets/CrunchbaseWrapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/servlets/CrunchbaseWrapper.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/servlets/Listener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/servlets/Listener.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/Authentication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/Authentication.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/JSONHelper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/JSONHelper.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/JSONLDHelper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/JSONLDHelper.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/MappingUtility.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/MappingUtility.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/SPARQLLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/SPARQLLoader.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/build/classes/utilities/URIEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelfaerber/linked-crunchbase/5746adb6620eb9946e67c01d51211c1820d05169/CrunchbaseWrapper/build/classes/utilities/URIEncoder.class -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/CDL.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This provides static methods to convert comma delimited text into a 29 | * JSONArray, and to convert a JSONArray into comma delimited text. Comma 30 | * delimited text is a very popular format for data interchange. It is 31 | * understood by most database, spreadsheet, and organizer programs. 32 | *

33 | * Each row of text represents a row in a table or a data record. Each row 34 | * ends with a NEWLINE character. Each row contains one or more values. 35 | * Values are separated by commas. A value can contain any character except 36 | * for comma, unless is is wrapped in single quotes or double quotes. 37 | *

38 | * The first row usually contains the names of the columns. 39 | *

40 | * A comma delimited list can be converted into a JSONArray of JSONObjects. 41 | * The names for the elements in the JSONObjects can be taken from the names 42 | * in the first row. 43 | * @author JSON.org 44 | * @version 2015-05-01 45 | */ 46 | public class CDL { 47 | 48 | /** 49 | * Get the next value. The value can be wrapped in quotes. The value can 50 | * be empty. 51 | * @param x A JSONTokener of the source text. 52 | * @return The value string, or null if empty. 53 | * @throws JSONException if the quoted string is badly formed. 54 | */ 55 | private static String getValue(JSONTokener x) throws JSONException { 56 | char c; 57 | char q; 58 | StringBuffer sb; 59 | do { 60 | c = x.next(); 61 | } while (c == ' ' || c == '\t'); 62 | switch (c) { 63 | case 0: 64 | return null; 65 | case '"': 66 | case '\'': 67 | q = c; 68 | sb = new StringBuffer(); 69 | for (;;) { 70 | c = x.next(); 71 | if (c == q) { 72 | break; 73 | } 74 | if (c == 0 || c == '\n' || c == '\r') { 75 | throw x.syntaxError("Missing close quote '" + q + "'."); 76 | } 77 | sb.append(c); 78 | } 79 | return sb.toString(); 80 | case ',': 81 | x.back(); 82 | return ""; 83 | default: 84 | x.back(); 85 | return x.nextTo(','); 86 | } 87 | } 88 | 89 | /** 90 | * Produce a JSONArray of strings from a row of comma delimited values. 91 | * @param x A JSONTokener of the source text. 92 | * @return A JSONArray of strings. 93 | * @throws JSONException 94 | */ 95 | public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { 96 | JSONArray ja = new JSONArray(); 97 | for (;;) { 98 | String value = getValue(x); 99 | char c = x.next(); 100 | if (value == null || 101 | (ja.length() == 0 && value.length() == 0 && c != ',')) { 102 | return null; 103 | } 104 | ja.put(value); 105 | for (;;) { 106 | if (c == ',') { 107 | break; 108 | } 109 | if (c != ' ') { 110 | if (c == '\n' || c == '\r' || c == 0) { 111 | return ja; 112 | } 113 | throw x.syntaxError("Bad character '" + c + "' (" + 114 | (int)c + ")."); 115 | } 116 | c = x.next(); 117 | } 118 | } 119 | } 120 | 121 | /** 122 | * Produce a JSONObject from a row of comma delimited text, using a 123 | * parallel JSONArray of strings to provides the names of the elements. 124 | * @param names A JSONArray of names. This is commonly obtained from the 125 | * first row of a comma delimited text file using the rowToJSONArray 126 | * method. 127 | * @param x A JSONTokener of the source text. 128 | * @return A JSONObject combining the names and values. 129 | * @throws JSONException 130 | */ 131 | public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) 132 | throws JSONException { 133 | JSONArray ja = rowToJSONArray(x); 134 | return ja != null ? ja.toJSONObject(names) : null; 135 | } 136 | 137 | /** 138 | * Produce a comma delimited text row from a JSONArray. Values containing 139 | * the comma character will be quoted. Troublesome characters may be 140 | * removed. 141 | * @param ja A JSONArray of strings. 142 | * @return A string ending in NEWLINE. 143 | */ 144 | public static String rowToString(JSONArray ja) { 145 | StringBuilder sb = new StringBuilder(); 146 | for (int i = 0; i < ja.length(); i += 1) { 147 | if (i > 0) { 148 | sb.append(','); 149 | } 150 | Object object = ja.opt(i); 151 | if (object != null) { 152 | String string = object.toString(); 153 | if (string.length() > 0 && (string.indexOf(',') >= 0 || 154 | string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 || 155 | string.indexOf(0) >= 0 || string.charAt(0) == '"')) { 156 | sb.append('"'); 157 | int length = string.length(); 158 | for (int j = 0; j < length; j += 1) { 159 | char c = string.charAt(j); 160 | if (c >= ' ' && c != '"') { 161 | sb.append(c); 162 | } 163 | } 164 | sb.append('"'); 165 | } else { 166 | sb.append(string); 167 | } 168 | } 169 | } 170 | sb.append('\n'); 171 | return sb.toString(); 172 | } 173 | 174 | /** 175 | * Produce a JSONArray of JSONObjects from a comma delimited text string, 176 | * using the first row as a source of names. 177 | * @param string The comma delimited text. 178 | * @return A JSONArray of JSONObjects. 179 | * @throws JSONException 180 | */ 181 | public static JSONArray toJSONArray(String string) throws JSONException { 182 | return toJSONArray(new JSONTokener(string)); 183 | } 184 | 185 | /** 186 | * Produce a JSONArray of JSONObjects from a comma delimited text string, 187 | * using the first row as a source of names. 188 | * @param x The JSONTokener containing the comma delimited text. 189 | * @return A JSONArray of JSONObjects. 190 | * @throws JSONException 191 | */ 192 | public static JSONArray toJSONArray(JSONTokener x) throws JSONException { 193 | return toJSONArray(rowToJSONArray(x), x); 194 | } 195 | 196 | /** 197 | * Produce a JSONArray of JSONObjects from a comma delimited text string 198 | * using a supplied JSONArray as the source of element names. 199 | * @param names A JSONArray of strings. 200 | * @param string The comma delimited text. 201 | * @return A JSONArray of JSONObjects. 202 | * @throws JSONException 203 | */ 204 | public static JSONArray toJSONArray(JSONArray names, String string) 205 | throws JSONException { 206 | return toJSONArray(names, new JSONTokener(string)); 207 | } 208 | 209 | /** 210 | * Produce a JSONArray of JSONObjects from a comma delimited text string 211 | * using a supplied JSONArray as the source of element names. 212 | * @param names A JSONArray of strings. 213 | * @param x A JSONTokener of the source text. 214 | * @return A JSONArray of JSONObjects. 215 | * @throws JSONException 216 | */ 217 | public static JSONArray toJSONArray(JSONArray names, JSONTokener x) 218 | throws JSONException { 219 | if (names == null || names.length() == 0) { 220 | return null; 221 | } 222 | JSONArray ja = new JSONArray(); 223 | for (;;) { 224 | JSONObject jo = rowToJSONObject(names, x); 225 | if (jo == null) { 226 | break; 227 | } 228 | ja.put(jo); 229 | } 230 | if (ja.length() == 0) { 231 | return null; 232 | } 233 | return ja; 234 | } 235 | 236 | 237 | /** 238 | * Produce a comma delimited text from a JSONArray of JSONObjects. The 239 | * first row will be a list of names obtained by inspecting the first 240 | * JSONObject. 241 | * @param ja A JSONArray of JSONObjects. 242 | * @return A comma delimited text. 243 | * @throws JSONException 244 | */ 245 | public static String toString(JSONArray ja) throws JSONException { 246 | JSONObject jo = ja.optJSONObject(0); 247 | if (jo != null) { 248 | JSONArray names = jo.names(); 249 | if (names != null) { 250 | return rowToString(names) + toString(names, ja); 251 | } 252 | } 253 | return null; 254 | } 255 | 256 | /** 257 | * Produce a comma delimited text from a JSONArray of JSONObjects using 258 | * a provided list of names. The list of names is not included in the 259 | * output. 260 | * @param names A JSONArray of strings. 261 | * @param ja A JSONArray of JSONObjects. 262 | * @return A comma delimited text. 263 | * @throws JSONException 264 | */ 265 | public static String toString(JSONArray names, JSONArray ja) 266 | throws JSONException { 267 | if (names == null || names.length() == 0) { 268 | return null; 269 | } 270 | StringBuffer sb = new StringBuffer(); 271 | for (int i = 0; i < ja.length(); i += 1) { 272 | JSONObject jo = ja.optJSONObject(i); 273 | if (jo != null) { 274 | sb.append(rowToString(jo.toJSONArray(names))); 275 | } 276 | } 277 | return sb.toString(); 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/Cookie.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | /** 28 | * Convert a web browser cookie specification to a JSONObject and back. 29 | * JSON and Cookies are both notations for name/value pairs. 30 | * @author JSON.org 31 | * @version 2014-05-03 32 | */ 33 | public class Cookie { 34 | 35 | /** 36 | * Produce a copy of a string in which the characters '+', '%', '=', ';' 37 | * and control characters are replaced with "%hh". This is a gentle form 38 | * of URL encoding, attempting to cause as little distortion to the 39 | * string as possible. The characters '=' and ';' are meta characters in 40 | * cookies. By convention, they are escaped using the URL-encoding. This is 41 | * only a convention, not a standard. Often, cookies are expected to have 42 | * encoded values. We encode '=' and ';' because we must. We encode '%' and 43 | * '+' because they are meta characters in URL encoding. 44 | * @param string The source string. 45 | * @return The escaped result. 46 | */ 47 | public static String escape(String string) { 48 | char c; 49 | String s = string.trim(); 50 | int length = s.length(); 51 | StringBuilder sb = new StringBuilder(length); 52 | for (int i = 0; i < length; i += 1) { 53 | c = s.charAt(i); 54 | if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { 55 | sb.append('%'); 56 | sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16)); 57 | sb.append(Character.forDigit((char)(c & 0x0f), 16)); 58 | } else { 59 | sb.append(c); 60 | } 61 | } 62 | return sb.toString(); 63 | } 64 | 65 | 66 | /** 67 | * Convert a cookie specification string into a JSONObject. The string 68 | * will contain a name value pair separated by '='. The name and the value 69 | * will be unescaped, possibly converting '+' and '%' sequences. The 70 | * cookie properties may follow, separated by ';', also represented as 71 | * name=value (except the secure property, which does not have a value). 72 | * The name will be stored under the key "name", and the value will be 73 | * stored under the key "value". This method does not do checking or 74 | * validation of the parameters. It only converts the cookie string into 75 | * a JSONObject. 76 | * @param string The cookie specification string. 77 | * @return A JSONObject containing "name", "value", and possibly other 78 | * members. 79 | * @throws JSONException 80 | */ 81 | public static JSONObject toJSONObject(String string) throws JSONException { 82 | String name; 83 | JSONObject jo = new JSONObject(); 84 | Object value; 85 | JSONTokener x = new JSONTokener(string); 86 | jo.put("name", x.nextTo('=')); 87 | x.next('='); 88 | jo.put("value", x.nextTo(';')); 89 | x.next(); 90 | while (x.more()) { 91 | name = unescape(x.nextTo("=;")); 92 | if (x.next() != '=') { 93 | if (name.equals("secure")) { 94 | value = Boolean.TRUE; 95 | } else { 96 | throw x.syntaxError("Missing '=' in cookie parameter."); 97 | } 98 | } else { 99 | value = unescape(x.nextTo(';')); 100 | x.next(); 101 | } 102 | jo.put(name, value); 103 | } 104 | return jo; 105 | } 106 | 107 | 108 | /** 109 | * Convert a JSONObject into a cookie specification string. The JSONObject 110 | * must contain "name" and "value" members. 111 | * If the JSONObject contains "expires", "domain", "path", or "secure" 112 | * members, they will be appended to the cookie specification string. 113 | * All other members are ignored. 114 | * @param jo A JSONObject 115 | * @return A cookie specification string 116 | * @throws JSONException 117 | */ 118 | public static String toString(JSONObject jo) throws JSONException { 119 | StringBuilder sb = new StringBuilder(); 120 | 121 | sb.append(escape(jo.getString("name"))); 122 | sb.append("="); 123 | sb.append(escape(jo.getString("value"))); 124 | if (jo.has("expires")) { 125 | sb.append(";expires="); 126 | sb.append(jo.getString("expires")); 127 | } 128 | if (jo.has("domain")) { 129 | sb.append(";domain="); 130 | sb.append(escape(jo.getString("domain"))); 131 | } 132 | if (jo.has("path")) { 133 | sb.append(";path="); 134 | sb.append(escape(jo.getString("path"))); 135 | } 136 | if (jo.optBoolean("secure")) { 137 | sb.append(";secure"); 138 | } 139 | return sb.toString(); 140 | } 141 | 142 | /** 143 | * Convert %hh sequences to single characters, and 144 | * convert plus to space. 145 | * @param string A string that may contain 146 | * + (plus) and 147 | * %hh sequences. 148 | * @return The unescaped string. 149 | */ 150 | public static String unescape(String string) { 151 | int length = string.length(); 152 | StringBuilder sb = new StringBuilder(length); 153 | for (int i = 0; i < length; ++i) { 154 | char c = string.charAt(i); 155 | if (c == '+') { 156 | c = ' '; 157 | } else if (c == '%' && i + 2 < length) { 158 | int d = JSONTokener.dehexchar(string.charAt(i + 1)); 159 | int e = JSONTokener.dehexchar(string.charAt(i + 2)); 160 | if (d >= 0 && e >= 0) { 161 | c = (char)(d * 16 + e); 162 | i += 2; 163 | } 164 | } 165 | sb.append(c); 166 | } 167 | return sb.toString(); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/CookieList.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.util.Iterator; 28 | 29 | /** 30 | * Convert a web browser cookie list string to a JSONObject and back. 31 | * @author JSON.org 32 | * @version 2014-05-03 33 | */ 34 | public class CookieList { 35 | 36 | /** 37 | * Convert a cookie list into a JSONObject. A cookie list is a sequence 38 | * of name/value pairs. The names are separated from the values by '='. 39 | * The pairs are separated by ';'. The names and the values 40 | * will be unescaped, possibly converting '+' and '%' sequences. 41 | * 42 | * To add a cookie to a cooklist, 43 | * cookielistJSONObject.put(cookieJSONObject.getString("name"), 44 | * cookieJSONObject.getString("value")); 45 | * @param string A cookie list string 46 | * @return A JSONObject 47 | * @throws JSONException 48 | */ 49 | public static JSONObject toJSONObject(String string) throws JSONException { 50 | JSONObject jo = new JSONObject(); 51 | JSONTokener x = new JSONTokener(string); 52 | while (x.more()) { 53 | String name = Cookie.unescape(x.nextTo('=')); 54 | x.next('='); 55 | jo.put(name, Cookie.unescape(x.nextTo(';'))); 56 | x.next(); 57 | } 58 | return jo; 59 | } 60 | 61 | /** 62 | * Convert a JSONObject into a cookie list. A cookie list is a sequence 63 | * of name/value pairs. The names are separated from the values by '='. 64 | * The pairs are separated by ';'. The characters '%', '+', '=', and ';' 65 | * in the names and values are replaced by "%hh". 66 | * @param jo A JSONObject 67 | * @return A cookie list string 68 | * @throws JSONException 69 | */ 70 | public static String toString(JSONObject jo) throws JSONException { 71 | boolean b = false; 72 | Iterator keys = jo.keys(); 73 | String string; 74 | StringBuilder sb = new StringBuilder(); 75 | while (keys.hasNext()) { 76 | string = keys.next(); 77 | if (!jo.isNull(string)) { 78 | if (b) { 79 | sb.append(';'); 80 | } 81 | sb.append(Cookie.escape(string)); 82 | sb.append("="); 83 | sb.append(Cookie.escape(jo.getString(string))); 84 | b = true; 85 | } 86 | } 87 | return sb.toString(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/HTTP.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.util.Iterator; 28 | 29 | /** 30 | * Convert an HTTP header to a JSONObject and back. 31 | * @author JSON.org 32 | * @version 2014-05-03 33 | */ 34 | public class HTTP { 35 | 36 | /** Carriage return/line feed. */ 37 | public static final String CRLF = "\r\n"; 38 | 39 | /** 40 | * Convert an HTTP header string into a JSONObject. It can be a request 41 | * header or a response header. A request header will contain 42 | *

{
 43 |      *    Method: "POST" (for example),
 44 |      *    "Request-URI": "/" (for example),
 45 |      *    "HTTP-Version": "HTTP/1.1" (for example)
 46 |      * }
47 | * A response header will contain 48 | *
{
 49 |      *    "HTTP-Version": "HTTP/1.1" (for example),
 50 |      *    "Status-Code": "200" (for example),
 51 |      *    "Reason-Phrase": "OK" (for example)
 52 |      * }
53 | * In addition, the other parameters in the header will be captured, using 54 | * the HTTP field names as JSON names, so that
 55 |      *    Date: Sun, 26 May 2002 18:06:04 GMT
 56 |      *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
 57 |      *    Cache-Control: no-cache
58 | * become 59 | *
{...
 60 |      *    Date: "Sun, 26 May 2002 18:06:04 GMT",
 61 |      *    Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
 62 |      *    "Cache-Control": "no-cache",
 63 |      * ...}
64 | * It does no further checking or conversion. It does not parse dates. 65 | * It does not do '%' transforms on URLs. 66 | * @param string An HTTP header string. 67 | * @return A JSONObject containing the elements and attributes 68 | * of the XML string. 69 | * @throws JSONException 70 | */ 71 | public static JSONObject toJSONObject(String string) throws JSONException { 72 | JSONObject jo = new JSONObject(); 73 | HTTPTokener x = new HTTPTokener(string); 74 | String token; 75 | 76 | token = x.nextToken(); 77 | if (token.toUpperCase().startsWith("HTTP")) { 78 | 79 | // Response 80 | 81 | jo.put("HTTP-Version", token); 82 | jo.put("Status-Code", x.nextToken()); 83 | jo.put("Reason-Phrase", x.nextTo('\0')); 84 | x.next(); 85 | 86 | } else { 87 | 88 | // Request 89 | 90 | jo.put("Method", token); 91 | jo.put("Request-URI", x.nextToken()); 92 | jo.put("HTTP-Version", x.nextToken()); 93 | } 94 | 95 | // Fields 96 | 97 | while (x.more()) { 98 | String name = x.nextTo(':'); 99 | x.next(':'); 100 | jo.put(name, x.nextTo('\0')); 101 | x.next(); 102 | } 103 | return jo; 104 | } 105 | 106 | 107 | /** 108 | * Convert a JSONObject into an HTTP header. A request header must contain 109 | *
{
110 |      *    Method: "POST" (for example),
111 |      *    "Request-URI": "/" (for example),
112 |      *    "HTTP-Version": "HTTP/1.1" (for example)
113 |      * }
114 | * A response header must contain 115 | *
{
116 |      *    "HTTP-Version": "HTTP/1.1" (for example),
117 |      *    "Status-Code": "200" (for example),
118 |      *    "Reason-Phrase": "OK" (for example)
119 |      * }
120 | * Any other members of the JSONObject will be output as HTTP fields. 121 | * The result will end with two CRLF pairs. 122 | * @param jo A JSONObject 123 | * @return An HTTP header string. 124 | * @throws JSONException if the object does not contain enough 125 | * information. 126 | */ 127 | public static String toString(JSONObject jo) throws JSONException { 128 | Iterator keys = jo.keys(); 129 | String string; 130 | StringBuilder sb = new StringBuilder(); 131 | if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { 132 | sb.append(jo.getString("HTTP-Version")); 133 | sb.append(' '); 134 | sb.append(jo.getString("Status-Code")); 135 | sb.append(' '); 136 | sb.append(jo.getString("Reason-Phrase")); 137 | } else if (jo.has("Method") && jo.has("Request-URI")) { 138 | sb.append(jo.getString("Method")); 139 | sb.append(' '); 140 | sb.append('"'); 141 | sb.append(jo.getString("Request-URI")); 142 | sb.append('"'); 143 | sb.append(' '); 144 | sb.append(jo.getString("HTTP-Version")); 145 | } else { 146 | throw new JSONException("Not enough material for an HTTP header."); 147 | } 148 | sb.append(CRLF); 149 | while (keys.hasNext()) { 150 | string = keys.next(); 151 | if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && 152 | !"Reason-Phrase".equals(string) && !"Method".equals(string) && 153 | !"Request-URI".equals(string) && !jo.isNull(string)) { 154 | sb.append(string); 155 | sb.append(": "); 156 | sb.append(jo.getString(string)); 157 | sb.append(CRLF); 158 | } 159 | } 160 | sb.append(CRLF); 161 | return sb.toString(); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/HTTPTokener.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | /** 28 | * The HTTPTokener extends the JSONTokener to provide additional methods 29 | * for the parsing of HTTP headers. 30 | * @author JSON.org 31 | * @version 2014-05-03 32 | */ 33 | public class HTTPTokener extends JSONTokener { 34 | 35 | /** 36 | * Construct an HTTPTokener from a string. 37 | * @param string A source string. 38 | */ 39 | public HTTPTokener(String string) { 40 | super(string); 41 | } 42 | 43 | 44 | /** 45 | * Get the next token or string. This is used in parsing HTTP headers. 46 | * @throws JSONException 47 | * @return A String. 48 | */ 49 | public String nextToken() throws JSONException { 50 | char c; 51 | char q; 52 | StringBuilder sb = new StringBuilder(); 53 | do { 54 | c = next(); 55 | } while (Character.isWhitespace(c)); 56 | if (c == '"' || c == '\'') { 57 | q = c; 58 | for (;;) { 59 | c = next(); 60 | if (c < ' ') { 61 | throw syntaxError("Unterminated string."); 62 | } 63 | if (c == q) { 64 | return sb.toString(); 65 | } 66 | sb.append(c); 67 | } 68 | } 69 | for (;;) { 70 | if (c == 0 || Character.isWhitespace(c)) { 71 | return sb.toString(); 72 | } 73 | sb.append(c); 74 | c = next(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONException.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /** 4 | * The JSONException is thrown by the JSON.org classes when things are amiss. 5 | * 6 | * @author JSON.org 7 | * @version 2014-05-03 8 | */ 9 | public class JSONException extends RuntimeException { 10 | private static final long serialVersionUID = 0; 11 | private Throwable cause; 12 | 13 | /** 14 | * Constructs a JSONException with an explanatory message. 15 | * 16 | * @param message 17 | * Detail about the reason for the exception. 18 | */ 19 | public JSONException(String message) { 20 | super(message); 21 | } 22 | 23 | /** 24 | * Constructs a new JSONException with the specified cause. 25 | * @param cause The cause. 26 | */ 27 | public JSONException(Throwable cause) { 28 | super(cause.getMessage()); 29 | this.cause = cause; 30 | } 31 | 32 | /** 33 | * Returns the cause of this exception or null if the cause is nonexistent 34 | * or unknown. 35 | * 36 | * @return the cause of this exception or null if the cause is nonexistent 37 | * or unknown. 38 | */ 39 | @Override 40 | public Throwable getCause() { 41 | return this.cause; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONML.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2008 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.util.Iterator; 28 | 29 | 30 | /** 31 | * This provides static methods to convert an XML text into a JSONArray or 32 | * JSONObject, and to covert a JSONArray or JSONObject into an XML text using 33 | * the JsonML transform. 34 | * 35 | * @author JSON.org 36 | * @version 2014-05-03 37 | */ 38 | public class JSONML { 39 | 40 | /** 41 | * Parse XML values and store them in a JSONArray. 42 | * @param x The XMLTokener containing the source string. 43 | * @param arrayForm true if array form, false if object form. 44 | * @param ja The JSONArray that is containing the current tag or null 45 | * if we are at the outermost level. 46 | * @return A JSONArray if the value is the outermost tag, otherwise null. 47 | * @throws JSONException 48 | */ 49 | private static Object parse( 50 | XMLTokener x, 51 | boolean arrayForm, 52 | JSONArray ja 53 | ) throws JSONException { 54 | String attribute; 55 | char c; 56 | String closeTag = null; 57 | int i; 58 | JSONArray newja = null; 59 | JSONObject newjo = null; 60 | Object token; 61 | String tagName = null; 62 | 63 | // Test for and skip past these forms: 64 | // 65 | // 66 | // 67 | // 68 | 69 | while (true) { 70 | if (!x.more()) { 71 | throw x.syntaxError("Bad XML"); 72 | } 73 | token = x.nextContent(); 74 | if (token == XML.LT) { 75 | token = x.nextToken(); 76 | if (token instanceof Character) { 77 | if (token == XML.SLASH) { 78 | 79 | // Close tag "); 99 | } else { 100 | x.back(); 101 | } 102 | } else if (c == '[') { 103 | token = x.nextToken(); 104 | if (token.equals("CDATA") && x.next() == '[') { 105 | if (ja != null) { 106 | ja.put(x.nextCDATA()); 107 | } 108 | } else { 109 | throw x.syntaxError("Expected 'CDATA['"); 110 | } 111 | } else { 112 | i = 1; 113 | do { 114 | token = x.nextMeta(); 115 | if (token == null) { 116 | throw x.syntaxError("Missing '>' after ' 0); 123 | } 124 | } else if (token == XML.QUEST) { 125 | 126 | // "); 129 | } else { 130 | throw x.syntaxError("Misshaped tag"); 131 | } 132 | 133 | // Open tag < 134 | 135 | } else { 136 | if (!(token instanceof String)) { 137 | throw x.syntaxError("Bad tagName '" + token + "'."); 138 | } 139 | tagName = (String)token; 140 | newja = new JSONArray(); 141 | newjo = new JSONObject(); 142 | if (arrayForm) { 143 | newja.put(tagName); 144 | if (ja != null) { 145 | ja.put(newja); 146 | } 147 | } else { 148 | newjo.put("tagName", tagName); 149 | if (ja != null) { 150 | ja.put(newjo); 151 | } 152 | } 153 | token = null; 154 | for (;;) { 155 | if (token == null) { 156 | token = x.nextToken(); 157 | } 158 | if (token == null) { 159 | throw x.syntaxError("Misshaped tag"); 160 | } 161 | if (!(token instanceof String)) { 162 | break; 163 | } 164 | 165 | // attribute = value 166 | 167 | attribute = (String)token; 168 | if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { 169 | throw x.syntaxError("Reserved attribute."); 170 | } 171 | token = x.nextToken(); 172 | if (token == XML.EQ) { 173 | token = x.nextToken(); 174 | if (!(token instanceof String)) { 175 | throw x.syntaxError("Missing value"); 176 | } 177 | newjo.accumulate(attribute, XML.stringToValue((String)token)); 178 | token = null; 179 | } else { 180 | newjo.accumulate(attribute, ""); 181 | } 182 | } 183 | if (arrayForm && newjo.length() > 0) { 184 | newja.put(newjo); 185 | } 186 | 187 | // Empty tag <.../> 188 | 189 | if (token == XML.SLASH) { 190 | if (x.nextToken() != XML.GT) { 191 | throw x.syntaxError("Misshaped tag"); 192 | } 193 | if (ja == null) { 194 | if (arrayForm) { 195 | return newja; 196 | } else { 197 | return newjo; 198 | } 199 | } 200 | 201 | // Content, between <...> and 202 | 203 | } else { 204 | if (token != XML.GT) { 205 | throw x.syntaxError("Misshaped tag"); 206 | } 207 | closeTag = (String)parse(x, arrayForm, newja); 208 | if (closeTag != null) { 209 | if (!closeTag.equals(tagName)) { 210 | throw x.syntaxError("Mismatched '" + tagName + 211 | "' and '" + closeTag + "'"); 212 | } 213 | tagName = null; 214 | if (!arrayForm && newja.length() > 0) { 215 | newjo.put("childNodes", newja); 216 | } 217 | if (ja == null) { 218 | if (arrayForm) { 219 | return newja; 220 | } else { 221 | return newjo; 222 | } 223 | } 224 | } 225 | } 226 | } 227 | } else { 228 | if (ja != null) { 229 | ja.put(token instanceof String 230 | ? XML.stringToValue((String)token) 231 | : token); 232 | } 233 | } 234 | } 235 | } 236 | 237 | 238 | /** 239 | * Convert a well-formed (but not necessarily valid) XML string into a 240 | * JSONArray using the JsonML transform. Each XML tag is represented as 241 | * a JSONArray in which the first element is the tag name. If the tag has 242 | * attributes, then the second element will be JSONObject containing the 243 | * name/value pairs. If the tag contains children, then strings and 244 | * JSONArrays will represent the child tags. 245 | * Comments, prologs, DTDs, and <[ [ ]]> are ignored. 246 | * @param string The source string. 247 | * @return A JSONArray containing the structured data from the XML string. 248 | * @throws JSONException 249 | */ 250 | public static JSONArray toJSONArray(String string) throws JSONException { 251 | return toJSONArray(new XMLTokener(string)); 252 | } 253 | 254 | 255 | /** 256 | * Convert a well-formed (but not necessarily valid) XML string into a 257 | * JSONArray using the JsonML transform. Each XML tag is represented as 258 | * a JSONArray in which the first element is the tag name. If the tag has 259 | * attributes, then the second element will be JSONObject containing the 260 | * name/value pairs. If the tag contains children, then strings and 261 | * JSONArrays will represent the child content and tags. 262 | * Comments, prologs, DTDs, and <[ [ ]]> are ignored. 263 | * @param x An XMLTokener. 264 | * @return A JSONArray containing the structured data from the XML string. 265 | * @throws JSONException 266 | */ 267 | public static JSONArray toJSONArray(XMLTokener x) throws JSONException { 268 | return (JSONArray)parse(x, true, null); 269 | } 270 | 271 | 272 | /** 273 | * Convert a well-formed (but not necessarily valid) XML string into a 274 | * JSONObject using the JsonML transform. Each XML tag is represented as 275 | * a JSONObject with a "tagName" property. If the tag has attributes, then 276 | * the attributes will be in the JSONObject as properties. If the tag 277 | * contains children, the object will have a "childNodes" property which 278 | * will be an array of strings and JsonML JSONObjects. 279 | 280 | * Comments, prologs, DTDs, and <[ [ ]]> are ignored. 281 | * @param x An XMLTokener of the XML source text. 282 | * @return A JSONObject containing the structured data from the XML string. 283 | * @throws JSONException 284 | */ 285 | public static JSONObject toJSONObject(XMLTokener x) throws JSONException { 286 | return (JSONObject)parse(x, false, null); 287 | } 288 | 289 | 290 | /** 291 | * Convert a well-formed (but not necessarily valid) XML string into a 292 | * JSONObject using the JsonML transform. Each XML tag is represented as 293 | * a JSONObject with a "tagName" property. If the tag has attributes, then 294 | * the attributes will be in the JSONObject as properties. If the tag 295 | * contains children, the object will have a "childNodes" property which 296 | * will be an array of strings and JsonML JSONObjects. 297 | 298 | * Comments, prologs, DTDs, and <[ [ ]]> are ignored. 299 | * @param string The XML source text. 300 | * @return A JSONObject containing the structured data from the XML string. 301 | * @throws JSONException 302 | */ 303 | public static JSONObject toJSONObject(String string) throws JSONException { 304 | return toJSONObject(new XMLTokener(string)); 305 | } 306 | 307 | 308 | /** 309 | * Reverse the JSONML transformation, making an XML text from a JSONArray. 310 | * @param ja A JSONArray. 311 | * @return An XML string. 312 | * @throws JSONException 313 | */ 314 | public static String toString(JSONArray ja) throws JSONException { 315 | int i; 316 | JSONObject jo; 317 | String key; 318 | Iterator keys; 319 | int length; 320 | Object object; 321 | StringBuilder sb = new StringBuilder(); 322 | String tagName; 323 | String value; 324 | 325 | // Emit = length) { 362 | sb.append('/'); 363 | sb.append('>'); 364 | } else { 365 | sb.append('>'); 366 | do { 367 | object = ja.get(i); 368 | i += 1; 369 | if (object != null) { 370 | if (object instanceof String) { 371 | sb.append(XML.escape(object.toString())); 372 | } else if (object instanceof JSONObject) { 373 | sb.append(toString((JSONObject)object)); 374 | } else if (object instanceof JSONArray) { 375 | sb.append(toString((JSONArray)object)); 376 | } else { 377 | sb.append(object.toString()); 378 | } 379 | } 380 | } while (i < length); 381 | sb.append('<'); 382 | sb.append('/'); 383 | sb.append(tagName); 384 | sb.append('>'); 385 | } 386 | return sb.toString(); 387 | } 388 | 389 | /** 390 | * Reverse the JSONML transformation, making an XML text from a JSONObject. 391 | * The JSONObject must contain a "tagName" property. If it has children, 392 | * then it must have a "childNodes" property containing an array of objects. 393 | * The other properties are attributes with string values. 394 | * @param jo A JSONObject. 395 | * @return An XML string. 396 | * @throws JSONException 397 | */ 398 | public static String toString(JSONObject jo) throws JSONException { 399 | StringBuilder sb = new StringBuilder(); 400 | int i; 401 | JSONArray ja; 402 | String key; 403 | Iterator keys; 404 | int length; 405 | Object object; 406 | String tagName; 407 | String value; 408 | 409 | //Emit '); 445 | } else { 446 | sb.append('>'); 447 | length = ja.length(); 448 | for (i = 0; i < length; i += 1) { 449 | object = ja.get(i); 450 | if (object != null) { 451 | if (object instanceof String) { 452 | sb.append(XML.escape(object.toString())); 453 | } else if (object instanceof JSONObject) { 454 | sb.append(toString((JSONObject)object)); 455 | } else if (object instanceof JSONArray) { 456 | sb.append(toString((JSONArray)object)); 457 | } else { 458 | sb.append(object.toString()); 459 | } 460 | } 461 | } 462 | sb.append('<'); 463 | sb.append('/'); 464 | sb.append(tagName); 465 | sb.append('>'); 466 | } 467 | return sb.toString(); 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONString.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | /** 3 | * The JSONString interface allows a toJSONString() 4 | * method so that a class can change the behavior of 5 | * JSONObject.toString(), JSONArray.toString(), 6 | * and JSONWriter.value(Object). The 7 | * toJSONString method will be used instead of the default behavior 8 | * of using the Object's toString() method and quoting the result. 9 | */ 10 | public interface JSONString { 11 | /** 12 | * The toJSONString method allows a class to produce its own JSON 13 | * serialization. 14 | * 15 | * @return A strictly syntactically correct JSON text. 16 | */ 17 | public String toJSONString(); 18 | } 19 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONStringer.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2006 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.io.StringWriter; 28 | 29 | /** 30 | * JSONStringer provides a quick and convenient way of producing JSON text. 31 | * The texts produced strictly conform to JSON syntax rules. No whitespace is 32 | * added, so the results are ready for transmission or storage. Each instance of 33 | * JSONStringer can produce one JSON text. 34 | *

35 | * A JSONStringer instance provides a value method for appending 36 | * values to the 37 | * text, and a key 38 | * method for adding keys before values in objects. There are array 39 | * and endArray methods that make and bound array values, and 40 | * object and endObject methods which make and bound 41 | * object values. All of these methods return the JSONWriter instance, 42 | * permitting cascade style. For example,

43 |  * myString = new JSONStringer()
44 |  *     .object()
45 |  *         .key("JSON")
46 |  *         .value("Hello, World!")
47 |  *     .endObject()
48 |  *     .toString();
which produces the string
49 |  * {"JSON":"Hello, World!"}
50 | *

51 | * The first method called must be array or object. 52 | * There are no methods for adding commas or colons. JSONStringer adds them for 53 | * you. Objects and arrays can be nested up to 20 levels deep. 54 | *

55 | * This can sometimes be easier than using a JSONObject to build a string. 56 | * @author JSON.org 57 | * @version 2008-09-18 58 | */ 59 | public class JSONStringer extends JSONWriter { 60 | /** 61 | * Make a fresh JSONStringer. It can be used to build one JSON text. 62 | */ 63 | public JSONStringer() { 64 | super(new StringWriter()); 65 | } 66 | 67 | /** 68 | * Return the JSON text. This method is used to obtain the product of the 69 | * JSONStringer instance. It will return null if there was a 70 | * problem in the construction of the JSON text (such as the calls to 71 | * array were not properly balanced with calls to 72 | * endArray). 73 | * @return The JSON text. 74 | */ 75 | public String toString() { 76 | return this.mode == 'd' ? this.writer.toString() : null; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONTokener.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.io.Reader; 8 | import java.io.StringReader; 9 | 10 | /* 11 | Copyright (c) 2002 JSON.org 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | The Software shall be used for Good, not Evil. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | */ 33 | 34 | /** 35 | * A JSONTokener takes a source string and extracts characters and tokens from 36 | * it. It is used by the JSONObject and JSONArray constructors to parse 37 | * JSON source strings. 38 | * @author JSON.org 39 | * @version 2014-05-03 40 | */ 41 | public class JSONTokener { 42 | 43 | private long character; 44 | private boolean eof; 45 | private long index; 46 | private long line; 47 | private char previous; 48 | private Reader reader; 49 | private boolean usePrevious; 50 | 51 | 52 | /** 53 | * Construct a JSONTokener from a Reader. 54 | * 55 | * @param reader A reader. 56 | */ 57 | public JSONTokener(Reader reader) { 58 | this.reader = reader.markSupported() 59 | ? reader 60 | : new BufferedReader(reader); 61 | this.eof = false; 62 | this.usePrevious = false; 63 | this.previous = 0; 64 | this.index = 0; 65 | this.character = 1; 66 | this.line = 1; 67 | } 68 | 69 | 70 | /** 71 | * Construct a JSONTokener from an InputStream. 72 | * @param inputStream The source. 73 | */ 74 | public JSONTokener(InputStream inputStream) throws JSONException { 75 | this(new InputStreamReader(inputStream)); 76 | } 77 | 78 | 79 | /** 80 | * Construct a JSONTokener from a string. 81 | * 82 | * @param s A source string. 83 | */ 84 | public JSONTokener(String s) { 85 | this(new StringReader(s)); 86 | } 87 | 88 | 89 | /** 90 | * Back up one character. This provides a sort of lookahead capability, 91 | * so that you can test for a digit or letter before attempting to parse 92 | * the next number or identifier. 93 | */ 94 | public void back() throws JSONException { 95 | if (this.usePrevious || this.index <= 0) { 96 | throw new JSONException("Stepping back two steps is not supported"); 97 | } 98 | this.index -= 1; 99 | this.character -= 1; 100 | this.usePrevious = true; 101 | this.eof = false; 102 | } 103 | 104 | 105 | /** 106 | * Get the hex value of a character (base16). 107 | * @param c A character between '0' and '9' or between 'A' and 'F' or 108 | * between 'a' and 'f'. 109 | * @return An int between 0 and 15, or -1 if c was not a hex digit. 110 | */ 111 | public static int dehexchar(char c) { 112 | if (c >= '0' && c <= '9') { 113 | return c - '0'; 114 | } 115 | if (c >= 'A' && c <= 'F') { 116 | return c - ('A' - 10); 117 | } 118 | if (c >= 'a' && c <= 'f') { 119 | return c - ('a' - 10); 120 | } 121 | return -1; 122 | } 123 | 124 | public boolean end() { 125 | return this.eof && !this.usePrevious; 126 | } 127 | 128 | 129 | /** 130 | * Determine if the source string still contains characters that next() 131 | * can consume. 132 | * @return true if not yet at the end of the source. 133 | */ 134 | public boolean more() throws JSONException { 135 | this.next(); 136 | if (this.end()) { 137 | return false; 138 | } 139 | this.back(); 140 | return true; 141 | } 142 | 143 | 144 | /** 145 | * Get the next character in the source string. 146 | * 147 | * @return The next character, or 0 if past the end of the source string. 148 | */ 149 | public char next() throws JSONException { 150 | int c; 151 | if (this.usePrevious) { 152 | this.usePrevious = false; 153 | c = this.previous; 154 | } else { 155 | try { 156 | c = this.reader.read(); 157 | } catch (IOException exception) { 158 | throw new JSONException(exception); 159 | } 160 | 161 | if (c <= 0) { // End of stream 162 | this.eof = true; 163 | c = 0; 164 | } 165 | } 166 | this.index += 1; 167 | if (this.previous == '\r') { 168 | this.line += 1; 169 | this.character = c == '\n' ? 0 : 1; 170 | } else if (c == '\n') { 171 | this.line += 1; 172 | this.character = 0; 173 | } else { 174 | this.character += 1; 175 | } 176 | this.previous = (char) c; 177 | return this.previous; 178 | } 179 | 180 | 181 | /** 182 | * Consume the next character, and check that it matches a specified 183 | * character. 184 | * @param c The character to match. 185 | * @return The character. 186 | * @throws JSONException if the character does not match. 187 | */ 188 | public char next(char c) throws JSONException { 189 | char n = this.next(); 190 | if (n != c) { 191 | throw this.syntaxError("Expected '" + c + "' and instead saw '" + 192 | n + "'"); 193 | } 194 | return n; 195 | } 196 | 197 | 198 | /** 199 | * Get the next n characters. 200 | * 201 | * @param n The number of characters to take. 202 | * @return A string of n characters. 203 | * @throws JSONException 204 | * Substring bounds error if there are not 205 | * n characters remaining in the source string. 206 | */ 207 | public String next(int n) throws JSONException { 208 | if (n == 0) { 209 | return ""; 210 | } 211 | 212 | char[] chars = new char[n]; 213 | int pos = 0; 214 | 215 | while (pos < n) { 216 | chars[pos] = this.next(); 217 | if (this.end()) { 218 | throw this.syntaxError("Substring bounds error"); 219 | } 220 | pos += 1; 221 | } 222 | return new String(chars); 223 | } 224 | 225 | 226 | /** 227 | * Get the next char in the string, skipping whitespace. 228 | * @throws JSONException 229 | * @return A character, or 0 if there are no more characters. 230 | */ 231 | public char nextClean() throws JSONException { 232 | for (;;) { 233 | char c = this.next(); 234 | if (c == 0 || c > ' ') { 235 | return c; 236 | } 237 | } 238 | } 239 | 240 | 241 | /** 242 | * Return the characters up to the next close quote character. 243 | * Backslash processing is done. The formal JSON format does not 244 | * allow strings in single quotes, but an implementation is allowed to 245 | * accept them. 246 | * @param quote The quoting character, either 247 | * " (double quote) or 248 | * ' (single quote). 249 | * @return A String. 250 | * @throws JSONException Unterminated string. 251 | */ 252 | public String nextString(char quote) throws JSONException { 253 | char c; 254 | StringBuilder sb = new StringBuilder(); 255 | for (;;) { 256 | c = this.next(); 257 | switch (c) { 258 | case 0: 259 | case '\n': 260 | case '\r': 261 | throw this.syntaxError("Unterminated string"); 262 | case '\\': 263 | c = this.next(); 264 | switch (c) { 265 | case 'b': 266 | sb.append('\b'); 267 | break; 268 | case 't': 269 | sb.append('\t'); 270 | break; 271 | case 'n': 272 | sb.append('\n'); 273 | break; 274 | case 'f': 275 | sb.append('\f'); 276 | break; 277 | case 'r': 278 | sb.append('\r'); 279 | break; 280 | case 'u': 281 | sb.append((char)Integer.parseInt(this.next(4), 16)); 282 | break; 283 | case '"': 284 | case '\'': 285 | case '\\': 286 | case '/': 287 | sb.append(c); 288 | break; 289 | default: 290 | throw this.syntaxError("Illegal escape."); 291 | } 292 | break; 293 | default: 294 | if (c == quote) { 295 | return sb.toString(); 296 | } 297 | sb.append(c); 298 | } 299 | } 300 | } 301 | 302 | 303 | /** 304 | * Get the text up but not including the specified character or the 305 | * end of line, whichever comes first. 306 | * @param delimiter A delimiter character. 307 | * @return A string. 308 | */ 309 | public String nextTo(char delimiter) throws JSONException { 310 | StringBuilder sb = new StringBuilder(); 311 | for (;;) { 312 | char c = this.next(); 313 | if (c == delimiter || c == 0 || c == '\n' || c == '\r') { 314 | if (c != 0) { 315 | this.back(); 316 | } 317 | return sb.toString().trim(); 318 | } 319 | sb.append(c); 320 | } 321 | } 322 | 323 | 324 | /** 325 | * Get the text up but not including one of the specified delimiter 326 | * characters or the end of line, whichever comes first. 327 | * @param delimiters A set of delimiter characters. 328 | * @return A string, trimmed. 329 | */ 330 | public String nextTo(String delimiters) throws JSONException { 331 | char c; 332 | StringBuilder sb = new StringBuilder(); 333 | for (;;) { 334 | c = this.next(); 335 | if (delimiters.indexOf(c) >= 0 || c == 0 || 336 | c == '\n' || c == '\r') { 337 | if (c != 0) { 338 | this.back(); 339 | } 340 | return sb.toString().trim(); 341 | } 342 | sb.append(c); 343 | } 344 | } 345 | 346 | 347 | /** 348 | * Get the next value. The value can be a Boolean, Double, Integer, 349 | * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. 350 | * @throws JSONException If syntax error. 351 | * 352 | * @return An object. 353 | */ 354 | public Object nextValue() throws JSONException { 355 | char c = this.nextClean(); 356 | String string; 357 | 358 | switch (c) { 359 | case '"': 360 | case '\'': 361 | return this.nextString(c); 362 | case '{': 363 | this.back(); 364 | return new JSONObject(this); 365 | case '[': 366 | this.back(); 367 | return new JSONArray(this); 368 | } 369 | 370 | /* 371 | * Handle unquoted text. This could be the values true, false, or 372 | * null, or it can be a number. An implementation (such as this one) 373 | * is allowed to also accept non-standard forms. 374 | * 375 | * Accumulate characters until we reach the end of the text or a 376 | * formatting character. 377 | */ 378 | 379 | StringBuilder sb = new StringBuilder(); 380 | while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { 381 | sb.append(c); 382 | c = this.next(); 383 | } 384 | this.back(); 385 | 386 | string = sb.toString().trim(); 387 | if ("".equals(string)) { 388 | throw this.syntaxError("Missing value"); 389 | } 390 | return JSONObject.stringToValue(string); 391 | } 392 | 393 | 394 | /** 395 | * Skip characters until the next character is the requested character. 396 | * If the requested character is not found, no characters are skipped. 397 | * @param to A character to skip to. 398 | * @return The requested character, or zero if the requested character 399 | * is not found. 400 | */ 401 | public char skipTo(char to) throws JSONException { 402 | char c; 403 | try { 404 | long startIndex = this.index; 405 | long startCharacter = this.character; 406 | long startLine = this.line; 407 | this.reader.mark(1000000); 408 | do { 409 | c = this.next(); 410 | if (c == 0) { 411 | this.reader.reset(); 412 | this.index = startIndex; 413 | this.character = startCharacter; 414 | this.line = startLine; 415 | return c; 416 | } 417 | } while (c != to); 418 | } catch (IOException exception) { 419 | throw new JSONException(exception); 420 | } 421 | this.back(); 422 | return c; 423 | } 424 | 425 | 426 | /** 427 | * Make a JSONException to signal a syntax error. 428 | * 429 | * @param message The error message. 430 | * @return A JSONException object, suitable for throwing 431 | */ 432 | public JSONException syntaxError(String message) { 433 | return new JSONException(message + this.toString()); 434 | } 435 | 436 | 437 | /** 438 | * Make a printable string of this JSONTokener. 439 | * 440 | * @return " at {index} [character {character} line {line}]" 441 | */ 442 | public String toString() { 443 | return " at " + this.index + " [character " + this.character + " line " + 444 | this.line + "]"; 445 | } 446 | } 447 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/JSONWriter.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | import java.io.IOException; 4 | import java.io.Writer; 5 | 6 | /* 7 | Copyright (c) 2006 JSON.org 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | The Software shall be used for Good, not Evil. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | */ 29 | 30 | /** 31 | * JSONWriter provides a quick and convenient way of producing JSON text. 32 | * The texts produced strictly conform to JSON syntax rules. No whitespace is 33 | * added, so the results are ready for transmission or storage. Each instance of 34 | * JSONWriter can produce one JSON text. 35 | *

36 | * A JSONWriter instance provides a value method for appending 37 | * values to the 38 | * text, and a key 39 | * method for adding keys before values in objects. There are array 40 | * and endArray methods that make and bound array values, and 41 | * object and endObject methods which make and bound 42 | * object values. All of these methods return the JSONWriter instance, 43 | * permitting a cascade style. For example,

 44 |  * new JSONWriter(myWriter)
 45 |  *     .object()
 46 |  *         .key("JSON")
 47 |  *         .value("Hello, World!")
 48 |  *     .endObject();
which writes
 49 |  * {"JSON":"Hello, World!"}
50 | *

51 | * The first method called must be array or object. 52 | * There are no methods for adding commas or colons. JSONWriter adds them for 53 | * you. Objects and arrays can be nested up to 20 levels deep. 54 | *

55 | * This can sometimes be easier than using a JSONObject to build a string. 56 | * @author JSON.org 57 | * @version 2011-11-24 58 | */ 59 | public class JSONWriter { 60 | private static final int maxdepth = 200; 61 | 62 | /** 63 | * The comma flag determines if a comma should be output before the next 64 | * value. 65 | */ 66 | private boolean comma; 67 | 68 | /** 69 | * The current mode. Values: 70 | * 'a' (array), 71 | * 'd' (done), 72 | * 'i' (initial), 73 | * 'k' (key), 74 | * 'o' (object). 75 | */ 76 | protected char mode; 77 | 78 | /** 79 | * The object/array stack. 80 | */ 81 | private final JSONObject stack[]; 82 | 83 | /** 84 | * The stack top index. A value of 0 indicates that the stack is empty. 85 | */ 86 | private int top; 87 | 88 | /** 89 | * The writer that will receive the output. 90 | */ 91 | protected Writer writer; 92 | 93 | /** 94 | * Make a fresh JSONWriter. It can be used to build one JSON text. 95 | */ 96 | public JSONWriter(Writer w) { 97 | this.comma = false; 98 | this.mode = 'i'; 99 | this.stack = new JSONObject[maxdepth]; 100 | this.top = 0; 101 | this.writer = w; 102 | } 103 | 104 | /** 105 | * Append a value. 106 | * @param string A string value. 107 | * @return this 108 | * @throws JSONException If the value is out of sequence. 109 | */ 110 | private JSONWriter append(String string) throws JSONException { 111 | if (string == null) { 112 | throw new JSONException("Null pointer"); 113 | } 114 | if (this.mode == 'o' || this.mode == 'a') { 115 | try { 116 | if (this.comma && this.mode == 'a') { 117 | this.writer.write(','); 118 | } 119 | this.writer.write(string); 120 | } catch (IOException e) { 121 | throw new JSONException(e); 122 | } 123 | if (this.mode == 'o') { 124 | this.mode = 'k'; 125 | } 126 | this.comma = true; 127 | return this; 128 | } 129 | throw new JSONException("Value out of sequence."); 130 | } 131 | 132 | /** 133 | * Begin appending a new array. All values until the balancing 134 | * endArray will be appended to this array. The 135 | * endArray method must be called to mark the array's end. 136 | * @return this 137 | * @throws JSONException If the nesting is too deep, or if the object is 138 | * started in the wrong place (for example as a key or after the end of the 139 | * outermost array or object). 140 | */ 141 | public JSONWriter array() throws JSONException { 142 | if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { 143 | this.push(null); 144 | this.append("["); 145 | this.comma = false; 146 | return this; 147 | } 148 | throw new JSONException("Misplaced array."); 149 | } 150 | 151 | /** 152 | * End something. 153 | * @param mode Mode 154 | * @param c Closing character 155 | * @return this 156 | * @throws JSONException If unbalanced. 157 | */ 158 | private JSONWriter end(char mode, char c) throws JSONException { 159 | if (this.mode != mode) { 160 | throw new JSONException(mode == 'a' 161 | ? "Misplaced endArray." 162 | : "Misplaced endObject."); 163 | } 164 | this.pop(mode); 165 | try { 166 | this.writer.write(c); 167 | } catch (IOException e) { 168 | throw new JSONException(e); 169 | } 170 | this.comma = true; 171 | return this; 172 | } 173 | 174 | /** 175 | * End an array. This method most be called to balance calls to 176 | * array. 177 | * @return this 178 | * @throws JSONException If incorrectly nested. 179 | */ 180 | public JSONWriter endArray() throws JSONException { 181 | return this.end('a', ']'); 182 | } 183 | 184 | /** 185 | * End an object. This method most be called to balance calls to 186 | * object. 187 | * @return this 188 | * @throws JSONException If incorrectly nested. 189 | */ 190 | public JSONWriter endObject() throws JSONException { 191 | return this.end('k', '}'); 192 | } 193 | 194 | /** 195 | * Append a key. The key will be associated with the next value. In an 196 | * object, every value must be preceded by a key. 197 | * @param string A key string. 198 | * @return this 199 | * @throws JSONException If the key is out of place. For example, keys 200 | * do not belong in arrays or if the key is null. 201 | */ 202 | public JSONWriter key(String string) throws JSONException { 203 | if (string == null) { 204 | throw new JSONException("Null key."); 205 | } 206 | if (this.mode == 'k') { 207 | try { 208 | this.stack[this.top - 1].putOnce(string, Boolean.TRUE); 209 | if (this.comma) { 210 | this.writer.write(','); 211 | } 212 | this.writer.write(JSONObject.quote(string)); 213 | this.writer.write(':'); 214 | this.comma = false; 215 | this.mode = 'o'; 216 | return this; 217 | } catch (IOException e) { 218 | throw new JSONException(e); 219 | } 220 | } 221 | throw new JSONException("Misplaced key."); 222 | } 223 | 224 | 225 | /** 226 | * Begin appending a new object. All keys and values until the balancing 227 | * endObject will be appended to this object. The 228 | * endObject method must be called to mark the object's end. 229 | * @return this 230 | * @throws JSONException If the nesting is too deep, or if the object is 231 | * started in the wrong place (for example as a key or after the end of the 232 | * outermost array or object). 233 | */ 234 | public JSONWriter object() throws JSONException { 235 | if (this.mode == 'i') { 236 | this.mode = 'o'; 237 | } 238 | if (this.mode == 'o' || this.mode == 'a') { 239 | this.append("{"); 240 | this.push(new JSONObject()); 241 | this.comma = false; 242 | return this; 243 | } 244 | throw new JSONException("Misplaced object."); 245 | 246 | } 247 | 248 | 249 | /** 250 | * Pop an array or object scope. 251 | * @param c The scope to close. 252 | * @throws JSONException If nesting is wrong. 253 | */ 254 | private void pop(char c) throws JSONException { 255 | if (this.top <= 0) { 256 | throw new JSONException("Nesting error."); 257 | } 258 | char m = this.stack[this.top - 1] == null ? 'a' : 'k'; 259 | if (m != c) { 260 | throw new JSONException("Nesting error."); 261 | } 262 | this.top -= 1; 263 | this.mode = this.top == 0 264 | ? 'd' 265 | : this.stack[this.top - 1] == null 266 | ? 'a' 267 | : 'k'; 268 | } 269 | 270 | /** 271 | * Push an array or object scope. 272 | * @param jo The scope to open. 273 | * @throws JSONException If nesting is too deep. 274 | */ 275 | private void push(JSONObject jo) throws JSONException { 276 | if (this.top >= maxdepth) { 277 | throw new JSONException("Nesting too deep."); 278 | } 279 | this.stack[this.top] = jo; 280 | this.mode = jo == null ? 'a' : 'k'; 281 | this.top += 1; 282 | } 283 | 284 | 285 | /** 286 | * Append either the value true or the value 287 | * false. 288 | * @param b A boolean. 289 | * @return this 290 | * @throws JSONException 291 | */ 292 | public JSONWriter value(boolean b) throws JSONException { 293 | return this.append(b ? "true" : "false"); 294 | } 295 | 296 | /** 297 | * Append a double value. 298 | * @param d A double. 299 | * @return this 300 | * @throws JSONException If the number is not finite. 301 | */ 302 | public JSONWriter value(double d) throws JSONException { 303 | return this.value(new Double(d)); 304 | } 305 | 306 | /** 307 | * Append a long value. 308 | * @param l A long. 309 | * @return this 310 | * @throws JSONException 311 | */ 312 | public JSONWriter value(long l) throws JSONException { 313 | return this.append(Long.toString(l)); 314 | } 315 | 316 | 317 | /** 318 | * Append an object value. 319 | * @param object The object to append. It can be null, or a Boolean, Number, 320 | * String, JSONObject, or JSONArray, or an object that implements JSONString. 321 | * @return this 322 | * @throws JSONException If the value is out of sequence. 323 | */ 324 | public JSONWriter value(Object object) throws JSONException { 325 | return this.append(JSONObject.valueToString(object)); 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/Property.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.util.Enumeration; 28 | import java.util.Iterator; 29 | import java.util.Properties; 30 | 31 | /** 32 | * Converts a Property file data into JSONObject and back. 33 | * @author JSON.org 34 | * @version 2015-05-05 35 | */ 36 | public class Property { 37 | /** 38 | * Converts a property file object into a JSONObject. The property file object is a table of name value pairs. 39 | * @param properties java.util.Properties 40 | * @return JSONObject 41 | * @throws JSONException 42 | */ 43 | public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException { 44 | JSONObject jo = new JSONObject(); 45 | if (properties != null && !properties.isEmpty()) { 46 | Enumeration enumProperties = properties.propertyNames(); 47 | while(enumProperties.hasMoreElements()) { 48 | String name = (String)enumProperties.nextElement(); 49 | jo.put(name, properties.getProperty(name)); 50 | } 51 | } 52 | return jo; 53 | } 54 | 55 | /** 56 | * Converts the JSONObject into a property file object. 57 | * @param jo JSONObject 58 | * @return java.util.Properties 59 | * @throws JSONException 60 | */ 61 | public static Properties toProperties(JSONObject jo) throws JSONException { 62 | Properties properties = new Properties(); 63 | if (jo != null) { 64 | Iterator keys = jo.keys(); 65 | while (keys.hasNext()) { 66 | String name = keys.next(); 67 | properties.put(name, jo.getString(name)); 68 | } 69 | } 70 | return properties; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/XML.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | import java.util.Iterator; 28 | 29 | /** 30 | * This provides static methods to convert an XML text into a JSONObject, 31 | * and to covert a JSONObject into an XML text. 32 | * @author JSON.org 33 | * @version 2014-05-03 34 | */ 35 | public class XML { 36 | 37 | /** The Character '&'. */ 38 | public static final Character AMP = '&'; 39 | 40 | /** The Character '''. */ 41 | public static final Character APOS = '\''; 42 | 43 | /** The Character '!'. */ 44 | public static final Character BANG = '!'; 45 | 46 | /** The Character '='. */ 47 | public static final Character EQ = '='; 48 | 49 | /** The Character '>'. */ 50 | public static final Character GT = '>'; 51 | 52 | /** The Character '<'. */ 53 | public static final Character LT = '<'; 54 | 55 | /** The Character '?'. */ 56 | public static final Character QUEST = '?'; 57 | 58 | /** The Character '"'. */ 59 | public static final Character QUOT = '"'; 60 | 61 | /** The Character '/'. */ 62 | public static final Character SLASH = '/'; 63 | 64 | /** 65 | * Replace special characters with XML escapes: 66 | *

 67 |      * & (ampersand) is replaced by &amp;
 68 |      * < (less than) is replaced by &lt;
 69 |      * > (greater than) is replaced by &gt;
 70 |      * " (double quote) is replaced by &quot;
 71 |      * 
72 | * @param string The string to be escaped. 73 | * @return The escaped string. 74 | */ 75 | public static String escape(String string) { 76 | StringBuilder sb = new StringBuilder(string.length()); 77 | for (int i = 0, length = string.length(); i < length; i++) { 78 | char c = string.charAt(i); 79 | switch (c) { 80 | case '&': 81 | sb.append("&"); 82 | break; 83 | case '<': 84 | sb.append("<"); 85 | break; 86 | case '>': 87 | sb.append(">"); 88 | break; 89 | case '"': 90 | sb.append("""); 91 | break; 92 | case '\'': 93 | sb.append("'"); 94 | break; 95 | default: 96 | sb.append(c); 97 | } 98 | } 99 | return sb.toString(); 100 | } 101 | 102 | /** 103 | * Throw an exception if the string contains whitespace. 104 | * Whitespace is not allowed in tagNames and attributes. 105 | * @param string A string. 106 | * @throws JSONException 107 | */ 108 | public static void noSpace(String string) throws JSONException { 109 | int i, length = string.length(); 110 | if (length == 0) { 111 | throw new JSONException("Empty string."); 112 | } 113 | for (i = 0; i < length; i += 1) { 114 | if (Character.isWhitespace(string.charAt(i))) { 115 | throw new JSONException("'" + string + 116 | "' contains a space character."); 117 | } 118 | } 119 | } 120 | 121 | /** 122 | * Scan the content following the named tag, attaching it to the context. 123 | * @param x The XMLTokener containing the source string. 124 | * @param context The JSONObject that will include the new material. 125 | * @param name The tag name. 126 | * @return true if the close tag is processed. 127 | * @throws JSONException 128 | */ 129 | private static boolean parse(XMLTokener x, JSONObject context, 130 | String name) throws JSONException { 131 | char c; 132 | int i; 133 | JSONObject jsonobject = null; 134 | String string; 135 | String tagName; 136 | Object token; 137 | 138 | // Test for and skip past these forms: 139 | // 140 | // 141 | // 142 | // 143 | // Report errors for these forms: 144 | // <> 145 | // <= 146 | // << 147 | 148 | token = x.nextToken(); 149 | 150 | // "); 157 | return false; 158 | } 159 | x.back(); 160 | } else if (c == '[') { 161 | token = x.nextToken(); 162 | if ("CDATA".equals(token)) { 163 | if (x.next() == '[') { 164 | string = x.nextCDATA(); 165 | if (string.length() > 0) { 166 | context.accumulate("content", string); 167 | } 168 | return false; 169 | } 170 | } 171 | throw x.syntaxError("Expected 'CDATA['"); 172 | } 173 | i = 1; 174 | do { 175 | token = x.nextMeta(); 176 | if (token == null) { 177 | throw x.syntaxError("Missing '>' after ' 0); 184 | return false; 185 | } else if (token == QUEST) { 186 | 187 | // "); 190 | return false; 191 | } else if (token == SLASH) { 192 | 193 | // Close tag 239 | 240 | } else if (token == SLASH) { 241 | if (x.nextToken() != GT) { 242 | throw x.syntaxError("Misshaped tag"); 243 | } 244 | if (jsonobject.length() > 0) { 245 | context.accumulate(tagName, jsonobject); 246 | } else { 247 | context.accumulate(tagName, ""); 248 | } 249 | return false; 250 | 251 | // Content, between <...> and 252 | 253 | } else if (token == GT) { 254 | for (;;) { 255 | token = x.nextContent(); 256 | if (token == null) { 257 | if (tagName != null) { 258 | throw x.syntaxError("Unclosed tag " + tagName); 259 | } 260 | return false; 261 | } else if (token instanceof String) { 262 | string = (String)token; 263 | if (string.length() > 0) { 264 | jsonobject.accumulate("content", 265 | XML.stringToValue(string)); 266 | } 267 | 268 | // Nested element 269 | 270 | } else if (token == LT) { 271 | if (parse(x, jsonobject, tagName)) { 272 | if (jsonobject.length() == 0) { 273 | context.accumulate(tagName, ""); 274 | } else if (jsonobject.length() == 1 && 275 | jsonobject.opt("content") != null) { 276 | context.accumulate(tagName, 277 | jsonobject.opt("content")); 278 | } else { 279 | context.accumulate(tagName, jsonobject); 280 | } 281 | return false; 282 | } 283 | } 284 | } 285 | } else { 286 | throw x.syntaxError("Misshaped tag"); 287 | } 288 | } 289 | } 290 | } 291 | 292 | 293 | /** 294 | * Try to convert a string into a number, boolean, or null. If the string 295 | * can't be converted, return the string. This is much less ambitious than 296 | * JSONObject.stringToValue, especially because it does not attempt to 297 | * convert plus forms, octal forms, hex forms, or E forms lacking decimal 298 | * points. 299 | * @param string A String. 300 | * @return A simple JSON value. 301 | */ 302 | public static Object stringToValue(String string) { 303 | if ("true".equalsIgnoreCase(string)) { 304 | return Boolean.TRUE; 305 | } 306 | if ("false".equalsIgnoreCase(string)) { 307 | return Boolean.FALSE; 308 | } 309 | if ("null".equalsIgnoreCase(string)) { 310 | return JSONObject.NULL; 311 | } 312 | 313 | // If it might be a number, try converting it, first as a Long, and then as a 314 | // Double. If that doesn't work, return the string. 315 | 316 | try { 317 | char initial = string.charAt(0); 318 | if (initial == '-' || (initial >= '0' && initial <= '9')) { 319 | Long value = new Long(string); 320 | if (value.toString().equals(string)) { 321 | return value; 322 | } 323 | } 324 | } catch (Exception ignore) { 325 | try { 326 | Double value = new Double(string); 327 | if (value.toString().equals(string)) { 328 | return value; 329 | } 330 | } catch (Exception ignoreAlso) { 331 | } 332 | } 333 | return string; 334 | } 335 | 336 | 337 | /** 338 | * Convert a well-formed (but not necessarily valid) XML string into a 339 | * JSONObject. Some information may be lost in this transformation 340 | * because JSON is a data format and XML is a document format. XML uses 341 | * elements, attributes, and content text, while JSON uses unordered 342 | * collections of name/value pairs and arrays of values. JSON does not 343 | * does not like to distinguish between elements and attributes. 344 | * Sequences of similar elements are represented as JSONArrays. Content 345 | * text may be placed in a "content" member. Comments, prologs, DTDs, and 346 | * <[ [ ]]> are ignored. 347 | * @param string The source string. 348 | * @return A JSONObject containing the structured data from the XML string. 349 | * @throws JSONException 350 | */ 351 | public static JSONObject toJSONObject(String string) throws JSONException { 352 | JSONObject jo = new JSONObject(); 353 | XMLTokener x = new XMLTokener(string); 354 | while (x.more() && x.skipPast("<")) { 355 | parse(x, jo, null); 356 | } 357 | return jo; 358 | } 359 | 360 | 361 | /** 362 | * Convert a JSONObject into a well-formed, element-normal XML string. 363 | * @param object A JSONObject. 364 | * @return A string. 365 | * @throws JSONException 366 | */ 367 | public static String toString(Object object) throws JSONException { 368 | return toString(object, null); 369 | } 370 | 371 | 372 | /** 373 | * Convert a JSONObject into a well-formed, element-normal XML string. 374 | * @param object A JSONObject. 375 | * @param tagName The optional name of the enclosing tag. 376 | * @return A string. 377 | * @throws JSONException 378 | */ 379 | public static String toString(Object object, String tagName) 380 | throws JSONException { 381 | StringBuilder sb = new StringBuilder(); 382 | int i; 383 | JSONArray ja; 384 | JSONObject jo; 385 | String key; 386 | Iterator keys; 387 | int length; 388 | String string; 389 | Object value; 390 | if (object instanceof JSONObject) { 391 | 392 | // Emit 393 | 394 | if (tagName != null) { 395 | sb.append('<'); 396 | sb.append(tagName); 397 | sb.append('>'); 398 | } 399 | 400 | // Loop thru the keys. 401 | 402 | jo = (JSONObject)object; 403 | keys = jo.keys(); 404 | while (keys.hasNext()) { 405 | key = keys.next(); 406 | value = jo.opt(key); 407 | if (value == null) { 408 | value = ""; 409 | } 410 | string = value instanceof String ? (String)value : null; 411 | 412 | // Emit content in body 413 | 414 | if ("content".equals(key)) { 415 | if (value instanceof JSONArray) { 416 | ja = (JSONArray)value; 417 | length = ja.length(); 418 | for (i = 0; i < length; i += 1) { 419 | if (i > 0) { 420 | sb.append('\n'); 421 | } 422 | sb.append(escape(ja.get(i).toString())); 423 | } 424 | } else { 425 | sb.append(escape(value.toString())); 426 | } 427 | 428 | // Emit an array of similar keys 429 | 430 | } else if (value instanceof JSONArray) { 431 | ja = (JSONArray)value; 432 | length = ja.length(); 433 | for (i = 0; i < length; i += 1) { 434 | value = ja.get(i); 435 | if (value instanceof JSONArray) { 436 | sb.append('<'); 437 | sb.append(key); 438 | sb.append('>'); 439 | sb.append(toString(value)); 440 | sb.append("'); 443 | } else { 444 | sb.append(toString(value, key)); 445 | } 446 | } 447 | } else if ("".equals(value)) { 448 | sb.append('<'); 449 | sb.append(key); 450 | sb.append("/>"); 451 | 452 | // Emit a new tag 453 | 454 | } else { 455 | sb.append(toString(value, key)); 456 | } 457 | } 458 | if (tagName != null) { 459 | 460 | // Emit the close tag 461 | 462 | sb.append("'); 465 | } 466 | return sb.toString(); 467 | 468 | // XML does not have good support for arrays. If an array appears in a place 469 | // where XML is lacking, synthesize an element. 470 | 471 | } else { 472 | if (object.getClass().isArray()) { 473 | object = new JSONArray(object); 474 | } 475 | if (object instanceof JSONArray) { 476 | ja = (JSONArray)object; 477 | length = ja.length(); 478 | for (i = 0; i < length; i += 1) { 479 | sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName)); 480 | } 481 | return sb.toString(); 482 | } else { 483 | string = (object == null) ? "null" : escape(object.toString()); 484 | return (tagName == null) ? "\"" + string + "\"" : 485 | (string.length() == 0) ? "<" + tagName + "/>" : 486 | "<" + tagName + ">" + string + ""; 487 | } 488 | } 489 | } 490 | } 491 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/org/json/XMLTokener.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | /** 28 | * The XMLTokener extends the JSONTokener to provide additional methods 29 | * for the parsing of XML texts. 30 | * @author JSON.org 31 | * @version 2014-05-03 32 | */ 33 | public class XMLTokener extends JSONTokener { 34 | 35 | 36 | /** The table of entity values. It initially contains Character values for 37 | * amp, apos, gt, lt, quot. 38 | */ 39 | public static final java.util.HashMap entity; 40 | 41 | static { 42 | entity = new java.util.HashMap(8); 43 | entity.put("amp", XML.AMP); 44 | entity.put("apos", XML.APOS); 45 | entity.put("gt", XML.GT); 46 | entity.put("lt", XML.LT); 47 | entity.put("quot", XML.QUOT); 48 | } 49 | 50 | /** 51 | * Construct an XMLTokener from a string. 52 | * @param s A source string. 53 | */ 54 | public XMLTokener(String s) { 55 | super(s); 56 | } 57 | 58 | /** 59 | * Get the text in the CDATA block. 60 | * @return The string up to the ]]>. 61 | * @throws JSONException If the ]]> is not found. 62 | */ 63 | public String nextCDATA() throws JSONException { 64 | char c; 65 | int i; 66 | StringBuilder sb = new StringBuilder(); 67 | for (;;) { 68 | c = next(); 69 | if (end()) { 70 | throw syntaxError("Unclosed CDATA"); 71 | } 72 | sb.append(c); 73 | i = sb.length() - 3; 74 | if (i >= 0 && sb.charAt(i) == ']' && 75 | sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { 76 | sb.setLength(i); 77 | return sb.toString(); 78 | } 79 | } 80 | } 81 | 82 | 83 | /** 84 | * Get the next XML outer token, trimming whitespace. There are two kinds 85 | * of tokens: the '<' character which begins a markup tag, and the content 86 | * text between markup tags. 87 | * 88 | * @return A string, or a '<' Character, or null if there is no more 89 | * source text. 90 | * @throws JSONException 91 | */ 92 | public Object nextContent() throws JSONException { 93 | char c; 94 | StringBuilder sb; 95 | do { 96 | c = next(); 97 | } while (Character.isWhitespace(c)); 98 | if (c == 0) { 99 | return null; 100 | } 101 | if (c == '<') { 102 | return XML.LT; 103 | } 104 | sb = new StringBuilder(); 105 | for (;;) { 106 | if (c == '<' || c == 0) { 107 | back(); 108 | return sb.toString().trim(); 109 | } 110 | if (c == '&') { 111 | sb.append(nextEntity(c)); 112 | } else { 113 | sb.append(c); 114 | } 115 | c = next(); 116 | } 117 | } 118 | 119 | 120 | /** 121 | * Return the next entity. These entities are translated to Characters: 122 | * & ' > < ". 123 | * @param ampersand An ampersand character. 124 | * @return A Character or an entity String if the entity is not recognized. 125 | * @throws JSONException If missing ';' in XML entity. 126 | */ 127 | public Object nextEntity(char ampersand) throws JSONException { 128 | StringBuilder sb = new StringBuilder(); 129 | for (;;) { 130 | char c = next(); 131 | if (Character.isLetterOrDigit(c) || c == '#') { 132 | sb.append(Character.toLowerCase(c)); 133 | } else if (c == ';') { 134 | break; 135 | } else { 136 | throw syntaxError("Missing ';' in XML entity: &" + sb); 137 | } 138 | } 139 | String string = sb.toString(); 140 | Object object = entity.get(string); 141 | return object != null ? object : ampersand + string + ";"; 142 | } 143 | 144 | 145 | /** 146 | * Returns the next XML meta token. This is used for skipping over 147 | * and structures. 148 | * @return Syntax characters (< > / = ! ?) are returned as 149 | * Character, and strings and names are returned as Boolean. We don't care 150 | * what the values actually are. 151 | * @throws JSONException If a string is not properly closed or if the XML 152 | * is badly structured. 153 | */ 154 | public Object nextMeta() throws JSONException { 155 | char c; 156 | char q; 157 | do { 158 | c = next(); 159 | } while (Character.isWhitespace(c)); 160 | switch (c) { 161 | case 0: 162 | throw syntaxError("Misshaped meta tag"); 163 | case '<': 164 | return XML.LT; 165 | case '>': 166 | return XML.GT; 167 | case '/': 168 | return XML.SLASH; 169 | case '=': 170 | return XML.EQ; 171 | case '!': 172 | return XML.BANG; 173 | case '?': 174 | return XML.QUEST; 175 | case '"': 176 | case '\'': 177 | q = c; 178 | for (;;) { 179 | c = next(); 180 | if (c == 0) { 181 | throw syntaxError("Unterminated string"); 182 | } 183 | if (c == q) { 184 | return Boolean.TRUE; 185 | } 186 | } 187 | default: 188 | for (;;) { 189 | c = next(); 190 | if (Character.isWhitespace(c)) { 191 | return Boolean.TRUE; 192 | } 193 | switch (c) { 194 | case 0: 195 | case '<': 196 | case '>': 197 | case '/': 198 | case '=': 199 | case '!': 200 | case '?': 201 | case '"': 202 | case '\'': 203 | back(); 204 | return Boolean.TRUE; 205 | } 206 | } 207 | } 208 | } 209 | 210 | 211 | /** 212 | * Get the next XML Token. These tokens are found inside of angle 213 | * brackets. It may be one of these characters: / > = ! ? or it 214 | * may be a string wrapped in single quotes or double quotes, or it may be a 215 | * name. 216 | * @return a String or a Character. 217 | * @throws JSONException If the XML is not well formed. 218 | */ 219 | public Object nextToken() throws JSONException { 220 | char c; 221 | char q; 222 | StringBuilder sb; 223 | do { 224 | c = next(); 225 | } while (Character.isWhitespace(c)); 226 | switch (c) { 227 | case 0: 228 | throw syntaxError("Misshaped element"); 229 | case '<': 230 | throw syntaxError("Misplaced '<'"); 231 | case '>': 232 | return XML.GT; 233 | case '/': 234 | return XML.SLASH; 235 | case '=': 236 | return XML.EQ; 237 | case '!': 238 | return XML.BANG; 239 | case '?': 240 | return XML.QUEST; 241 | 242 | // Quoted string 243 | 244 | case '"': 245 | case '\'': 246 | q = c; 247 | sb = new StringBuilder(); 248 | for (;;) { 249 | c = next(); 250 | if (c == 0) { 251 | throw syntaxError("Unterminated string"); 252 | } 253 | if (c == q) { 254 | return sb.toString(); 255 | } 256 | if (c == '&') { 257 | sb.append(nextEntity(c)); 258 | } else { 259 | sb.append(c); 260 | } 261 | } 262 | default: 263 | 264 | // Name 265 | 266 | sb = new StringBuilder(); 267 | for (;;) { 268 | sb.append(c); 269 | c = next(); 270 | if (Character.isWhitespace(c)) { 271 | return sb.toString(); 272 | } 273 | switch (c) { 274 | case 0: 275 | return sb.toString(); 276 | case '>': 277 | case '/': 278 | case '=': 279 | case '!': 280 | case '?': 281 | case '[': 282 | case ']': 283 | back(); 284 | return sb.toString(); 285 | case '<': 286 | case '"': 287 | case '\'': 288 | throw syntaxError("Bad character in a name"); 289 | } 290 | } 291 | } 292 | } 293 | 294 | 295 | /** 296 | * Skip characters until past the requested string. 297 | * If it is not found, we are left at the end of the source with a result of false. 298 | * @param to A string to skip past. 299 | * @throws JSONException 300 | */ 301 | public boolean skipPast(String to) throws JSONException { 302 | boolean b; 303 | char c; 304 | int i; 305 | int j; 306 | int offset = 0; 307 | int length = to.length(); 308 | char[] circle = new char[length]; 309 | 310 | /* 311 | * First fill the circle buffer with as many characters as are in the 312 | * to string. If we reach an early end, bail. 313 | */ 314 | 315 | for (i = 0; i < length; i += 1) { 316 | c = next(); 317 | if (c == 0) { 318 | return false; 319 | } 320 | circle[i] = c; 321 | } 322 | 323 | /* We will loop, possibly for all of the remaining characters. */ 324 | 325 | for (;;) { 326 | j = offset; 327 | b = true; 328 | 329 | /* Compare the circle buffer with the to string. */ 330 | 331 | for (i = 0; i < length; i += 1) { 332 | if (circle[j] != to.charAt(i)) { 333 | b = false; 334 | break; 335 | } 336 | j += 1; 337 | if (j >= length) { 338 | j -= length; 339 | } 340 | } 341 | 342 | /* If we exit the loop with b intact, then victory is ours. */ 343 | 344 | if (b) { 345 | return true; 346 | } 347 | 348 | /* Get the next character. If there isn't one, then defeat is ours. */ 349 | 350 | c = next(); 351 | if (c == 0) { 352 | return false; 353 | } 354 | /* 355 | * Shove the character in the circle buffer and advance the 356 | * circle offset. The offset is mod n. 357 | */ 358 | circle[offset] = c; 359 | offset += 1; 360 | if (offset >= length) { 361 | offset -= length; 362 | } 363 | } 364 | } 365 | } 366 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/servlets/Authenticate.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.annotation.WebServlet; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import utilities.Authentication; 12 | 13 | /** 14 | * Servlet implementation class Authenticate 15 | */ 16 | @WebServlet("/auth") 17 | public class Authenticate extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public Authenticate() { 24 | super(); 25 | } 26 | 27 | /** 28 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 29 | * response) 30 | */ 31 | protected void doGet(HttpServletRequest request, 32 | HttpServletResponse response) throws ServletException, IOException { 33 | doPost(request, response); 34 | } 35 | 36 | /** 37 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 38 | * response) 39 | */ 40 | protected void doPost(HttpServletRequest request, 41 | HttpServletResponse response) throws ServletException, IOException { 42 | String apikey = Authentication.getAPIKey(request); 43 | boolean isValid = Authentication.isAPIKeyValid(apikey); 44 | 45 | if (apikey == null || !isValid) { 46 | Authentication.requireAuthentication(request, response); 47 | } else { 48 | response.getWriter().println("Authorization was successfull!"); 49 | } 50 | 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/servlets/CrunchbaseWrapper.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.StringWriter; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.hp.hpl.jena.rdf.model.Model; 14 | import com.hp.hpl.jena.rdf.model.ModelFactory; 15 | import com.hp.hpl.jena.rdf.model.Resource; 16 | import com.squareup.okhttp.HttpUrl; 17 | import com.squareup.okhttp.OkHttpClient; 18 | import com.squareup.okhttp.Request; 19 | import com.squareup.okhttp.Response; 20 | 21 | import utilities.Authentication; 22 | import utilities.JSONLDHelper; 23 | import utilities.MappingUtility; 24 | import utilities.SPARQLLoader; 25 | 26 | /** 27 | * Servlet implementation class CrunchbaseWrapper 28 | */ 29 | @WebServlet("/api/*") 30 | public class CrunchbaseWrapper extends HttpServlet { 31 | private static final long serialVersionUID = 1L; 32 | private static final boolean SPARQLendpoint = false; // introduced 2018 33 | private static final String CB_API_BASE_URI = "https://api.crunchbase.com/v3.1"; 34 | 35 | // local testing 36 | //private static final String PUBLIC_URL = "http://localhost:8081/CrunchbaseWrapper/api/"; 37 | //private static final String PUBLIC_CONTEXT = "http://localhost:8081/CrunchbaseWrapper/context.jsonld"; 38 | // productive use 39 | // private static final String PUBLIC_URL = "http://corse.informatik.uni-freiburg.de:8080/CrunchbaseWrapper/api/"; 40 | // private static final String PUBLIC_CONTEXT = "http://corse.informatik.uni-freiburg.de:8080/CrunchbaseWrapper/context.jsonld"; 41 | private static final String PUBLIC_URL = "http://linked-crunchbase.org/api/"; 42 | private static final String PUBLIC_CONTEXT = "http://linked-crunchbase.org/context.jsonld"; 43 | 44 | private OkHttpClient client; 45 | private JSONLDHelper jsonldHelper; 46 | 47 | /** 48 | * @see HttpServlet#HttpServlet() 49 | */ 50 | public CrunchbaseWrapper() { 51 | super(); 52 | } 53 | 54 | /** 55 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 56 | * response) 57 | */ 58 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 59 | throws ServletException, IOException { 60 | doPost(request, response); 61 | } 62 | 63 | /** 64 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 65 | * response) 66 | */ 67 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 68 | throws ServletException, IOException { 69 | String endpoint = request.getRequestURI().replaceFirst(request.getContextPath(), ""); // extract api endpoint 70 | // from 71 | // query 72 | endpoint = endpoint.substring(4, endpoint.length()); // remove "/api" 73 | 74 | // determine accept header 75 | String requestAccept = request.getHeader("Accept"); 76 | if (requestAccept == null) { 77 | // set default here 78 | requestAccept = "application/ld+json"; 79 | } 80 | 81 | MappingUtility mu = (MappingUtility) getServletContext().getAttribute(Listener.MAPPING); 82 | 83 | if (request.getHeader("Authorization") == null) { 84 | if (SPARQLendpoint) { 85 | // load sparql stuff 86 | if (requestAccept.contains("json")) { 87 | response.getWriter().println(SPARQLLoader.loadTriple(endpoint, mu, "JSON-LD")); 88 | response.setCharacterEncoding("UTF-8"); 89 | response.setContentType("application/ld+json"); 90 | } else { 91 | response.getWriter().println(SPARQLLoader.loadTriple(endpoint, mu, "N-TRIPLES")); 92 | response.setCharacterEncoding("UTF-8"); 93 | response.setContentType("text/turtle"); 94 | } 95 | } else { 96 | /** use no SPARQL endpoint: **/ 97 | if (requestAccept.contains("json")) { 98 | // response.getWriter().println(SPARQLLoader.loadTriple(endpoint, mu, "JSON-LD")); 99 | response.setCharacterEncoding("UTF-8"); 100 | response.setContentType("application/ld+json"); 101 | response.getWriter().println(addSameAsMappingPredicate(endpoint, mu, "JSON-LD")); 102 | } else { 103 | // response.getWriter().println(SPARQLLoader.loadTriple(endpoint, mu, "N-TRIPLES")); 104 | response.setCharacterEncoding("UTF-8"); 105 | response.setContentType("text/turtle"); 106 | response.getWriter().println(addSameAsMappingPredicate(endpoint, mu, "TTL")); 107 | } 108 | } 109 | } else { 110 | String apikey = Authentication.getAPIKey(request); 111 | 112 | jsonldHelper = new JSONLDHelper(PUBLIC_CONTEXT, CB_API_BASE_URI, PUBLIC_URL, mu); 113 | client = new OkHttpClient(); 114 | client.setConnectTimeout(30, TimeUnit.SECONDS); // maybe increase, 115 | // crunchbase isnt 116 | // always fast 117 | String query = endpoint; 118 | if (request.getQueryString() != null) { 119 | query += "?" + request.getQueryString(); 120 | } 121 | 122 | HttpUrl url = HttpUrl.parse(CB_API_BASE_URI + query); 123 | 124 | url = url.newBuilder().addQueryParameter("user_key", apikey).build(); 125 | // finally build api request for crunchbase 126 | Request apiRequest = new Request.Builder().url(url).build(); 127 | // get api response 128 | Response apiResponse = client.newCall(apiRequest).execute(); 129 | 130 | // set response header of this servlet 131 | response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); 132 | response.setStatus(apiResponse.code()); 133 | response.setCharacterEncoding("UTF-8"); 134 | 135 | String result = apiResponse.body().string(); 136 | // System.out.println(result); 137 | 138 | if (apiResponse.code() == 200) { // errorhandling 139 | // content negotiation 140 | if (requestAccept.contains("text/turtle") || requestAccept.contains("application/x-turtle")) { 141 | // do rdf 142 | response.setContentType("text/turtle"); 143 | response.getWriter().write(jsonldHelper.json2rdf(result, endpoint)); 144 | // System.out.println("DidRDF"); 145 | } else if (requestAccept.contains("application/ld+json") || requestAccept.contains("*/*")) { 146 | // do jsonld 147 | response.setContentType("application/ld+json"); 148 | response.getWriter().write(jsonldHelper.json2jsonld(result, endpoint)); 149 | System.out.println("DidJSONLD"); 150 | } else { 151 | // just display the json from crunchbase 152 | response.setContentType("application/json"); 153 | response.getWriter().write(result); 154 | } 155 | } else if (apiResponse.code() == 401) { 156 | Authentication.requireAuthentication(request, response); 157 | return; 158 | } else { 159 | response.getWriter().write(result); 160 | } 161 | } 162 | } 163 | 164 | /** 165 | * this function generates the baseURI for the RDF transformation from the given 166 | * endpoint and public URL 167 | * 168 | * @param endpoint 169 | * @return 170 | */ 171 | private static String getBaseURI(String endpoint) { 172 | if (endpoint.endsWith("/")) { 173 | endpoint = endpoint.substring(0, endpoint.lastIndexOf("/")); 174 | } 175 | return PUBLIC_URL + "api" + endpoint.substring(0, endpoint.lastIndexOf("/") + 1); 176 | } 177 | 178 | /** 179 | * Takes the given permalink, processes it a bit, checks whether it's an 180 | * organization or a person, then grabs the appropriate mapping for it and 181 | * outputs it with a SAMEAS predicate into a model which is transformed into the 182 | * wanted form of type and returned as such in string representation 183 | * 184 | * @param permalink link to be processed 185 | * @param mu MappingUtility object used for the organization/people 186 | * mapping 187 | * @param type what kind of output type is chosen (e.g. "RDF/XML", 188 | * "RDF/XML-ABBREV", "N-TRIPLE", "TURTLE", (and "TTL") or "N3") 189 | * @return String representation of 190 | * triple 191 | */ 192 | public static String addSameAsMappingPredicate(String permalink, MappingUtility mu, String type) { 193 | final Model model = ModelFactory.createDefaultModel(); 194 | String identifier = permalink.substring(permalink.lastIndexOf("/") + 1) + "#id"; // sth like "facebook#id" 195 | String uri = SPARQLLoader.CBWPREFIX + permalink + "#id"; 196 | 197 | String mapping = null; 198 | if (identifier.startsWith("/organization")) { 199 | mapping = mu.getOrganizationMapping(identifier); 200 | } else if (identifier.startsWith("/people")) { 201 | mapping = mu.getPersonMapping(identifier); 202 | } 203 | 204 | // Add a SAMEAS triple 205 | final Resource cbEntity = model.createResource(uri); 206 | final Resource cbDoc = model.createResource(mapping); 207 | cbEntity.addProperty(SPARQLLoader.sameAs, cbDoc); 208 | StringWriter out = new StringWriter(); 209 | model.write(out, type); 210 | return out.toString(); 211 | 212 | } 213 | 214 | } 215 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/servlets/Listener.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.ServletContextEvent; 5 | import javax.servlet.ServletContextListener; 6 | import javax.servlet.annotation.WebListener; 7 | 8 | import utilities.MappingUtility; 9 | 10 | /** 11 | * Application Lifecycle Listener implementation class Listener 12 | * 13 | */ 14 | @WebListener 15 | public class Listener implements ServletContextListener { 16 | public static String MAPPING = "mapping"; 17 | /** 18 | * @see ServletContextListener#contextDestroyed(ServletContextEvent) 19 | */ 20 | public void contextDestroyed(ServletContextEvent arg0) { 21 | // TODO Auto-generated method stub 22 | } 23 | 24 | /** 25 | * @see ServletContextListener#contextInitialized(ServletContextEvent) 26 | */ 27 | public void contextInitialized(ServletContextEvent event) { 28 | ServletContext ctx = event.getServletContext(); 29 | MappingUtility mu = new MappingUtility(ctx.getResourceAsStream("/organization-mappings.nt"), ctx.getResourceAsStream("/people-mappings.nt")); 30 | ctx.setAttribute(MAPPING, mu); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/Authentication.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.apache.commons.codec.binary.Base64; 12 | 13 | import com.squareup.okhttp.HttpUrl; 14 | import com.squareup.okhttp.OkHttpClient; 15 | import com.squareup.okhttp.Request; 16 | import com.squareup.okhttp.Response; 17 | 18 | public class Authentication { 19 | public static void requireAuthentication(HttpServletRequest request, HttpServletResponse response) 20 | throws IOException { 21 | response.setHeader("WWW-Authenticate", "Basic"); 22 | response.setStatus(401); 23 | response.setContentType("text/html"); 24 | // response.getWriter() 25 | // .print("Please provide the Crunchbase API key as username with empty password"); 26 | RequestDispatcher rd = request.getRequestDispatcher("/html/authentication.html"); 27 | try { 28 | rd.forward(request, response); 29 | } catch (ServletException e) { 30 | // TODO Auto-generated catch block 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | public static String getAPIKey(HttpServletRequest request) { 36 | String apikey = null; 37 | String auth = request.getHeader("Authorization"); 38 | if (auth != null && auth.startsWith("Basic")) { 39 | String base64 = auth.substring("Basic".length()).trim(); 40 | String cred = new String(Base64.decodeBase64(base64.getBytes())); 41 | // credentials = username:password 42 | final String[] values = cred.split(":", 2); 43 | if (values.length == 2 && values[0].trim().length() > 0) { 44 | apikey = values[0].trim(); 45 | } 46 | } 47 | return apikey; 48 | } 49 | 50 | public static boolean isAPIKeyValid(String apikey) throws IOException { 51 | String urlStr = "https://api.crunchbase.com/v3.1/organizations/facebook?user_key=" + apikey; 52 | OkHttpClient client = new OkHttpClient(); 53 | client.setConnectTimeout(30, TimeUnit.SECONDS); 54 | 55 | HttpUrl url = HttpUrl.parse(urlStr); 56 | Request apiRequest = new Request.Builder().url(url).build(); 57 | // get api response 58 | Response apiResponse = client.newCall(apiRequest).execute(); 59 | 60 | return apiResponse.code() == 200; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/JSONHelper.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | public class JSONHelper { 10 | /** 11 | * moves recursivley the content of keyName one step up and removes the key 12 | * @param json 13 | * @param keyName 14 | */ 15 | public static void removeAndMoveUp(JSONObject json, String keyName) { 16 | if (json.has(keyName)) { 17 | JSONObject keyObjects = json.getJSONObject(keyName); 18 | Iterator keyIterator = keyObjects.keys(); 19 | while (keyIterator.hasNext()) { 20 | String key = keyIterator.next(); 21 | json.put(key, keyObjects.get(key)); 22 | } 23 | json.remove(keyName); 24 | } 25 | 26 | Iterator keyIterator = json.keys(); 27 | while (keyIterator.hasNext()) { 28 | String key = keyIterator.next(); 29 | try { 30 | Object object = json.get(key); 31 | if (object instanceof JSONObject) { 32 | JSONHelper.removeAndMoveUp((JSONObject)object, keyName); 33 | } else if (object instanceof JSONArray) { 34 | JSONArray array = (JSONArray) object; 35 | Iterator arrayIterator = array.iterator(); 36 | while (arrayIterator.hasNext()) { 37 | Object jso = arrayIterator.next(); 38 | if (jso instanceof JSONObject) { 39 | JSONHelper.removeAndMoveUp((JSONObject)jso, keyName); 40 | } 41 | } 42 | } 43 | } catch (JSONException e) { 44 | } 45 | } 46 | } 47 | 48 | /** 49 | * Sets a the keyName with the @id tag. The backwardSlashes are important to resolve URLs correctly 50 | * @param json 51 | * @param keyName 52 | * @param backward sth like ../, ../../, or just an empty string 53 | */ 54 | public static void useAsID(JSONObject json, String keyName, String backward) { 55 | if (json.has(keyName)) { 56 | String id = URIEncoder.encodeURIPath(backward+json.getString(keyName)); 57 | json.put("@id", id+"#id"); 58 | 59 | JSONObject documentLicense = new JSONObject(); 60 | documentLicense.put("@id", id); 61 | documentLicense.put("cc:license", "http://creativecommons.org/licenses/by-nc/4.0/"); 62 | json.put("foaf:page", documentLicense); 63 | } 64 | 65 | Iterator keyIterator = json.keys(); 66 | while (keyIterator.hasNext()) { 67 | String key = keyIterator.next(); 68 | try { 69 | Object object = json.get(key); 70 | if (object instanceof JSONObject) { 71 | JSONHelper.useAsID((JSONObject)object, keyName, backward); 72 | } else if (object instanceof JSONArray) { 73 | JSONArray array = (JSONArray) object; 74 | Iterator arrayIterator = array.iterator(); 75 | while (arrayIterator.hasNext()) { 76 | Object jso = arrayIterator.next(); 77 | if (jso instanceof JSONObject) { 78 | JSONHelper.useAsID((JSONObject)jso, keyName, backward); 79 | } 80 | } 81 | } 82 | 83 | } catch (JSONException e) { 84 | 85 | } 86 | 87 | } 88 | } 89 | 90 | 91 | /** 92 | * This replaces the value of the key with backwardSlashes and the URI-Encoded version of the url. 93 | * This is important to resolve urls correctly 94 | * @param json 95 | * @param keyName 96 | * @param backwardSlashes 97 | */ 98 | public static void addPrefixToAllValuesOfKey(JSONObject json, String keyName, 99 | String backwardSlashes) { 100 | if (json.has(keyName)) { 101 | json.put(keyName, URIEncoder.encodeURIPath(backwardSlashes+json.getString(keyName))); 102 | } 103 | 104 | Iterator keyIterator = json.keys(); 105 | while (keyIterator.hasNext()) { 106 | String key = keyIterator.next(); 107 | try { 108 | Object object = json.get(key); 109 | if (object instanceof JSONObject) { 110 | JSONHelper.addPrefixToAllValuesOfKey((JSONObject)object, keyName, backwardSlashes); 111 | } else if (object instanceof JSONArray) { 112 | JSONArray array = (JSONArray) object; 113 | Iterator arrayIterator = array.iterator(); 114 | while (arrayIterator.hasNext()) { 115 | Object jso = arrayIterator.next(); 116 | if (jso instanceof JSONObject) { 117 | JSONHelper.addPrefixToAllValuesOfKey((JSONObject)jso, keyName, backwardSlashes); 118 | } 119 | } 120 | } 121 | } catch (JSONException e) { 122 | } 123 | } 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/JSONLDHelper.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.OutputStream; 6 | import java.util.Collection; 7 | import java.util.Iterator; 8 | 9 | import org.apache.jena.atlas.json.io.parser.JSONParser; 10 | import org.apache.jena.riot.Lang; 11 | import org.apache.jena.riot.RDFDataMgr; 12 | import org.apache.jena.riot.lang.CollectorStreamTriples; 13 | import org.json.JSONObject; 14 | 15 | import com.hp.hpl.jena.graph.Triple; 16 | 17 | /** 18 | * This class is the core of our 19 | * @author Carsten 20 | * 21 | */ 22 | public class JSONLDHelper { 23 | private static final String PREFIX = "cbw:"; // for fetching data 24 | private String context; 25 | private String baseURI; 26 | private String baseURIRDF; 27 | 28 | private MappingUtility mu; 29 | 30 | public JSONLDHelper(String context, String cbApiBaseUri, String baseURIRDF, MappingUtility mu) { 31 | this.mu = mu; 32 | this.context = context; 33 | this.baseURI = cbApiBaseUri; 34 | this.baseURIRDF = baseURIRDF; 35 | } 36 | 37 | /** 38 | * This Method converts a given JSON string to JSON-LD 39 | * @param json JSON String 40 | * @param endpoint the called API-Endpoint 41 | * @param addMapping if true, add mapping to known types 42 | * @return 43 | */ 44 | public String json2jsonld(String json, String endpoint) { 45 | System.out.println("Endpoint " + endpoint); 46 | String id = endpoint; 47 | // JSON as given from Crunchbase 48 | JSONObject jsonObject = new JSONObject(json); 49 | 50 | // output jsonld object 51 | JSONObject jsonld = new JSONObject(); 52 | 53 | jsonld.put("@context", context); 54 | 55 | int slashCount = id.length() - id.replace("/", "").length(); 56 | String backwardSlashes = ""; // this is used to indicate the api depth. a dirty solution, but it works... 57 | // if (slashCount == 1) { 58 | backwardSlashes = "./"; 59 | id = backwardSlashes +id.substring(1); 60 | // } else if (slashCount == 2) { 61 | // backwardSlashes = "../"; 62 | // id = backwardSlashes +id.substring(1); //permalink as ID 63 | // } else if (slashCount == 3) { 64 | // backwardSlashes = "../../"; 65 | // id = backwardSlashes + id.substring(1, id.lastIndexOf("/")); 66 | // } 67 | jsonld.put("@id", URIEncoder.encodeURIPath(id)+"#id"); 68 | JSONObject documentLicense = new JSONObject(); 69 | System.out.println(URIEncoder.encodeURIPath(id)); 70 | documentLicense.put("@id", URIEncoder.encodeURIPath(id)); 71 | documentLicense.put("cc:license", "http://creativecommons.org/licenses/by-nc/4.0/"); 72 | jsonld.put("foaf:page", documentLicense); 73 | 74 | // get relevant json data from response 75 | JSONObject data = jsonObject.getJSONObject("data"); 76 | for (String prop: JSONObject.getNames(data)) { 77 | jsonld.put(prop, data.get(prop)); 78 | } 79 | 80 | if (jsonld.has("paging")) { 81 | JSONObject paging = jsonld.getJSONObject("paging"); 82 | if (!paging.isNull("next_page_url")) { 83 | if (paging.has("number_of_pages") && paging.has("current_page")) { 84 | if (paging.getInt("current_page") < paging.getInt("number_of_pages")) { 85 | String pagingURI = backwardSlashes + paging.getString("next_page_url").replace(baseURI+"/", "/"); 86 | jsonld.put(PREFIX+"next_page_url", URIEncoder.encodeURIPath(pagingURI)); 87 | //System.out.print("PagingUrl" + URIEncoder.encodeURIPath(pagingURI)); 88 | } 89 | } 90 | } 91 | //by ali for key_set_url part1 92 | if (!paging.isNull("key_set_url")) { 93 | String keySetURI = backwardSlashes + paging.getString("key_set_url").replace(baseURI+"/", "/"); 94 | jsonld.put(PREFIX+"key_set_url", URIEncoder.encodeURIPath(keySetURI)); 95 | //System.out.print("KeySetUrl" + URIEncoder.encodeURIPath(keySetURI)); 96 | } 97 | //End of by ali for key_set_url part1 98 | 99 | jsonld.put("total_items", paging.getInt("total_items")); 100 | jsonld.remove("paging"); // To test Ali 101 | } 102 | 103 | 104 | if (jsonld.has("items")) { // for facebook/news 105 | String relationship = endpoint.substring(endpoint.lastIndexOf("/")+1); 106 | jsonld.put(relationship, jsonld.get("items")); // use API prefix to avoid confusion: api_news contains a link to news, news the blanknodes with actual news 107 | jsonld.remove("items"); 108 | JSONObject newObject = new JSONObject(); 109 | newObject.put("@id", backwardSlashes + endpoint.substring(1)); 110 | newObject.put("total_items", jsonld.get("total_items")); 111 | jsonld.remove("total_items"); 112 | 113 | if (jsonld.has(PREFIX+"next_page_url")) { 114 | newObject.put(PREFIX+"next_page_url", jsonld.get(PREFIX+"next_page_url")); 115 | jsonld.remove(PREFIX+"next_page_url"); 116 | } 117 | jsonld.put(PREFIX+relationship, newObject); 118 | } else if (jsonld.has("relationships")) { 119 | JSONObject relationships = jsonld.getJSONObject("relationships"); 120 | Iterator relations = relationships.keys(); 121 | while (relations.hasNext()) { 122 | String key = relations.next(); 123 | JSONObject relationship = relationships.getJSONObject(key); 124 | if (relationship.has("paging")) { 125 | JSONObject paging = relationship.getJSONObject("paging"); 126 | int totalItems = paging.getInt("total_items"); 127 | String firstPageURL = paging.getString("first_page_url").replace(baseURI+"/", ""); 128 | JSONObject newObject = new JSONObject(); 129 | newObject.put("@id", backwardSlashes + firstPageURL); 130 | newObject.put("total_items", totalItems); 131 | jsonld.put(PREFIX+key, newObject); 132 | } 133 | 134 | if (relationship.has("items")) { 135 | jsonld.put(key, relationship.get("items")); 136 | } 137 | if (relationship.has("item")) { 138 | jsonld.put(key, relationship.get("item")); 139 | } 140 | } 141 | jsonld.remove("relationships"); 142 | } 143 | 144 | // get every child in "relationships" and move it one step up 145 | JSONHelper.removeAndMoveUp(jsonld, "relationships"); 146 | // get every child in "properties" and move it one step up 147 | JSONHelper.removeAndMoveUp(jsonld, "properties"); 148 | // use the api_path as "@id" in json-ld 149 | JSONHelper.useAsID(jsonld, "api_path", backwardSlashes); 150 | // add "backwardslashes" to every api_path, so it is relative to the right url 151 | JSONHelper.addPrefixToAllValuesOfKey(jsonld, "api_path", backwardSlashes); 152 | //JSONHelper.addPrefixToAllValuesOfKey(jsonld, "next_page_url", backwardSlashes);//By Ali 153 | 154 | mu.insertMapping(jsonld); 155 | 156 | return jsonld.toString(2); 157 | } 158 | 159 | public String json2rdf(String json, String endpoint) { 160 | CollectorStreamTriples sink = new CollectorStreamTriples(); 161 | //System.out.println("This is Json:"); 162 | //System.out.println("This is Json:" +json); 163 | try { 164 | String jsonld = this.json2jsonld(json, endpoint); 165 | ByteArrayInputStream jsonldStream = new ByteArrayInputStream(jsonld.getBytes()); 166 | RDFDataMgr.parse(sink, jsonldStream, baseURIRDF, Lang.JSONLD); 167 | OutputStream out = new ByteArrayOutputStream(); 168 | Collection triples = sink.getCollected(); 169 | RDFDataMgr.writeTriples(out, triples.iterator()); 170 | return out.toString(); 171 | } 172 | catch (Exception e) {//By Ali to handle invalid urls in news summary 173 | String jsonld = this.json2jsonld(json, endpoint); 174 | JSONObject jsonObject = new JSONObject(jsonld); 175 | jsonObject.remove("news"); 176 | String jsonldObjectString = jsonObject.toString(2); 177 | ByteArrayInputStream jsonldStream = new ByteArrayInputStream(jsonldObjectString.getBytes()); 178 | RDFDataMgr.parse(sink, jsonldStream, baseURIRDF, Lang.JSONLD); 179 | OutputStream out = new ByteArrayOutputStream(); 180 | Collection triples = sink.getCollected(); 181 | RDFDataMgr.writeTriples(out, triples.iterator()); 182 | return out.toString(); 183 | } 184 | 185 | 186 | 187 | 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/MappingUtility.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | import org.json.JSONArray; 10 | import org.json.JSONException; 11 | import org.json.JSONObject; 12 | 13 | 14 | 15 | public class MappingUtility { 16 | private final static String TYPE = "type"; 17 | private final static String SAMEAS = "owl:sameAs"; 18 | private HashMap organizationMapping; 19 | private HashMap personMapping; 20 | 21 | public MappingUtility(InputStream inputStream, InputStream inputStream2) { 22 | 23 | try { 24 | readMappings(inputStream, inputStream2); 25 | } catch (IOException e) { 26 | // TODO Auto-generated catch block 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | /** 32 | * Iterates recursively over the whole JSON structure and inserts the mapping 33 | */ 34 | public void insertMapping(JSONObject json) { 35 | if (json.has(TYPE)) { 36 | String type = json.getString(TYPE); 37 | String sameAs = ""; 38 | if (!json.isNull("permalink")) { 39 | String permalink = json.getString("permalink")+ "#id"; 40 | if (type.equals("Organization")) { 41 | sameAs = organizationMapping.get(permalink); 42 | } 43 | else if(type.equals("Person")) { 44 | sameAs = personMapping.get(permalink); 45 | } 46 | } 47 | if ((sameAs != null) && (!sameAs.isEmpty())) { 48 | json.put(SAMEAS, sameAs); 49 | } 50 | } 51 | 52 | Iterator keyIterator = json.keys(); 53 | while (keyIterator.hasNext()) { 54 | String key = keyIterator.next(); 55 | try { 56 | Object object = json.get(key); 57 | if (object instanceof JSONObject) { 58 | this.insertMapping((JSONObject)object); 59 | } else if (object instanceof JSONArray) { 60 | JSONArray array = (JSONArray) object; 61 | Iterator arrayIterator = array.iterator(); 62 | while (arrayIterator.hasNext()) { 63 | Object jso = arrayIterator.next(); 64 | if (jso instanceof JSONObject) { 65 | this.insertMapping((JSONObject)jso); 66 | } 67 | } 68 | } 69 | } catch (JSONException e) { 70 | } 71 | } 72 | } 73 | 74 | public String getOrganizationMapping(String identifier) { 75 | return organizationMapping.get(identifier); 76 | } 77 | 78 | public String getPersonMapping(String identifier) { 79 | return personMapping.get(identifier); 80 | } 81 | 82 | 83 | private void readMappings(InputStream inputStreamMappings1, InputStream inputStreamMappings2) throws IOException { 84 | /** organization mappings **/ 85 | organizationMapping = new HashMap<>(); 86 | BufferedReader br; 87 | String line; 88 | int startIndex = 46; // length of http://linked-crunchbase.org/api/organization/ organization-mappings.nt file. Need to change when 89 | // the mapping file has new address for organizations corresponding to my project 90 | br = new BufferedReader(new InputStreamReader(inputStreamMappings1)); 91 | String tmp; 92 | while ((line = br.readLine()) != null) { 93 | tmp = line.trim(); 94 | if (!tmp.isEmpty()) { 95 | String[] splittedStrings = tmp.split("\\s+"); // split by whitespace: . 96 | String cbEntity = splittedStrings[0]; 97 | String dbpEntity = splittedStrings[2]; 98 | dbpEntity = dbpEntity.substring(1, dbpEntity.length()-1); // remove braces < > 99 | cbEntity = cbEntity.substring(1, cbEntity.length()-1); // remove braces < > 100 | cbEntity = cbEntity.substring(startIndex); // remove the prefix http://linked-crunchbase.org/api/organization/ 101 | organizationMapping.put(cbEntity, dbpEntity); 102 | } 103 | } 104 | br.close(); 105 | br = null; 106 | 107 | /** person mappings **/ 108 | personMapping = new HashMap<>(); 109 | line = null; 110 | startIndex = 40; // length of "http://linked-crunchbase.org/api/people/" in people-mappings.nt file . Need to change when 111 | // the mapping file has new address for organizations corresponding to my project 112 | br = new BufferedReader(new InputStreamReader(inputStreamMappings2)); 113 | tmp = null; 114 | while ((line = br.readLine()) != null) { 115 | tmp = line.trim(); 116 | if (!tmp.isEmpty()) { 117 | String[] splittedStrings = tmp.split("\\s+"); // split by whitespace: . 118 | String cbEntity = splittedStrings[0]; 119 | String dbpEntity = splittedStrings[2]; 120 | dbpEntity = dbpEntity.substring(1, dbpEntity.length()-1); // remove braces < > 121 | cbEntity = cbEntity.substring(1, cbEntity.length()-1); // remove braces < > 122 | cbEntity = cbEntity.substring(startIndex); // remove the prefix http://linked-crunchbase.org/api/organization/ 123 | organizationMapping.put(cbEntity, dbpEntity); 124 | } 125 | 126 | } 127 | br.close(); 128 | br = null; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/SPARQLLoader.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.io.StringWriter; 4 | 5 | import com.hp.hpl.jena.query.Query; 6 | import com.hp.hpl.jena.query.QueryExecution; 7 | import com.hp.hpl.jena.query.QueryExecutionFactory; 8 | import com.hp.hpl.jena.query.QueryFactory; 9 | import com.hp.hpl.jena.rdf.model.Model; 10 | import com.hp.hpl.jena.rdf.model.ModelFactory; 11 | import com.hp.hpl.jena.rdf.model.Property; 12 | import com.hp.hpl.jena.rdf.model.Resource; 13 | import com.hp.hpl.jena.rdf.model.ResourceFactory; 14 | 15 | 16 | public class SPARQLLoader { 17 | public final static String CBWPREFIX = "http://linked-crunchbase.org/api"; 18 | private final static String SERVICE = "http://linked-crunchbase.org:8890/sparql"; // invalid now, since data cannot be provided via SPARQL 19 | private final static String constructQueryString = "PREFIX cb: " 20 | + "PREFIX foaf: " + "PREFIX rdf: " 21 | + "CONSTRUCT {" + "?s foaf:homepage ?url . " + "?s rdf:type ?type . " 22 | + "} FROM where {" + "?s cb:web_path ?o. " + "?s a ?type . " 23 | + "BIND (URI(CONCAT(\"https://www.crunchbase.com/\", ?o)) AS ?url) " + "VALUES ?s { <%s>}" + "}"; 24 | 25 | public final static Property sameAs = ResourceFactory.createProperty("http://www.w3.org/2002/07/owl#sameAs"); 26 | private final static Property document = ResourceFactory.createProperty("http://xmlns.com/foaf/0.1/page"); 27 | private final static Property license = ResourceFactory.createProperty("http://creativecommons.org/ns#license"); 28 | 29 | public SPARQLLoader() { 30 | // TODO Auto-generated constructor stub 31 | } 32 | 33 | 34 | public static String loadTriple(String permalink, MappingUtility mu, String type) { 35 | // e.g., permalink=="/organizations/facebook" 36 | String identifier = permalink.substring(permalink.lastIndexOf("/") + 1) + "#id"; // sth like "facebook#id" 37 | String uri = CBWPREFIX + permalink + "#id"; 38 | String docUri = CBWPREFIX + permalink; 39 | Query query = QueryFactory.create(String.format(constructQueryString, uri)); 40 | QueryExecution quexec = QueryExecutionFactory.sparqlService(SERVICE, query); 41 | 42 | Model results = quexec.execConstruct(); 43 | String mapping = null; 44 | if (identifier.startsWith("/organization")) { 45 | mapping = mu.getOrganizationMapping(identifier); 46 | } else if (identifier.startsWith("/people")) { 47 | mapping = mu.getPersonMapping(identifier); 48 | } 49 | // System.out.println(identifier + " -- " + mapping); 50 | 51 | Resource cbEntity = results.getResource(uri); 52 | Resource cbDoc = results.createResource(docUri); 53 | if (mapping != null) { 54 | cbEntity.addProperty(sameAs, results.createResource(mapping)); 55 | } 56 | cbEntity.addProperty(document, cbDoc); 57 | cbDoc.addProperty(license, results.createResource("http://creativecommons.org/licenses/by-nc/4.0/")); 58 | 59 | StringWriter out = new StringWriter(); 60 | results.write(out, type); 61 | return out.toString(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /CrunchbaseWrapper/src/utilities/URIEncoder.java: -------------------------------------------------------------------------------- 1 | package utilities; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.URLEncoder; 5 | 6 | public class URIEncoder { 7 | /** 8 | * this function encodes a given URI Path, but keeps the URL Structure and URL Parameters 9 | */ 10 | public static String encodeURIPath(String path) { 11 | String delimiter = "/"; 12 | StringBuilder sb = new StringBuilder(); 13 | for (String str : path.split(delimiter)) { 14 | try { 15 | sb.append(URLEncoder.encode(str, "UTF-8")); 16 | } catch (UnsupportedEncodingException e) { 17 | // TODO Auto-generated catch block 18 | e.printStackTrace(); 19 | } 20 | sb.append(delimiter); 21 | } 22 | 23 | String encodedURIPath = sb.toString(); 24 | if (!path.endsWith(delimiter)) { 25 | encodedURIPath = encodedURIPath.substring(0, encodedURIPath.length()-1); 26 | } 27 | encodedURIPath = encodedURIPath.replace("%3F", "?"); 28 | encodedURIPath = encodedURIPath.replace("%3D", "="); 29 | encodedURIPath = encodedURIPath.replace("%26", "&"); 30 | //Change 5 for next_page_url 31 | encodedURIPath = encodedURIPath.replace("%2520", "%20"); 32 | //End of Change 5 33 | return encodedURIPath; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linked-crunchbase 2 | 3 | This repository provides 4 | * the **code for a Linked Data API for [Crunchbase](https://data.crunchbase.com/)**. See the Java project in the subfolder [CrunchbaseWrapper](CrunchbaseWrapper/README.md). 5 | * **instructions how to obtain a Crunchbase RDF data set** (i.e, knowledge graph) by crawling this Linked Data API. See the following. 6 | 7 | 8 | ## Instructions for Crawling CrunchBase 9 | __Prerequisites__: You need to have an API key from Crunchbase (either for research purposes or for commercial interests). New API keys can be requested [here](https://data.crunchbase.com/docs/license-agreement). 10 | 11 | ### Overview 12 | The following steps need to be performed: 13 | 1. Downloading the CSV files from the Crunchbase API website. 14 | 2. Converting the CSV files data into the RDF format to be readable by linked data tools. 15 | 3. Using our Crunchbase wrapper and a data integration/crawling tool, such as Linked Data-Fu, to perform the crawling. 16 | 17 | In the following, we explain these steps in more detail. Generally, we first crawl the data concerning organizations, people, and other entity types except news. Then, the data about news are separately crawled to ensure that all data is retrieved (due to data provisioning constraints of Crunchbase). Since the Crunchbase API has increased its functionality recently, all steps can be crawled now also with the second method directly. 18 | 19 | ### Crawling Organizations etc. 20 | #### Step 1: Downloading CSV Files 21 | Firstly, the CSV node keys files need to be downloaded from the Crunchbase website (https://data.crunchbase.com/docs/node-export). The direct download link is as follows: 22 | 23 | https://api.crunchbase.com/v3.1/node_keys/node_keys.tar.gz?user_key={user_key} 24 | 25 | _user_key_ is thereby the Crunchbase API key of the user. In the downloaded compressed file, there is a CSV file for (almost) each entity type. As we exemplarily crawl organizations, we pick the file _organizations.csv_. 26 | This CSV file includes a _NAME_ and _PERMALINK_ of all existing companies in Crunchbase. 27 | 28 | #### Step 2: Converting Data of CSV files to RDF 29 | We use a program to convert the _permalinks_ in the CSV files to the RDF format. To that end, we use [this](crawling/CsvReader.java) Java class. The permalinks, which has the form _/organizations/facebook_ is converted into the form of 30 | ``` 31 | . 32 | ``` 33 | Note that the specification of 250 as _items_per_page_ is meant for indicating that 250 items should be returned for the given resource (here: _/organizations/facebook_ ). In our evaluation, 250 was the highest number which was supported by the Crunchbase API. Using this parameter, we can reach 99.99% of the Crunchbase data. Only all data concerning news articles might not be reached with this parameter. In our Java implementation, we store the RDF data as an nt-file, which is used in the following steps. 34 | 35 | #### Step 3: Running Linked Data-Fu 36 | Using the nt file of the previous step, we use _Linked Data-Fu_ to crawl the Crunchbase data. [Linked Data Fu](https://linked-data-fu.github.io) can be requested from the developers. 37 | 38 | The following command starts the Linked Data-Fu program for our crawling of organizations: 39 | ``` 40 | time linked-data-fu-0.9.12/bin/ldfu.sh -p get-organizations-crawling-rule.n3 -i output-of-java-program.nt -c ldfu.properties -o complete-organization-data.nt 41 | ``` 42 | The used files are described in the following: 43 | 44 | - **get-organizations-crawling-rule.n3** is a N3 file that includes the rule which is used by Linked Data-Fu to understand how to follow the _api_path_ of organizations. An example configuration is given in the following: 45 | ``` 46 | @prefix rdf: . 47 | @prefix foaf: . 48 | @prefix http: . 49 | @prefix httpm: . 50 | @prefix rdfs: . 51 | @prefix owl: . 52 | @prefix dbpedia: . 53 | @prefix dbo: . 54 | @prefix cb: . 55 | @prefix cbw: . 56 | 57 | 58 | { 59 | ?x cbw:api_path ?next . 60 | } => { 61 | [] http:mthd httpm:GET ; 62 | http:requestURI ?next ; 63 | http:fieldName "Authorization" ; 64 | http:fieldValue "Basic Y3J1bmNoYmFzZSBpcyB0aGUga2V5" . 65 | } . 66 | ``` 67 | 68 | "Basic Y3J1bmNoYmFzZSBpcyB0aGUga2V5" is thereby the Base64 encoded version of the user's Crunchbase API key. 69 | This N3 file is kept general and can be used for crawling also the other entity types. 70 | 71 | - **output-of-java-program.nt** is the RDF file that we created in the step above and which serves now as input file. It includes the api_path's of all organizations. 72 | 73 | - **ldfu.properties** includes the settings for controlling the delays and parallelism of requests to fulfill Crunchbase API limitations. We use the following configuration as content of ldfu.properties: 74 | ``` 75 | # timeouts managed by HttpClient 76 | ldfu.http.connecttimeout=16000 77 | ldfu.http.sockettimeout=32000 78 | # how many parallel connections to one host 79 | # managed by HttpClient; use in combination with 80 | # ldfu.originqueue (rule of thumb: use originqueue=POLITE for 81 | # maxroutesperhost == 1, originqueue=FIFO for maxroutesperhost > 1 82 | ldfu.http.maxroutesperhost=1 83 | # at what rate to do lookups; works only with originqueue=POLITE 84 | # 1 request per crawlrate ms 85 | ldfu.http.crawlrate=1 86 | # number of retries for failing HTTP requests 87 | ldfu.http.retries=8 88 | ldfu.originqueue = POLITE 89 | ``` 90 | - **complete-organization-data.nt** is the output RDF file containing (hopefully) all Crunchbase data about organizations. 91 | 92 | The outlined steps can be used to crawl also other entity types. In case there is no _permalink_ in the CSV file (e.g., acquisitions do not have any permalink, as a permalink is a natural-language naming but acquisitions do not have names), the _uuid_ should be used instead. 93 | 94 | ### Crawling News 95 | For crawling all data represented about news articles, we use the following method. In this method, the parameter _key_set_url_ of the Crunchbase API is used. We directly use Linked Data-Fu without downloading any CSV file here. The below command should be run and uses again Linked Data-Fu: 96 | ``` 97 | time linked-data-fu-0.9.12/bin/ldfu.sh -p get-news-summary-using-keyseturl.n3 -c ldfu.properties -o all-news.nt 98 | ``` 99 | The files are identical to the previous crawling method. _all-news.nt_ is the output nt file. 100 | _get-news-summary-using-keyseturl.n3_ can be specified as follows: 101 | ``` 102 | @prefix rdf: . 103 | @prefix foaf: . 104 | @prefix http: . 105 | @prefix httpm: . 106 | @prefix rdfs: . 107 | @prefix owl: . 108 | @prefix dbpedia: . 109 | @prefix dbo: . 110 | @prefix cb: . 111 | @prefix cbw: . 112 | 113 | { 114 | [] http:mthd httpm:GET ; 115 | http:requestURI 116 | ; 117 | http:fieldName "Authorization" ; 118 | http:fieldValue "Basic Y3J1bmNoYmFzZSBpcyB0aGUga2V5" . 119 | } 120 | 121 | { 122 | ?x cbw:key_set_url ?next . 123 | } => { 124 | [] http:mthd httpm:GET ; 125 | http:requestURI ?next ; 126 | http:fieldName "Authorization" ; 127 | http:fieldValue "Basic Y3J1bmNoYmFzZSBpcyB0aGUga2V5" . 128 | } . 129 | ``` 130 | "Basic Y3J1bmNoYmFzZSBpcyB0aGUga2V5" is again the Base64 encoding of the user's API key for Crunchbase. Note that this second method can be used for crawling the summary of other entity types as well. We did not do that so far, since Crunchbase' API functionality for that was added at a later stage. 131 | 132 | ## Contributors 133 | * Michael Färber, michael.faerber@kit.edu, Karlsruhe Institute of Technoogy (previously: University of Freiburg) 134 | * Ali Aghaee, University of Freiburg 135 | * Andreas Harth, Friedrich-Alexander-Universität Erlangen-Nürnberg 136 | 137 | ## Contact 138 | michael.faerber@kit.edu 139 | 140 | ## Further Information and References 141 | 1. Michael Färber: [Linked Crunchbase: A Linked Data API and RDF Data Set About Innovative Companies](https://arxiv.org/pdf/1907.08671.pdf), arXiv preprint arXiv:1907.08671, 2019. 142 | 2. Michael Färber, Carsten Menne, Andreas Harth: [A Linked Data Wrapper for CrunchBase](http://semantic-web-journal.net/system/files/swj1493.pdf), Semantic Web Journal 9(4), IOS Press, 2018, pp. 505–5015. 143 | 144 | _Last change: Aug 2019_ 145 | -------------------------------------------------------------------------------- /crawling/CsvReader.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedWriter; 2 | import java.io.File; 3 | import java.io.FileOutputStream; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.io.OutputStreamWriter; 7 | 8 | //https://mvnrepository.com/artifact/au.com.bytecode/opencsv/2.4 9 | import au.com.bytecode.opencsv.CSVReader; 10 | 11 | public class CsvReader { 12 | 13 | //Here you should write the file name of the CSV input file and the NT output file 14 | //In case CSV file is too large, you could divide the output file to 2 parts by specifying the middle of the file 15 | public static String OutputNtFileNamePart1= "summary-organization-part1.nt"; 16 | public static String OutputNtFileNamePart2= "summary-organization-part2.nt"; 17 | public static String inputCsvFileName= "organizations.csv"; 18 | public static int midDataRow=300000; 19 | 20 | 21 | public static void main(String[] args) throws IOException { 22 | 23 | File fout1 = new File(OutputNtFileNamePart1); 24 | FileOutputStream fos1 = new FileOutputStream(fout1); 25 | 26 | BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(fos1)); 27 | 28 | File fout2 = new File(OutputNtFileNamePart2); 29 | FileOutputStream fos2 = new FileOutputStream(fout2); 30 | 31 | BufferedWriter bw2 = new BufferedWriter(new OutputStreamWriter(fos2)); 32 | 33 | //The library for CSV reader should be added from https://mvnrepository.com/artifact/au.com.bytecode/opencsv/2.4 34 | CSVReader reader = new CSVReader(new FileReader(inputCsvFileName)); 35 | 36 | String [] nextLine; 37 | int i=0; 38 | while ((nextLine = reader.readNext()) != null) { 39 | if(i ."); 44 | bw1.newLine(); 45 | i++; 46 | } 47 | else { 48 | bw2.write(" ."); 49 | bw2.newLine(); 50 | } 51 | 52 | } 53 | 54 | bw1.close(); 55 | bw2.close(); 56 | } 57 | 58 | } 59 | --------------------------------------------------------------------------------