예제 #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);
  }
예제 #2
0
  /** Tests the various ways to get fields from a {@link Record}. */
  @Test
  public void testGetFields() {
    String cn = record.getControlNumber();
    assertEquals("12883376", cn);

    ControlField cf = record.getControlNumberField();
    assertEquals("001", cf.getTag());
    assertEquals("12883376", cf.getData());

    List<? extends VariableField> fieldList = record.getVariableFields();
    assertEquals(15, fieldList.size());

    fieldList = record.getControlFields();
    assertEquals(3, fieldList.size());

    fieldList = record.getDataFields();
    assertEquals(12, fieldList.size());

    VariableField field = record.getVariableField("245");
    assertEquals("245", field.getTag());

    fieldList = record.getVariableFields("650");
    assertEquals(3, fieldList.size());

    String[] fields = {"245", "260", "300"};
    fieldList = record.getVariableFields(fields);
    assertEquals(3, fieldList.size());
  }
예제 #3
0
  public boolean importRecord(
      AbstractWorkGroup workGroup,
      Class<CustomStorageRecord> persistentClass,
      TempDatabankDefinition storageDatabak,
      Record record,
      boolean isFromDos,
      boolean addToNews,
      int NewsDuration) {
    String controlNumber = "";

    ControlField cf = record.getControlField(Tags.ID);
    if (cf == null) {
      cf = new ControlField(Tags.ID, "0");
      record.getControlFieldList().add(0, cf);
    }
    controlNumber = String.copyValueOf(cf.getData());
    if (controlNumber == null || controlNumber.length() == 0) {
      controlNumber = "0";
    }
    //		CustomStorageRecord storageRecord = StorageUtils
    //				.createNewStorageRecord(StorageUtils
    //						.getStorageClassByClassType(databaseType));
    //		storageRecord.setContent(MarcUtils.marshalContent(record));

    //		if (isFromDos) {
    UniBibUtils.setCharacterSets(record, "50");
    //			storageRecord.setCharacterSets("50");
    //        String docType = UniBibUtils.getLocalDocType(record);
    //        if ("AF".equals(docType)) {
    //            String file = MarcUtils.getSubfieldData(record, Tags.BIB_ELECTRONICAL_LOCATION, 0,
    // 'd', 0);
    //            if (file != null && file.length() != 0)
    //                MarcUtils.setSubfieldData(record, Tags.CUSTOM_CATEGORY, 'a', "G");
    //        }
    //		}
    /** @todo move to server */
    //		storageRecord.setDateEnterdOnFile(insertDate);

    //		storageRecord.setId(0);

    try {
      List holdings = generateHoldings(record);
      CustomStorageRecord storageRecord =
          (CustomStorageRecord) StorageUtils.createNewStorageRecord(persistentClass);
      if (storageRecord instanceof TempDatabankRecord) {
        ((TempDatabankRecord) storageRecord).setDatabank(storageDatabak);
      }
      if (storageRecord instanceof BaseBibliographicRecord) {
        storageRecord.setWorkGroup(workGroup);
      }

      storageRecord.setContent(MarcUtils.marshalContent(record));
      long id = saveFast(storageRecord, holdings);
      logger.info("Saved: New record no. = " + id, null);
      if (holdings.size() > 0)
        logger.info(holdings.size() + " holding(s) has been attached to record no. " + id, null);

    } catch (Exception ex) {
      logger.error("Not saved!: Old recordNo = " + controlNumber, ex);
    }

    return true;
  }
 public String getControlNumber() {
   ControlField f = getControlNumberField();
   String result = (f == null || f.getData() == null) ? null : new String(f.getData());
   return (result);
 }