1 23 24 package org.apache.slide.webdav.util.resourcekind; 25 26 import java.lang.reflect.Method ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 import java.util.Collections ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Set ; 36 37 import org.apache.slide.common.NamespaceAccessToken; 38 import org.apache.slide.common.NamespaceConfig; 39 import org.apache.slide.content.NodeRevisionDescriptor; 40 import org.apache.slide.content.NodeRevisionDescriptors; 41 import org.apache.slide.util.Configuration; 42 import org.apache.slide.util.XMLValue; 43 import org.apache.slide.webdav.util.AclConstants; 44 import org.apache.slide.webdav.util.BindConstants; 45 import org.apache.slide.webdav.util.DaslConstants; 46 import org.apache.slide.webdav.util.DeltavConstants; 47 import org.apache.slide.webdav.util.UriHandler; 48 import org.apache.slide.webdav.util.WebdavConstants; 49 import org.jdom.Element; 50 import org.jdom.JDOMException; 51 52 55 abstract public class AbstractResourceKind implements ResourceKind, WebdavConstants, DeltavConstants, AclConstants, DaslConstants, BindConstants { 56 57 60 public static final String EMPTY_STRING = ""; 61 62 protected static Set supportedFeatures = new HashSet (); 64 65 protected static Set liveProperties = new HashSet (); 67 68 protected static Set protectedProperties = new HashSet (); 70 71 protected static Set computedProperties = new HashSet (); 73 74 79 protected final static String [] SUPPORTED_AUTO_VERSION_ELEMENTS = 80 new String [] {EMPTY_STRING, E_CHECKOUT, E_CHECKOUT_IGNORE_UNLOCK, E_CHECKOUT_CHECKIN, E_CHECKOUT_UNLOCKED_CHECKIN, E_LOCKED_CHECKOUT}; 81 82 87 protected final static String [] SUPPORTED_CHECKOUT_FORK_ELEMENTS = 88 new String [] {EMPTY_STRING, E_DISCOURAGED, E_FORBIDDEN}; 89 90 95 protected final static String [] SUPPORTED_CHECKIN_FORK_ELEMENTS = 96 new String [] {EMPTY_STRING, E_DISCOURAGED, E_FORBIDDEN}; 97 98 102 protected final static List SUPPORTED_AUTO_VERSION_ELEMENTS_LIST = Collections.unmodifiableList(Arrays.asList(SUPPORTED_AUTO_VERSION_ELEMENTS)); 103 104 108 protected final static List SUPPORTED_CHECKOUT_FORK_ELEMENTS_LIST = Collections.unmodifiableList(Arrays.asList(SUPPORTED_CHECKOUT_FORK_ELEMENTS)); 109 110 114 protected final static List SUPPORTED_CHECKIN_FORK_ELEMENTS_LIST = Collections.unmodifiableList(Arrays.asList(SUPPORTED_CHECKIN_FORK_ELEMENTS)); 115 116 121 protected final static Map RESTRICTED_PROPERTY_VALUE_MAP = new HashMap (); 122 123 124 static { 126 supportedFeatures.add( F_WEBDAV ); 128 supportedFeatures.add( F_SLIDE ); 129 if( Configuration.useIntegratedLocking() ) 130 supportedFeatures.add( F_LOCKING ); 131 if( Configuration.useIntegratedSecurity() ) 132 supportedFeatures.add( F_ACCESS_CONTROL ); 133 if( Configuration.useSearch() ) 134 supportedFeatures.add( F_SEARCHING_AND_LOCATING ); 135 if( Configuration.useVersionControl() ) { 136 supportedFeatures.add( F_VERSION_CONTROL ); 137 supportedFeatures.add( F_VERSION_HISTORY ); 138 supportedFeatures.add( F_CHECKOUT_IN_PLACE ); 139 supportedFeatures.add( F_WORKSPACE ); 140 supportedFeatures.add( F_WORKING_RESOURCE ); 141 supportedFeatures.add( F_LABEL ); 142 supportedFeatures.add( F_UPDATE ); 143 } 144 if (Configuration.useGlobalBinding()) { 145 supportedFeatures.add( F_BINDING ); 146 } 147 148 computedProperties.add( P_ACL); 150 computedProperties.add( P_ACL_RESTRICTIONS ); 151 computedProperties.add( P_ACTIVITY_CHECKOUT_SET ); 152 computedProperties.add( P_ACTIVITY_VERSION_SET ); 153 computedProperties.add( P_BASELINE_CONTROLLED_COLLECTION_SET ); 154 computedProperties.add( P_CREATIONUSER ); 155 computedProperties.add( P_CURRENT_USER_PRIVILEGE_SET); 156 computedProperties.add( P_CURRENT_WORKSPACE_SET ); 157 computedProperties.add( P_ECLIPSED_SET ); 158 computedProperties.add( P_GROUP_MEMBERSHIP ); 159 computedProperties.add( P_INHERITED_ACL_SET ); 160 computedProperties.add( P_LOCKDISCOVERY ); 161 computedProperties.add( P_MODIFICATIONUSER ); 162 computedProperties.add( P_OWNER); 163 computedProperties.add( P_PRINCIPAL_COLLECTION_SET); 164 computedProperties.add( P_PRIVILEGE_COLLECTION_SET); 165 computedProperties.add( P_ROOT_VERSION ); 166 computedProperties.add( P_SUCCESSOR_SET ); 167 computedProperties.add( P_SUPPORTEDLOCK ); 168 computedProperties.add( P_SUPPORTED_LIVE_PROPERTY_SET ); computedProperties.add( P_SUPPORTED_METHOD_SET ); computedProperties.add( P_SUPPORTED_PRIVILEGE_SET); 171 computedProperties.add( P_SUPPORTED_REPORT_SET ); computedProperties.add( P_VERSION_CONTROLLED_CONFIGURATION ); 173 computedProperties.add( P_VERSION_HISTORY ); 174 computedProperties.add( P_WORKSPACE ); computedProperties.add( P_WORKSPACE_CHECKOUT_SET ); 176 177 protectedProperties.addAll( computedProperties ); 179 protectedProperties.add( P_ALTERNATE_URI_SET ); 180 protectedProperties.add( P_AUTO_UPDATE ); 181 protectedProperties.add( P_BASELINE_COLLECTION ); 182 protectedProperties.add( P_BASELINE_CONTROLLED_COLLECTION ); 183 protectedProperties.add( P_CHECKED_IN ); 184 protectedProperties.add( P_CHECKED_OUT ); 185 protectedProperties.add( P_CHECKOUT_SET ); protectedProperties.add( P_CREATIONDATE ); 187 protectedProperties.add( P_MODIFICATIONDATE ); 188 protectedProperties.add( P_GETLASTMODIFIED ); 189 protectedProperties.add( P_GETCONTENTLENGTH ); 191 protectedProperties.add( P_GETETAG ); 192 protectedProperties.add( P_LABEL_NAME_SET ); 193 protectedProperties.add( P_PARENT_SET ); 194 protectedProperties.add( P_PREDECESSOR_SET ); 195 protectedProperties.add( P_RESOURCE_ID ); 196 protectedProperties.add( P_RESOURCETYPE ); 197 protectedProperties.add( P_SOURCE ); 198 protectedProperties.add( P_SUBBASELINE_SET ); 199 protectedProperties.add( P_VERSION_CONTROLLED_BINDING_SET ); 200 protectedProperties.add( P_VERSION_NAME ); 201 protectedProperties.add( P_VERSION_SET ); 202 protectedProperties.add( P_PRIVILEGE_MEMBERSHIP ); 204 liveProperties.addAll( WebdavConstants.WEBDAV_PROPERTY_LIST ); 206 liveProperties.addAll( AclConstants.ACL_PROPERTY_LIST ); 207 liveProperties.addAll( DeltavConstants.DELTAV_PROPERTY_LIST ); 208 liveProperties.addAll( BindConstants.BIND_PROPERTY_LIST ); 209 210 RESTRICTED_PROPERTY_VALUE_MAP.put(P_AUTO_VERSION, SUPPORTED_AUTO_VERSION_ELEMENTS_LIST); 212 RESTRICTED_PROPERTY_VALUE_MAP.put(P_CHECKOUT_FORK, SUPPORTED_CHECKOUT_FORK_ELEMENTS_LIST); 213 RESTRICTED_PROPERTY_VALUE_MAP.put(P_CHECKIN_FORK, SUPPORTED_CHECKIN_FORK_ELEMENTS_LIST); 214 } 215 216 219 static public ResourceKind getInstance() { 220 return null; 221 } 222 223 226 static public ResourceKind determineResourceKind( NamespaceAccessToken nsaToken, NodeRevisionDescriptors nrds, NodeRevisionDescriptor nrd ) { 227 UriHandler uh = UriHandler.getUriHandler( nrds, nrd ); 228 return determineResourceKind( nsaToken, uh.toString(), nrd ); 229 } 230 231 234 static public ResourceKind determineResourceKind( NamespaceAccessToken nsaToken, String resourcePath, NodeRevisionDescriptor nrd ) { 235 UriHandler uh = UriHandler.getUriHandler( resourcePath ); 236 NamespaceConfig config = nsaToken.getNamespaceConfig(); 237 238 if( nrd == null ) { 239 return DeltavCompliantUnmappedUrlImpl.getInstance(); 240 } 241 else if( uh.isHistoryUri() ) { 242 return VersionHistoryImpl.getInstance(); 243 } 244 else if( uh.isVersionUri() ) { 245 return VersionImpl.getInstance(); 246 } 247 else if( uh.isWorkspaceUri() ) { 248 return WorkspaceImpl.getInstance(); 249 } 250 else if( uh.isWorkingresourceUri() ) { 251 return WorkingImpl.getInstance(); 252 } 253 else if( nrd.exists(P_CHECKED_IN) ) { 254 return CheckedInVersionControlledImpl.getInstance(); 255 } 256 else if( nrd.exists(P_CHECKED_OUT) ) { 257 return CheckedOutVersionControlledImpl.getInstance(); 258 } 259 else if( config.isPrincipal(resourcePath) ) { 260 return PrincipalImpl.getInstance(); 261 } 262 else if( nrd.propertyValueContains(P_RESOURCETYPE, E_COLLECTION) ) { 263 return DeltavCompliantCollectionImpl.getInstance(); 264 } 265 else { 266 return VersionableImpl.getInstance(); 267 } 268 } 269 270 273 protected static boolean isSupportedFeature( String feature ) { 274 return supportedFeatures.contains( feature ); 275 } 276 277 280 protected static boolean isSupportedFeature( String feature, String [] excludedFeatures ) { 281 return supportedFeatures.contains( feature ) 282 && (Arrays.binarySearch(excludedFeatures, feature) < 0); 283 } 284 285 288 public static boolean isLiveProperty( String propName ) { 289 return( liveProperties.contains(propName) ); 290 } 291 292 295 public static boolean isProtectedProperty( String propName ) { 296 return( protectedProperties.contains(propName) ); 297 } 298 299 302 public static boolean isComputedProperty( String propName ) { 303 return( computedProperties.contains(propName) ); 304 } 305 306 309 public static Set getAllLiveProperties() { 310 return( Collections.unmodifiableSet(liveProperties) ); 311 } 312 313 316 public static Set getAllProtectedProperties() { 317 return( Collections.unmodifiableSet(protectedProperties) ); 318 } 319 320 323 public static Set getAllComputedProperties() { 324 return( Collections.unmodifiableSet(computedProperties) ); 325 } 326 327 328 329 332 public Set getSupportedLiveProperties() { 333 return getSupportedLiveProperties( new String [0] ); 334 } 335 336 344 public Set getSupportedLiveProperties( String filter ) { 345 Set s = getSupportedLiveProperties( new String [0] ); 346 if( Q_COMPUTED_ONLY.equals(filter) ) { 347 s.retainAll( computedProperties ); 348 } 349 if( Q_PROTECTED_ONLY.equals(filter) ) { 350 s.retainAll( protectedProperties ); 351 } 352 return s; 353 } 354 355 363 public Set getSupportedLiveProperties( String [] excludedFeatures ) { 364 Set s = new HashSet (); 365 Iterator it = getSuperKinds().iterator(); 366 while( it.hasNext() ) { 367 ResourceKind superkind = (ResourceKind)it.next(); 368 s.addAll( superkind.getSupportedLiveProperties(excludedFeatures) ); 369 } 370 return s; 371 } 372 373 382 public Set getSupportedLiveProperties( String filter, String [] excludedFeatures ) { 383 Set s = getSupportedLiveProperties( excludedFeatures ); 384 if( Q_COMPUTED_ONLY.equals(filter) ) { 385 s.retainAll( computedProperties ); 386 } 387 if( Q_PROTECTED_ONLY.equals(filter) ) { 388 s.retainAll( protectedProperties ); 389 } 390 return s; 391 } 392 393 396 public Set getSupportedMethods() { 397 Set result = new HashSet (); 398 Iterator it = getSuperKinds().iterator(); 399 while( it.hasNext() ) { 400 ResourceKind superkind = (ResourceKind)it.next(); 401 result.addAll( superkind.getSupportedMethods() ); 402 } 403 return result; 404 } 405 406 409 public boolean isSupportedLiveProperty( String prop ) { 410 return getSupportedLiveProperties().contains( prop ); 411 } 412 413 416 public boolean isSupportedMethod( String method ) { 417 return getSupportedMethods().contains( method ); 418 } 419 420 423 public Set getSupportedReports() { 424 Set result = new HashSet (); 425 Iterator it = getSuperKinds().iterator(); 426 while( it.hasNext() ) { 427 ResourceKind superkind = (ResourceKind)it.next(); 428 result.addAll( superkind.getSupportedReports() ); 429 } 430 return result; 431 } 432 433 446 public boolean isSupportedPropertyValue(String propertyName, Object value) { 447 448 boolean isSupported = true; 449 List listOfRestrictedValues = (List )RESTRICTED_PROPERTY_VALUE_MAP.get(propertyName); 450 if (listOfRestrictedValues != null) { 451 452 if (value == null) { 453 return false; 454 } 455 456 if (EMPTY_STRING.equals(value.toString())) { 458 return listOfRestrictedValues.contains(EMPTY_STRING); 459 } 460 461 XMLValue xmlValue = null; 462 if (value instanceof XMLValue) { 463 xmlValue = (XMLValue)value; 464 } 465 else { 466 try { 467 xmlValue = new XMLValue(value.toString()); 468 } 469 catch (JDOMException e) { 470 return false; 471 } 472 } 473 isSupported = 474 (xmlValue.size() > 0) && 475 listOfRestrictedValues.contains(((Element)xmlValue.iterator().next()).getName()); 476 } 477 478 return isSupported; 479 } 480 481 484 public String toString() { 485 return plainClassName( getClass() ); 486 } 487 488 protected List getSuperKinds() { 489 List result = new ArrayList (); 490 Class myclass = getClass(); 491 String myclassName = plainClassName( myclass ); 492 Class [] ifs = myclass.getInterfaces(); 493 for( int i = 0; i < ifs.length; i++ ) { 494 Class myif = ifs[i]; 495 String myifName = plainClassName( myif ); 496 if( !myclassName.startsWith(myifName) ) 497 continue; 498 Class [] superifs = myif.getInterfaces(); 499 for( int j = 0; j < superifs.length; j++ ) { 500 Class superif = superifs[j]; 501 String superifName = plainClassName( superif ); 502 if( "ResourceKind".equals(superifName) ) 503 continue; 504 Class superclass = null; 505 ResourceKind superkind = null; 506 try { 507 superclass = Class.forName( superif.getName()+"Impl" ); 508 Class [] ptypes = new Class [0]; 509 Method facmeth = superclass.getMethod( "getInstance", ptypes ); 510 Object [] parms = new Object [0]; 511 result.add( facmeth.invoke(null, parms) ); 512 } 513 catch( Exception x ) { 514 x.printStackTrace(); 515 throw new IllegalStateException ( x.getMessage() ); 516 } 517 } 518 } 519 520 return result; 521 } 522 523 private String plainClassName( Class c ) { 524 String n = c.getName(); 525 int i = n.lastIndexOf( '.' ); 526 return n.substring( i + 1 ); 527 } 528 529 532 public static void main(String [] args) { 533 String rkn = args[0]; 534 Class [] pt = new Class [0]; 535 Object [] p = new Object [0]; 536 Iterator i; 537 538 if( rkn == null || rkn.length() == 0 ) 539 return; 540 try { 541 Class rkc = Class.forName( 542 "org.apache.slide.webdav.util.resourcekind."+rkn+"Impl"); 543 ResourceKind rk = 544 (ResourceKind)rkc.getMethod("getInstance", pt).invoke(null, p); 545 System.out.println("\nResource kind: "+rk); 546 System.out.println("\nSupported live properties:"); 547 i = rk.getSupportedLiveProperties().iterator(); 548 while( i.hasNext() ) 549 System.out.println("- "+i.next()); 550 System.out.println("\nSupported methods:"); 551 i = rk.getSupportedMethods().iterator(); 552 while( i.hasNext() ) 553 System.out.println("- "+i.next()); 554 System.out.println("\nSupported reports:"); 555 i = rk.getSupportedReports().iterator(); 556 while( i.hasNext() ) 557 System.out.println("- "+i.next()); 558 } 559 catch( Exception x ) { x.printStackTrace(); } 560 } 561 } 562 563 | Popular Tags |