NotifyChange.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2006-2010 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.alfresco.jlan.client;
  20. /**
  21. * Notify Change Transaction Class
  22. *
  23. * <p>Contains constants used when registering a change notification handler via the CIFSDiskSession.NTNotifyChange() method.
  24. *
  25. * <p>Contains static methods for converting change notification flags and actions to strings.
  26. *
  27. * @author gkspencer
  28. */
  29. public class NotifyChange {
  30. // Change notification filter flags
  31. public final static int FileName = 0x0001;
  32. public final static int DirectoryName = 0x0002;
  33. public final static int Attributes = 0x0004;
  34. public final static int Size = 0x0008;
  35. public final static int LastWrite = 0x0010;
  36. public final static int LastAccess = 0x0020;
  37. public final static int Creation = 0x0040;
  38. public final static int Security = 0x0100;
  39. // Change notifcation actions
  40. public final static int ActionAdded = 1;
  41. public final static int ActionRemoved = 2;
  42. public final static int ActionModified = 3;
  43. public final static int ActionRenamedNewName = 4;
  44. public final static int ActionRenamedOldName = 5;
  45. public final static int ActionAddedStream = 6;
  46. public final static int ActionRemovedStream = 7;
  47. public final static int ActionModifiedStream = 8;
  48. // Change notification action names
  49. private final static String[] _actnNames = {"Added",
  50. "Removed",
  51. "Modified",
  52. "Rename New Name",
  53. "Rename Old Name",
  54. "Added Stream",
  55. "Removed Stream",
  56. "Modified Stream"
  57. };
  58. /**
  59. * Return the change notification action as a string
  60. *
  61. * @param action int
  62. * @return String
  63. */
  64. public static final String getActionAsString(int action) {
  65. // Range check the action
  66. if ( action <= 0 || action > _actnNames.length)
  67. return "Unknown";
  68. // Return the action as a string
  69. return _actnNames[action - 1];
  70. }
  71. /**
  72. * Return the change notification filter flag as a string. This method assumes a single flag is
  73. * set.
  74. *
  75. * @param filter int
  76. * @return String
  77. */
  78. public static final String getFilterAsString(int filter) {
  79. // Check if there are any flags set
  80. if ( filter == 0)
  81. return "";
  82. // Determine the filter type
  83. String filtStr = null;
  84. switch (filter) {
  85. case FileName:
  86. filtStr = "FileName";
  87. break;
  88. case DirectoryName:
  89. filtStr = "DirectoryName";
  90. break;
  91. case Attributes:
  92. filtStr = "Attributes";
  93. break;
  94. case Size:
  95. filtStr = "Size";
  96. break;
  97. case LastWrite:
  98. filtStr = "LastWrite";
  99. break;
  100. case LastAccess:
  101. filtStr = "LastAccess";
  102. break;
  103. case Creation:
  104. filtStr = "Creation";
  105. break;
  106. case Security:
  107. filtStr = "Security";
  108. break;
  109. }
  110. // Return the filter type string
  111. return filtStr;
  112. }
  113. /**
  114. * Return the change notification filter flags as a string.
  115. *
  116. * @param filter int
  117. * @return String
  118. */
  119. public static final String getFilterFlagsAsString(int filter) {
  120. // Check if there are any flags set
  121. if ( filter == 0)
  122. return "";
  123. // Build the filter flags string
  124. StringBuffer filtStr = new StringBuffer();
  125. int i = 0x0001;
  126. while (i < Security) {
  127. // Check if the current filter flag is set
  128. if ( (filter & i) != 0) {
  129. // Get the filter flag name
  130. String name = getFilterAsString(i);
  131. if ( name != null) {
  132. if ( filtStr.length() > 0)
  133. filtStr.append(",");
  134. filtStr.append(name);
  135. }
  136. }
  137. // Update the filter flag mask
  138. i = i << 1;
  139. }
  140. // Return the filter flags string
  141. return filtStr.toString();
  142. }
  143. }