Package org.marc4j

Examples of org.marc4j.MarcXmlWriter


        OutputStream out = new FileOutputStream(outputFile);

        //MarcReader reader = new MarcStreamReader(in, inputEncoding );
        MarcReader reader = new MarcPermissiveStreamReader(in,true,true,"IS05426");
        System.err.println("Using IS05426 for conversion");
        MarcXmlWriter writer = new MarcXmlWriter(out, outputEncoding, true);

        while (reader.hasNext()) {
            Record record = reader.next();

            writer.write(record);
        }
        writer.close();
    }
View Full Code Here


        }
       
        try {
            OutputStream os = new FileOutputStream(tempFile);
            try {
                MarcWriter writer = new MarcXmlWriter(os, true);
               
                MarcPermissiveStreamReader reader = new MarcPermissiveStreamReader(
                    inputStream, true, true);
                while (reader.hasNext()) {
                    Record record = reader.next();
                    writer.write(record);
                }
                writer.close();
            } finally {
                try {
                    os.close();
                } catch (IOException e) {
                    // Just ignore - not much we can do anyway
View Full Code Here

        InputStream input = ReadMarcExample.class
                .getResourceAsStream("resources/summerland.mrc");
        MarcReader reader = new MarcStreamReader(input);

        MarcXmlWriter writer = new MarcXmlWriter(result, stylesheet);
        writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = (Record) reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

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

            // parse the input
            MarcReader reader = new MarcStreamReader(input);
            MarcWriter writer = new MarcXmlWriter(result);
            while (reader.hasNext()) {
                Record record = reader.next();
                writer.write(record);
            }
            writer.close();
           
            out.close();
        }
    }
View Full Code Here

                e.printStackTrace();
            }
        else
            out = System.out;

        MarcXmlWriter writer = null;

        if (stylesheet == null) {
            if (convert != null)
                writer = new MarcXmlWriter(out, "UTF8");
            else
                writer = new MarcXmlWriter(out, "UTF8");
        } else {
            Writer outputWriter = null;
            if (convert != null) {
                try {
                    outputWriter = new OutputStreamWriter(out, "UTF8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                outputWriter = new BufferedWriter(outputWriter);
            } else {
                outputWriter = new OutputStreamWriter(out);
                outputWriter = new BufferedWriter(outputWriter);
            }
            Result result = new StreamResult(outputWriter);
            Source source = new StreamSource(stylesheet);
            writer = new MarcXmlWriter(result, source);
        }
        writer.setIndent(true);

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

        if (normalize)
            writer.setUnicodeNormalization(true);

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

        System.err.println("Total time: "
                + (System.currentTimeMillis() - start) + " miliseconds");
    }
View Full Code Here

                .getResourceAsStream("resources/summerland.mrc");

        MarcReader reader = new MarcStreamReader(input);

        DOMResult result = new DOMResult();
        MarcXmlWriter writer = new MarcXmlWriter(result);
        writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = (Record) reader.next();
            writer.write(record);
        }
        writer.close();

        Document doc = (Document) result.getNode();
        System.out.println(doc.getDocumentElement().getLocalName());

    }
View Full Code Here

    }

    public void testMarcXmlWriter() throws Exception {
        InputStream input = getClass().getResourceAsStream(
                "resources/summerland.mrc");
        MarcXmlWriter writer = new MarcXmlWriter(System.out, true);
        MarcStreamReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        input.close();
        writer.close();
    }
View Full Code Here

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

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcXmlWriter(System.out, true);

        AnselToUnicode converter = new AnselToUnicode();
        writer.setConverter(converter);

        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

                .getResourceAsStream("resources/brkrtest.mrc");

        OutputStream out = new FileOutputStream("c:/temp/summerland.xml");

        MarcReader reader = new MarcStreamReader(input);
        MarcWriter writer = new MarcXmlWriter(out, true);

        AnselToUnicode converter = new AnselToUnicode();
        writer.setConverter(converter);

        while (reader.hasNext()) {
            Record record = reader.next();
            writer.write(record);
        }
        writer.close();
    }
View Full Code Here

        String stylesheetUrl = "http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3.xsl";
        Source stylesheet = new StreamSource(stylesheetUrl);
       
        DOMResult result = new DOMResult();
        MarcXmlWriter writer = new MarcXmlWriter(result, stylesheet);
        writer.setConverter(new AnselToUnicode());
        while (reader.hasNext()) {
            Record record = (Record) reader.next();
            writer.write(record);
        }
        writer.close();

        Document doc = (Document) result.getNode();
       
        System.out.println(doc.getDocumentElement().getLocalName());
View Full Code Here

TOP

Related Classes of org.marc4j.MarcXmlWriter

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.