Class MetadataUtilities

java.lang.Object
org.dspace.app.itemupdate.MetadataUtilities

public class MetadataUtilities extends Object
Miscellaneous methods for metadata handling that build on the API which might have general utility outside of the specific use in context in ItemUpdate. The XML methods were based on those in ItemImport
  • Field Details

    • itemService

      protected static final ItemService itemService
  • Method Details

    • deleteMetadataByValue

      public static boolean deleteMetadataByValue(Context context, Item item, org.dspace.app.itemupdate.DtoMetadata dtom, boolean isLanguageStrict) throws SQLException
      Working around Item API to delete a value-specific Metadatum For a given element/qualifier/lang: get all DCValues clear (i.e. delete) all of these DCValues add them back, minus the one to actually delete
      Parameters:
      context - DSpace Context
      item - Item Object
      dtom - metadata field
      isLanguageStrict - whether strict or not
      Returns:
      true if metadata field is found with matching value and was deleted
      Throws:
      SQLException - if database error
    • appendMetadata

      public static void appendMetadata(Context context, Item item, org.dspace.app.itemupdate.DtoMetadata dtom, boolean isLanguageStrict, String textToAppend) throws IllegalArgumentException, SQLException
      Append text to value metadata field to item
      Parameters:
      context - DSpace Context
      item - DSpace Item
      dtom - metadata field
      isLanguageStrict - if strict
      textToAppend - text to append
      Throws:
      IllegalArgumentException - - When target metadata field is not found
      SQLException - if database error
    • loadDublinCore

      public static List<org.dspace.app.itemupdate.DtoMetadata> loadDublinCore(DocumentBuilder docBuilder, InputStream is) throws IOException, XPathExpressionException, SAXException
      Modification of method from ItemImporter.loadDublinCore as a Factory method
      Parameters:
      docBuilder - DocumentBuilder
      is - - InputStream of dublin_core.xml
      Returns:
      list of DtoMetadata representing the metadata fields relating to an Item
      Throws:
      IOException - if IO error
      ParserConfigurationException - if parser config error
      SAXException - if XML error
      XPathExpressionException
    • writeDublinCore

      public static Document writeDublinCore(DocumentBuilder docBuilder, List<org.dspace.app.itemupdate.DtoMetadata> dtomList) throws ParserConfigurationException, TransformerConfigurationException, TransformerException
      Write dublin_core.xml
      Parameters:
      docBuilder - DocumentBuilder
      dtomList - List of metadata fields
      Returns:
      xml document
      Throws:
      ParserConfigurationException - if parser config error
      TransformerConfigurationException - if transformer config error
      TransformerException - if transformer error
    • writeDocument

      public static void writeDocument(Document doc, Transformer transformer, OutputStream out) throws IOException, TransformerException
      write xml document to output stream
      Parameters:
      doc - XML Document
      transformer - XML Transformer
      out - OutputStream
      Throws:
      IOException - if IO Error
      TransformerException - if Transformer error
    • readContentsFile

      public static List<ContentsEntry> readContentsFile(File f) throws FileNotFoundException, IOException, ParseException
      Rewrite of ItemImport's functionality but just the parsing of the file, not the processing of its elements.
      Parameters:
      f - file
      Returns:
      list of ContentsEntry
      Throws:
      FileNotFoundException - if file doesn't exist
      IOException - if IO error
      ParseException - if parse error
    • readDeleteContentsFile

      public static List<String> readDeleteContentsFile(File f) throws FileNotFoundException, IOException
      Parameters:
      f - file
      Returns:
      list of lines as strings
      Throws:
      FileNotFoundException - if file doesn't exist
      IOException - if IO Error
    • getDCValueString

      public static String getDCValueString(MetadataValue dcv)
      Get display of Metadatum
      Parameters:
      dcv - MetadataValue
      Returns:
      string displaying elements of the Metadatum
    • getCompoundForm

      public static String getCompoundForm(String schema, String element, String qualifier)
      Return compound form of a metadata field (i.e. schema.element.qualifier)
      Parameters:
      schema - schema
      element - element
      qualifier - qualifier
      Returns:
      a String representation of the two- or three-part form of a metadata element e.g. dc.identifier.uri
    • parseCompoundForm

      public static String[] parseCompoundForm(String compoundForm) throws ParseException
      Parses metadata field given in the form <schema>.<element>[.<qualifier>|.*] checks for correct number of elements (2 or 3) and for empty strings
      Parameters:
      compoundForm - compound form of metadata field
      Returns:
      String Array
      Throws:
      ParseException - if validity checks fail