package no.deichman.services.marc;

import java.io.ByteArrayOutputStream;

import org.marc4j.MarcWriter;
import org.marc4j.MarcXmlWriter;
import org.marc4j.marc.Leader;
import org.marc4j.marc.Record;

import info.freelibrary.marc4j.impl.LeaderImpl;
import info.freelibrary.marc4j.impl.RecordImpl;

/**
 * Responsibility: Make a MARCXML record.
 */
public final class MarcXmlProvider {

    private Record record;

    public MarcXmlProvider() {}

    private Leader createLeader() {
        Leader leader = new LeaderImpl();
        leader.unmarshal("                        ");
        return leader;
    }

    public void createRecord() {
        this.record = new RecordImpl();
        this.record.setLeader(createLeader());
    }

    public String getMarcXml() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MarcWriter writer = new MarcXmlWriter(baos);
        writer.write(this.getRecord());
        writer.close();
        return baos.toString();
    }

    public Record getRecord() {
        return this.record;
    }
}

@@ -379,16 +379,97 @@
 ider %7B%0A%0A
+    private static final String TWENTY_FOUR_SPACES = %22                        %22;%0A
     priv
@@ -628,34 +628,26 @@
 hal(
-%22                        %22
+TWENTY_FOUR_SPACES
 );%0A 

Refactor magic spaces to constant