BrightSide Workbench Full Report + Source Code
UploadAction.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.IOException;
22 import java.util.List;
23 import java.util.Properties;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.command.Command;
27 import org.turro.command.Context;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.impl.util.ShellExecutor;
30 import org.turro.file.FileWrapper;
31 import org.turro.i18n.I_;
32 
37 public class UploadAction implements FileAction {
38 
39  private final FileWrapper fw;
40 
42  this.fw = fw;
43  }
44 
45  @Override
46  public String getLabel() {
47  return I_.get("Upload");
48  }
49 
50  @Override
51  public String getImage() {
52  return "/_zul/images/upload.png";
53  }
54 
55  @Override
56  public Object doAction() {
57  try {
58  final Properties props = fw.getProperties();
59  fw.upload(new Command() {
60  @Override
61  public Object execute(Context context) {
62  List<File> newFiles = (List<File>) context.get("files");
63  if(newFiles != null) {
64  for(File newFile : newFiles) {
65  if(newFile != null) {
66  for(int i = 0; i < 20; i++) {
67  String command = props.getProperty("cmdupl" + i, null);
68  if (command != null) {
69  new ShellExecutor().execute(command.replaceAll("#file", newFile.getAbsolutePath()));
70  }
71  }
72  }
73  }
74  }
75  return null;
76  }
77  });
78  } catch (IOException ex) {
79  Logger.getLogger(UploadAction.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
80  }
81  return null;
82  }
83 
84  @Override
85  public boolean refreshParent() {
86  return false;
87  }
88 
89  @Override
90  public boolean refreshSelf() {
91  return true;
92  }
93 
94  @Override
95  public boolean isClientSide() {
96  return false;
97  }
98 
99 }
void upload(final Command command)
static String get(String msg)
Definition: I_.java:41