public abstract class AbstractIndexer {
+ public static boolean isImage(final String fileExtension) {
+ for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
+ if (ext.equals(fileExtension))
+ return true;
+ return false;
+ }
+
+ public static boolean isOgv(final String fileExtension) {
+ return fileExtension.equalsIgnoreCase("ogv");
+ }
+
+ public static boolean shallFileBeIndexed(final File file) {
+
+ if (file.getName().startsWith("."))
+ return false;
+ if (file.getName().startsWith("index"))
+ if (file.getName().endsWith(".html"))
+ return false;
+
+ return true;
+ }
+
public void compileHtml(final Layout layout,
final DirectoryMetadata directory)
- throws UnsupportedEncodingException {
+ throws UnsupportedEncodingException {
for (final AbstractFile file : directory.getFiles())
if (file instanceof GeneralFile) {
layout.enlistFile(file);
} else if (file instanceof Picture)
- layout.enlistImage(file);
+ layout.enlistImage((Picture) file);
else if (file instanceof DirectoryFile)
layout.enlistDirectory(file);
public abstract String getThumbnailUrl(Picture picture,
final Dimension desiredDimension, IndexingContext context);
- public static boolean isImage(final String fileExtension) {
- for (final String ext : Constants.SUPPORTED_IMAGE_EXTENSIONS)
- if (ext.equals(fileExtension))
- return true;
- return false;
- }
-
- public static boolean isOgv(final String fileExtension) {
- return fileExtension.equalsIgnoreCase("ogv");
- }
-
- public static boolean shallFileBeIndexed(final File file) {
-
- if (file.getName().startsWith("."))
- return false;
- if (file.getName().startsWith("index"))
- if (file.getName().endsWith(".html"))
- return false;
-
- return true;
- }
-
}
/*
* Meviz - Various tools collection to work with multimedia.
* Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
public FilesystemIndexer(final File directoryToIndex,
final CommandlineHandler commandlineHandler,
- final List<String> pathElements) throws IOException,
- ImageFormatError {
+ final List<String> pathElements) throws Exception {
this.directoryToIndex = directoryToIndex;
this.commandlineHandler = commandlineHandler;
validMetadataFiles.add(thumbnailFileName);
final File thumbnailFile = new File(
Utils.getThumbnailsDirectoryPath(directoryToIndex)
- + thumbnailFileName);
+ + thumbnailFileName);
if (!thumbnailFile.exists()) {
desiredDimension.getAwtDimension());
}
return Constants.THUMBNAILS_DIRECTORY_NAME + "/"
- + UrlParamEncoder.encode(thumbnailFileName);
+ + UrlParamEncoder.encode(thumbnailFileName);
}
public void indexForLayout(final Layout layout)
layout.enlistFile(abstractFile);
} else if (abstractFile instanceof Picture)
- layout.enlistImage(abstractFile);
+ layout.enlistImage((Picture) abstractFile);
else if (abstractFile instanceof DirectoryFile)
layout.enlistDirectory(abstractFile);
metadataFile = new File(
Utils.getThumbnailsDirectoryPath(directoryToIndex)
- + Constants.METADATA_FILE_NAME);
+ + Constants.METADATA_FILE_NAME);
metadata = MetadadaHelper.initDirectoryMetadata(metadataFile);
}
}
- public void updateMetadata() throws IOException, ImageFormatError {
+ public void updateMetadata() throws Exception {
- final File[] directoryContent = directoryToIndex.listFiles();
-
- for (final File file : directoryContent)
+ for (final File file : directoryToIndex.listFiles())
if (shallFileBeIndexed(file)) {
metadata.ensureFileMetainfoIsUpToDate(directoryToIndex, file);
/*
* Meviz - Various tools collection to work with multimedia.
* Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
import java.util.List;
import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
+import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
/**
* In order to have possibility of several different layouts per directory.
* Universal interface is defined.
- *
+ *
* Layout implementation is responsible for actual HTML generation.
*/
/**
* Enlist image file.
*/
- public void enlistImage(AbstractFile picture);
+ public void enlistImage(Picture picture);
/**
* Enlist video in OGV format.
- *
+ *
* @throws UnsupportedEncodingException
*/
public void enlistOgv(AbstractFile file)
}
@Override
- public void enlistImage(final AbstractFile abstractFile) {
+ public void enlistImage(final Picture picture) {
try {
- final Picture picture = (Picture) abstractFile;
-
final Dimension imageSize = picture.getDimensions();
final List<Dimension> recommendedDimensions = Picture
+ e.toString()
+ ", thumbnail generation skipped, enlisting as ordinary file instead.",
e);
- enlistFile(abstractFile);
+ enlistFile(picture);
}
}
}
public void ensureFileMetainfoIsUpToDate(final File parentDirectory,
- final File file) throws IOException, ImageFormatError {
+ final File file) throws Exception {
final String fileName = file.getName();
}
private AbstractFile getAbstractFile(final File parentDirectory,
- final File file, final String fileName) throws IOException,
- ImageFormatError {
+ final File file, final String fileName) throws Exception {
if (file.isDirectory())
return new DirectoryFile(parentDirectory, fileName);
.toLowerCase();
if (AbstractIndexer.isImage(fileExtension))
- return new Picture(parentDirectory, fileName);
+ try {
+ return new Picture(parentDirectory, fileName);
+ } catch (final Exception exception) {
+ // in case image decoding failed, handle image as general file
+ return new GeneralFile(parentDirectory, fileName);
+ }
if (fileExtension.equals("meviz"))
return new MevizSpecialFile(parentDirectory, fileName);
}
public AbstractFile registerFile(final File parentDirectory, final File file)
- throws IOException, ImageFormatError {
+ throws Exception {
final String fileName = file.getName();
private transient boolean metaInfoVerified;
public AbstractFile(final File parentDirectory, final String fileName)
- throws IOException {
+ throws Exception {
this.fileName = fileName;
ensureFileMetainfoIsUpToDate(parentDirectory);
}
* @return <code>true</code> if file metadata was updated.
*/
public boolean ensureFileMetainfoIsUpToDate(final File parentDirectory)
- throws IOException {
+ throws Exception {
if (!isMetainfoUpToDate(parentDirectory)) {
fileLength = getFile(parentDirectory).length();
updateFileMetainfo(parentDirectory);
}
protected abstract void updateFileMetainfo(final File parentDirectory)
- throws IOException;
+ throws Exception;
}
private static final long serialVersionUID = 2387153281300820532L;
public DirectoryFile(final File parentDirectory, final String fileName)
- throws IOException {
+ throws Exception {
super(parentDirectory, fileName);
}
private static final long serialVersionUID = -2373609481729401415L;
public GeneralFile(final File parentDirectory, final String fileName)
- throws IOException {
+ throws Exception {
super(parentDirectory, fileName);
}
private static final long serialVersionUID = -8749190459653455640L;
public MevizSpecialFile(final File parentDirectory, final String fileName)
- throws IOException {
+ throws Exception {
super(parentDirectory, fileName);
}
import java.awt.image.ImageProducer;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import eu.svjatoslav.commons.file.FilePathParser;
import eu.svjatoslav.meviz.htmlindexer.Constants;
-import eu.svjatoslav.meviz.htmlindexer.ImageFormatError;
import eu.svjatoslav.meviz.htmlindexer.Utils;
import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
private Dimension dimensions;
public Picture(final File parentDirectory, final String fileName)
- throws IOException, ImageFormatError {
+ throws Exception {
super(parentDirectory, fileName);
}
}
@Override
- public void updateFileMetainfo(final File parentDirectory)
- throws IOException {
- BufferedImage image;
- try {
- image = Utils.getBufferedImage(getFile(parentDirectory));
- } catch (final ImageFormatError e) {
- throw new RuntimeException(e);
- }
+ public void updateFileMetainfo(final File parentDirectory) throws Exception {
+ final BufferedImage image = Utils
+ .getBufferedImage(getFile(parentDirectory));
dimensions = new Dimension(image.getWidth(), image.getHeight());
}