From d3b53baf367412ccd97f4845f7c9e5bac57fafc4 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Mon, 18 Jan 2021 21:42:14 +0100 Subject: [PATCH 01/16] implements nonflat directory direct request according to #240 --- .../uniwue/web/controller/DataController.java | 51 ++++++-- .../uniwue/web/controller/FileController.java | 65 ++++++---- .../controller/ImageProcessingController.java | 4 +- .../web/controller/LibraryController.java | 2 +- .../controller/SegmentationController.java | 21 +++- .../web/controller/ViewerController.java | 88 +++++++++++++- .../web/facade/segmentation/LarexFacade.java | 30 ++++- .../java/de/uniwue/web/io/FileDatabase.java | 115 +++++++++++++++++- .../de/uniwue/web/io/FilePathManager.java | 113 ++++++++++++++++- 9 files changed, 428 insertions(+), 61 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/DataController.java b/src/main/java/de/uniwue/web/controller/DataController.java index 51dd8438..9c82e62b 100644 --- a/src/main/java/de/uniwue/web/controller/DataController.java +++ b/src/main/java/de/uniwue/web/controller/DataController.java @@ -12,6 +12,7 @@ import javax.servlet.ServletContext; import de.uniwue.web.communication.BatchLoadRequest; +import de.uniwue.web.communication.BatchSegmentationRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -70,9 +71,13 @@ private void init() { @RequestMapping(value = "data/book", method = RequestMethod.POST) public @ResponseBody Book getBook(@RequestParam("bookid") int bookID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); + if(fileManager.checkFlat()) { + return database.getBook(bookID); + } else { + return database.getBook(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(),fileManager.getLocalImageMap()); + } - return database.getBook(bookID); } /** @@ -85,11 +90,21 @@ private void init() { @RequestMapping(value = "data/page/annotations", method = RequestMethod.POST) public @ResponseBody PageAnnotations getAnnotations(@RequestParam("bookid") int bookID, @RequestParam("pageid") int pageID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); + + Book book; + Page page; + File annotationsPath; - final Book book = database.getBook(bookID); - final Page page = book.getPage(pageID); - final File annotationsPath = fileManager.getAnnotationPath(book.getName(), page.getName()); + if(fileManager.checkFlat()) { + book = database.getBook(bookID); + page = book.getPage(pageID); + annotationsPath = fileManager.getAnnotationPath(book.getName(), page.getName()); + } else { + book = database.getBook(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(),fileManager.getLocalImageMap()); + page = book.getPage(pageID); + annotationsPath = new File(fileManager.getLocalXmlMap().get(page.getName() + ".xml")); + } if (annotationsPath.exists()) { return PageXMLReader.loadPageAnnotationsFromDisc(annotationsPath); @@ -109,13 +124,23 @@ private void init() { produces = "application/json", consumes = "application/json") public @ResponseBody List getBatchAnnotations(@RequestBody BatchLoadRequest batchLoadRequest) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); - final Book book = database.getBook(batchLoadRequest.getBookid()); + Book book; + if(fileManager.checkFlat()) { + book = database.getBook(batchLoadRequest.getBookid()); + } else { + book = database.getBook(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(),fileManager.getLocalImageMap()); + } List pageAnnotations = new ArrayList<>(); for( int pageID : batchLoadRequest.getPages()) { Page page = book.getPage(pageID); - File annotationsPath = fileManager.getAnnotationPath(book.getName(), page.getName()); + File annotationsPath; + if(fileManager.checkFlat()) { + annotationsPath = fileManager.getAnnotationPath(book.getName(), page.getName()); + } else { + annotationsPath = new File(fileManager.getLocalXmlMap().get(page.getName() + ".xml")); + } if (annotationsPath.exists()) { pageAnnotations.add(PageXMLReader.loadPageAnnotationsFromDisc(annotationsPath)); } else { @@ -136,8 +161,12 @@ private void init() { @RequestMapping(value = "data/status/all/annotations", method = RequestMethod.POST) public @ResponseBody Collection getAnnotationAllStatus(@RequestParam("bookid") int bookID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); - return database.getPagesWithAnnotations(bookID); + config.getListSetting("imagefilter"), fileManager.checkFlat()); + if(fileManager.checkFlat()) { + return database.getPagesWithAnnotations(bookID); + } else { + return database.getPagesWithAnnotations(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(), fileManager.getLocalImageMap(), fileManager.getLocalXmlMap()); + } } /** diff --git a/src/main/java/de/uniwue/web/controller/FileController.java b/src/main/java/de/uniwue/web/controller/FileController.java index 0173d8e7..88a164e5 100644 --- a/src/main/java/de/uniwue/web/controller/FileController.java +++ b/src/main/java/de/uniwue/web/controller/FileController.java @@ -103,28 +103,32 @@ public ResponseEntity getImage(@PathVariable("book") final String book, @PathVariable("image") final String image, @RequestParam(value = "resize", defaultValue = "false") boolean doResize) throws IOException { try { - // Find file with image name - final File directory = new File(fileManager.getLocalBooksPath() + File.separator + book); - final String imageName = image.replace(".png", ""); - - final File[] matchingFiles = directory.listFiles((File dir, String name) -> { - final int extStart = name.lastIndexOf("."); - if (extStart > 0 && name.substring(0, extStart).equals(imageName)) { - final String extension = name.substring(extStart + 1); - return Arrays.asList("png", "jpg", "jpeg", "tif", "tiff").contains(extension); - } else { - return false; - } - } - ); - - assert matchingFiles != null; - if (matchingFiles.length == 0) - throw new IOException("File does not exist"); + File imageFile; byte[] imageBytes = null; - - File imageFile = matchingFiles[0]; + if(fileManager.checkFlat()) { + // Find file with image name + final File directory = new File(fileManager.getLocalBooksPath() + File.separator + book); + final String imageName = image.replace(".png", ""); + + final File[] matchingFiles = directory.listFiles((File dir, String name) -> { + final int extStart = name.lastIndexOf("."); + if (extStart > 0 && name.substring(0, extStart).equals(imageName)) { + final String extension = name.substring(extStart + 1); + return Arrays.asList("png", "jpg", "jpeg", "tif", "tiff").contains(extension); + } else { + return false; + } + } + ); + assert matchingFiles != null; + if (matchingFiles.length == 0) + throw new IOException("File does not exist"); + imageFile = matchingFiles[0]; + } else { + String imagePath = fileManager.getLocalImageMap().get(new File(image).getName() + ".png"); + imageFile = new File(imagePath); + } if (doResize) { // load Mat @@ -170,6 +174,7 @@ public ResponseEntity getImage(@PathVariable("book") final String book, return new ResponseEntity(imageBytes, headers, HttpStatus.OK); } catch (Exception e) { + e.printStackTrace(); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -200,6 +205,13 @@ public ResponseEntity getImage(@PathVariable("book") final String book, final Document pageXML = PageXMLWriter.getPageXML(request.getSegmentation(), request.getVersion(), xmlFile); saveDocument(pageXML, xmlName, bookId); + + if(fileManager.checkFlat()) { + saveDocument(pageXML, xmlName, request.getBookid()); + } else { + File tmpXml = File.createTempFile(xmlName,".xml"); + saveDocument(pageXML, tmpXml.getAbsolutePath(), request.getBookid()); + } byte[] docBytes = convertDocumentToByte(pageXML); return convertByteToResponse(docBytes, request.getSegmentation().getName() + ".xml", "application/xml"); } catch (Exception e) { @@ -225,7 +237,12 @@ public ResponseEntity getImage(@PathVariable("book") final String book, Document pageXML = PageXMLWriter.getPageXML(segmentations.get(i), request.getVersion(), xmlFile); filenames.add(xmlName); docs.add(pageXML); - saveDocument(pageXML, xmlName, request.getBookid()); + if(fileManager.checkFlat()) { + saveDocument(pageXML, xmlName, request.getBookid()); + } else { + File tmpXml = File.createTempFile(xmlName,".xml"); + saveDocument(pageXML, tmpXml.getAbsolutePath(), request.getBookid()); + } } if(request.getDownload()) { @@ -265,7 +282,7 @@ public ResponseEntity getImage(@PathVariable("book") final String book, @RequestParam("bookID") int bookID) { SegmentationSettings settings = null; FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"),fileManager.checkFlat()); if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); @@ -366,14 +383,14 @@ private File getXMLFilePath(String xmlName, Integer bookid){ switch (config.getSetting("localsave")) { case "bookpath": database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); String bookdir = fileManager.getLocalBooksPath() + File.separator + database.getBookName(bookid); return new File(bookdir + File.separator + xmlName); case "savedir": database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); String savedir = fileManager.getSaveDir(); if (savedir != null && !savedir.equals("")) { diff --git a/src/main/java/de/uniwue/web/controller/ImageProcessingController.java b/src/main/java/de/uniwue/web/controller/ImageProcessingController.java index 2aabefcf..9cac4afa 100644 --- a/src/main/java/de/uniwue/web/controller/ImageProcessingController.java +++ b/src/main/java/de/uniwue/web/controller/ImageProcessingController.java @@ -51,7 +51,7 @@ public class ImageProcessingController { public @ResponseBody Region combinecontours(@RequestBody ContourCombineRequest combineRequest) { if (combineRequest.getContours().size() > 0) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); return ImageProcessingFacade.combineContours(combineRequest.getContours(), combineRequest.getPageWidth(), combineRequest.getPageHeight(), combineRequest.getAccuracy(), fileManager, database); } else @@ -70,7 +70,7 @@ public class ImageProcessingController { @RequestParam("pageid") int pageID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); return ImageProcessingFacade.extractContours(pageID, bookID, fileManager, database); } diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index aafc871b..518cc34a 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -53,7 +53,7 @@ public String home(Model model) throws IOException { } File bookPath = new File(fileManager.getLocalBooksPath()); bookPath.isDirectory(); - FileDatabase database = new FileDatabase(bookPath, config.getListSetting("imagefilter")); + FileDatabase database = new FileDatabase(bookPath, config.getListSetting("imagefilter"), true); Library lib = new Library(database); model.addAttribute("library", lib); diff --git a/src/main/java/de/uniwue/web/controller/SegmentationController.java b/src/main/java/de/uniwue/web/controller/SegmentationController.java index 6de499f5..b82eef3f 100644 --- a/src/main/java/de/uniwue/web/controller/SegmentationController.java +++ b/src/main/java/de/uniwue/web/controller/SegmentationController.java @@ -74,7 +74,7 @@ private void init() { produces = "application/json", consumes = "application/json") public @ResponseBody PageAnnotations segment(@RequestBody SegmentationRequest segmentationRequest) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); return LarexFacade.segmentPage(segmentationRequest.getSettings(), segmentationRequest.getPage(), fileManager, database); } @@ -82,7 +82,7 @@ private void init() { produces = "application/json", consumes = "application/json") public @ResponseBody List batchSegment(@RequestBody BatchSegmentationRequest batchSegmentationRequest) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); List results = new ArrayList<>(); this.segProgress = 0; for(int page: batchSegmentationRequest.getPages()){ @@ -96,17 +96,26 @@ private void init() { @RequestMapping(value = "segmentation/settings", method = RequestMethod.POST) public @ResponseBody SegmentationSettings getBook(@RequestParam("bookid") int bookID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); + if(fileManager.checkFlat()) { + return new SegmentationSettings(database.getBook(bookID)); + } else { + return new SegmentationSettings(database.getBook(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(),fileManager.getLocalImageMap())); + } - return new SegmentationSettings(database.getBook(bookID)); } @RequestMapping(value = "segmentation/empty", method = RequestMethod.POST) public @ResponseBody PageAnnotations emptysegment(@RequestParam("bookid") int bookID, @RequestParam("pageid") int pageID) { FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), fileManager.checkFlat()); + Page page; + if(fileManager.checkFlat()) { + page = database.getBook(bookID).getPage(pageID); + } else { + page = database.getBook(fileManager.getNonFlatBookName(),fileManager.getNonFlatBookId(),fileManager.getLocalImageMap()).getPage(pageID); + } - Page page = database.getBook(bookID).getPage(pageID); return new PageAnnotations(page.getName(), page.getWidth(), page.getHeight(), page.getId(), false); } diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index 03f0f441..219055f8 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -2,12 +2,13 @@ import java.io.File; import java.io.IOException; -import java.util.SortedMap; -import java.util.TreeMap; +import java.nio.file.Files; +import java.util.*; import javax.annotation.PostConstruct; import javax.servlet.ServletContext; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -69,7 +70,7 @@ public String viewer(Model model, @RequestParam(value = "book", required = true) } FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter")); + config.getListSetting("imagefilter"), true); Book book = database.getBook(bookID); if (book == null) { @@ -82,11 +83,37 @@ public String viewer(Model model, @RequestParam(value = "book", required = true) model.addAttribute("globalSettings", config); + return "editor"; + } + + /** + * Open the viewer in direct nonflat mode and display the contents of its "book" + **/ + @RequestMapping(value = "/directviewer", method = RequestMethod.GET) + public String directViewer(Model model, @RequestParam(value = "book", required = true) Integer bookID + , @RequestParam(value = "bookname", required = false) String bookName + , @RequestParam(value = "imagemap", required = true) Map imageMap) { + if (bookID == null || imageMap.isEmpty()) { + return "redirect:/404"; + } + FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), + config.getListSetting("imagefilter"), false); + Book book = database.getBook(bookName, bookID, imageMap); + if (book == null) { + return "redirect:/404"; + } + + model.addAttribute("book", book); + model.addAttribute("regionTypes", getRegionTypes()); + model.addAttribute("bookPath", "images/books/"); + model.addAttribute("globalSettings", config); + + return "editor"; } /** - * Open the viewer with a direct request if direct request is enabled + * Open the viewer with a direct request if direct request is enabled using hierarchical directory structures * and display the contents of a selected book. */ @RequestMapping(value = "/direct", method = RequestMethod.POST) @@ -124,6 +151,59 @@ public String direct(Model model, @RequestParam(value = "bookpath", required = t return viewer(model, bookID); } + /** + * Open the viewer with a direct request if direct request is enabled using non-flat directory structures + * and display the contents of a selected book. + */ + @RequestMapping(value = "/direct2", method = RequestMethod.POST) + public String direct(Model model, + @RequestParam(value = "imageMap", required = true) String imagemapString, + @RequestParam(value = "xmlMap", required = true) String xmlmapString, + @RequestParam(value = "bookname", required = true) String bookname, + @RequestParam(value = "localsave", required = false) String localsave, + @RequestParam(value = "savedir", required = false) String savedir, + @RequestParam(value = "websave", required = false) String websave, + @RequestParam(value = "imagefilter", required = false) String imagefilter, + @RequestParam(value = "modes", required = false) String modes) throws IOException { + if (!config.getSetting("directrequest").equals("enable")) { + return "redirect:/error/403"; + } + ObjectMapper mapper = new ObjectMapper(); + Map imagemap; + Map xmlmap; + + try { + imagemap = mapper.readValue(imagemapString, Hashtable.class); + xmlmap = mapper.readValue(xmlmapString, Hashtable.class); + } catch (IOException e) { + e.printStackTrace(); + return "redirect:/error/500"; + } + File tmpBookpath = Files.createTempDirectory("tempdir").toFile(); + fileManager.setIsFlat(false); + fileManager.setLocalBooksPath(tmpBookpath.getPath()); + fileManager.setLocalBookMap(xmlmap, imagemap); + fileManager.setNonFlatBookName(bookname); + int bookID = tmpBookpath.getName().hashCode(); + + if (localsave != null) { + config.setSetting("localsave", localsave); + } + if (savedir != null) { + config.setSetting("savedir", savedir); + } + if (websave != null) { + config.setSetting("websave", websave); + } + if (imagefilter != null) { + config.setSetting("imagefilter", imagefilter); + } + if (modes != null){ + config.setSetting("modes", modes); + } + return directViewer(model,bookID,bookname,imagemap); + } + private static SortedMap getRegionTypes() { SortedMap regionTypes = new TreeMap((c1, c2) -> { diff --git a/src/main/java/de/uniwue/web/facade/segmentation/LarexFacade.java b/src/main/java/de/uniwue/web/facade/segmentation/LarexFacade.java index 107a52f1..ebc9020b 100644 --- a/src/main/java/de/uniwue/web/facade/segmentation/LarexFacade.java +++ b/src/main/java/de/uniwue/web/facade/segmentation/LarexFacade.java @@ -3,9 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; +import java.util.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -43,12 +41,32 @@ public class LarexFacade { * @return */ public static PageAnnotations segmentPage(SegmentationSettings settings, int pageNr, - FilePathManager fileManager, FileDatabase database) { - final Page page = database.getBook(settings.getBookID()).getPage(pageNr); - + FilePathManager fileManager, FileDatabase database) { + Page page; + if(fileManager.checkFlat()) { + page = database.getBook(settings.getBookID()).getPage(pageNr); + } else { + page = database.getBook(fileManager.getNonFlatBookName(), fileManager.getNonFlatBookId(), fileManager.getLocalImageMap()).getPage(pageNr); + } PageAnnotations segmentation = null; Collection segmentationResult = null; String imagePath = fileManager.getLocalBooksPath() + File.separator + page.getImages().get(0); + if(fileManager.checkFlat()) { + imagePath = fileManager.getLocalBooksPath() + File.separator + page.getImages().get(0); + } else { + try{ + List imagesWithExt = new LinkedList<>(); + for(Map.Entry entry : fileManager.getLocalImageMap().entrySet()) { + if(entry.getKey().matches("^" + page.getName() + "\\..*")) { + imagesWithExt.add(entry.getValue()); + } + } + imagePath = imagesWithExt.get(0); + } catch (Exception e) { + e.printStackTrace(); + } + + } File imageFile = new File(imagePath); if (imageFile.exists()) { diff --git a/src/main/java/de/uniwue/web/io/FileDatabase.java b/src/main/java/de/uniwue/web/io/FileDatabase.java index b8bc648b..10a5372b 100644 --- a/src/main/java/de/uniwue/web/io/FileDatabase.java +++ b/src/main/java/de/uniwue/web/io/FileDatabase.java @@ -41,6 +41,7 @@ public class FileDatabase { private File databaseFolder; private List supportedFileExtensions; private List imageSubFilter; + private Boolean isFlat; /** * Initialize a FileDatabase with its root databaseFolder, all supported image @@ -66,11 +67,12 @@ public class FileDatabase { * @param supportedFileExtensions supported image types to load * @param imageSubFilter file extensions that are to be filtered */ - public FileDatabase(File databaseFolder, List supportedFileExtensions, List imageSubFilter) { + public FileDatabase(File databaseFolder, List supportedFileExtensions, List imageSubFilter, Boolean isFlat) { this.databaseFolder = databaseFolder; this.books = new HashMap(); this.supportedFileExtensions = new ArrayList(supportedFileExtensions); this.imageSubFilter = new ArrayList(imageSubFilter); + this.isFlat = isFlat; } /** @@ -95,8 +97,8 @@ public FileDatabase(File databaseFolder, List supportedFileExtensions, L * @param databaseFolder Root database folder containing all books * @param imageSubFilter file extensions that are to be filtered */ - public FileDatabase(File databaseFolder, List imageSubFilter) { - this(databaseFolder, Arrays.asList("png", "jpg", "jpeg", "tif", "tiff"), imageSubFilter); + public FileDatabase(File databaseFolder, List imageSubFilter, Boolean isFlat) { + this(databaseFolder, Arrays.asList("png", "jpg", "jpeg", "tif", "tiff"), imageSubFilter, isFlat); } /** @@ -111,8 +113,8 @@ public FileDatabase(File databaseFolder, List imageSubFilter) { * * @param databaseFolder Root database folder containing all books */ - public FileDatabase(File databaseFolder) { - this(databaseFolder, new ArrayList<>()); + public FileDatabase(File databaseFolder, Boolean isFlat) { + this(databaseFolder, new ArrayList<>(), isFlat); } /** @@ -166,6 +168,18 @@ public Book getBook(int id) { return readBook(bookFile, id); } + + /** + * Load a book object via Map. + * + * @param bookName name of book + * @param bookID Identifier of the book to load + * @param imageMap map of images from book + * @return Loaded book + */ + public Book getBook(String bookName, Integer bookID, Map imageMap) { + return readBook(bookName,imageMap, bookID); + } /** * Retrieve name of a book without loading it into ram @@ -200,6 +214,30 @@ public Collection getPagesWithAnnotations(int bookID) { return segmentedIds; } + /** + * Get the IDs of all book pages, for which a segmentation file exists. + * + * @param bookID Identifier for the book of which pages are to be checked + * @return Collection of all book pages in the selected book with a segmentation + * file + */ + public Collection getPagesWithAnnotations(String bookName, Integer bookID, Map imageMap, Map xmlMap) { + Collection segmentedIds = new HashSet<>(); + try { + Book book = getBook(bookName,bookID,imageMap); + for (Page page : book.getPages()) { + String key = page.getName() + ".xml"; + + if (xmlMap.get(key) != null && new File(xmlMap.get(key)).exists()) + segmentedIds.add(page.getId()); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return segmentedIds; + } + /** * Read contents of a book from the folder structure. * @@ -262,6 +300,73 @@ private Book readBook(File bookFile, int bookID) { return new Book(bookID, bookName, pages); } + /** + * Read contents of a book from the folder structure. + * + * @param bookName name of book + * @param imagemap map of all book images + * @param bookID Identifier that is to be used for the loaded book + * @return + */ + private Book readBook(String bookName, Map imagemap, int bookID) { + try{ + LinkedList pages = new LinkedList(); + int pageCounter = 0; + + if(imageSubFilter.isEmpty()) { + // Interpret every image as its own page + for(String imgPath: imagemap.values()) { + File imageFile = new File(imgPath); + Size imageSize = ImageLoader.readDimensions(imageFile); + String name = removeAllExtensions(imageFile.getName()); + if(isSupportedImage(imageFile)) { + pages.add(new Page(pageCounter++, name, Collections.singletonList(imgPath), (int) imageSize.width, (int) imageSize.height)); + } + } + } else { + // Combine images with the same base name and different (sub)extensions + List imageFileList = new ArrayList(); + for( String imgPath : imagemap.values()) { imageFileList.add(new File(imgPath)); } + File[] fileArray = imageFileList.toArray(new File[imageFileList.size()]); + Map> imageFiles = Arrays.stream(Objects.requireNonNull(fileArray)) + .filter(f -> isSupportedImage(f) && (imageSubFilter.isEmpty() || passesSubFilter(f.getName()))) + .collect(Collectors.groupingBy(f -> removeAllExtensions(f.getName()))); + + ArrayList sortedPages = new ArrayList<>(imageFiles.keySet()); + sortedPages.sort(String::compareTo); + + for (String pageName : sortedPages) { + Map> groupedImages = imageFiles.get(pageName).stream() + .collect(Collectors.groupingBy(f -> extractSubExtension(f.getName()))); + List images = new ArrayList<>(); + + Size imageSize = null; + for(String subExtension: imageSubFilter) { + List subImages = !subExtension.equals(".") ? groupedImages.get(subExtension) + : groupedImages.get(""); + + if(subImages != null) { + for(File subImage: subImages) { + if(imageSize == null) { + imageSize = ImageLoader.readDimensions(subImage); + } + images.add(subImage.getParentFile().getName() + File.separator + subImage.getName()); + } + } + } + + assert imageSize != null; + pages.add(new Page(pageCounter++, pageName, images, (int) imageSize.width, (int) imageSize.height)); + } + } + + return new Book(bookID, bookName, pages); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + /** * Check if a file is a supported image file * diff --git a/src/main/java/de/uniwue/web/io/FilePathManager.java b/src/main/java/de/uniwue/web/io/FilePathManager.java index 79567629..17b5cd6f 100644 --- a/src/main/java/de/uniwue/web/io/FilePathManager.java +++ b/src/main/java/de/uniwue/web/io/FilePathManager.java @@ -1,6 +1,8 @@ package de.uniwue.web.io; import java.io.File; +import java.util.List; +import java.util.Map; import javax.servlet.ServletContext; @@ -21,6 +23,11 @@ public class FilePathManager { private ServletContext servletContext; private String booksPath; private String saveDir; + private Map xmlMap; + private Map imageMap; + private Boolean isFlat; + private String nonFlatBookName; + private int nonFlatBookId; /** * Init FileManager with servletContext in order to provide f @@ -31,7 +38,21 @@ public class FilePathManager { public void init(ServletContext servletContext) { this.isInit = true; this.servletContext = servletContext; - booksPath = servletContext.getRealPath("resources" + File.separator + "books"); + this.booksPath = servletContext.getRealPath("resources" + File.separator + "books"); + this.isFlat = true; + } + + /** + * Init FileManager with servletContext in order to provide f + * + * @param servletContext ServletContext of the current web application, in order + * to get abs disc paths + */ + public void init(ServletContext servletContext, Boolean isFlat) { + this.isInit = true; + this.servletContext = servletContext; + this.booksPath = servletContext.getRealPath("resources" + File.separator + "books"); + this.isFlat = false; } /** @@ -40,7 +61,30 @@ public void init(ServletContext servletContext) { * @return disc path to the books folder */ public String getLocalBooksPath() { - return booksPath; + if(isFlat) { + return booksPath; + } else { + return ""; + } + + } + + /** + * Get the local map to all pagexml paths + * + * @return map to all local xml paths + */ + public Map getLocalXmlMap() { + return xmlMap; + } + + /** + * Get the local disc path to the books folder + * + * @return disc path to the books folder + */ + public Map getLocalImageMap() { + return imageMap; } /** @@ -97,6 +141,17 @@ public void setSaveDir(String saveDir) { this.saveDir = new File(saveDir).getAbsolutePath(); } + /** + * Change the local disc book map structure + * + * @param xmlmap Map linking every pageID to a path for its pagexml + * @param imagemap Map linking every pageID to a path for its image + */ + public void setLocalBookMap( Map xmlmap, Map imagemap) { + this.xmlMap = xmlmap; + this.imageMap = imagemap; + } + /** * Find the local disc path to a page image * @@ -136,4 +191,58 @@ public File getAnnotationPath(String bookname, String pagename) { public boolean isInit() { return isInit; } + + /** + * Set file managar structure flag + * + * @return true if has been initialized, else false + */ + public void setIsFlat(Boolean isFlat) { + this.isFlat = isFlat; + } + + /** + * Set bookname for nonflat + * + * @return true if has been initialized, else false + */ + public void setNonFlatBookName(String bookName) { + this.nonFlatBookName = bookName; + } + + /** + * Get bookname for nonflat + * + * @return true if has been initialized, else false + */ + public String getNonFlatBookName() { + return this.nonFlatBookName; + } + + /** + * Set bookname for nonflat + * + * @return true if has been initialized, else false + */ + public void setNonFlatBookId(int bookId) { + this.nonFlatBookId = bookId; + } + + /** + * Get bookname for nonflat + * + * @return true if has been initialized, else false + */ + public int getNonFlatBookId() { + return this.nonFlatBookId; + } + + /** + * Check if the FileManager is flat + * + * @return true if has been initialized, else false + */ + public Boolean checkFlat() { + return this.isFlat; + } } From 0028e2dca4d32654cb2ab6a3e47cd67ef42fd5f1 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Wed, 7 Apr 2021 09:05:03 +0200 Subject: [PATCH 02/16] adds some mets.xml (image and fileGrp) support to Larex and necessary changes for non-flat transition, expands library --- pom.xml | 7 + .../uniwue/web/controller/DataController.java | 12 +- .../uniwue/web/controller/FileController.java | 38 +++-- .../web/controller/LibraryController.java | 118 ++++++++++++++- .../web/controller/ViewerController.java | 71 +++++++++- .../java/de/uniwue/web/io/FileDatabase.java | 30 +++- .../java/de/uniwue/web/io/MetsReader.java | 86 +++++++++++ .../java/de/uniwue/web/model/Library.java | 11 +- src/main/webapp/WEB-INF/views/editor.jsp | 1 + src/main/webapp/WEB-INF/views/lib.jsp | 114 +++++++++++++-- src/main/webapp/resources/js/navigation.js | 134 +++++++++++++++++- .../resources/js/viewer/communicator.js | 15 +- src/main/webapp/resources/js/viewer/gui.js | 4 +- 13 files changed, 590 insertions(+), 51 deletions(-) create mode 100644 src/main/java/de/uniwue/web/io/MetsReader.java diff --git a/pom.xml b/pom.xml index d57181d0..49a04884 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,13 @@ 4.3.0-2 + + + org.json + json + 20210307 + + commons-fileupload diff --git a/src/main/java/de/uniwue/web/controller/DataController.java b/src/main/java/de/uniwue/web/controller/DataController.java index 9c82e62b..5a931a17 100644 --- a/src/main/java/de/uniwue/web/controller/DataController.java +++ b/src/main/java/de/uniwue/web/controller/DataController.java @@ -221,4 +221,14 @@ private void init() { String ocr4allMode = config.getSetting("ocr4all"); return ocr4allMode.equals("enable"); } -} + + /** + * Returns whether LAREX is configured to be used direct request mode or not. + */ + @RequestMapping(value = "config/directrequest", method = RequestMethod.POST, headers = "Accept=*/*", + produces = "application/json") + public @ResponseBody Boolean isDirectRequest() { + String directrequestMode = config.getSetting("directrequest"); + return directrequestMode.equals("enable"); + } +} \ No newline at end of file diff --git a/src/main/java/de/uniwue/web/controller/FileController.java b/src/main/java/de/uniwue/web/controller/FileController.java index 88a164e5..7fe3dcc4 100644 --- a/src/main/java/de/uniwue/web/controller/FileController.java +++ b/src/main/java/de/uniwue/web/controller/FileController.java @@ -2,10 +2,9 @@ import java.awt.image.BufferedImage; import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -98,17 +97,18 @@ private void init() { * Request an image of a book, by book name and image name. * Use resize to get a downscaled preview image, with a width of 300px. */ - @RequestMapping(value = "/images/books/{book}/{image}", method = RequestMethod.GET) - public ResponseEntity getImage(@PathVariable("book") final String book, - @PathVariable("image") final String image, + @RequestMapping(value = "loadImage/{imageEnc}", method = RequestMethod.GET) + public ResponseEntity getImage(@PathVariable("imageEnc") final String imageEnc, @RequestParam(value = "resize", defaultValue = "false") boolean doResize) throws IOException { try { File imageFile; byte[] imageBytes = null; + String image = java.net.URLDecoder.decode(imageEnc, StandardCharsets.UTF_8.name()).replaceAll("‡","/"); + if(image.startsWith("\"")) { image = image.substring(1); } if(fileManager.checkFlat()) { // Find file with image name - final File directory = new File(fileManager.getLocalBooksPath() + File.separator + book); + final File directory = new File(fileManager.getLocalBooksPath() + File.separator); final String imageName = image.replace(".png", ""); final File[] matchingFiles = directory.listFiles((File dir, String name) -> { @@ -126,8 +126,19 @@ public ResponseEntity getImage(@PathVariable("book") final String book, throw new IOException("File does not exist"); imageFile = matchingFiles[0]; } else { - String imagePath = fileManager.getLocalImageMap().get(new File(image).getName() + ".png"); - imageFile = new File(imagePath); + List supportedImageExt = Arrays.asList(".png", ".jpg", ".jpeg", ".tif", ".tiff"); + List foundImages = new LinkedList<>(); + Map localImageMap = fileManager.getLocalImageMap(); + int extStart = image.lastIndexOf("."); + for ( String ext: supportedImageExt) { + String imgWithExt = new File(image).getName() + ext; + String imgWithExt2 = image + ext; + if(localImageMap.containsKey(imgWithExt)) { + foundImages.add(localImageMap.get(imgWithExt)); + } + } + //String imagePath = fileManager.getLocalImageMap().get(new File(image).getName() + ".png"); + imageFile = new File(foundImages.get(0)); } if (doResize) { @@ -209,8 +220,8 @@ public ResponseEntity getImage(@PathVariable("book") final String book, if(fileManager.checkFlat()) { saveDocument(pageXML, xmlName, request.getBookid()); } else { - File tmpXml = File.createTempFile(xmlName,".xml"); - saveDocument(pageXML, tmpXml.getAbsolutePath(), request.getBookid()); + String xmlPath = fileManager.getLocalXmlMap().get(request.getSegmentation().getName() + ".xml"); + saveDocument(pageXML, xmlPath, request.getBookid()); } byte[] docBytes = convertDocumentToByte(pageXML); return convertByteToResponse(docBytes, request.getSegmentation().getName() + ".xml", "application/xml"); @@ -240,8 +251,8 @@ public ResponseEntity getImage(@PathVariable("book") final String book, if(fileManager.checkFlat()) { saveDocument(pageXML, xmlName, request.getBookid()); } else { - File tmpXml = File.createTempFile(xmlName,".xml"); - saveDocument(pageXML, tmpXml.getAbsolutePath(), request.getBookid()); + String xmlPath = fileManager.getLocalXmlMap().get(segmentations.get(i).getName() + ".xml"); + saveDocument(pageXML, xmlPath, request.getBookid()); } } @@ -394,7 +405,6 @@ private File getXMLFilePath(String xmlName, Integer bookid){ String savedir = fileManager.getSaveDir(); if (savedir != null && !savedir.equals("")) { - savedir = savedir + File.separator + database.getBookName(bookid); return new File(savedir + File.separator + xmlName); } else { System.err.println("Warning: Save dir is not set. File could not been saved."); diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index 518cc34a..f1b6512c 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -1,20 +1,30 @@ package de.uniwue.web.controller; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import javax.servlet.ServletContext; +import com.fasterxml.jackson.databind.ser.std.CollectionSerializer; +import de.uniwue.web.io.MetsReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import org.json.JSONObject; +import de.uniwue.web.io.MetsReader; import de.uniwue.web.config.LarexConfiguration; import de.uniwue.web.io.FileDatabase; import de.uniwue.web.io.FilePathManager; import de.uniwue.web.model.Library; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; /** * Communication Controller to handle simple requests about the book library. @@ -30,6 +40,24 @@ public class LibraryController { @Autowired private LarexConfiguration config; + /** + * Initialize the controller by loading the fileManager and settings if not + * loaded already. + **/ + @PostConstruct + private void init() { + if (!fileManager.isInit()) { + fileManager.init(servletContext); + } + if (!config.isInitiated()) { + config.read(new File(fileManager.getConfigurationFile())); + String bookFolder = config.getSetting("bookpath"); + if (!bookFolder.equals("")) { + fileManager.setLocalBooksPath(bookFolder); + } + } + } + /** * Display a list of all books present in the book path. Clicking on a book will * open it in the larex view. @@ -41,8 +69,6 @@ public class LibraryController { @RequestMapping(value = "/") public String home(Model model) throws IOException { // Reset config - fileManager.init(servletContext); - config.read(new File(fileManager.getConfigurationFile())); String bookFolder = config.getSetting("bookpath"); String saveDir = config.getSetting("savedir"); if (!bookFolder.equals("")) { @@ -53,10 +79,92 @@ public String home(Model model) throws IOException { } File bookPath = new File(fileManager.getLocalBooksPath()); bookPath.isDirectory(); - FileDatabase database = new FileDatabase(bookPath, config.getListSetting("imagefilter"), true); + FileDatabase database = new FileDatabase(bookPath, config.getListSetting("imagefilter"), false); Library lib = new Library(database); model.addAttribute("library", lib); return "lib"; } + + /** + * Display a list of all books present in the book path. Clicking on a book will + * open it in the larex view. + * + * @param bookid + * @param bookpath + * @param type + * @return + * @throws IOException + */ + @RequestMapping(value = "library/getPageLocations", method = RequestMethod.POST, headers = "Accept=*/*") + public @ResponseBody Map getPageLocations(@RequestParam(value = "bookid") int bookid, @RequestParam(value = "bookpath") String bookpath, @RequestParam(value = "booktype") String type) throws IOException { + fileManager.init(servletContext); + String booktype = ""; + try { + booktype = java.net.URLDecoder.decode(type, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + File baseFolder = new File(bookpath); + if(!baseFolder.isDirectory()) { + throw new IOException("Path is no directory, but should be in this instance"); + } + try { + switch (booktype) { + + case "legacy": + Map map = getFileMap(baseFolder.getAbsolutePath(), ".png"); + return map; + default: + System.out.println("Attempting to open empty directory"); + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + /** + * Opens Mets file and returns all known filegroups and each imageLocation + * + * @param metsPath path to mets.xml + * @return + * @throws IOException + */ + @RequestMapping(value = "library/getMetsData", method = RequestMethod.POST, headers = "Accept=*/*") + public @ResponseBody Map> getMetsData(@RequestParam("metspath") String metsPath) throws IOException { + if (!fileManager.isInit()) { + fileManager.init(servletContext); + } + String mets = ""; + try { + mets = java.net.URLDecoder.decode(metsPath, StandardCharsets.UTF_8.name()) + File.separator + "mets.xml"; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + File metsFile = new File(mets); + if(!metsFile.exists()) { throw new IOException("Mets file doesn't exist anymore"); } + return MetsReader.getFileGroups(mets, false); + } + + /** + * Opens Mets file and returns all known filegroups and each imageLocation + * + * @param baseFolder path to legacy baseFolder + * @param ext file extension to map + * @return map containing imageName and path + */ + public Map getFileMap(String baseFolder, String ext) { + Map fileMap = new LinkedHashMap(); + File directFolder = new File(baseFolder); + List files = Arrays.stream(directFolder.listFiles()).sorted(Comparator.naturalOrder()).collect(Collectors.toList()); + for (File file : files) { + if(file.getName().endsWith(ext)) { + String path = file.getAbsolutePath(); + fileMap.put(file.getName(), path); + } + } + return fileMap; + } } diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index 219055f8..7ddc1e6c 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; @@ -79,7 +80,7 @@ public String viewer(Model model, @RequestParam(value = "book", required = true) model.addAttribute("book", book); model.addAttribute("regionTypes", getRegionTypes()); - model.addAttribute("bookPath", "images/books/"); + model.addAttribute("bookPath", "loadImage/"); model.addAttribute("globalSettings", config); @@ -89,7 +90,7 @@ public String viewer(Model model, @RequestParam(value = "book", required = true) /** * Open the viewer in direct nonflat mode and display the contents of its "book" **/ - @RequestMapping(value = "/directviewer", method = RequestMethod.GET) + @RequestMapping(value = "/directviewer", method = RequestMethod.POST) public String directViewer(Model model, @RequestParam(value = "book", required = true) Integer bookID , @RequestParam(value = "bookname", required = false) String bookName , @RequestParam(value = "imagemap", required = true) Map imageMap) { @@ -105,7 +106,7 @@ public String directViewer(Model model, @RequestParam(value = "book", required = model.addAttribute("book", book); model.addAttribute("regionTypes", getRegionTypes()); - model.addAttribute("bookPath", "images/books/"); + model.addAttribute("bookPath", "loadImage/"); model.addAttribute("globalSettings", config); @@ -204,6 +205,70 @@ public String direct(Model model, return directViewer(model,bookID,bookname,imagemap); } + /** + * Open the viewer from library navigation. + */ + @RequestMapping(value = "/directLibrary", method = RequestMethod.GET) + public String direct(Model model, + @RequestParam(value = "imageMap", required = true) String imagemapString, + @RequestParam(value = "customFlag", required = true) String customFlag, + @RequestParam(value = "customFolder", required = false) String customFolder) throws IOException { + System.out.println("In directLibrary"); + ObjectMapper mapper = new ObjectMapper(); + Map imagemap; + Map xmlmap = new LinkedHashMap<>(); + + try { + System.out.println("tried mapper"); + imagemap = mapper.readValue(java.net.URLDecoder.decode(imagemapString, StandardCharsets.UTF_8.name()).replaceAll("‡","\"").replaceAll("…",":"), HashMap.class); + System.out.println("finished mapper"); + } catch (IOException e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + return "redirect:/error/500"; + } + for(Map.Entry entry : imagemap.entrySet()) { + //Map.Entry xmlEntry = new Map.Entry(); + String imageName = entry.getKey(); + String imagePath = entry.getValue(); + if(imagePath.startsWith("/")) { + imagePath = entry.getValue().substring(1); + entry.setValue(imagePath); + } + System.out.println(imageName + ":" + imagePath); + String xmlName = imageName.split("\\.")[0] + ".xml"; + System.out.println("xmlName is: " + xmlName); + if(customFlag.equals("true")) { + if(!customFolder.endsWith(File.separator)) { customFolder += File.separator; } + xmlmap.put(xmlName,customFolder + xmlName); + } else { + String parentFolder = new File(imagePath).getParentFile().getAbsolutePath(); + if(!parentFolder.endsWith(File.separator)) { parentFolder += File.separator; } + xmlmap.put(xmlName,parentFolder + xmlName); + } + + System.out.println(xmlName + ":" + xmlmap.get(xmlName)); + } + + File tmpBookpath = Files.createTempDirectory("tempdir").toFile(); + fileManager.setIsFlat(false); + fileManager.setLocalBooksPath(tmpBookpath.getPath()); + fileManager.setLocalBookMap(xmlmap, imagemap); + fileManager.setNonFlatBookName("bookname"); + int bookID = tmpBookpath.getName().hashCode(); + System.out.println("finished other stuff"); + + FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), + config.getListSetting("imagefilter"), false); + Book book = database.getBook("libraryBook", bookID, imagemap); + + model.addAttribute("book", book); + model.addAttribute("regionTypes", getRegionTypes()); + model.addAttribute("bookPath", "loadImage/"); + model.addAttribute("globalSettings", config); + + return "editor"; + } private static SortedMap getRegionTypes() { SortedMap regionTypes = new TreeMap((c1, c2) -> { diff --git a/src/main/java/de/uniwue/web/io/FileDatabase.java b/src/main/java/de/uniwue/web/io/FileDatabase.java index 10a5372b..ca935457 100644 --- a/src/main/java/de/uniwue/web/io/FileDatabase.java +++ b/src/main/java/de/uniwue/web/io/FileDatabase.java @@ -118,20 +118,40 @@ public FileDatabase(File databaseFolder, Boolean isFlat) { } /** - * List all books by their id and name. + * List all books by their id, name and type. * * @return Map of -> */ - public Map listBooks() { - Map booknames = new HashMap<>(); - + public Map> listBooks() { + Map> booknames = new LinkedHashMap<>(); // Extract book names from book files for (Entry bookEntry : listBookFiles().entrySet()) { - booknames.put(bookEntry.getKey(), bookEntry.getValue().getName()); + ArrayList list = new ArrayList(); + list.add(bookEntry.getValue().getName()); + list.add(checkType(bookEntry.getValue())); + list.add(bookEntry.getValue().getAbsolutePath()); + booknames.put(bookEntry.getKey(), list); } return booknames; } + /** + * Checks type of book Folder + * + * @return String type + */ + public String checkType(File bookfolder) { + File[] metsFiles = bookfolder.listFiles((d, name) -> name.endsWith("mets.xml")); + File[] imgFiles = bookfolder.listFiles((d, name) -> name.endsWith(".png")); + if( metsFiles.length != 0) { + return "mets"; + } else if(imgFiles.length != 0) { + return "legacy"; + } else { + return "empty"; + } + } + /** * List all book files by their id. * diff --git a/src/main/java/de/uniwue/web/io/MetsReader.java b/src/main/java/de/uniwue/web/io/MetsReader.java new file mode 100644 index 00000000..a42f3520 --- /dev/null +++ b/src/main/java/de/uniwue/web/io/MetsReader.java @@ -0,0 +1,86 @@ +package de.uniwue.web.io; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.*; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * MetsReader reads mets filegroup data and file locations from a mets.xml + */ +public class MetsReader { + + public static Map> getFileGroups(String metsPath, boolean useRelativePath){ + List fileList; + Map> fileGroupMap = new LinkedHashMap<>(); + File metsFile = new File(metsPath); + try { + Document mets = parseXML(metsPath); + Element rootElement = mets.getDocumentElement(); + NodeList sectorList = rootElement.getChildNodes(); + NodeList fileSector = null; + for(int i = 0; i < sectorList.getLength() ;i++) { + if (sectorList.item(i).getNodeName().equals("mets:fileSec")) { + fileSector = sectorList.item(i).getChildNodes(); + } + } + if(fileSector == null) { throw new NoSuchElementException("No file sector found."); } + for(int i = 0; i < fileSector.getLength(); i++) { + if(fileSector.item(i).getNodeType() == Node.ELEMENT_NODE){ + fileList = new ArrayList<>(); + Element fileGrp = (Element) fileSector.item(i); + String fileGrpName = fileGrp.getAttribute("USE"); + NodeList fileGrpChilds = fileGrp.getChildNodes(); + for(int j = 0; j < fileGrpChilds.getLength(); j++) { + Node fileNode = fileGrpChilds.item(j); + if(fileNode.getNodeType() == Node.ELEMENT_NODE){ + Element fileElement = (Element) fileNode; + if(fileElement.getAttribute("MIMETYPE").equals("image/png")) { + for(int h = 0; h < fileElement.getChildNodes().getLength(); h++) { + if(fileElement.getChildNodes().item(h).getNodeType() == Node.ELEMENT_NODE) { + Element fileLoc = (Element) fileElement.getChildNodes().item(h); + String filePath = fileLoc.getAttribute("xlink:href"); + if(!useRelativePath) { + filePath = metsFile.getParentFile().getAbsolutePath() + File.separator + filePath; + } + fileList.add(filePath); + } + } + } + } + } + fileList.sort(Comparator.naturalOrder()); + fileGroupMap.put(fileGrpName,fileList); + } + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return fileGroupMap; + } + + private static Document parseXML(String filePath) throws ParserConfigurationException, + IOException, + org.xml.sax.SAXException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(filePath); + doc.getDocumentElement().normalize(); + return doc; + } +} diff --git a/src/main/java/de/uniwue/web/model/Library.java b/src/main/java/de/uniwue/web/model/Library.java index 3cc202c5..68c7a951 100644 --- a/src/main/java/de/uniwue/web/model/Library.java +++ b/src/main/java/de/uniwue/web/model/Library.java @@ -1,6 +1,7 @@ package de.uniwue.web.model; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -12,15 +13,15 @@ */ public class Library { - private final Map books; - private final List> sortedBooks; + private final Map> books; + private final List>> sortedBooks; public Library(FileDatabase database) { this.books = database.listBooks(); sortedBooks = new ArrayList<>(); sortedBooks.addAll(books.entrySet()); - sortedBooks.sort(Entry.comparingByValue()); + sortedBooks.sort(Entry.comparingByKey()); } /** @@ -28,7 +29,7 @@ public Library(FileDatabase database) { * * @return book map of all books in the bookPath */ - public Map getBooks() { + public Map> getBooks() { return books; } @@ -37,7 +38,7 @@ public Map getBooks() { * * @return sorted list of all books in the bookPath */ - public List> getSortedBooks(){ + public List>> getSortedBooks(){ return sortedBooks; } } diff --git a/src/main/webapp/WEB-INF/views/editor.jsp b/src/main/webapp/WEB-INF/views/editor.jsp index 713286f6..0122984a 100644 --- a/src/main/webapp/WEB-INF/views/editor.jsp +++ b/src/main/webapp/WEB-INF/views/editor.jsp @@ -19,6 +19,7 @@ src="resources/js/viewer/viewerInput.js"> + Larex - Library @@ -14,33 +15,124 @@ + + + + \ No newline at end of file diff --git a/src/main/webapp/resources/js/navigation.js b/src/main/webapp/resources/js/navigation.js index 65f498de..aeb3d078 100644 --- a/src/main/webapp/resources/js/navigation.js +++ b/src/main/webapp/resources/js/navigation.js @@ -1,10 +1,138 @@ +let _customXmlFolder = false; +let _communicator; +//const _communicator = new Communicator(); $(document).ready(function () { + _communicator = new Communicator(); + let metsMap = new Map; + $('.modal').modal(); + _communicator.getDirectRequestMode().done((data) => { + console.log("directrequest" + data); + /*if(data == true) { + $('#mets_tab').removeClass('hide'); + }*/ + }); $('.bookopen').click(function () { - //$().redirect('viewer', {'bookid': $(this).attr('id'), 'page': '0'}); - var form = $('
' + + $('#viewerNext').addClass('disabled'); + let book_id = $(this).attr('id'); + let path = String($(this).attr('data-path')); + let type = String($(this).attr('data-type')); + $('#pageSection').hide(); + if(type === "mets") { + $('#fileGrp-div').show(); + _communicator.getMetsData(path).done((data) => { + $('#openBookModal').modal('open'); + + //remove old filegrps + let node = document.getElementById('file-grp') + while(node.firstChild) { + node.removeChild(node.lastChild); + } + metsMap = data; + for( let fileGrp of Object.keys(data)) { + let pathList = data[fileGrp]; + if(pathList.length > 0) { + let fileGrpItem = document.createElement('li'); + fileGrpItem.setAttribute('data',fileGrp); + fileGrpItem.setAttribute('class', "selectFileGrp") + fileGrpItem.appendChild(document.createTextNode(fileGrp)); + document.getElementById('file-grp').appendChild(fileGrpItem); + } + } + }); + } else if(type === "legacy") { + $('#fileGrp-div').hide(); + _communicator.getLibraryBookPages(book_id,path,type).done((data) => { + let pageList = new Array(); + for( let key of Object.keys(data)) { + let path = data[key]; + pageList.push(path); + } + showPages(pageList); + $('#openBookModal').modal('open'); + }); + } else { + console.log("No viable files found in directory"); + } + /*var form = $('' + '' + '
'); $('body').append(form); - $(form).submit(); + $(form).submit();*/ + }); + + $("#fileGrp-div").on('click', 'li.selectFileGrp',function () { + let fileGrp = String($(this).attr('data')); + document.getElementById("FileGrpBtn").innerHTML = fileGrp; + let pageList = metsMap[fileGrp]; + showPages(pageList); + }); + + $('.library-xml-setting').click(function () { + const $this = $(this); + const $switchBox = $this.find('input'); + _customXmlFolder = $switchBox.prop('checked'); + if(_customXmlFolder) { + $('#xml_folder_input').removeClass('hide'); + } else { + $('#xml_folder_input').addClass('hide'); + } + }); + + $('#viewerNext').click(function (e) { + let customFolder; + if(_customXmlFolder) { + customFolder = document.getElementById("xml_folder").value; + } + let pageElemList = document.getElementsByClassName('libraryPage'); + let imageMap = JSON.parse('{}'); + for(let i = 0; i").attr('src', "images/books/" + image_path).on('load', () => { + let pathEnc = encodeURIComponent(JSON.stringify(image_path.replace(/\//g, "‡"))); + const img = $("").attr('src', "loadImage/" + pathEnc).on('load', () => { img.attr('id', id); $('body').append(img); status.resolve(); @@ -165,6 +165,10 @@ class Communicator { return this.request("config/ocr4all", {}, DataType.JSON); } + getDirectRequestMode(){ + return this.request("config/directrequest", {}, DataType.JSON); + } + getBatchSegmentationProgress(){ return $.ajax({ type: "GET", @@ -173,6 +177,13 @@ class Communicator { }); } + getLibraryBookPages(book_id, bookpath, booktype) { + return this.request("library/getPageLocations", {bookid:book_id,bookpath:bookpath,booktype:booktype}, DataType.SIMPLE) + } + + getMetsData(mets_path) { + return this.request("library/getMetsData", {metspath : mets_path}, DataType.SIMPLE) + } getBatchExportProgress(){ return $.ajax({ type: "GET", diff --git a/src/main/webapp/resources/js/viewer/gui.js b/src/main/webapp/resources/js/viewer/gui.js index ef9ba9f1..19d9e328 100644 --- a/src/main/webapp/resources/js/viewer/gui.js +++ b/src/main/webapp/resources/js/viewer/gui.js @@ -924,8 +924,8 @@ function GUI(canvas, viewer, colors, accessible_modes) { const imageSrc = $p.data("image"); const imageId = $p.data("page"); const title = $p.data("title"); - - const $image = $(''+title+''); + let imageSource = encodeURIComponent(JSON.stringify(imageSrc.replace(/\//g, "‡"))); + const $image = $(''+title+''); const $status = $('
'+ 'assignment_late'+ 'save'+ From 307b2a11adc7e900643410de23825930f350a65e Mon Sep 17 00:00:00 2001 From: maxnth Date: Mon, 3 May 2021 09:07:41 +0200 Subject: [PATCH 03/16] remove unused imports --- .../java/de/uniwue/web/controller/DataController.java | 3 +-- .../de/uniwue/web/controller/LibraryController.java | 7 ++----- src/main/java/de/uniwue/web/io/MetsReader.java | 5 ----- src/main/java/de/uniwue/web/model/Library.java | 11 +++++------ 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/DataController.java b/src/main/java/de/uniwue/web/controller/DataController.java index 5a931a17..80025408 100644 --- a/src/main/java/de/uniwue/web/controller/DataController.java +++ b/src/main/java/de/uniwue/web/controller/DataController.java @@ -12,7 +12,6 @@ import javax.servlet.ServletContext; import de.uniwue.web.communication.BatchLoadRequest; -import de.uniwue.web.communication.BatchSegmentationRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -231,4 +230,4 @@ private void init() { String directrequestMode = config.getSetting("directrequest"); return directrequestMode.equals("enable"); } -} \ No newline at end of file +} diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index f1b6512c..b515dd76 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -8,16 +8,13 @@ import javax.annotation.PostConstruct; import javax.servlet.ServletContext; -import com.fasterxml.jackson.databind.ser.std.CollectionSerializer; import de.uniwue.web.io.MetsReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; -import org.json.JSONObject; -import de.uniwue.web.io.MetsReader; import de.uniwue.web.config.LarexConfiguration; import de.uniwue.web.io.FileDatabase; import de.uniwue.web.io.FilePathManager; @@ -28,7 +25,7 @@ /** * Communication Controller to handle simple requests about the book library. - * + * */ @Controller @Scope("request") @@ -61,7 +58,7 @@ private void init() { /** * Display a list of all books present in the book path. Clicking on a book will * open it in the larex view. - * + * * @param model * @return * @throws IOException diff --git a/src/main/java/de/uniwue/web/io/MetsReader.java b/src/main/java/de/uniwue/web/io/MetsReader.java index a42f3520..3ac05519 100644 --- a/src/main/java/de/uniwue/web/io/MetsReader.java +++ b/src/main/java/de/uniwue/web/io/MetsReader.java @@ -1,17 +1,12 @@ package de.uniwue.web.io; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/src/main/java/de/uniwue/web/model/Library.java b/src/main/java/de/uniwue/web/model/Library.java index 68c7a951..fe44c650 100644 --- a/src/main/java/de/uniwue/web/model/Library.java +++ b/src/main/java/de/uniwue/web/model/Library.java @@ -1,7 +1,6 @@ package de.uniwue.web.model; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -12,7 +11,7 @@ * Library of all books. List of all books in the bookPath with their id (key) and name (value). */ public class Library { - + private final Map> books; private final List>> sortedBooks; @@ -23,19 +22,19 @@ public Library(FileDatabase database) { sortedBooks.sort(Entry.comparingByKey()); } - + /** * Retrieve all books in a map of "id -> name" - * + * * @return book map of all books in the bookPath */ public Map> getBooks() { return books; } - + /** * Retrieve a list of all books with id and name, sorted in lexical order. - * + * * @return sorted list of all books in the bookPath */ public List>> getSortedBooks(){ From 066694ecdbee499c972dd76856cfd2a096d0ff40 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 14 May 2021 02:55:00 +0200 Subject: [PATCH 04/16] get imagePaths from pagexml in mets --- .../web/controller/LibraryController.java | 15 ++++--- .../web/controller/ViewerController.java | 3 -- .../java/de/uniwue/web/io/FileDatabase.java | 12 ++++++ .../java/de/uniwue/web/io/MetsReader.java | 43 +++++++++++++++++++ src/main/webapp/resources/js/navigation.js | 2 +- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index b515dd76..56e1a0e7 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -134,19 +134,22 @@ public String home(Model model) throws IOException { if (!fileManager.isInit()) { fileManager.init(servletContext); } - String mets = ""; + String path = ""; try { - mets = java.net.URLDecoder.decode(metsPath, StandardCharsets.UTF_8.name()) + File.separator + "mets.xml"; + path = java.net.URLDecoder.decode(metsPath, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } - File metsFile = new File(mets); - if(!metsFile.exists()) { throw new IOException("Mets file doesn't exist anymore"); } - return MetsReader.getFileGroups(mets, false); + File metsFile = new File(path + File.separator + "mets.xml"); + if(!metsFile.exists()) { + metsFile = new File(path + File.separator + "data" + File.separator + "mets.xml"); + if (!metsFile.exists()) { throw new IOException("Mets file doesn't exist anymore"); } + } + return MetsReader.getFileGroups(metsFile.getAbsolutePath(), false); } /** - * Opens Mets file and returns all known filegroups and each imageLocation + * returns each imagePath in given directory * * @param baseFolder path to legacy baseFolder * @param ext file extension to map diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index 7ddc1e6c..b7d03fb1 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -219,9 +219,7 @@ public String direct(Model model, Map xmlmap = new LinkedHashMap<>(); try { - System.out.println("tried mapper"); imagemap = mapper.readValue(java.net.URLDecoder.decode(imagemapString, StandardCharsets.UTF_8.name()).replaceAll("‡","\"").replaceAll("…",":"), HashMap.class); - System.out.println("finished mapper"); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); @@ -256,7 +254,6 @@ public String direct(Model model, fileManager.setLocalBookMap(xmlmap, imagemap); fileManager.setNonFlatBookName("bookname"); int bookID = tmpBookpath.getName().hashCode(); - System.out.println("finished other stuff"); FileDatabase database = new FileDatabase(new File(fileManager.getLocalBooksPath()), config.getListSetting("imagefilter"), false); diff --git a/src/main/java/de/uniwue/web/io/FileDatabase.java b/src/main/java/de/uniwue/web/io/FileDatabase.java index ca935457..2b111e89 100644 --- a/src/main/java/de/uniwue/web/io/FileDatabase.java +++ b/src/main/java/de/uniwue/web/io/FileDatabase.java @@ -148,6 +148,18 @@ public String checkType(File bookfolder) { } else if(imgFiles.length != 0) { return "legacy"; } else { + //try ./data/mets.xml + File dataFolder = new File(bookfolder.getAbsolutePath() + File.separator + "data"); + if(dataFolder.exists() && dataFolder.isDirectory()) { + metsFiles = dataFolder.listFiles((d, name) -> name.endsWith("mets.xml")); + if( metsFiles.length != 0) { + return "mets-data"; + } else { + System.out.println("data folder exists but contains no mets"); + } + } else { + System.out.println("data folder does not exist"); + } return "empty"; } } diff --git a/src/main/java/de/uniwue/web/io/MetsReader.java b/src/main/java/de/uniwue/web/io/MetsReader.java index 3ac05519..3a7aa2ef 100644 --- a/src/main/java/de/uniwue/web/io/MetsReader.java +++ b/src/main/java/de/uniwue/web/io/MetsReader.java @@ -12,6 +12,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.xml.sax.SAXParseException; /** * MetsReader reads mets filegroup data and file locations from a mets.xml @@ -34,6 +35,7 @@ public static Map> getFileGroups(String metsPath, boolean u } if(fileSector == null) { throw new NoSuchElementException("No file sector found."); } for(int i = 0; i < fileSector.getLength(); i++) { + Boolean isImgGrp = false; if(fileSector.item(i).getNodeType() == Node.ELEMENT_NODE){ fileList = new ArrayList<>(); Element fileGrp = (Element) fileSector.item(i); @@ -44,6 +46,7 @@ public static Map> getFileGroups(String metsPath, boolean u if(fileNode.getNodeType() == Node.ELEMENT_NODE){ Element fileElement = (Element) fileNode; if(fileElement.getAttribute("MIMETYPE").equals("image/png")) { + isImgGrp = true; for(int h = 0; h < fileElement.getChildNodes().getLength(); h++) { if(fileElement.getChildNodes().item(h).getNodeType() == Node.ELEMENT_NODE) { Element fileLoc = (Element) fileElement.getChildNodes().item(h); @@ -54,6 +57,20 @@ public static Map> getFileGroups(String metsPath, boolean u fileList.add(filePath); } } + } else if(!isImgGrp && fileElement.getAttribute("MIMETYPE").equals("application/vnd.prima.page+xml")) { + for(int h = 0; h < fileElement.getChildNodes().getLength(); h++) { + if(fileElement.getChildNodes().item(h).getNodeType() == Node.ELEMENT_NODE) { + Element fileLoc = (Element) fileElement.getChildNodes().item(h); + String filePath = fileLoc.getAttribute("xlink:href"); + if(!useRelativePath) { + filePath = metsFile.getParentFile().getAbsolutePath() + File.separator + filePath; + fileList.add(metsFile.getParentFile().getAbsolutePath() + File.separator + getImagePathFromPage(filePath)); + } else { + fileList.add(getImagePathFromPage(filePath)); + } + + } + } } } } @@ -78,4 +95,30 @@ private static Document parseXML(String filePath) throws ParserConfigurationExce doc.getDocumentElement().normalize(); return doc; } + + private static String getImagePathFromPage(String pageXmlPath) { + try { + Document pageXml = parseXML(pageXmlPath); + Element rootElement = pageXml.getDocumentElement(); + NodeList nodeList = rootElement.getChildNodes(); + NodeList pageNode = null; + for(int i = 0; i < nodeList.getLength() ;i++) { + if (nodeList.item(i).getNodeName().contains("Page") || nodeList.item(i).getNodeName().equals("Page")) { + pageNode = nodeList.item(i).getChildNodes(); + } + } + if(pageNode == null) { throw new NoSuchElementException("No page element found."); } + String imagePath = null; + for(int i = 0; i < pageNode.getLength() ;i++) { + if (pageNode.item(i).getNodeName().contains("AlternativeImage") && pageNode.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element elem = (Element) pageNode.item(i); + imagePath = elem.getAttribute("filename"); + } + } + return imagePath; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } } diff --git a/src/main/webapp/resources/js/navigation.js b/src/main/webapp/resources/js/navigation.js index aeb3d078..8922bb39 100644 --- a/src/main/webapp/resources/js/navigation.js +++ b/src/main/webapp/resources/js/navigation.js @@ -17,7 +17,7 @@ $(document).ready(function () { let path = String($(this).attr('data-path')); let type = String($(this).attr('data-type')); $('#pageSection').hide(); - if(type === "mets") { + if(type === "mets" || type === "mets-data") { $('#fileGrp-div').show(); _communicator.getMetsData(path).done((data) => { $('#openBookModal').modal('open'); From 2f26bc09f1e48b9ef80bd1e36867d529a8aee2c1 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Wed, 30 Jun 2021 02:12:13 +0200 Subject: [PATCH 05/16] remove debug code and small rebase fix --- .../uniwue/web/controller/FileController.java | 31 +++++++++++-------- .../web/controller/ViewerController.java | 3 -- src/main/webapp/WEB-INF/views/lib.jsp | 5 --- src/main/webapp/resources/js/navigation.js | 8 ----- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/FileController.java b/src/main/java/de/uniwue/web/controller/FileController.java index 7fe3dcc4..f4715600 100644 --- a/src/main/java/de/uniwue/web/controller/FileController.java +++ b/src/main/java/de/uniwue/web/controller/FileController.java @@ -137,7 +137,7 @@ public ResponseEntity getImage(@PathVariable("imageEnc") final String im foundImages.add(localImageMap.get(imgWithExt)); } } - //String imagePath = fileManager.getLocalImageMap().get(new File(image).getName() + ".png"); + imageFile = new File(foundImages.get(0)); } @@ -395,20 +395,25 @@ private File getXMLFilePath(String xmlName, Integer bookid){ case "bookpath": database = new FileDatabase(new File(fileManager.getLocalBooksPath()), config.getListSetting("imagefilter"), fileManager.checkFlat()); - - String bookdir = fileManager.getLocalBooksPath() + File.separator - + database.getBookName(bookid); - return new File(bookdir + File.separator + xmlName); + if( fileManager.checkFlat()) { + String bookdir = fileManager.getLocalBooksPath() + File.separator + + database.getBookName(bookid); + if(!bookdir.endsWith(File.separator)) { bookdir += File.separator; } + return new File(bookdir + xmlName); + } else { + return new File(xmlName); + } case "savedir": - database = new FileDatabase(new File(fileManager.getLocalBooksPath()), - config.getListSetting("imagefilter"), fileManager.checkFlat()); - - String savedir = fileManager.getSaveDir(); - if (savedir != null && !savedir.equals("")) { - return new File(savedir + File.separator + xmlName); + if( fileManager.checkFlat()) { + String savedir = config.getSetting("savedir"); + if (savedir != null && !savedir.equals("")) { + if(!savedir.endsWith(File.separator)) { savedir += File.separator; } + return new File(savedir + xmlName); + } else { + System.err.println("Warning: Save dir is not set. File could not been saved."); + } } else { - System.err.println("Warning: Save dir is not set. File could not been saved."); - return null; + return new File(fileManager.getLocalXmlMap().get(xmlName)); } case "none": case "default": diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index b7d03fb1..90b26267 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -213,7 +213,6 @@ public String direct(Model model, @RequestParam(value = "imageMap", required = true) String imagemapString, @RequestParam(value = "customFlag", required = true) String customFlag, @RequestParam(value = "customFolder", required = false) String customFolder) throws IOException { - System.out.println("In directLibrary"); ObjectMapper mapper = new ObjectMapper(); Map imagemap; Map xmlmap = new LinkedHashMap<>(); @@ -233,9 +232,7 @@ public String direct(Model model, imagePath = entry.getValue().substring(1); entry.setValue(imagePath); } - System.out.println(imageName + ":" + imagePath); String xmlName = imageName.split("\\.")[0] + ".xml"; - System.out.println("xmlName is: " + xmlName); if(customFlag.equals("true")) { if(!customFolder.endsWith(File.separator)) { customFolder += File.separator; } xmlmap.put(xmlName,customFolder + xmlName); diff --git a/src/main/webapp/WEB-INF/views/lib.jsp b/src/main/webapp/WEB-INF/views/lib.jsp index 75c72cc8..ad96a3c8 100644 --- a/src/main/webapp/WEB-INF/views/lib.jsp +++ b/src/main/webapp/WEB-INF/views/lib.jsp @@ -68,11 +68,6 @@

