Exemplo n.º 1
0
  protected void toXml(Record record) throws SAXException {
    if (!MarcFactory.newInstance().validateRecord(record)) {
      throw new MarcException("Marc record didn't validate");
    }
    char temp[];
    AttributesImpl atts = new AttributesImpl();
    if (indent) handler.ignorableWhitespace("\n  ".toCharArray(), 0, 3);

    handler.startElement(Constants.MARCXML_NS_URI, RECORD, RECORD, atts);

    if (indent) handler.ignorableWhitespace("\n    ".toCharArray(), 0, 5);

    handler.startElement(Constants.MARCXML_NS_URI, LEADER, LEADER, atts);
    Leader leader = record.getLeader();
    temp = leader.toString().toCharArray();
    handler.characters(temp, 0, temp.length);
    handler.endElement(Constants.MARCXML_NS_URI, LEADER, LEADER);

    for (ControlField field : record.getControlFields()) {
      atts = new AttributesImpl();
      atts.addAttribute("", "tag", "tag", "CDATA", field.getTag());

      if (indent) handler.ignorableWhitespace("\n    ".toCharArray(), 0, 5);

      handler.startElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD, atts);
      temp = getDataElement(field.getData());
      handler.characters(temp, 0, temp.length);
      handler.endElement(Constants.MARCXML_NS_URI, CONTROL_FIELD, CONTROL_FIELD);
    }

    for (DataField field : record.getDataFields()) {
      atts = new AttributesImpl();
      atts.addAttribute("", "tag", "tag", "CDATA", field.getTag());
      atts.addAttribute("", "ind1", "ind1", "CDATA", String.valueOf(field.getIndicator1()));
      atts.addAttribute("", "ind2", "ind2", "CDATA", String.valueOf(field.getIndicator2()));

      if (indent) handler.ignorableWhitespace("\n    ".toCharArray(), 0, 5);

      handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD, atts);
      for (Subfield subfield : field.getSubfields()) {
        atts = new AttributesImpl();
        atts.addAttribute("", "code", "code", "CDATA", String.valueOf(subfield.getCode()));

        if (indent) handler.ignorableWhitespace("\n      ".toCharArray(), 0, 7);

        handler.startElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD, atts);
        temp = getDataElement(subfield.getData());
        handler.characters(temp, 0, temp.length);
        handler.endElement(Constants.MARCXML_NS_URI, SUBFIELD, SUBFIELD);
      }

      if (indent) handler.ignorableWhitespace("\n    ".toCharArray(), 0, 5);

      handler.endElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD);
    }

    if (indent) handler.ignorableWhitespace("\n  ".toCharArray(), 0, 3);

    handler.endElement(Constants.MARCXML_NS_URI, RECORD, RECORD);
  }
Exemplo n.º 2
0
 @Override
 public String[] getValues(VariableField vf) {
   DataField df = (DataField) vf;
   String value = df.getSubfield('a').getData();
   String tag = df.getTag();
   if (tag.equals("100")) {
     Subfield csf = df.getSubfield('c');
     if (csf != null) {
       String data = csf.getData();
       int dlen = data.length();
       StringBuffer sb = new StringBuffer(value.length() + data.length() + 1);
       sb.append(value);
       sb.append(' ');
       char c = data.charAt(dlen - 1);
       if (c == ',' || c == '.') {
         sb.append(data, 0, dlen - 1);
       } else sb.append(data);
       value = sb.toString();
     }
   } else { // 110 & 710
     List<Subfield> sfs = df.getSubfields('b');
     if (sfs.size() > 0) {
       StringBuffer buf = new StringBuffer(value.length() + sfs.size() * 5);
       buf.append(value);
       Iterator<Subfield> sfi = sfs.iterator();
       while (sfi.hasNext()) {
         buf.append(' ');
         buf.append(sfi.next().getData());
       }
       int last = buf.length() - 1;
       char c = buf.charAt(last);
       if (c == ',' || c == '.') {
         buf.setLength(last);
       }
       value = buf.toString();
     }
   }
   return new String[] {trim(value).toString()};
 }