From d9513d45f60c377077996bdf3e597a1fe9e51943 Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Thu, 16 Feb 2012 13:09:21 +0100 Subject: [PATCH] Move namespace URI from Constants. --- src/org/marc4j/MarcXmlWriter.java | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/org/marc4j/MarcXmlWriter.java b/src/org/marc4j/MarcXmlWriter.java index 43066f3..0448d43 100644 --- a/src/org/marc4j/MarcXmlWriter.java +++ b/src/org/marc4j/MarcXmlWriter.java @@ -196,6 +196,8 @@ import com.ibm.icu.text.Normalizer; */ public class MarcXmlWriter implements MarcWriter { + public static final String MARCXML_NS_URI = "http://www.loc.gov/MARC21/slim"; + protected static final String prefix = "marc:"; protected static final String CONTROL_FIELD = "controlfield"; protected static final String Q_CONTROL_FIELD = prefix + "controlfield"; @@ -415,11 +417,11 @@ public class MarcXmlWriter implements MarcWriter { AttributesImpl atts = new AttributesImpl(); handler.startDocument(); // The next line duplicates the namespace declaration for Marc XML - handler.startPrefixMapping("marc", Constants.MARCXML_NS_URI); + handler.startPrefixMapping("marc", MARCXML_NS_URI); // add namespace declaration using attribute - need better solution - atts.addAttribute(Constants.MARCXML_NS_URI, "xmlns", "xmlns:marc", - "CDATA", Constants.MARCXML_NS_URI); - handler.startElement(Constants.MARCXML_NS_URI, COLLECTION, Q_COLLECTION, atts); + atts.addAttribute(MARCXML_NS_URI, "xmlns", "xmlns:marc", + "CDATA", MARCXML_NS_URI); + handler.startElement(MARCXML_NS_URI, COLLECTION, Q_COLLECTION, atts); } catch (SAXException e) { throw new MarcException( "SAX error occured while writing start document", e); @@ -437,7 +439,7 @@ public class MarcXmlWriter implements MarcWriter { handler.ignorableWhitespace("\n".toCharArray(), 0, 1); handler - .endElement(Constants.MARCXML_NS_URI, COLLECTION, + .endElement(MARCXML_NS_URI, COLLECTION, Q_COLLECTION); handler.endPrefixMapping(""); handler.endDocument(); @@ -486,16 +488,16 @@ public class MarcXmlWriter implements MarcWriter { if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); - handler.startElement(Constants.MARCXML_NS_URI, RECORD, Q_RECORD, atts); + handler.startElement(MARCXML_NS_URI, RECORD, Q_RECORD, atts); if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); - handler.startElement(Constants.MARCXML_NS_URI, LEADER, Q_LEADER, atts); + handler.startElement(MARCXML_NS_URI, LEADER, Q_LEADER, atts); Leader leader = record.getLeader(); temp = leader.toString().toCharArray(); handler.characters(temp, 0, temp.length); - handler.endElement(Constants.MARCXML_NS_URI, LEADER, Q_LEADER); + handler.endElement(MARCXML_NS_URI, LEADER, Q_LEADER); Iterator ci = record.getControlFields().iterator(); while (ci.hasNext()) { @@ -506,11 +508,11 @@ public class MarcXmlWriter implements MarcWriter { if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); - handler.startElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, + handler.startElement(MARCXML_NS_URI, CONTROL_FIELD, Q_CONTROL_FIELD, atts); temp = getDataElement(field.getData()); handler.characters(temp, 0, temp.length); - handler.endElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, + handler.endElement(MARCXML_NS_URI, CONTROL_FIELD, Q_CONTROL_FIELD); } @@ -527,7 +529,7 @@ public class MarcXmlWriter implements MarcWriter { if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); - handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD, + handler.startElement(MARCXML_NS_URI, DATA_FIELD, Q_DATA_FIELD, atts); Iterator si = field.getSubfields().iterator(); while (si.hasNext()) { @@ -539,12 +541,12 @@ public class MarcXmlWriter implements MarcWriter { if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 7); - handler.startElement(Constants.MARCXML_NS_URI, SUBFIELD, + handler.startElement(MARCXML_NS_URI, SUBFIELD, Q_SUBFIELD, atts); temp = getDataElement(subfield.getData()); handler.characters(temp, 0, temp.length); handler - .endElement(Constants.MARCXML_NS_URI, SUBFIELD, + .endElement(MARCXML_NS_URI, SUBFIELD, Q_SUBFIELD); } @@ -552,14 +554,13 @@ public class MarcXmlWriter implements MarcWriter { handler.ignorableWhitespace("\n ".toCharArray(), 0, 5); handler - .endElement(Constants.MARCXML_NS_URI, DATA_FIELD, - Q_DATA_FIELD); + .endElement(MARCXML_NS_URI, DATA_FIELD, Q_DATA_FIELD); } if (indent) handler.ignorableWhitespace("\n ".toCharArray(), 0, 3); - handler.endElement(Constants.MARCXML_NS_URI, RECORD, Q_RECORD); + handler.endElement(MARCXML_NS_URI, RECORD, Q_RECORD); } protected char[] getDataElement(String data) { -- 1.7.10.4