186 |
186 |
return pbr;
|
187 |
187 |
}
|
188 |
188 |
|
|
189 |
|
189 |
190 |
/**
|
|
191 |
* Read inline data from the metacat server session, accessed by
|
|
192 |
* inlinedataid and returned as a Reader.
|
|
193 |
*
|
|
194 |
* @param inlinedataid the identifier of the data to be read
|
|
195 |
* @return a Reader for accessing the document
|
|
196 |
* @throws InsufficientKarmaException when the user has insufficent rights
|
|
197 |
* for the operation
|
|
198 |
* @throws MetacatInaccessibleException when the metacat server can not be
|
|
199 |
* reached or does not respond
|
|
200 |
* @throws MetacatException when the metacat server generates another error
|
|
201 |
*/
|
|
202 |
public Reader readInlineData(String inlinedataid)
|
|
203 |
throws InsufficientKarmaException,
|
|
204 |
MetacatInaccessibleException, MetacatException
|
|
205 |
{
|
|
206 |
PushbackReader pbr = null;
|
|
207 |
|
|
208 |
Properties prop = new Properties();
|
|
209 |
prop.put("action", "readinlinedata");
|
|
210 |
prop.put("inlinedataid", inlinedataid);
|
|
211 |
|
|
212 |
InputStream response = null;
|
|
213 |
try {
|
|
214 |
response = sendData(prop, null);
|
|
215 |
} catch (Exception e) {
|
|
216 |
throw new MetacatInaccessibleException(e.getMessage());
|
|
217 |
}
|
|
218 |
|
|
219 |
pbr = new PushbackReader(new InputStreamReader(response), 512);
|
|
220 |
try {
|
|
221 |
char[] characters = new char[512];
|
|
222 |
int len = pbr.read(characters, 0, 512);
|
|
223 |
StringWriter sw = new StringWriter();
|
|
224 |
sw.write(characters, 0, len);
|
|
225 |
String message = sw.toString();
|
|
226 |
sw.close();
|
|
227 |
pbr.unread(characters, 0, len);
|
|
228 |
|
|
229 |
if (message.indexOf("<error>") != -1) {
|
|
230 |
if (message.indexOf("does not have permission") != -1) {
|
|
231 |
throw new InsufficientKarmaException(message);
|
|
232 |
} else {
|
|
233 |
throw new MetacatException(message);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
} catch (IOException ioe) {
|
|
237 |
throw new MetacatException(
|
|
238 |
"MetacatClient: Error converting Reader to String."
|
|
239 |
+ ioe.getMessage());
|
|
240 |
}
|
|
241 |
|
|
242 |
return pbr;
|
|
243 |
}
|
|
244 |
|
|
245 |
/**
|
190 |
246 |
* Query the metacat document store with the given metacat-compatible
|
191 |
247 |
* query document, and return the result set as a Reader.
|
192 |
248 |
*
|
Added method to metacat client for reading inline data - readInlineData()