Ejemplo n.º 1
0
 private int getMetadataSchemaID(DCValue dcv) throws SQLException {
   int schemaID;
   MetadataSchema schema = MetadataSchema.find(ourContext, dcv.schema);
   if (schema == null) {
     schemaID = MetadataSchema.DC_SCHEMA_ID;
   } else {
     schemaID = schema.getSchemaID();
   }
   return schemaID;
 }
Ejemplo n.º 2
0
    List<DCValue> get(Context c, int resourceId, int resourceTypeId, Logger log)
        throws SQLException {
      if (metadata == null) {
        metadata = new ArrayList<DCValue>();

        // Get Dublin Core metadata
        TableRowIterator tri = retrieveMetadata(resourceId, resourceTypeId);

        if (tri != null) {
          try {
            while (tri.hasNext()) {
              TableRow resultRow = tri.next();

              // Get the associated metadata field and schema information
              int fieldID = resultRow.getIntColumn("metadata_field_id");
              MetadataField field = MetadataField.find(c, fieldID);

              if (field == null) {
                log.error("Loading item - cannot find metadata field " + fieldID);
              } else {
                MetadataSchema schema = MetadataSchema.find(c, field.getSchemaID());
                if (schema == null) {
                  log.error(
                      "Loading item - cannot find metadata schema "
                          + field.getSchemaID()
                          + ", field "
                          + fieldID);
                } else {
                  // Make a DCValue object
                  DCValue dcv = new DCValue();
                  dcv.element = field.getElement();
                  dcv.qualifier = field.getQualifier();
                  dcv.value = resultRow.getStringColumn("text_value");
                  dcv.language = resultRow.getStringColumn("text_lang");
                  // dcv.namespace = schema.getNamespace();
                  dcv.schema = schema.getName();
                  dcv.authority = resultRow.getStringColumn("authority");
                  dcv.confidence = resultRow.getIntColumn("confidence");

                  // Add it to the list
                  metadata.add(dcv);
                }
              }
            }
          } finally {
            // close the TableRowIterator to free up resources
            if (tri != null) {
              tri.close();
            }
          }
        }
      }

      return metadata;
    }
Ejemplo n.º 3
0
  /**
   * Utility method for pattern-matching metadata elements. This method will return <code>true
   * </code> if the given schema, element, qualifier and language match the schema, element,
   * qualifier and language of the <code>DCValue</code> object passed in. Any or all of the element,
   * qualifier and language passed in can be the <code>Item.ANY</code> wildcard.
   *
   * @param schema the schema for the metadata field. <em>Must</em> match the <code>name</code> of
   *     an existing metadata schema.
   * @param element the element to match, or <code>Item.ANY</code>
   * @param qualifier the qualifier to match, or <code>Item.ANY</code>
   * @param language the language to match, or <code>Item.ANY</code>
   * @param metadataValue the Dublin Core value
   * @return <code>true</code> if there is a match
   */
  protected boolean match(
      String schema,
      String element,
      String qualifier,
      String language,
      MetadataValue metadataValue) {

    MetadataField metadataField = metadataValue.getMetadataField();
    MetadataSchema metadataSchema = metadataField.getMetadataSchema();
    // We will attempt to disprove a match - if we can't we have a match
    if (!element.equals(Item.ANY) && !element.equals(metadataField.getElement())) {
      // Elements do not match, no wildcard
      return false;
    }

    if (qualifier == null) {
      // Value must be unqualified
      if (metadataField.getQualifier() != null) {
        // Value is qualified, so no match
        return false;
      }
    } else if (!qualifier.equals(Item.ANY)) {
      // Not a wildcard, so qualifier must match exactly
      if (!qualifier.equals(metadataField.getQualifier())) {
        return false;
      }
    }

    if (language == null) {
      // Value must be null language to match
      if (metadataValue.getLanguage() != null) {
        // Value is qualified, so no match
        return false;
      }
    } else if (!language.equals(Item.ANY)) {
      // Not a wildcard, so language must match exactly
      if (!language.equals(metadataValue.getLanguage())) {
        return false;
      }
    }

    if (!schema.equals(Item.ANY)) {
      if (metadataSchema != null && !metadataSchema.getName().equals(schema)) {
        // The namespace doesn't match
        return false;
      }
    }

    // If we get this far, we have a match
    return true;
  }