Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,25 @@ public static Transformer getTransformer(String style, String defaultStyle, Map<
*/
public static List<String> selectWithXpath(String xPath, Predicate<String> filter,
Function<MCRObjectID, MCRBase> mapper) {
List<String> objectIds = MCRXMLMetadataManager.getInstance().listIDs();
return filterWithXpath(objectIds, xPath, filter, mapper);
}

/**
* Select MCRObjectIDs by applying a XPath to the corresponding MCRBase-objects XML representation.
* <p>
* This method iterates over all given objects IDs, filters them using a given filter and
* maps them to a MCRBase-object using the given mapper. For each such object, the corresponding XML
* representation is created and the given XPath applied. If the Xpath evaluates to a non-empty result,
* the corresponding object ID is selected and included in the result list.
*/
public static List<String> filterWithXpath(List<String> objectIds, String xPath, Predicate<String> filter,
Function<MCRObjectID, MCRBase> mapper) {

XPathExpression<Object> xPathExpression = XPathFactory.instance()
.compile(xPath, Filters.fpassthrough(), null, MCRConstants.getStandardNamespaces());

return MCRXMLMetadataManager
.getInstance()
.listIDs()
return objectIds
.stream()
.filter(filter)
.map(MCRObjectID::getInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
* @author Frank Lützenkirchen
*/
@MCRCommandGroup(name = "Derivate Commands")
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class MCRDerivateCommands extends MCRAbstractCommands {

/** The logger */
Expand All @@ -105,14 +106,27 @@ public class MCRDerivateCommands extends MCRAbstractCommands {

@MCRCommand(
syntax = "select derivates with xpath {0}",
help = "Selects MCRDerivates with XPath {0}, if that XPath evaluates to a non-empty result list" +
help = "Selects MCRDerivates with XPath {0}," +
" if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void selectObjectsWithXpath(String xPath) {
public static void selectDerivatesWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.selectWithXpath(
xPath, DERIVATE_ID_PREDICATE, MCRMetadataManager::retrieveMCRDerivate));
}

@MCRCommand(
syntax = "filter derivate selection with xpath {0}",
help = "Filters the selection as MCRDerivates with XPath {0}," +
" if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void filterDerivateSelectionWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
MCRBasicCommands.getSelectedValues(),
xPath, DERIVATE_ID_PREDICATE, MCRMetadataManager::retrieveMCRDerivate));
}

/**
* deletes all MCRDerivate from the datastore.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
* @author Robert Stephan
*/
@MCRCommandGroup(name = "Object Commands")
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class MCRObjectCommands extends MCRAbstractCommands {

private static final String EXPORT_OBJECT_TO_DIRECTORY_WITH_STYLESHEET_COMMAND =
Expand Down Expand Up @@ -144,24 +145,50 @@ public static List<String> getSelectedObjectIDs() {

@MCRCommand(
syntax = "select objects with xpath {0}",
help = "Selects MCRObjects with XPath {0}, if that XPath evaluates to a non-empty result list" +
help = "Selects MCRObjects with XPath {0}," +
" if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void selectWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.selectWithXpath(
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRObject));
}

@MCRCommand(
syntax = "filter object selection with xpath {0}",
help = "Filters the selection as MCRObjects with XPath {0}," +
" if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 11)
public static void filterObjectSelectionWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
MCRBasicCommands.getSelectedValues(),
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRObject));
}

@MCRCommand(
syntax = "select expanded objects with xpath {0}",
help = "Selects expanded MCRObjects with XPath {0}, if that XPath evaluates to a non-empty result list" +
help = "Selects expanded MCRObjects with XPath {0}," +
" if that XPath evaluates to a non-empty result list" +
" (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void selectExpandedObjectsWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.selectWithXpath(
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRExpandedObject));
}

@MCRCommand(
syntax = "filter expanded object selection with xpath {0}",
help = "Filters the selection as expanded MCRObjects with XPath {0}," +
" if that XPath evaluates to a non-empty result list"
+ " (this command may take a while, use with care in case of a large number of objects)",
order = 10)
public static void filterExpandedObjectSelectionWithXpath(String xPath) {
MCRBasicCommands.setSelectedValues(MCRCommandUtils.filterWithXpath(
MCRBasicCommands.getSelectedValues(),
xPath, OBJECT_ID_PREDICATE, MCRMetadataManager::retrieveMCRExpandedObject));
}

@MCRCommand(
syntax = "select descendants of object {0}",
help = "Selects MCRObjects that are descendants of {0} (children, grandchildren, ...) and {0} itself.",
Expand Down