1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
/* ------------------------------------ JavaOnTracks Thibaut Colar tcolar-jot AT colar DOT net Artistic Licence 2.0 http://www.javaontracks.net ------------------------------------ */ package net.jot.web.filebrowser; import java.io.File; import java.util.Vector; import net.jot.utils.JOTUtilities; /** * This reprsents a user current "view" of a file manager. (ie: which folder he is in, how the file listing is ordered etc...) * It stores that "filemanager view" data into the user session. * This "view" is originally configured by the programmer to allow certain actions and expect certain results. * It is a lightweight object, just varibales and get/setters. * Most of the "Logic" going with this is in JotFileBrowserHelper * @author thibautc * */ public class JOTFileBrowserSession { //TODO: image password verification t protect from robots ?? /** user can not browse "higher" than this folder.*/ protected File rootFolder=null; /** which folder to start in (rootFolder if null)*/ protected File startFolder=null; /** You will want to set this depending what you want the user to do: ie: upload a file, select a file, just browse etc....*/ protected int browseType=JOTFileBrowserHelper.TYPE_BROWSE; /** if you want to set a title (ie: "Please choose a file")*/ protected String title=null; /** where the temporary upload data will be stored during a file upload.*/ protected String tempUploadFolder=JOTUtilities.getStandardTmpDir().getAbsolutePath(); // flags /** If false then user won't se the existing files at all.*/ protected boolean allowListFiles=true; /** wether stuck in exisiting folder or can browse around.*/ protected boolean allowBrowsing=true; /** wether to show the current directory full path or not (ex: /home/blah/files/)**/ protected boolean allowShowPath=true; protected boolean allowListHiddenFiles=false; protected boolean allowCreateFolders=false; protected boolean allowDelete=false; /** allow renaming files/folders */ protected boolean allowRenaming=false; /** allow deleting recursively a filled folder or not */ protected boolean allowDeleteFilledFolders=false; protected boolean allowUploadFile=false; /** allow updating/uplaoding a new version of an existing file ?*/ protected boolean allowUpdateFile=false; /** allo view/download files ?*/ protected boolean allowDownloadFile=false; /** when selecting a folder, can the user pick the root folder itself (or only a subfolder of it) ?*/ protected boolean allowPickRootFolder=false; /** maximum TOTAL size in bytes of file(s) uploaded. Default : ~5MB*/ protected long maxUploadSize=5000000; protected long maxFolderNameLength=200; /** If file uploads are enabled, how many file do we allow to upload at a time ?*/ protected Integer nbOfUploadFields=new Integer(1); /** pattern for new dir names (for security reasons), default:letters,numbers,-,_ only**/ protected String newDirPattern="[ a-zA-Z0-9_-]+"; /** pattern for new/uploaded file names (for security reasons), default:letters,numbers,-,_,. only*/ protected String newFilePattern="[\\.a-zA-Z0-9_-]+"; /** by default sort by filename in alphabetical order*/ protected int sortBy=JOTUtilities.SORT_BY_NAME_ASC; /** warning messages : null = no warning, not null. Warning if a file with same name already exists*/ protected String updateWarning="This file already exists: $1<br>Check the 'Overwrite Existing files' to replace."; protected String fullFolderWarning="The folder is not empty: $1"; protected String forbiddenWarning="You are not allowed to do this. $1"; protected String failedWarning="Operation failed.<br>$1"; /** warning messages : null = no warning, not null. File/folder name contains unallowed characters*/ protected String fileNameWarning="File name can only contain: a-z,0-9,-,_"; /** warning messages : null = no warning, not null. The session timed out, need to start over*/ protected String sessionTimeoutWarning="Your session timed out, please try again."; // brosweType warnings: /** warning messages : null = no warning, not null. We want the user to pick only 1 file*/ protected String oneFileWarning="Please select 1 and only 1 file."; /** warning messages : null = no warning, not null. We want the user to pick 1 or more file(s)*/ protected String multipleFilesWarning="Please select at least 1 file."; /** warning messages : null = no warning, not null. We want the user to pick a folder*/ protected String oneFolderWarning="Please select 1 and only 1 folder."; /** internal value*/ protected File currentFolder=null; /** internal value*/ protected Vector fileListing=null; /** internal value*/ protected String currentWarning=null; /** internal value*/ protected File upFolder=null; /** * Generic constructor, setting "Default" permissions * @param rootFolder * @param startFolder */ public JOTFileBrowserSession(File rootFolder, File startFolder, int browseType) { this.rootFolder=rootFolder; this.startFolder=startFolder; this.currentFolder=startFolder; this.browseType=browseType; if(browseType==JOTFileBrowserHelper.TYPE_UPLOAD_1_FILE) { setAllowUploadFile(true); setNbOfUploadFields(1); setAllowListFiles(false); } } public boolean isAllowBrowsing() { return allowBrowsing; } public void setAllowBrowsing(boolean allowBrowsing) { this.allowBrowsing = allowBrowsing; } public boolean isAllowCreateFolders() { return allowCreateFolders; } public void setAllowCreateFolders(boolean allowCreateFolders) { this.allowCreateFolders = allowCreateFolders; } public boolean isAllowDelete() { return allowDelete; } public void setAllowDelete(boolean allowDelete) { this.allowDelete = allowDelete; } public boolean isAllowDeleteFilledFolders() { return allowDeleteFilledFolders; } public void setAllowDeleteFilledFolders(boolean allowDeleteFilledFolders) { this.allowDeleteFilledFolders = allowDeleteFilledFolders; } public boolean isAllowRenaming() { return allowRenaming; } public void setAllowRenaming(boolean allowRenaming) { this.allowRenaming = allowRenaming; } public boolean isAllowUpdateFile() { return allowUpdateFile; } public void setAllowUpdateFile(boolean allowUpdateFile) { this.allowUpdateFile = allowUpdateFile; } public boolean isAllowUploadFile() { return allowUploadFile; } public void setAllowUploadFile(boolean allowUploadFile) { this.allowUploadFile = allowUploadFile; } public int getBrowseType() { return browseType; } public void setBrowseType(int browseType) { this.browseType = browseType; } public File getCurrentFolder() { return currentFolder; } public void setCurrentFolder(File currentFolder) { this.currentFolder = currentFolder; } public String getCurrentWarning() { return currentWarning; } public void setCurrentWarning(String currentWarning) { this.currentWarning = currentWarning; } public String getFailedWarning() { return failedWarning; } public void setFailedWarning(String failedWarning) { this.failedWarning = failedWarning; } public String getNewDirPattern() { return newDirPattern; } public void setNewDirPattern(String pattern) { newDirPattern = pattern; } public String getFileNameWarning() { return fileNameWarning; } public void setFileNameWarning(String fileNameWarning) { this.fileNameWarning = fileNameWarning; } public Vector getFileListing() { return fileListing; } public void setFileListing(Vector folderListing) { this.fileListing = folderListing; } public String getForbiddenWarning() { return forbiddenWarning; } public void setForbiddenWarning(String forbiddenWarning) { this.forbiddenWarning = forbiddenWarning; } public long getMaxFolderNameLength() { return maxFolderNameLength; } public void setMaxFolderNameLength(long maxFolderNameLength) { this.maxFolderNameLength = maxFolderNameLength; } public long getMaxUploadSize() { return maxUploadSize; } public void setMaxUploadSize(long maxUploadSize) { this.maxUploadSize = maxUploadSize; } public File getRootFolder() { return rootFolder; } public void setRootFolder(File rootFolder) { this.rootFolder = rootFolder; } public String getSessionTimeoutWarning() { return sessionTimeoutWarning; } public void setSessionTimeoutWarning(String sessionTimeoutWarning) { this.sessionTimeoutWarning = sessionTimeoutWarning; } public boolean isAllowListHiddenFiles() { return allowListHiddenFiles; } public void setAllowListHiddenFiles(boolean showHiddenFiles) { this.allowListHiddenFiles = showHiddenFiles; } public File getStartFolder() { return startFolder; } public void setStartFolder(File startFolder) { this.startFolder = startFolder; } public String getTempUploadFolder() { return tempUploadFolder; } public void setTempUploadFolder(String tempUploadFolder) { this.tempUploadFolder = tempUploadFolder; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getUpdateWarning() { return updateWarning; } public void setUpdateWarning(String updateWarning) { this.updateWarning = updateWarning; } public File getUpFolder() { return upFolder; } public void setUpFolder(File upFolder) { this.upFolder = upFolder; } public boolean isAllowDownloadFile() { return allowDownloadFile; } public void setAllowDownloadFile(boolean allowDownloadFile) { this.allowDownloadFile = allowDownloadFile; } public boolean isAllowListFiles() { return allowListFiles; } public void setAllowListFiles(boolean allowListFiles) { this.allowListFiles = allowListFiles; } public Integer getNbOfUploadFields() { return nbOfUploadFields; } public void setNbOfUploadFields(int nb) { this.nbOfUploadFields = new Integer(nb); } public boolean isAllowShowPath() { return allowShowPath; } public void setAllowShowPath(boolean allowShowPath) { this.allowShowPath = allowShowPath; } public boolean isAllowPickRootFolder() { return allowPickRootFolder; } public void setAllowPickRootFolder(boolean allowPickRootFolder) { this.allowPickRootFolder = allowPickRootFolder; } public String getNewFilePattern() { return newFilePattern; } public void setNewFilePattern(String newFilePattern) { this.newFilePattern = newFilePattern; } public int getSortBy() { return sortBy; } public void setSortBy(int sortBy) { this.sortBy = sortBy; } public String getFullFolderWarning() { return fullFolderWarning; } public void setFullFolderWarning(String fullFolderWarning) { this.fullFolderWarning = fullFolderWarning; } public String getMultipleFilesWarning() { return multipleFilesWarning; } public void setMultipleFilesWarning(String multipleFilesWarning) { this.multipleFilesWarning = multipleFilesWarning; } public String getOneFileWarning() { return oneFileWarning; } public void setOneFileWarning(String oneFileWarning) { this.oneFileWarning = oneFileWarning; } public String getOneFolderWarning() { return oneFolderWarning; } public void setOneFolderWarning(String oneFolderWarning) { this.oneFolderWarning = oneFolderWarning; } public Boolean lookingForFile() { return new Boolean(browseType==JOTFileBrowserHelper.TYPE_CHOOSE_1_FILE || browseType==JOTFileBrowserHelper.TYPE_CHOOSE_1PLUS_FILE); } public Boolean lookingForFolder() { return new Boolean(browseType==JOTFileBrowserHelper.TYPE_CHOOSE_1_FOLDER); } public Boolean lookingForSingleFileUpload() { return new Boolean(browseType==JOTFileBrowserHelper.TYPE_UPLOAD_1_FILE); } }