use of org.marc4j.MarcReader in project z3950-server by mol-pl.
the class iso2709RecordFactory method getCanonicalXML.
/**
* create the canonica XML for this object
*/
public Document getCanonicalXML(Object native_object) throws RecordBuilderException {
org.w3c.dom.Document retval = null;
try {
MarcReader reader = new MarcStreamReader(new ByteArrayInputStream((byte[]) native_object));
javax.xml.transform.dom.DOMResult result = new javax.xml.transform.dom.DOMResult();
MarcXmlWriter writer = new MarcXmlWriter(result);
writer.setConverter(new org.marc4j.converter.impl.AnselToUnicode());
if (reader.hasNext()) {
Record record = (Record) reader.next();
writer.write(record);
}
writer.close();
retval = (Document) result.getNode();
} catch (Exception e) {
throw new RecordBuilderException("Problem creating marcxml from iso2709", e);
}
return retval;
}
use of org.marc4j.MarcReader in project z3950-server by mol-pl.
the class HttpDataProvider method getList.
/**
* Pobiera listę rekordów z bazy tenenta
*
* @param params kryteria pobierania
* @param start pierwszy rekord
* @param limit liczba rekordów
* @return tablica rekordów
* @throws UnsupportedEncodingException nieprawidłowe kodowanie
* @throws MalformedURLException nieprawidłowy url
* @throws IOException nie udało się odpytać tenanta
* @throws Exception baza nie istnieje
*/
public Record[] getList(HttpQueryParams params, Integer start, Integer limit) throws UnsupportedEncodingException, MalformedURLException, IOException, Exception {
String url = params.getTenantUrl() + "/api/z3950server/?" + prepareGetParams(params, start, limit);
GetMethod method = new GetMethod(url);
try {
if (client.executeMethod(method) == HttpStatus.SC_OK) {
List<Record> list = new ArrayList<>();
MarcReader reader = new MarcStreamReader(method.getResponseBodyAsStream(), "UTF8");
while (reader.hasNext()) {
list.add(reader.next());
}
Record[] records = new Record[limit];
return (Record[]) list.toArray(records);
} else {
throw new Exception("Database not found");
}
} finally {
method.releaseConnection();
}
}
Aggregations