use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRMETSGeneratorFactory method getOldMets.
private static Optional<Mets> getOldMets(MCRPath derivatePath) throws IOException, JDOMException {
if (derivatePath == null) {
return Optional.empty();
}
Path metsPath = derivatePath.resolve("mets.xml");
if (!Files.exists(metsPath)) {
return Optional.empty();
}
SAXBuilder builder = new SAXBuilder();
try (InputStream is = Files.newInputStream(metsPath)) {
Document metsDocument = builder.build(is);
return Optional.of(new Mets(metsDocument));
}
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRMETSHierarchyGenerator method createFileSection.
/**
* Creates the file section.
*
* @return generated file secion.
*/
protected FileSec createFileSection() throws IOException {
FileSec fileSec = new FileSec();
List<MCRPath> filePaths = MCRMetsSave.listFiles(getDerivatePath(), getIgnorePaths());
List<FileGrp> fileGrps = MCRMetsSave.buildFileGroups(filePaths);
fileGrps.forEach(fileSec::addFileGrp);
for (MCRPath file : filePaths) {
String contentType = MCRContentTypes.probeContentType(file);
FileRef ref = new FileRef(file, contentType);
this.files.add(ref);
}
for (FileRef ref : this.files) {
MCRMetsFileUse use = MCRMetsFileUse.get(ref.path);
FileGrp fileGrp = fileGrps.stream().filter(grp -> grp.getUse().equals(use.toString())).findFirst().orElse(null);
if (fileGrp == null) {
LOGGER.warn("Unable to add file '" + ref.toId() + "' because cannot find corresponding group " + " with @USE='" + use.toString() + "'. Ignore file and continue.");
continue;
}
addFile(ref.toId(), fileGrp, ref.getPath(), ref.getContentType());
}
return fileSec;
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRImageThumbnailGenerator method getThumbnail.
@Override
public Optional<BufferedImage> getThumbnail(MCRPath path, int size) throws IOException {
Path iviewFile = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), path.getOwner(), path.getFileName().toString());
MCRTiledPictureProps iviewFileProps = getIviewFileProps(iviewFile);
final double width = iviewFileProps.getWidth();
final double height = iviewFileProps.getHeight();
final int newWidth = width > height ? (int) Math.ceil(size * width / height) : size;
final int newHeight = width > height ? size : (int) Math.ceil(size * height / width);
// this value determines the zoom level!
final double scale = newWidth / width;
// We always want to use the the best needed zoom level!
int sourceZoomLevel = (int) Math.min(Math.max(0, Math.ceil(iviewFileProps.getZoomlevel() - Math.log(scale) / Math.log(1.0 / 2.0))), iviewFileProps.getZoomlevel());
// scale is the real scale which is needed! zoomLevelScale is the scale of the nearest zoom level!
double zoomLevelScale = Math.min(1.0, Math.pow(0.5, iviewFileProps.getZoomlevel() - sourceZoomLevel));
// this is the scale which is needed from the nearest zoom level to the required size of image
double drawScale = (newWidth / (width * zoomLevelScale));
try (FileSystem zipFileSystem = MCRIView2Tools.getFileSystem(iviewFile)) {
Path rootPath = zipFileSystem.getPath("/");
ImageReader imageReader = MCRIView2Tools.getTileImageReader();
BufferedImage testTile = MCRIView2Tools.readTile(rootPath, imageReader, sourceZoomLevel, 0, 0);
BufferedImage targetImage = getTargetImage(newWidth, newHeight, testTile);
Graphics2D graphics = targetImage.createGraphics();
graphics.scale(drawScale, drawScale);
for (int x = 0; x < Math.ceil(width * zoomLevelScale / 256); x++) {
for (int y = 0; y < Math.ceil(height * zoomLevelScale / 256); y++) {
BufferedImage tile = MCRIView2Tools.readTile(rootPath, imageReader, sourceZoomLevel, x, y);
graphics.drawImage(tile, x * 256, y * 256, null);
}
}
return Optional.of(targetImage);
}
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRMediaSourceProvider method getContentPath.
private static String getContentPath(String derivateId, String path) {
try {
MCRPath mcrPath = MCRPath.getPath(derivateId, path);
MCRAbstractFileStore fileStore = (MCRAbstractFileStore) Files.getFileStore(mcrPath);
java.nio.file.Path absolutePath = fileStore.getPhysicalPath(mcrPath);
java.nio.file.Path relativePath = fileStore.getBaseDirectory().relativize(absolutePath);
LogManager.getLogger().info("{} -> {} -> {}", mcrPath, absolutePath, relativePath);
return relativePath.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRMetsCommands method addMetsFileForDerivate.
@MCRCommand(syntax = "add mets files for derivate {0}", order = 20)
public static void addMetsFileForDerivate(String derivateID) {
MCRPath metsFile = MCRPath.getPath(derivateID, "/mets.xml");
if (!Files.exists(metsFile)) {
try {
LOGGER.debug("Start MCRMETSGenerator for derivate {}", derivateID);
Document mets = MCRMETSGeneratorFactory.create(MCRPath.getPath(derivateID, "/")).generate().asDocument();
MCRMetsSave.saveMets(mets, MCRObjectID.getInstance(derivateID));
LOGGER.debug("Stop MCRMETSGenerator for derivate {}", derivateID);
} catch (Exception e) {
LOGGER.error("Can't create mets file for derivate {}", derivateID);
}
}
}
Aggregations