Пример #1
0
  /**
   * Serialize a single metadata field registry entry to xml
   *
   * @param context DSpace context
   * @param xmlSerializer xml serializer
   * @param mdField DSpace metadata field
   * @throws SAXException if XML error
   * @throws RegistryExportException if export error
   * @throws SQLException if database error
   * @throws IOException if IO error
   */
  private static void saveType(Context context, XMLSerializer xmlSerializer, MetadataField mdField)
      throws SAXException, RegistryExportException, SQLException, IOException {
    // If we haven't been given a field, it's an error
    if (mdField == null) {
      throw new RegistryExportException("no field to export");
    }

    // Get the data from the metadata field
    String schemaName = getSchemaName(context, mdField);
    String element = mdField.getElement();
    String qualifier = mdField.getQualifier();
    String scopeNote = mdField.getScopeNote();

    // We must have a schema and element
    if (schemaName == null || element == null) {
      throw new RegistryExportException("incomplete field information");
    }

    // Output the parent tag
    xmlSerializer.startElement("dc-type", null);

    // Output the schema name
    xmlSerializer.startElement("schema", null);
    xmlSerializer.characters(schemaName.toCharArray(), 0, schemaName.length());
    xmlSerializer.endElement("schema");

    // Output the element
    xmlSerializer.startElement("element", null);
    xmlSerializer.characters(element.toCharArray(), 0, element.length());
    xmlSerializer.endElement("element");

    // Output the qualifier, if present
    if (qualifier != null) {
      xmlSerializer.startElement("qualifier", null);
      xmlSerializer.characters(qualifier.toCharArray(), 0, qualifier.length());
      xmlSerializer.endElement("qualifier");
    } else {
      xmlSerializer.comment("unqualified");
    }

    // Output the scope note, if present
    if (scopeNote != null) {
      xmlSerializer.startElement("scope_note", null);
      xmlSerializer.characters(scopeNote.toCharArray(), 0, scopeNote.length());
      xmlSerializer.endElement("scope_note");
    } else {
      xmlSerializer.comment("no scope note");
    }

    xmlSerializer.endElement("dc-type");
  }
Пример #2
0
  protected void comment(Element element) throws SAXException, IOException {
    if (serializer instanceof XMLSerializer) {
      NodeList children = element.getChildNodes();

      for (int i = 0; i < children.getLength(); i++) {
        Node text = (Node) children.item(i);
        ((XMLSerializer) serializer).comment(text.getNodeValue());
      }
    }
  }