Search in sources :

Example 16 with MarcReader

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;
}
Also used : MarcStreamReader(org.marc4j.MarcStreamReader) Document(org.w3c.dom.Document) MarcReader(org.marc4j.MarcReader) org.marc4j(org.marc4j) Record(org.marc4j.marc.Record)

Example 17 with MarcReader

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();
    }
}
Also used : MarcReader(org.marc4j.MarcReader) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) Record(org.marc4j.marc.Record) MarcStreamReader(org.marc4j.MarcStreamReader) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

MarcReader (org.marc4j.MarcReader)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 JsonObject (io.vertx.core.json.JsonObject)10 MarcJsonWriter (org.marc4j.MarcJsonWriter)10 MarcStreamWriter (org.marc4j.MarcStreamWriter)9 MarcWriter (org.marc4j.MarcWriter)9 MarcFactory (org.marc4j.marc.MarcFactory)7 VariableField (org.marc4j.marc.VariableField)7 DataField (org.marc4j.marc.DataField)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PostProcessingException (org.folio.services.exceptions.PostProcessingException)5 Record (org.marc4j.marc.Record)5 MarcStreamReader (org.marc4j.MarcStreamReader)4 ControlField (org.marc4j.marc.ControlField)4 MarcJsonReader (org.marc4j.MarcJsonReader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MarcFieldProtectionSetting (org.folio.rest.jaxrs.model.MarcFieldProtectionSetting)2 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1