- <%--
- - -
- --%> diff --git a/src/main/webapp/resources/js/navigation.js b/src/main/webapp/resources/js/navigation.js index 8922bb39..c2d1a16e 100644 --- a/src/main/webapp/resources/js/navigation.js +++ b/src/main/webapp/resources/js/navigation.js @@ -7,9 +7,6 @@ $(document).ready(function () { $('.modal').modal(); _communicator.getDirectRequestMode().done((data) => { console.log("directrequest" + data); - /*if(data == true) { - $('#mets_tab').removeClass('hide'); - }*/ }); $('.bookopen').click(function () { $('#viewerNext').addClass('disabled'); @@ -53,11 +50,6 @@ $(document).ready(function () { } else { console.log("No viable files found in directory"); } - /*var form = $('
' + - '' + - '
'); - $('body').append(form); - $(form).submit();*/ }); $("#fileGrp-div").on('click', 'li.selectFileGrp',function () { From 6df379bac655aade6b9185016bfa642f791fed99 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 2 Jul 2021 03:08:52 +0200 Subject: [PATCH 06/16] fix relative tomcat paths to absolute --- .../java/de/uniwue/web/controller/ViewerController.java | 7 ------- src/main/java/de/uniwue/web/io/FileDatabase.java | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index 90b26267..866fcdc9 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -225,13 +225,8 @@ public String direct(Model model, return "redirect:/error/500"; } for(Map.Entry entry : imagemap.entrySet()) { - //Map.Entry xmlEntry = new Map.Entry(); String imageName = entry.getKey(); String imagePath = entry.getValue(); - if(imagePath.startsWith("/")) { - imagePath = entry.getValue().substring(1); - entry.setValue(imagePath); - } String xmlName = imageName.split("\\.")[0] + ".xml"; if(customFlag.equals("true")) { if(!customFolder.endsWith(File.separator)) { customFolder += File.separator; } @@ -241,8 +236,6 @@ public String direct(Model model, if(!parentFolder.endsWith(File.separator)) { parentFolder += File.separator; } xmlmap.put(xmlName,parentFolder + xmlName); } - - System.out.println(xmlName + ":" + xmlmap.get(xmlName)); } File tmpBookpath = Files.createTempDirectory("tempdir").toFile(); diff --git a/src/main/java/de/uniwue/web/io/FileDatabase.java b/src/main/java/de/uniwue/web/io/FileDatabase.java index 2b111e89..c4188f55 100644 --- a/src/main/java/de/uniwue/web/io/FileDatabase.java +++ b/src/main/java/de/uniwue/web/io/FileDatabase.java @@ -157,8 +157,6 @@ public String checkType(File bookfolder) { } else { System.out.println("data folder exists but contains no mets"); } - } else { - System.out.println("data folder does not exist"); } return "empty"; } From 02bc445875d634113e26a3abfbc861c62337f851 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Wed, 7 Jul 2021 16:43:45 +0200 Subject: [PATCH 07/16] fixed error on reload --- src/main/java/de/uniwue/web/io/FilePathManager.java | 7 +------ src/main/webapp/resources/js/navigation.js | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/uniwue/web/io/FilePathManager.java b/src/main/java/de/uniwue/web/io/FilePathManager.java index 17b5cd6f..e6762a05 100644 --- a/src/main/java/de/uniwue/web/io/FilePathManager.java +++ b/src/main/java/de/uniwue/web/io/FilePathManager.java @@ -61,12 +61,7 @@ public void init(ServletContext servletContext, Boolean isFlat) { * @return disc path to the books folder */ public String getLocalBooksPath() { - if(isFlat) { - return booksPath; - } else { - return ""; - } - + return booksPath; } /** diff --git a/src/main/webapp/resources/js/navigation.js b/src/main/webapp/resources/js/navigation.js index c2d1a16e..b7a68053 100644 --- a/src/main/webapp/resources/js/navigation.js +++ b/src/main/webapp/resources/js/navigation.js @@ -87,10 +87,10 @@ $(document).ready(function () { type: "GET", data: { "imageMap" : JSON.stringify(imageMap), "customFlag" : _customXmlFolder, "customFolder" : JSON.stringify(customFolder)}, async : false, - target : '_blank', + target : '_self', success : function(data) { console.log("Direct request successful!") - let win = window.open("text/html", "_blank"); + let win = window.open("text/html", "_self"); win.document.write(data); win.document.close(); }, From f751a4b81fa83f5ee544c187a33fe9ecdb3e20e3 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Thu, 8 Jul 2021 01:34:40 +0200 Subject: [PATCH 08/16] add 'load last open project' functionality to library --- .../web/communication/DirectRequest.java | 54 +++++++++++++++++++ .../web/controller/LibraryController.java | 12 ++++- .../web/controller/ViewerController.java | 5 ++ .../de/uniwue/web/io/FilePathManager.java | 22 +++++++- src/main/webapp/WEB-INF/views/lib.jsp | 7 +++ src/main/webapp/resources/js/navigation.js | 33 ++++++++++++ .../resources/js/viewer/communicator.js | 3 ++ 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/uniwue/web/communication/DirectRequest.java diff --git a/src/main/java/de/uniwue/web/communication/DirectRequest.java b/src/main/java/de/uniwue/web/communication/DirectRequest.java new file mode 100644 index 00000000..ed626384 --- /dev/null +++ b/src/main/java/de/uniwue/web/communication/DirectRequest.java @@ -0,0 +1,54 @@ +package de.uniwue.web.communication; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import de.uniwue.web.model.PageAnnotations; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Communication object for the library to request the editor + * + */ +public class DirectRequest { + private String imagemapString; + private String customFlag; + private String customFolder; + + @JsonCreator + public DirectRequest(String imagemapString, + String customFlag, + String customFolder) { + this.imagemapString = imagemapString; + this.customFlag = customFlag; + if(customFolder != null) { + this.customFolder = customFolder; + } else { + this.customFolder = ""; + } + } + + public String getImagemapString() { + return imagemapString; + } + + public String getCustomFlag() { + return customFlag; + } + + public String getCustomFolder() { + return customFolder; + } + + public void setImagemapString(String imagemapString) { + this.imagemapString = imagemapString; + } + + public void setCustomFlag(String customFlag) { + this.customFlag = customFlag; + } + + public void setCustomFolder(String customFolder) { + this.customFolder = customFolder; + } +} diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index 56e1a0e7..066958f5 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -8,6 +8,7 @@ import javax.annotation.PostConstruct; import javax.servlet.ServletContext; +import de.uniwue.web.communication.DirectRequest; import de.uniwue.web.io.MetsReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -147,7 +148,16 @@ public String home(Model model) throws IOException { } return MetsReader.getFileGroups(metsFile.getAbsolutePath(), false); } - + /** + * Returns old Request to resend directrequest + * + * @return + * @throws IOException + */ + @RequestMapping(value = "library/getOldRequest", method = RequestMethod.POST, headers = "Accept=*/*") + public @ResponseBody DirectRequest getOldRequest() { + return fileManager.getDirectRequest(); + } /** * returns each imagePath in given directory * diff --git a/src/main/java/de/uniwue/web/controller/ViewerController.java b/src/main/java/de/uniwue/web/controller/ViewerController.java index 866fcdc9..3d4efa3a 100644 --- a/src/main/java/de/uniwue/web/controller/ViewerController.java +++ b/src/main/java/de/uniwue/web/controller/ViewerController.java @@ -10,10 +10,12 @@ import javax.servlet.ServletContext; import com.fasterxml.jackson.databind.ObjectMapper; +import de.uniwue.web.communication.DirectRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -216,6 +218,9 @@ public String direct(Model model, ObjectMapper mapper = new ObjectMapper(); Map imagemap; Map xmlmap = new LinkedHashMap<>(); + DirectRequest directRequest = new DirectRequest(imagemapString, customFlag, customFolder); + + fileManager.setDirectRequest(directRequest); try { imagemap = mapper.readValue(java.net.URLDecoder.decode(imagemapString, StandardCharsets.UTF_8.name()).replaceAll("‡","\"").replaceAll("…",":"), HashMap.class); diff --git a/src/main/java/de/uniwue/web/io/FilePathManager.java b/src/main/java/de/uniwue/web/io/FilePathManager.java index e6762a05..c9817b66 100644 --- a/src/main/java/de/uniwue/web/io/FilePathManager.java +++ b/src/main/java/de/uniwue/web/io/FilePathManager.java @@ -1,11 +1,11 @@ package de.uniwue.web.io; import java.io.File; -import java.util.List; import java.util.Map; import javax.servlet.ServletContext; +import de.uniwue.web.communication.DirectRequest; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -28,6 +28,9 @@ public class FilePathManager { private Boolean isFlat; private String nonFlatBookName; private int nonFlatBookId; + private Boolean customFlag; + private String customFolder; + private DirectRequest directRequest = null; /** * Init FileManager with servletContext in order to provide f @@ -240,4 +243,21 @@ public int getNonFlatBookId() { public Boolean checkFlat() { return this.isFlat; } + + /** + * Get customFolder + * @return customFolder + */ + public String getCustomFolder() { + return customFolder; + } + + public DirectRequest getDirectRequest() { + return directRequest; + } + + public void setDirectRequest(DirectRequest directRequest) { + this.directRequest = directRequest; + } + } diff --git a/src/main/webapp/WEB-INF/views/lib.jsp b/src/main/webapp/WEB-INF/views/lib.jsp index ad96a3c8..e9a4f465 100644 --- a/src/main/webapp/WEB-INF/views/lib.jsp +++ b/src/main/webapp/WEB-INF/views/lib.jsp @@ -23,6 +23,13 @@
+
+ Load last project + cached
+ +
diff --git a/src/main/webapp/resources/js/navigation.js b/src/main/webapp/resources/js/navigation.js index b7a68053..bf694332 100644 --- a/src/main/webapp/resources/js/navigation.js +++ b/src/main/webapp/resources/js/navigation.js @@ -8,6 +8,16 @@ $(document).ready(function () { _communicator.getDirectRequestMode().done((data) => { console.log("directrequest" + data); }); + let checkForOldProject = function () { + _communicator.getOldRequestData().done((data) => { + if(data) { + $('#reloadLastProject').show(); + } else { + $('#reloadLastProject').hide(); + } + }); + } + checkForOldProject(); $('.bookopen').click(function () { $('#viewerNext').addClass('disabled'); let book_id = $(this).attr('id'); @@ -95,6 +105,7 @@ $(document).ready(function () { win.document.close(); }, }); + checkForOldProject(); }); function showPages(pageList) { @@ -127,4 +138,26 @@ $(document).ready(function () { let splitName = function (str) { return str.split('\\').pop().split('/').pop(); } + $('#reloadLastProject').click(function () { + _communicator.getOldRequestData().done((oldRequest) => { + if(oldRequest){ + + $.ajax({ + url : "/Larex/directLibrary", + type: "GET", + data: { "imageMap" : oldRequest.imagemapString, "customFlag" : oldRequest.customFlag, "customFolder" : oldRequest.customFolder}, + async : false, + target : '_self', + success : function(data) { + console.log("Direct request successful!") + let win = window.open("", "_self"); + win.document.write(data); + win.document.close(); + }, + }); + } else { + console.log("no last project found"); + } + }); + }); }); diff --git a/src/main/webapp/resources/js/viewer/communicator.js b/src/main/webapp/resources/js/viewer/communicator.js index 11bafa8a..aa6e7bba 100644 --- a/src/main/webapp/resources/js/viewer/communicator.js +++ b/src/main/webapp/resources/js/viewer/communicator.js @@ -184,6 +184,9 @@ class Communicator { getMetsData(mets_path) { return this.request("library/getMetsData", {metspath : mets_path}, DataType.SIMPLE) } + getOldRequestData() { + return this.request("library/getOldRequest") + } getBatchExportProgress(){ return $.ajax({ type: "GET", From 97e681827b1cf622a2a7db3c21036df73eba5c8c Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Thu, 8 Jul 2021 14:05:19 +0200 Subject: [PATCH 09/16] add reload current project and return to library button --- src/main/webapp/WEB-INF/tags/base/baseMenu.tag | 5 +++++ src/main/webapp/resources/js/navigation.js | 5 +++++ src/main/webapp/resources/js/viewer/controller.js | 10 ++++++++++ src/main/webapp/resources/js/viewer/guiInput.js | 2 ++ 4 files changed, 22 insertions(+) diff --git a/src/main/webapp/WEB-INF/tags/base/baseMenu.tag b/src/main/webapp/WEB-INF/tags/base/baseMenu.tag index 17f1bfc4..ad98a562 100644 --- a/src/main/webapp/WEB-INF/tags/base/baseMenu.tag +++ b/src/main/webapp/WEB-INF/tags/base/baseMenu.tag @@ -25,6 +25,11 @@ Zoom fit + Library + Reload + Undo { if(data) { $('#reloadLastProject').show(); + let reloading = sessionStorage.getItem("reloading"); + if (reloading && reloading == "true") { + sessionStorage.removeItem("reloading"); + $('#reloadLastProject').trigger('click'); + } } else { $('#reloadLastProject').hide(); } diff --git a/src/main/webapp/resources/js/viewer/controller.js b/src/main/webapp/resources/js/viewer/controller.js index a80b4b1c..cead84d4 100644 --- a/src/main/webapp/resources/js/viewer/controller.js +++ b/src/main/webapp/resources/js/viewer/controller.js @@ -314,6 +314,16 @@ function Controller(bookID, accessible_modes, canvasID, regionColors, colors, gl this._imageVersion = imageVersion; } + this.loadLibrary = function () { + sessionStorage.setItem("reloading", "false") + document.location.reload(); + } + + this.reloadProject = function () { + sessionStorage.setItem("reloading", "true") + document.location.reload(); + } + this.redo = function () { _actionController.redo(_currentPage); } diff --git a/src/main/webapp/resources/js/viewer/guiInput.js b/src/main/webapp/resources/js/viewer/guiInput.js index 39ffd643..325eea06 100644 --- a/src/main/webapp/resources/js/viewer/guiInput.js +++ b/src/main/webapp/resources/js/viewer/guiInput.js @@ -152,6 +152,8 @@ function GuiInput(navigationController, controller, gui, textViewer, selector, c $('.moveup').click(() => _navigationController.move(0, -10)); $('.movecenter').click(() => _navigationController.center()); + $('.loadLibrary').click(() => _controller.loadLibrary()); + $('.reloadProject').click(() => _controller.reloadProject()); $('.undo').click(() => _controller.undo()); $('.redo').click(() => _controller.redo()); From 44714c38ecda90135310941b5daf17cd30a7b960 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 9 Jul 2021 12:00:27 +0200 Subject: [PATCH 10/16] add missing other imgExts --- .../web/controller/LibraryController.java | 15 ++++++++----- .../java/de/uniwue/web/io/FileDatabase.java | 7 +++++- .../java/de/uniwue/web/io/MetsReader.java | 22 ++++++++++++------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/uniwue/web/controller/LibraryController.java b/src/main/java/de/uniwue/web/controller/LibraryController.java index 066958f5..a18a6f25 100644 --- a/src/main/java/de/uniwue/web/controller/LibraryController.java +++ b/src/main/java/de/uniwue/web/controller/LibraryController.java @@ -111,7 +111,8 @@ public String home(Model model) throws IOException { switch (booktype) { case "legacy": - Map map = getFileMap(baseFolder.getAbsolutePath(), ".png"); + List supportedImageExt = Arrays.asList(".png", ".jpg", ".jpeg", ".tif", ".tiff"); + Map map = getFileMap(baseFolder.getAbsolutePath(), supportedImageExt); return map; default: System.out.println("Attempting to open empty directory"); @@ -162,17 +163,19 @@ public String home(Model model) throws IOException { * returns each imagePath in given directory * * @param baseFolder path to legacy baseFolder - * @param ext file extension to map + * @param extList file extension to map * @return map containing imageName and path */ - public Map getFileMap(String baseFolder, String ext) { + public Map getFileMap(String baseFolder, List extList) { Map fileMap = new LinkedHashMap(); File directFolder = new File(baseFolder); List files = Arrays.stream(directFolder.listFiles()).sorted(Comparator.naturalOrder()).collect(Collectors.toList()); for (File file : files) { - if(file.getName().endsWith(ext)) { - String path = file.getAbsolutePath(); - fileMap.put(file.getName(), path); + for (String ext : extList) { + if(file.getName().endsWith(ext)) { + String path = file.getAbsolutePath(); + fileMap.put(file.getName(), path); + } } } return fileMap; diff --git a/src/main/java/de/uniwue/web/io/FileDatabase.java b/src/main/java/de/uniwue/web/io/FileDatabase.java index c4188f55..7379e32e 100644 --- a/src/main/java/de/uniwue/web/io/FileDatabase.java +++ b/src/main/java/de/uniwue/web/io/FileDatabase.java @@ -1,6 +1,7 @@ package de.uniwue.web.io; import java.io.File; +import java.io.FileFilter; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -142,7 +143,11 @@ public Map> listBooks() { */ public String checkType(File bookfolder) { File[] metsFiles = bookfolder.listFiles((d, name) -> name.endsWith("mets.xml")); - File[] imgFiles = bookfolder.listFiles((d, name) -> name.endsWith(".png")); + List imgFileList = new ArrayList<>(); + for(String ext : supportedFileExtensions) { + imgFileList.addAll(Arrays.asList(bookfolder.listFiles((d, name) -> name.endsWith(ext)))); + } + File[] imgFiles = imgFileList.toArray(new File[0]); if( metsFiles.length != 0) { return "mets"; } else if(imgFiles.length != 0) { diff --git a/src/main/java/de/uniwue/web/io/MetsReader.java b/src/main/java/de/uniwue/web/io/MetsReader.java index 3a7aa2ef..8e6e8a4a 100644 --- a/src/main/java/de/uniwue/web/io/MetsReader.java +++ b/src/main/java/de/uniwue/web/io/MetsReader.java @@ -46,15 +46,21 @@ public static Map> getFileGroups(String metsPath, boolean u if(fileNode.getNodeType() == Node.ELEMENT_NODE){ Element fileElement = (Element) fileNode; if(fileElement.getAttribute("MIMETYPE").equals("image/png")) { - isImgGrp = true; - for(int h = 0; h < fileElement.getChildNodes().getLength(); h++) { - if(fileElement.getChildNodes().item(h).getNodeType() == Node.ELEMENT_NODE) { - Element fileLoc = (Element) fileElement.getChildNodes().item(h); - String filePath = fileLoc.getAttribute("xlink:href"); - if(!useRelativePath) { - filePath = metsFile.getParentFile().getAbsolutePath() + File.separator + filePath; + List supportedImageExt = Arrays.asList(".png", ".jpg", ".jpeg", ".tif", ".tiff"); + for(String fileExt : supportedImageExt) { + String ext = fileExt.replace(".","image/"); + if(fileElement.getAttribute("MIMETYPE").equals(ext)) { + isImgGrp = true; + for(int h = 0; h < fileElement.getChildNodes().getLength(); h++) { + if(fileElement.getChildNodes().item(h).getNodeType() == Node.ELEMENT_NODE) { + Element fileLoc = (Element) fileElement.getChildNodes().item(h); + String filePath = fileLoc.getAttribute("xlink:href"); + if(!useRelativePath) { + filePath = metsFile.getParentFile().getAbsolutePath() + File.separator + filePath; + } + fileList.add(filePath); + } } - fileList.add(filePath); } } } else if(!isImgGrp && fileElement.getAttribute("MIMETYPE").equals("application/vnd.prima.page+xml")) { From 814e5ee6ea6f13cf2078bcd3d47e1b76d8021ec7 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 9 Jul 2021 12:08:16 +0200 Subject: [PATCH 11/16] change browser reload to project reload --- src/main/webapp/resources/js/viewer/controller.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/webapp/resources/js/viewer/controller.js b/src/main/webapp/resources/js/viewer/controller.js index cead84d4..bb0a830e 100644 --- a/src/main/webapp/resources/js/viewer/controller.js +++ b/src/main/webapp/resources/js/viewer/controller.js @@ -69,6 +69,10 @@ function Controller(bookID, accessible_modes, canvasID, regionColors, colors, gl // Unsaved warning window.onbeforeunload = () => { + let reloading = sessionStorage.getItem("reloading"); + if(!reloading || reloading != "false") { + sessionStorage.setItem("reloading", "true"); + } if(!this.isCurrentPageSaved() && _actionController.hasActions(_currentPage)){ // Warning message if browser supports it return 'You have unsaved progress. Leaving the page will discard every change.\n' From 5ab0b6e05228a845643c1e2b98982f055ba214e0 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 9 Jul 2021 12:25:12 +0200 Subject: [PATCH 12/16] read other supported imgExt from mets --- src/main/java/de/uniwue/web/io/MetsReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/uniwue/web/io/MetsReader.java b/src/main/java/de/uniwue/web/io/MetsReader.java index 8e6e8a4a..0abe99fd 100644 --- a/src/main/java/de/uniwue/web/io/MetsReader.java +++ b/src/main/java/de/uniwue/web/io/MetsReader.java @@ -45,7 +45,7 @@ public static Map> getFileGroups(String metsPath, boolean u Node fileNode = fileGrpChilds.item(j); if(fileNode.getNodeType() == Node.ELEMENT_NODE){ Element fileElement = (Element) fileNode; - if(fileElement.getAttribute("MIMETYPE").equals("image/png")) { + if(fileElement.getAttribute("MIMETYPE").startsWith("image")) { List supportedImageExt = Arrays.asList(".png", ".jpg", ".jpeg", ".tif", ".tiff"); for(String fileExt : supportedImageExt) { String ext = fileExt.replace(".","image/"); From dd963ec59035240b54d88e3c2c80409a183886e7 Mon Sep 17 00:00:00 2001 From: chaddy314 Date: Fri, 9 Jul 2021 13:30:05 +0200 Subject: [PATCH 13/16] add tooltip --- src/main/webapp/WEB-INF/views/lib.jsp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/lib.jsp b/src/main/webapp/WEB-INF/views/lib.jsp index e9a4f465..1f26e620 100644 --- a/src/main/webapp/WEB-INF/views/lib.jsp +++ b/src/main/webapp/WEB-INF/views/lib.jsp @@ -23,8 +23,8 @@
-
- Load last project +
+ Load last loaded project cached