Package org.dspace.app.itemupdate
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 Summary
Fields Modifier and Type Field Description protected static ItemServiceitemService
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendMetadata(Context context, Item item, org.dspace.app.itemupdate.DtoMetadata dtom, boolean isLanguageStrict, String textToAppend)Append text to value metadata field to itemstatic booleandeleteMetadataByValue(Context context, Item item, org.dspace.app.itemupdate.DtoMetadata dtom, boolean isLanguageStrict)Working around Item API to delete a value-specific Metadatum For a given element/qualifier/lang: get all DCValues clear (i.e.static StringgetCompoundForm(String schema, String element, String qualifier)Return compound form of a metadata field (i.e.static StringgetDCValueString(MetadataValue dcv)Get display of Metadatumstatic List<org.dspace.app.itemupdate.DtoMetadata>loadDublinCore(DocumentBuilder docBuilder, InputStream is)Modification of method from ItemImporter.loadDublinCore as a Factory methodstatic String[]parseCompoundForm(String compoundForm)Parses metadata field given in the form<schema>.<element>[.<qualifier>|.*]checks for correct number of elements (2 or 3) and for empty stringsstatic List<ContentsEntry>readContentsFile(File f)Rewrite of ItemImport's functionality but just the parsing of the file, not the processing of its elements.static List<String>readDeleteContentsFile(File f)static voidwriteDocument(Document doc, Transformer transformer, OutputStream out)write xml document to output streamstatic DocumentwriteDublinCore(DocumentBuilder docBuilder, List<org.dspace.app.itemupdate.DtoMetadata> dtomList)Write dublin_core.xml
-
-
-
Field Detail
-
itemService
protected static final ItemService itemService
-
-
Method Detail
-
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 Contextitem- Item Objectdtom- metadata fieldisLanguageStrict- 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 Contextitem- DSpace Itemdtom- metadata fieldisLanguageStrict- if stricttextToAppend- text to append- Throws:
IllegalArgumentException- - When target metadata field is not foundSQLException- 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- DocumentBuilderis- - InputStream of dublin_core.xml- Returns:
- list of DtoMetadata representing the metadata fields relating to an Item
- Throws:
IOException- if IO errorParserConfigurationException- if parser config errorSAXException- if XML errorXPathExpressionException
-
writeDublinCore
public static Document writeDublinCore(DocumentBuilder docBuilder, List<org.dspace.app.itemupdate.DtoMetadata> dtomList) throws ParserConfigurationException, TransformerConfigurationException, TransformerException
Write dublin_core.xml- Parameters:
docBuilder- DocumentBuilderdtomList- List of metadata fields- Returns:
- xml document
- Throws:
ParserConfigurationException- if parser config errorTransformerConfigurationException- if transformer config errorTransformerException- 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 Documenttransformer- XML Transformerout- OutputStream- Throws:
IOException- if IO ErrorTransformerException- 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 existIOException- if IO errorParseException- 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 existIOException- 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- schemaelement- elementqualifier- 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
-
-