@Override public void beginDataField(Field designator) { if (designator == null) { return; } try { if (designator.isControlField()) { beginControlField(designator); endControlField(designator); return; } if (datafieldOpen) { return; } AttributesImpl attrs = new AttributesImpl(); String tag = designator.tag(); if (tag == null || tag.length() == 0) { tag = Field.NULL_TAG; // fallback designator.tag(tag); } attrs.addAttribute(nsUri, TAG, TAG, "CDATA", tag); int ind = designator.indicator() != null ? designator.indicator().length() : 0; // force at least two default blank indicators if schema is Marc 21 if ("MARC21".equalsIgnoreCase(schema)) { for (int i = (ind == 0 ? 1 : ind); i <= 2; i++) { attrs.addAttribute(null, IND + i, IND + i, "CDATA", " "); } } // set indicators for (int i = 1; i <= ind; i++) { attrs.addAttribute( null, IND + i, IND + i, "CDATA", designator.indicator().substring(i - 1, i)); } if (contentHandler != null) { contentHandler.startElement(nsUri, DATAFIELD, DATAFIELD, attrs); } if (listener != null) { listener.beginDataField(designator); } datafieldOpen = true; } catch (Exception ex) { if (fatalerrors) { throw new RuntimeException(ex); } else if (!silenterrors) { logger.warn(designator + ": " + ex.getMessage(), ex); } } }
@Override public void beginControlField(Field designator) { if (designator == null) { return; } try { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(nsUri, TAG, TAG, "CDATA", designator.tag()); if (contentHandler != null) { contentHandler.startElement(nsUri, CONTROLFIELD, CONTROLFIELD, attrs); } if (listener != null) { listener.beginControlField(designator); } } catch (Exception ex) { if (fatalerrors) { throw new RuntimeException(ex); } else if (!silenterrors) { logger.warn(designator + ": " + ex.getMessage(), ex); } } }
@Override public void endControlField(Field designator) { try { if (listener != null) { listener.endControlField(designator); } if (designator != null) { String value = designator.data(); if (!value.isEmpty()) { switch (designator.tag()) { case "001": this.id = value; break; case "006": case "007": case "008": // fix fill characters here value = value.replace('^', '|'); break; } if (contentHandler != null) { contentHandler.characters(value.toCharArray(), 0, value.length()); } } } if (contentHandler != null) { contentHandler.endElement(nsUri, CONTROLFIELD, CONTROLFIELD); } } catch (Exception ex) { if (fatalerrors) { throw new RuntimeException(ex); } else if (!silenterrors) { logger.warn(designator + ": " + ex.getMessage(), ex); } } }