refactored code for better readability
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 3 Jan 2015 12:19:09 +0000 (14:19 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 3 Jan 2015 12:19:09 +0000 (14:19 +0200)
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java

index 08a308b..4e6b5bf 100755 (executable)
@@ -75,49 +75,7 @@ public class MixedLayout implements Layout {
        public void enlistImage(final Picture picture,
                        final DirectoryMetadata parentDirectoryMetadata) {
                try {
-
-                       final Dimension imageSize = picture.getDimensions();
-
-                       final List<Dimension> recommendedDimensions = Picture
-                                       .getThumbnailDimensions(imageSize);
-
-                       Dimension listingDimension = new Dimension(1500, 450);
-
-                       if (listingDimension.width > imageSize.width)
-                               if (listingDimension.height > imageSize.height)
-                                       listingDimension = imageSize;
-
-                       final String listingThumbnailUrl = indexer.getThumbnailUrl(picture,
-                                       listingDimension, indexingContext);
-
-                       filesHtml.append("<div style=\"float:left; margin: 10px;\">");
-                       filesHtml.append("<a href=\""
-                                       + indexingContext.getGlobalUrl()
-                                       + UrlParamEncoder.encode(indexingContext.getLocalUrl()
-                                                       + "/" + picture.fileName) + "\">\n");
-
-                       filesHtml.append("<img border=\"0\" src=\"" + listingThumbnailUrl
-                                       + "\"/></a>\n");
-                       filesHtml.append("<br/><b>"
-                                       + FilePathParser
-                                                       .getFileNameWithoutExtension(picture.fileName)
-                                       + "</b><br/>(");
-
-                       int count = 0;
-                       for (final Dimension dimension : recommendedDimensions) {
-                               count++;
-                               if (count > 1)
-                                       filesHtml.append(", ");
-                               filesHtml.append("<a href=\""
-                                               + indexer.getThumbnailUrl(picture, dimension,
-                                                               indexingContext) + "\">");
-                               filesHtml.append(dimension.width + "x" + dimension.height);
-                               filesHtml.append("</a>");
-                       }
-
-                       filesHtml.append(")\n");
-                       filesHtml.append("</div>");
-
+                       enlistImageInternal(picture);
                } catch (final Exception e) {
                        logger.error(
                                        "Error generating thumbnails for image file: "
@@ -128,6 +86,50 @@ public class MixedLayout implements Layout {
                }
        }
 
+       private String enlistImageDimensions(final Picture picture) {
+               final StringBuilder html = new StringBuilder();
+
+               final List<Dimension> recommendedDimensions = Picture
+                               .getThumbnailDimensions(picture.getDimensions());
+
+               int count = 0;
+               for (final Dimension dimension : recommendedDimensions) {
+                       count++;
+                       if (count > 1)
+                               html.append(", ");
+                       html.append("<a href=\""
+                                       + indexer.getThumbnailUrl(picture, dimension,
+                                                       indexingContext) + "\">");
+                       html.append(dimension.width + "x" + dimension.height);
+                       html.append("</a>");
+               }
+
+               return html.toString();
+       }
+
+       private void enlistImageInternal(final Picture picture) {
+
+               filesHtml.append("<div style=\"float:left; margin: 10px;\">");
+
+               // clickable image thumbnail
+               filesHtml.append("<a href=\""
+                               + indexingContext.getGlobalUrl()
+                               + UrlParamEncoder.encode(indexingContext.getLocalUrl() + "/"
+                                               + picture.fileName) + "\">\n");
+               filesHtml.append("<img border=\"0\" src=\""
+                               + getImageThumbnailUrl(picture) + "\"/></a><br/>\n");
+
+               // file name
+               filesHtml.append("<b>"
+                               + FilePathParser.getFileNameWithoutExtension(picture.fileName)
+                               + "</b><br/>");
+
+               // links to thumbnails of various sizes
+               filesHtml.append("(" + enlistImageDimensions(picture) + ")\n");
+
+               filesHtml.append("</div>");
+       }
+
        /** {@inheritDoc} */
        @Override
        public void enlistOgv(final AbstractFile abstractFile,
@@ -136,29 +138,34 @@ public class MixedLayout implements Layout {
 
                final GeneralFile file = (GeneralFile) abstractFile;
 
+               filesHtml.append("<div style=\"margin: 30px; clear: both;\">");
+
+               // watchable video
                filesHtml
-                               .append("<div style=\"margin: 30px; clear: both;\">"
-                                               + "<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
+                               .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
                filesHtml
                                .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
                                                + indexingContext.getGlobalUrl()
                                                + UrlParamEncoder.encode(indexingContext.getLocalUrl()
                                                                + "/" + file.fileName) + "\">\n");
                filesHtml.append("</source>\n");
-
                filesHtml.append("</video>\n");
-
                filesHtml.append("<br/>\n");
 
+               // video title
                filesHtml
                                .append("Video: <b>"
                                                + FilePathParser
                                                                .getFileNameWithoutExtension(file.fileName)
                                                + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+
+               // video download link
                filesHtml.append("<a href=\""
                                + indexingContext.getGlobalUrl()
                                + UrlParamEncoder.encode(indexingContext.getLocalUrl() + "/"
-                                               + file.fileName) + "\">download as OGV</a></div>\n");
+                                               + file.fileName) + "\">download as OGV</a>");
+
+               filesHtml.append("</div>\n");
 
                filesHtml.append("\n");
 
@@ -208,6 +215,19 @@ public class MixedLayout implements Layout {
                return finalHtml.toString();
        }
 
+       private String getImageThumbnailUrl(final Picture picture) {
+               final Dimension imageSize = picture.getDimensions();
+
+               Dimension listingDimension = new Dimension(1500, 450);
+
+               if (listingDimension.width > imageSize.width)
+                       if (listingDimension.height > imageSize.height)
+                               listingDimension = imageSize;
+
+               return indexer.getThumbnailUrl(picture, listingDimension,
+                               indexingContext);
+       }
+
        @Override
        public void init(final String galleryTitle, final List<String> path,
                        final AbstractIndexer indexer, final IndexingContext indexingContext) {
index f4ddc20..fa692d6 100644 (file)
@@ -3,8 +3,12 @@ package eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes;
 import java.io.File;
 import java.io.IOException;
 
+import eu.svjatoslav.commons.file.IOHelper;
+
 public class MevizSpecialFile extends AbstractFile {
 
+       private String fileContent;
+
        private static final long serialVersionUID = -8749190459653455640L;
 
        public MevizSpecialFile(final File parentDirectory, final String fileName)
@@ -12,9 +16,16 @@ public class MevizSpecialFile extends AbstractFile {
                super(parentDirectory, fileName);
        }
 
+       public String getFileContent() {
+               return fileContent;
+       }
+
        @Override
        protected void updateFileMetainfo(final File parentDirectory)
                        throws IOException {
+
+               fileContent = IOHelper
+                               .getFileContentsAsString(getFile(parentDirectory));
        }
 
 }