BrightSide Workbench Full Report + Source Code
GalleryAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.file.action;
19 
20 import java.io.File;
21 import java.io.FileNotFoundException;
22 import java.io.FilenameFilter;
23 import java.io.IOException;
24 import java.util.Properties;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.impl.util.ShellExecutor;
29 import org.turro.file.FolderFile;
30 import org.turro.i18n.I_;
31 
36 public class GalleryAction implements FileAction {
37 
38  private FolderFile ff;
39 
41  this.ff = ff;
42  }
43 
44  @Override
45  public String getLabel() {
46  return I_.get("Create a gallery");
47  }
48 
49  @Override
50  public String getImage() {
51  return "/_zul/images/gallery.png";
52  }
53 
54  @Override
55  public Object doAction() {
56  try {
57  File thumbs = new File(ff.getFile().getAbsolutePath() + "/thumbs");
58  Properties props = ff.getProperties();
59  if (!thumbs.exists()) {
60  thumbs.mkdirs();
61  // Images
62  for (File file : ff.getFile().listFiles(new FilenameFilter() {
63  @Override
64  public boolean accept(File dir, String name) {
65  return !name.endsWith(".properties") && name.contains(".") && name.matches(".*\\.(jpg|jpeg|png|gif|tif)");
66  }
67  })) {
68  for (int i = 0; i < 20; i++) {
69  String command = props.getProperty("cmdimg" + i, null);
70  if (command != null) {
71  String thumbName = file.getName();
72  thumbName = thumbName.substring(0, thumbName.lastIndexOf(".")) + ".png";
73  new ShellExecutor().execute(command.replaceAll("#file", file.getAbsolutePath()).replaceAll("#thumb", thumbs.getAbsolutePath() + "/" + thumbName));
74  }
75  }
76  }
77  // Videos
78  for (File file : ff.getFile().listFiles(new FilenameFilter() {
79  @Override
80  public boolean accept(File dir, String name) {
81  return !name.endsWith(".properties") && name.contains(".") && name.matches(".*\\.(avi|mpeg|mpg|vob|divx)");
82  }
83  })) {
84  for (int i = 0; i < 20; i++) {
85  String command = props.getProperty("cmdvid" + i, null);
86  if (command != null) {
87  String flvName = file.getAbsolutePath();
88  flvName = flvName.substring(0, flvName.lastIndexOf(".")) + ".flv";
89  new ShellExecutor().execute(command.replaceAll("#file", file.getAbsolutePath()).replaceAll("#flv", flvName));
90  }
91  }
92  }
93  // Flvs
94  for (File file : ff.getFile().listFiles(new FilenameFilter() {
95  @Override
96  public boolean accept(File dir, String name) {
97  return !name.endsWith(".properties") && name.contains(".") && name.matches(".*\\.(flv)");
98  }
99  })) {
100  for (int i = 0; i < 20; i++) {
101  String command = props.getProperty("cmdflv" + i, null);
102  if (command != null) {
103  String thumbName = file.getName();
104  thumbName = thumbName.substring(0, thumbName.lastIndexOf(".")) + ".png";
105  new ShellExecutor().execute(command.replaceAll("#file", file.getAbsolutePath()).replaceAll("#thumb", thumbs.getAbsolutePath() + "/" + thumbName));
106  }
107  }
108  }
109  for (File file : thumbs.listFiles(new FilenameFilter() {
110  @Override
111  public boolean accept(File dir, String name) {
112  return name.endsWith(".png");
113  }
114  })) {
115  for (int i = 0; i < 20; i++) {
116  String command = props.getProperty("cmdthumb" + i, null);
117  if (command != null) {
118  new ShellExecutor().execute(command.replaceAll("#thumb", file.getAbsolutePath()));
119  }
120  }
121  }
122  }
123  } catch (FileNotFoundException ex) {
124  Logger.getLogger(GalleryAction.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
125  } catch (IOException ex) {
126  Logger.getLogger(GalleryAction.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
127  }
128  return null;
129  }
130 
131  @Override
132  public boolean refreshParent() {
133  return false;
134  }
135 
136  @Override
137  public boolean refreshSelf() {
138  return true;
139  }
140 
141  @Override
142  public boolean isClientSide() {
143  return false;
144  }
145 
146 }
static String get(String msg)
Definition: I_.java:41