| | |
| | |
|
| | | package de.uhilger.filecms.api;
|
| | |
|
| | | import de.uhilger.wbx.Bild;
|
| | | import java.io.BufferedReader;
|
| | | import java.io.File;
|
| | | import java.io.FileFilter;
|
| | |
| | | import java.io.PrintWriter;
|
| | | import java.util.logging.Level;
|
| | | import java.util.logging.Logger;
|
| | | import net.coobird.thumbnailator.Thumbnails;
|
| | | import org.apache.commons.io.FileUtils;
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * Es werden nur .htmi-Dateien exortiert, die im mit relPath bezeichneten
|
| | | * Ordner liegen. Eventuell in darin befindlichen Unterordnern befindliche
|
| | | * .htmk-Dateien werden nicht exportiert.
|
| | | * .htmi-Dateien werden nicht exportiert.
|
| | | *
|
| | | * Es sollten also keine komplexen Webseiten-Strukturen mit dieser Methode |
| | | * Es sollen keine komplexen Webseiten-Strukturen mit dieser Methode |
| | | * erzeugt werden sondern einfache Dokumente mit einer oder wenigen
|
| | | * einzelnen Dateien.
|
| | | *
|
| | |
| | | BufferedReader br = null;
|
| | | try {
|
| | | File out = new File(outDir, stripExt(files[i].getName()) + ".html");
|
| | | if(!out.exists()) {
|
| | | logger.fine(out.getAbsolutePath() + " existiert nicht, erzeuge Datei..");
|
| | | out.getParentFile().mkdirs();
|
| | | out.createNewFile();
|
| | | }
|
| | | PrintWriter w = new PrintWriter(out);
|
| | | printHeader(w);
|
| | | br = new BufferedReader(new FileReader(files[i]));
|
| | | String line = br.readLine();
|
| | | while(line != null) {
|
| | | w.print(line);
|
| | | w.print(line.replace("htmi", "html"));
|
| | | w.print("\r\n");
|
| | | line = br.readLine();
|
| | | }
|
| | | printFooter(w);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | File catalinaBase = new File(getCatalinaBase());
|
| | | File catalinaBase = new File(getCatalinaBase(getServletContext()));
|
| | | File bsDir = new File(catalinaBase, "webapps/jslib/bootstrap/css/");
|
| | | try {
|
| | | FileUtils.copyFile(new File(bsDir, "bootstrap.min.css"), new File(outDir, "bootstrap.min.css"), true);
|
| | |
| | | if(stile.exists()) {
|
| | | FileUtils.copyFile(stile, new File(outDir, "stile.css"), true);
|
| | | }
|
| | | buildThumbnailImages(outDir, new Bild());
|
| | | |
| | | File lbDir = new File(catalinaBase, "webapps/jslib/lightbox/");
|
| | | FileUtils.copyDirectoryToDirectory(lbDir, outDir);
|
| | | |
| | | File jqDir = new File(catalinaBase, "webapps/jslib/jquery/");
|
| | | FileUtils.copyDirectoryToDirectory(jqDir, outDir);
|
| | | |
| | | File lbimgDir = new File(catalinaBase, "webapps/jslib/lightbox/img");
|
| | | FileUtils.copyDirectoryToDirectory(lbimgDir, outDir);
|
| | | |
| | | |
| | | result = "Export nach HTML ausgefuehrt.";
|
| | | } catch (IOException ex) {
|
| | | result = ex.getLocalizedMessage();
|
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | | |
| | | /**
|
| | | * Minituransichten der Bilddateien erzeugen, die beim HTML-Export |
| | | * entstanden sind.
|
| | | * |
| | | * Die Methode erstellt fuer alle Dateien mit Endung png oder jpg |
| | | * eine weitere Bilddatei mit Namen [Name]_tn.[Endung]. Also z.B.
|
| | | * bild_tn.jpg fuer die Datei bild.jpg
|
| | | */
|
| | | private void buildThumbnailImages(File dir, Bild bild) {
|
| | | logger.fine("Minituransichten dir: " + dir.getAbsolutePath());
|
| | | File[] files = dir.listFiles(new ImageFileFilter());
|
| | | if(files != null) {
|
| | | for(int i = 0; i < files.length; i++) {
|
| | | if(files[i].isDirectory()) {
|
| | | buildThumbnailImages(files[i], bild);
|
| | | } else {
|
| | | String absPath = files[i].getAbsolutePath();
|
| | | logger.fine("Miniaturansicht fuer Bild " + absPath);
|
| | | String fname = files[i].getName();
|
| | | logger.fine("fname: " + fname);
|
| | | int dotPos = fname.lastIndexOf(".");
|
| | | logger.fine("dotPos: " + dotPos);
|
| | | StringBuffer tnFileName = new StringBuffer();
|
| | | if(dotPos > -1) {
|
| | | String fname_no_ext = fname.substring(0, dotPos);
|
| | | logger.fine("fname_no_ext: " + fname_no_ext);
|
| | | String fext = fname.substring(dotPos);
|
| | | logger.fine("fext: " + fext);
|
| | | tnFileName.append(fname_no_ext);
|
| | | tnFileName.append("_tn");
|
| | | //tnFileName.append(".");
|
| | | tnFileName.append(fext);
|
| | | } else {
|
| | | tnFileName.append(fname);
|
| | | tnFileName.append("_tn");
|
| | | }
|
| | | String outFileName = new File(dir, tnFileName.toString()).getAbsolutePath();
|
| | | logger.fine("outFileName: " + outFileName);
|
| | | |
| | | try {
|
| | | Thumbnails.of(absPath)
|
| | | .size(bild.getVariantenGroesse(Bild.WINZIG), bild.getVariantenGroesse(Bild.WINZIG))
|
| | | .keepAspectRatio(true)
|
| | | .outputQuality(0.7)
|
| | | .toFile(outFileName);
|
| | | } catch (IOException ex) {
|
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
|
| | | }
|
| | | /*
|
| | | Image image = Toolkit.getDefaultToolkit().getImage(absPath);
|
| | | MediaTracker mediaTracker = new MediaTracker(new Container());
|
| | | mediaTracker.addImage(image, 0);
|
| | | try {
|
| | | mediaTracker.waitForID(0);
|
| | |
|
| | | if (!mediaTracker.isErrorAny()) {
|
| | | bild.writeImageFile(image, bild.getVariantenGroesse(Bild.WINZIG), bild.getMimeType(files[i]), outFileName);
|
| | | } else {
|
| | | logger.fine("Fehler: Miniaturansicht konnte nicht erzeugt werden");
|
| | | }
|
| | | } catch (InterruptedException | IOException ex) {
|
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
|
| | | } |
| | | */
|
| | | }
|
| | | }
|
| | | } else {
|
| | | logger.fine("files ist null");
|
| | | }
|
| | | }
|
| | |
|
| | | private String stripExt(String name) {
|
| | |
| | |
|
| | | }
|
| | |
|
| | | public class ImageFileFilter implements FileFilter {
|
| | |
|
| | | @Override
|
| | | public boolean accept(File pathname) {
|
| | | boolean doAccept = false;
|
| | | String lcName = pathname.getName().toLowerCase();
|
| | | if( lcName.endsWith(".jpg") || |
| | | lcName.endsWith(".jpeg") || |
| | | lcName.endsWith(".png") || |
| | | pathname.isDirectory()) {
|
| | | if(!lcName.contains("_tn")) {
|
| | | doAccept = true;
|
| | | }
|
| | | }
|
| | | return doAccept;
|
| | | }
|
| | | |
| | | } |
| | | |
| | | private void printHeader(PrintWriter out) throws IOException {
|
| | | out.print("<!DOCTYPE html><html><head>\r\n");
|
| | | out.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>");
|
| | | out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"bootstrap.min.css\">\r\n");
|
| | | out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"lightbox/lightbox.css\">\r\n");
|
| | | out.print("<link rel=\"stylesheet\" type=\"text/css\" href=\"stile.css\">\r\n");
|
| | | out.print("</head><body class=\"p-3\">\r\n");
|
| | | }
|
| | |
|
| | | private void printFooter(PrintWriter out) throws IOException {
|
| | | out.print("<script src=\"jquery/jquery.min.js\"></script>\r\n");
|
| | | out.print("<script src=\"lightbox/lightbox.min.js\"></script>\r\n");
|
| | | out.print("</body></html>");
|
| | | }
|
| | |
|