Revision 1789
Added by Matt Jones almost 21 years ago
MetacatClient.java | ||
---|---|---|
185 | 185 |
* @param xmlDocument a Reader for accessing the XML document to be inserted |
186 | 186 |
* @param schema a Reader for accessing the DTD or XML Schema for |
187 | 187 |
* the document |
188 |
* @return the metacat response message |
|
188 | 189 |
* @throws InsufficientKarmaException when the user has insufficent rights |
189 | 190 |
* for the operation |
191 |
* @throws MetacatInaccessibleException when the metacat server can not be |
|
192 |
* reached or does not respond |
|
193 |
* @throws MetacatException when the metacat server generates another error |
|
194 |
* @throws IOException when there is an error reading the xml document |
|
190 | 195 |
*/ |
191 |
public void insert(String docid, Reader xmlDocument, Reader schema) |
|
192 |
throws InsufficientKarmaException |
|
196 |
public String insert(String docid, Reader xmlDocument, Reader schema) |
|
197 |
throws InsufficientKarmaException, MetacatException, IOException, |
|
198 |
MetacatInaccessibleException |
|
193 | 199 |
{ |
200 |
Reader reader = null; |
|
201 |
String doctext = null; |
|
202 |
String schematext = null; |
|
203 |
try { |
|
204 |
doctext = IOUtil.getAsString(xmlDocument, true); |
|
205 |
if (schema != null) { |
|
206 |
schematext = IOUtil.getAsString(schema, true); |
|
207 |
} |
|
208 |
} catch (IOException ioE) { |
|
209 |
throw ioE; |
|
210 |
} |
|
211 |
|
|
212 |
//set up properties |
|
213 |
Properties prop = new Properties(); |
|
214 |
prop.put("action", "insert"); |
|
215 |
prop.put("docid", docid); |
|
216 |
prop.put("doctext", doctext); |
|
217 |
if (schematext != null) { |
|
218 |
prop.put("dtdtext", schematext); |
|
219 |
} |
|
220 |
|
|
221 |
String response = null; |
|
222 |
try { |
|
223 |
response = sendDataForString(prop); |
|
224 |
} catch (Exception e) { |
|
225 |
throw new MetacatInaccessibleException(e.getMessage()); |
|
226 |
} |
|
227 |
|
|
228 |
// Check for an error condition |
|
229 |
if (response.indexOf("<error>") != -1) { |
|
230 |
if (response.indexOf("does not have permission") != -1) { |
|
231 |
throw new InsufficientKarmaException(response); |
|
232 |
} else { |
|
233 |
throw new MetacatException(response); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
return response; |
|
194 | 238 |
} |
195 | 239 |
|
196 | 240 |
/** |
Also available in: Unified diff
Implemented the "insert()" method and wrote a test to test it. The new test
depends on the property "newdocid" be set to something unique in the build.xml
file so that the insert will work properly. Probably need to fix this to be
some kind of autoincrement counter or random number so that it can be run
several times in succession. Right now, if you run the test without resetting
the newdocid property (and touch the test file), it will fail on the second
and subsequent passes.