use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method doResolvePath.
private static MCRFilesystemNode doResolvePath(MCRPath path) throws IOException {
if (path.getNameCount() == 0) {
// root components
MCRDirectory rootDirectory = MCRDirectory.getRootDirectory(path.getOwner());
if (rootDirectory == null) {
throw new NoSuchFileException(path.toString());
}
// prepare cache
rootDirectory.getChildren();
return rootDirectory;
}
MCRDirectory parent = getParentDirectory(path);
MCRFilesystemNode child;
try {
child = parent.getChild(path.getFileName().toString());
} catch (RuntimeException e) {
throw new IOException(e);
}
if (child == null) {
throw new NoSuchFileException(parent.toPath().toString(), path.toString(), null);
}
return child;
}
use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.
the class MCRFileTypeDetector method probeContentType.
/* (non-Javadoc)
* @see java.nio.file.spi.FileTypeDetector#probeContentType(java.nio.file.Path)
*/
@Override
public String probeContentType(Path path) throws IOException {
LOGGER.debug(() -> "Probing content type of: " + path);
if (!(path.getFileSystem() instanceof MCRIFSFileSystem)) {
return null;
}
MCRFilesystemNode resolvePath = MCRFileSystemProvider.resolvePath(MCRPath.toMCRPath(path));
if (resolvePath == null) {
throw new NoSuchFileException(path.toString());
}
if (resolvePath instanceof MCRDirectory) {
throw new NoSuchFileException(path.toString());
}
MCRFile file = (MCRFile) resolvePath;
String mimeType = file.getContentType().getMimeType();
LOGGER.debug(() -> "IFS mime-type: " + mimeType);
if (defaultMimeType.equals(mimeType)) {
Path dummy = Paths.get(path.getFileName().toString());
String dummyType = Files.probeContentType(dummy);
if (dummyType != null) {
LOGGER.debug(() -> "System mime-type #1: " + dummyType);
return dummyType;
}
String systemMimeType = Files.probeContentType(file.getLocalFile().toPath());
if (systemMimeType != null) {
LOGGER.debug(() -> "System mime-type #2: " + systemMimeType);
return systemMimeType;
}
}
return mimeType;
}
use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.
the class MCROAIObjectManager method formatURI.
protected String formatURI(String uri, String id, String metadataPrefix) {
MCRObjectID mcrID = MCRObjectID.isValid(id) ? MCRObjectID.getInstance(id) : null;
boolean exists;
String objectType;
if (mcrID != null) {
exists = MCRMetadataManager.exists(mcrID);
objectType = mcrID.getTypeId();
} else {
MCRFilesystemNode node = MCRFilesystemNode.getNode(id);
exists = node != null;
objectType = "data_file";
}
return uri.replace("{id}", id).replace("{format}", metadataPrefix).replace("{objectType}", objectType).replace(":{flag}", !exists ? ":deletedMcrObject" : "");
}
use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.
the class MCRIFSCommands method deleteIFSNode.
@MCRCommand(syntax = "delete ifs node {0}", help = "deletes ifs node {0} recursivly")
public static void deleteIFSNode(String nodeID) {
MCRFilesystemNode node = MCRFilesystemNode.getNode(nodeID);
if (node == null) {
LOGGER.warn("IFS Node {} does not exist.", nodeID);
return;
}
LOGGER.info(MessageFormat.format("Deleting IFS Node {0}: {1}{2}", nodeID, node.getOwnerID(), node.getAbsolutePath()));
node.delete();
}
Aggregations