1 19 20 package com.sslexplorer.networkplaces.forms; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.action.ActionErrors; 31 import org.apache.struts.action.ActionMapping; 32 33 import com.sslexplorer.networkplaces.NetworkPlace; 34 import com.sslexplorer.networkplaces.model.FileSystemItem; 35 import com.sslexplorer.networkplaces.model.FileSystemItemModel; 36 import com.sslexplorer.policyframework.LaunchSession; 37 import com.sslexplorer.policyframework.forms.AbstractResourcesForm; 38 import com.sslexplorer.security.SessionInfo; 39 import com.sslexplorer.vfs.VFSPath; 40 import com.sslexplorer.vfs.VFSResource; 41 42 50 public class FileSystemForm extends AbstractResourcesForm { 51 52 private static final long serialVersionUID = -8944288890287463553L; 53 static Log log = LogFactory.getLog(FileSystemForm.class); 54 55 private String path; 56 private boolean confirmDeletion; 57 private String newFolder; 58 private String newName; 59 private String fileName; 60 private List paths; 61 private boolean viewOnly; 62 private LaunchSession launchSession; 63 private String launchId; 64 private VFSResource vfsResource; 65 66 69 public FileSystemForm() { 70 super(new FileSystemItemModel("fileSystem")); 71 this.path = null; 72 this.confirmDeletion = false; 73 this.newFolder = null; 74 this.newName = null; 75 this.fileName = null; 76 this.launchSession = null; 77 this.paths = new ArrayList (); 78 } 79 80 86 public void setLaunchId(String launchId) { 87 this.launchId = launchId; 88 } 89 90 95 public void setVFSResource(VFSResource vfsResource) { 96 this.vfsResource = vfsResource; 97 98 } 99 100 105 public VFSResource getVFSResource() { 106 return vfsResource; 107 108 } 109 110 116 public String getLaunchId() { 117 return launchId; 118 } 119 120 125 public void setLaunchSession(LaunchSession launchSession) { 126 this.launchSession = launchSession; 127 launchId = launchSession.getId(); 128 } 129 130 135 public LaunchSession getLaunchSession() { 136 return launchSession; 137 } 138 139 142 public String [] getSelectedFileNames() { 143 List selected = new ArrayList (); 144 for (Iterator i = getModel().getItems().iterator(); i.hasNext();) { 145 FileSystemItem ti = (FileSystemItem) i.next(); 146 if (ti.getChecked()) 147 selected.add(ti.getFileName()); 148 } 149 return (String []) selected.toArray(new String [selected.size()]); 150 } 151 152 158 public boolean isConfirmDeletion() { 159 return confirmDeletion; 160 } 161 162 165 public void setConfirmDeletion(boolean confirmDeletion) { 166 this.confirmDeletion = confirmDeletion; 167 } 168 169 172 public String getPath() { 173 return path; 174 } 175 176 179 public void setPath(String path) { 180 this.path = path; 181 } 182 183 186 public String getHome() { 187 VFSPath tmp = (VFSPath) this.paths.get(0); 188 this.paths.clear(); 189 this.paths.add(0, tmp); 190 return tmp.getPath(); 191 } 192 193 196 public void setHome(String home) { 197 this.paths.add(new VFSPath(0, home)); 198 } 199 200 public List getPaths() { 201 return this.paths; 202 } 203 204 207 public int getResourceId() { 208 return getNetworkPlace() == null ? -1 : getNetworkPlace().getResourceId(); 209 } 210 211 214 public String getNewFolder() { 215 return newFolder; 216 } 217 218 221 public void setNewFolder(String newFolderString) { 222 this.newFolder = newFolderString; 223 } 224 225 228 public String getNewName() { 229 return newName; 230 } 231 232 235 public void setNewName(String newName) { 236 this.newName = newName; 237 } 238 239 242 public String getFileName() { 243 return fileName; 244 } 245 246 249 public void setFileName(String fileName) { 250 this.fileName = fileName; 251 } 252 253 261 public void initialize(HttpServletRequest request, List allFileSystemItems, SessionInfo session) throws Exception { 262 super.initialize(session.getHttpSession(), "name"); 263 264 try { 265 Iterator i = allFileSystemItems.iterator(); 266 267 while (i.hasNext()) { 268 FileSystemItem it = (FileSystemItem) i.next(); 269 it.setSortFoldersFirst(true); 270 getModel().addItem(it); 271 } 272 getPager().setSortReverse(getSortReverse()); 273 getPager().rebuild(getFilterText()); 274 } catch (Throwable t) { 275 log.error("Failed to initialise resources form.", t); 276 } 277 } 278 279 284 public void setReadWrite() { 285 viewOnly = false; 286 } 287 288 291 public void setViewOnly() { 292 viewOnly = true; 293 } 294 295 301 public boolean isViewOnly() { 302 return viewOnly; 303 } 304 305 312 public NetworkPlace getNetworkPlace() { 313 return launchSession == null ? null : (NetworkPlace)launchSession.getResource(); 314 } 315 316 319 public void addPath(String path) { 320 VFSPath newPath = new VFSPath(this.paths.size(), path); 321 VFSPath oldPath = null; 322 boolean add = true; 323 List newPaths = new ArrayList (); 324 Iterator iter = this.paths.iterator(); 325 while (iter.hasNext()) { 326 VFSPath element = (VFSPath) iter.next(); 327 if (element.getPath().equals(newPath.getPath())) { 328 add = false; 329 newPaths.add(element); 330 break; 331 } else { 332 newPaths.add(element); 333 } 334 } 335 this.paths = newPaths; 336 if (add) 337 this.paths.add(newPath); 338 } 339 340 343 public void clearPathsTo(String _id) { 344 int id = Integer.parseInt(_id); 345 Iterator iter = this.paths.iterator(); 346 List newPaths = new ArrayList (); 347 while (iter.hasNext()) { 348 VFSPath element = (VFSPath) iter.next(); 349 if (element.getPosition() <= id) 350 newPaths.add(element); 351 } 352 this.paths = newPaths; 353 } 354 355 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 356 359 if ("list".equals(getActionTarget())) { 360 if (this.getPath()!=null && this.getPath().endsWith("/")) { 361 this.setPath(this.getPath().substring(0, this.getPath().length() - 1)); 362 } 363 } 364 return super.validate(mapping, request); 365 } 366 367 public String getFullURI() { 368 if (vfsResource == null ) { 369 return null; 370 } else { 371 return vfsResource.getFullPath(); 372 } 373 } 374 375 378 public void reset(ActionMapping mapping, HttpServletRequest request) { 379 super.reset(mapping, request); 380 viewOnly = true; 381 } 382 } 383 | Popular Tags |