1 17 package org.alfresco.filesys.server.filesys; 18 19 import org.alfresco.filesys.smb.SharingMode; 20 import org.alfresco.filesys.smb.WinNT; 21 22 27 public class FileOpenParams 28 { 29 31 public final static String StreamSeparator = ":"; 32 33 35 private static int[] _NTToLMOpenCode = { 36 FileAction.TruncateExisting + FileAction.CreateNotExist, 37 FileAction.OpenIfExists, 38 FileAction.CreateNotExist, 39 FileAction.OpenIfExists + FileAction.CreateNotExist, 40 FileAction.TruncateExisting, 41 FileAction.TruncateExisting + FileAction.CreateNotExist }; 42 43 45 private static String [] _openMode = { "Supersede", "Open", "Create", "OpenIf", "Overwrite", "OverwriteIf" }; 46 47 49 private String m_path; 50 51 53 private String m_stream; 54 55 57 private int m_openAction; 58 59 61 private int m_accessMode; 62 63 65 private int m_attr; 66 67 69 private long m_allocSize; 70 71 73 private int m_sharedAccess = SharingMode.READWRITE; 74 75 77 private long m_createDate; 78 79 81 private int m_rootFID; 82 83 85 private int m_createOptions; 86 87 89 private int m_secLevel; 90 91 93 private int m_secFlags; 94 95 97 private int m_gid = -1; 98 private int m_uid = -1; 99 100 102 private int m_mode = -1; 103 104 112 public FileOpenParams(String path, int openAction, int accessMode, int fileAttr) 113 { 114 115 117 parseFileName(path); 118 119 m_openAction = convertToNTOpenAction(openAction); 120 m_accessMode = convertToNTAccessMode(accessMode); 121 m_attr = fileAttr; 122 123 125 if (FileAttribute.isDirectory(m_attr)) 126 m_createOptions = WinNT.CreateDirectory; 127 128 130 m_secLevel = -1; 131 } 132 133 144 public FileOpenParams(String path, int openAction, int accessMode, int fileAttr, int gid, int uid, int mode) 145 { 146 147 149 parseFileName(path); 150 151 m_openAction = convertToNTOpenAction(openAction); 152 m_accessMode = convertToNTAccessMode(accessMode); 153 m_attr = fileAttr; 154 155 157 if (FileAttribute.isDirectory(m_attr)) 158 m_createOptions = WinNT.CreateDirectory; 159 160 162 m_secLevel = -1; 163 164 m_gid = gid; 165 m_uid = uid; 166 m_mode = mode; 167 } 168 169 180 public FileOpenParams(String path, int openAction, int accessMode, int searchAttr, int fileAttr, int allocSize, 181 long createDate) 182 { 183 184 186 parseFileName(path); 187 188 m_openAction = convertToNTOpenAction(openAction); 189 m_accessMode = convertToNTAccessMode(accessMode); 190 m_attr = fileAttr; 191 m_sharedAccess = convertToNTSharedMode(accessMode); 192 m_allocSize = (long) allocSize; 193 m_createDate = createDate; 194 195 197 if (FileAttribute.isDirectory(m_attr)) 198 m_createOptions = WinNT.CreateDirectory; 199 200 202 m_secLevel = -1; 203 } 204 205 219 public FileOpenParams(String path, int openAction, int accessMode, int attr, int sharedAccess, long allocSize, 220 int createOption, int rootFID, int secLevel, int secFlags) 221 { 222 223 225 parseFileName(path); 226 227 m_openAction = openAction; 228 m_accessMode = accessMode; 229 m_attr = attr; 230 m_sharedAccess = sharedAccess; 231 m_allocSize = allocSize; 232 m_createOptions = createOption; 233 m_rootFID = rootFID; 234 m_secLevel = secLevel; 235 m_secFlags = secFlags; 236 237 239 if ((createOption & WinNT.CreateDirectory) != 0 && (m_attr & FileAttribute.Directory) == 0) 240 m_attr += FileAttribute.Directory; 241 } 242 243 248 public final String getPath() 249 { 250 return m_path; 251 } 252 253 258 public final String getFullPath() 259 { 260 if (isStream()) 261 return m_path + m_stream; 262 else 263 return m_path; 264 } 265 266 271 public final int getAttributes() 272 { 273 return m_attr; 274 } 275 276 281 public final long getAllocationSize() 282 { 283 return m_allocSize; 284 } 285 286 291 public final boolean hasCreationDateTime() 292 { 293 return m_createDate != 0L ? true : false; 294 } 295 296 301 public final long getCreationDateTime() 302 { 303 return m_createDate; 304 } 305 306 312 public final int getOpenAction() 313 { 314 return m_openAction; 315 } 316 317 322 public final int getRootDirectoryFID() 323 { 324 return m_rootFID; 325 } 326 327 332 public final String getStreamName() 333 { 334 return m_stream; 335 } 336 337 343 public final boolean hasCreateOption(int flag) 344 { 345 return (m_createOptions & flag) != 0 ? true : false; 346 } 347 348 353 public final boolean isStream() 354 { 355 return m_stream != null ? true : false; 356 } 357 358 363 public final boolean isReadOnlyAccess() 364 { 365 367 if (( m_accessMode & AccessMode.NTReadWrite) == AccessMode.NTRead || 368 (m_accessMode & AccessMode.NTExecute) != 0) 369 return true; 370 return false; 371 } 372 373 378 public final boolean isWriteOnlyAccess() 379 { 380 return (m_accessMode & AccessMode.NTReadWrite) == AccessMode.NTWrite ? true : false; 381 } 382 383 388 public final boolean isReadWriteAccess() 389 { 390 return (m_accessMode & AccessMode.NTReadWrite) == AccessMode.NTReadWrite ? true : false; 391 } 392 393 399 public final boolean hasAccessMode(int mode) 400 { 401 return (m_accessMode & mode) == mode ? true : false; 402 } 403 404 409 public final boolean isDirectory() 410 { 411 return hasCreateOption(WinNT.CreateDirectory); 412 } 413 414 419 public final boolean isSequentialAccessOnly() 420 { 421 return hasCreateOption(WinNT.CreateSequential); 422 } 423 424 429 public final boolean isDeleteOnClose() 430 { 431 return hasCreateOption(WinNT.CreateDeleteOnClose); 432 } 433 434 439 public final boolean isWriteThrough() 440 { 441 return hasCreateOption(WinNT.CreateWriteThrough); 442 } 443 444 449 public final boolean isOverwrite() 450 { 451 if (getOpenAction() == FileAction.NTSupersede || getOpenAction() == FileAction.NTOverwrite 452 || getOpenAction() == FileAction.NTOverwriteIf) 453 return true; 454 return false; 455 } 456 457 462 public final int getSharedAccess() 463 { 464 return m_sharedAccess; 465 } 466 467 472 public final boolean hasSecurityLevel() 473 { 474 return m_secLevel != -1 ? true : false; 475 } 476 477 482 public final int getSecurityLevel() 483 { 484 return m_secLevel; 485 } 486 487 492 public final boolean hasSecurityContextTracking() 493 { 494 return (m_secFlags & WinNT.SecurityContextTracking) != 0 ? true : false; 495 } 496 497 502 public final boolean hasSecurityEffectiveOnly() 503 { 504 return (m_secFlags & WinNT.SecurityEffectiveOnly) != 0 ? true : false; 505 } 506 507 512 public final boolean hasGid() 513 { 514 return m_gid != -1 ? true : false; 515 } 516 517 522 public final int getGid() 523 { 524 return m_gid; 525 } 526 527 532 public final boolean hasUid() 533 { 534 return m_uid != -1 ? true : false; 535 } 536 537 542 public final int getUid() 543 { 544 return m_uid; 545 } 546 547 552 public final boolean hasMode() 553 { 554 return m_mode != -1 ? true : false; 555 } 556 557 562 public final int getMode() 563 { 564 return m_mode; 565 } 566 567 572 public final void setMode(int mode) 573 { 574 m_mode = mode; 575 } 576 577 582 public final void setCreateOption(int flag) 583 { 584 m_createOptions = m_createOptions | flag; 585 } 586 587 593 private final int convertToNTAccessMode(int accessMode) 594 { 595 596 598 int mode = 0; 599 600 switch (AccessMode.getAccessMode(accessMode)) 601 { 602 case AccessMode.ReadOnly: 603 mode = AccessMode.NTRead; 604 break; 605 case AccessMode.WriteOnly: 606 mode = AccessMode.NTWrite; 607 break; 608 case AccessMode.ReadWrite: 609 mode = AccessMode.NTReadWrite; 610 break; 611 } 612 return mode; 613 } 614 615 621 private final int convertToNTOpenAction(int openAction) 622 { 623 624 626 int action = FileAction.NTOpen; 627 628 for (int i = 0; i < _NTToLMOpenCode.length; i++) 629 { 630 if (_NTToLMOpenCode[i] == openAction) 631 action = i; 632 } 633 return action; 634 } 635 636 642 private final int convertToNTSharedMode(int sharedAccess) 643 { 644 645 647 int shr = AccessMode.getSharingMode(sharedAccess); 648 int ret = SharingMode.READWRITE; 649 650 switch (shr) 651 { 652 case AccessMode.Exclusive: 653 ret = SharingMode.NOSHARING; 654 break; 655 case AccessMode.DenyRead: 656 ret = SharingMode.WRITE; 657 break; 658 case AccessMode.DenyWrite: 659 ret = SharingMode.READ; 660 break; 661 } 662 return ret; 663 } 664 665 670 private final void parseFileName(String fileName) 671 { 672 673 675 int pos = fileName.indexOf(StreamSeparator); 676 if (pos == -1) 677 { 678 m_path = fileName; 679 return; 680 } 681 682 684 m_path = fileName.substring(0, pos); 685 m_stream = fileName.substring(pos); 686 } 687 688 693 public String toString() 694 { 695 StringBuffer str = new StringBuffer (); 696 str.append("["); 697 698 str.append(getPath()); 699 700 str.append(","); 701 str.append(_openMode[getOpenAction()]); 702 str.append(",acc=0x"); 703 str.append(Integer.toHexString(m_accessMode)); 704 str.append(",attr=0x"); 705 str.append(Integer.toHexString(getAttributes())); 706 str.append(",alloc="); 707 str.append(getAllocationSize()); 708 str.append(",share=0x"); 709 str.append(Integer.toHexString(getSharedAccess())); 710 711 if (getRootDirectoryFID() != 0) 712 { 713 str.append(",fid="); 714 str.append(getRootDirectoryFID()); 715 } 716 717 if (hasCreationDateTime()) 718 { 719 str.append(",cdate="); 720 str.append(getCreationDateTime()); 721 } 722 723 if (m_createOptions != 0) 724 { 725 str.append(",copt=0x"); 726 str.append(Integer.toHexString(m_createOptions)); 727 } 728 729 if (hasSecurityLevel()) 730 { 731 str.append(",seclev="); 732 str.append(getSecurityLevel()); 733 str.append(",secflg=0x"); 734 str.append(Integer.toHexString(m_secFlags)); 735 } 736 str.append("]"); 737 738 if (hasGid() || hasUid()) 739 { 740 str.append(",gid="); 741 str.append(getGid()); 742 str.append(",uid="); 743 str.append(getUid()); 744 str.append(",mode="); 745 str.append(getMode()); 746 } 747 return str.toString(); 748 } 749 } 750 | Popular Tags |