Package org.marc4j

Examples of org.marc4j.MarcXmlReader


  private final static Logger logger = Logger
      .getLogger(MarcImporterTest.class);

  public void testNewPropertyRecord() throws FileNotFoundException {
    MarcXmlReader marcXmlReader = new MarcXmlReader(new FileInputStream(
        new File("test/input/singleOne.xml")));
    Record marcRecord = marcXmlReader.next();
    logger.info(marcRecord);
    MarcImporter marcImporter = new MarcImporter();
    HashMap<String, String> mappings = new HashMap<String, String>();
    marcImporter.setMappings(mappings);
    mappings.put("001", "_id");
View Full Code Here


  public void importMarcXmlFromStream(InputStream in) throws CultureGraphException {
    if (propertyRecordDao == null) {
      throw new IllegalStateException("propertyRecordDao not set!");
    }
    MarcXmlReader marcXmlReader = new MarcXmlReader(in);
    while (marcXmlReader.hasNext()) {
      Record record = marcXmlReader.next();
      PropertyRecord propertyRecord = newPropertyRecord(record);

      propertyRecordDao.registerEntity(propertyRecord, null);
    }
  }
View Full Code Here

    log.debug("iso2709 from marcxml");
    try {
      log.debug("open pip output stream");
      PipedOutputStream pos = new PipedOutputStream();
      XMLSerializer serializer = new XMLSerializer();
      MarcXmlReader reader = new MarcXmlReader(new PipedInputStream(pos));
      serializer.setOutputByteStream(pos);
      log.debug("Serialize dom to output stream");
      serializer.serialize(input_dom);
      log.debug("flush");
      pos.flush();
      pos.close();
      log.debug("attempt to read marcxml from pipe");
      if (reader.hasNext()) {
        Record record = reader.next();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MarcWriter writer = new MarcStreamWriter(baos);
        writer.write(record);
        result = baos.toByteArray();
        log.debug("Result of transform to marc: "+new String(result));
View Full Code Here

    public void testMarcXmlReader() throws Exception {
        int i = 0;
        InputStream input = getClass().getResourceAsStream(
                "resources/chabon.xml");
        MarcXmlReader reader = new MarcXmlReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.err.println(record.toString());
            i++;
        }
        input.close();
        assertEquals(2, i);
View Full Code Here

        try {
            in = new FileInputStream(new File(input));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        MarcXmlReader reader = null;
        if (stylesheet == null)
            reader = new MarcXmlReader(in);
        else {
            Source source = new StreamSource(stylesheet);
            reader = new MarcXmlReader(in, source);
        }

        OutputStream out = null;
        if (output != null)
            try {
                out = new FileOutputStream(output);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        else
            out = System.out;

        MarcStreamWriter writer = null;
        if (encoding != null)
            writer = new MarcStreamWriter(out, encoding);
        else
            writer = new MarcStreamWriter(out);

        if (convert != null) {
            CharConverter charconv = null;
            if (Constants.MARC_8_ENCODING.equals(convert))
                charconv = new UnicodeToAnsel();
            else if (Constants.ISO5426_ENCODING.equals(convert))
                charconv = new UnicodeToIso5426();
            else if (Constants.ISO6937_ENCODING.equals(convert))
                charconv = new UnicodeToIso6937();
            else {
                System.err.println("Unknown character set");
                System.exit(1);
            }
            writer.setConverter(charconv);
        }

        while (reader.hasNext()) {
            Record record = reader.next();
            if (Constants.MARC_8_ENCODING.equals(convert))
                record.getLeader().setCharCodingScheme(' ');
            writer.write(record);
        }
        writer.close();
View Full Code Here

                TransformerHandler handler = saxTFactory
                        .newTransformerHandler(templates);

                // parse the input
                MarcReader reader = new MarcXmlReader(input, handler);
                while (reader.hasNext()) {
                    Record record = reader.next();
                    System.out.println(record.toString());
                }
            }
        }
    }
View Full Code Here

    public static void main(String args[]) throws Exception {

        InputStream input = ReadMarcExample.class
                .getResourceAsStream("resources/summerland.xml");

        MarcReader reader = new MarcXmlReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.out.println(record.toString());
        }

    }
View Full Code Here

    public void testMarcXmlReader() throws Exception {
        int i = 0;
        InputStream input = getClass().getResourceAsStream(
                "resources/chabon.xml");
        MarcXmlReader reader = new MarcXmlReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.err.println(record.toString());
            i++;
        }
        input.close();
        assertEquals(2, i);
View Full Code Here

    public static void main(String args[]) throws Exception {

        InputStream input = ModsToMarc21lExample.class
                .getResourceAsStream("resources/modsoutput.xml");

        MarcReader reader = new MarcXmlReader(input,
                "http://www.loc.gov/standards/marcxml/xslt/MODS2MARC21slim.xsl");

        while (reader.hasNext()) {
            Record record = reader.next();
            System.out.println(record.toString());

        }
    }
View Full Code Here

    public static void main(String args[]) throws Exception {

        String systemId = "http://www.loc.gov/standards/marcxml/Sandburg/sandburg.xml";
        InputSource input = new InputSource(systemId);

        MarcReader reader = new MarcXmlReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            System.out.println(record.toString());
        }

    }
View Full Code Here

TOP

Related Classes of org.marc4j.MarcXmlReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.