/** * Returns a list of possible resource identifiers for a given workspace path. * * @param workspace * @param path * @return */ public static List<ResourceIdentifier<?>> getPossibleIdentifiers( Workspace workspace, String path ) { List<ResourceManager<?>> list = getManagersForWorkspacePath( workspace, path ); List<ResourceIdentifier<?>> result = new ArrayList<ResourceIdentifier<?>>(); for ( ResourceManager<?> mgr : list ) { Class<?> cls = mgr.getMetadata().getProviderClass(); int one = mgr.getMetadata().getWorkspacePath().endsWith( "/" ) ? 0 : 1; String id = path.substring( mgr.getMetadata().getWorkspacePath().length() + one ); result.add( new DefaultResourceIdentifier( cls, id ) ); } return result; }
/** * Searches for resource managers corresponding to a workspace path. * * @param workspace * may not be <code>null</code> * @param path * may not be <code>null</code>, may contain other path elements * @return a list of matching resource managers, may be empty but never <code>null</code> */ public static List<ResourceManager<?>> getManagersForWorkspacePath( Workspace workspace, String path ) { List<ResourceManager<?>> result = new ArrayList<ResourceManager<?>>(); List<ResourceManager<?>> list = workspace.getResourceManagers(); for ( ResourceManager<?> mgr : list ) { ResourceManagerMetadata<?> md = mgr.getMetadata(); if ( path.startsWith( md.getWorkspacePath() ) ) { result.add( mgr ); } } return result; }
ResourceManager<?> mgr = iter.next(); LOG.info( "Found resource manager {}.", mgr.getClass().getSimpleName() ); resourceManagers.put( mgr.getMetadata().getProviderClass(), mgr ); LOG.info( "Starting up resource manager {}.", mgr.getClass().getSimpleName() );
@Override public <T extends Resource> ResourceLocation<T> persist( ResourceLocation<T> location ) { ResourceManager<?> mgr = managers.get( location.getIdentifier().getProvider() ); File file = new File( directory, mgr.getMetadata().getWorkspacePath() ); file = new File( file, location.getIdentifier().getId() + ".xml" ); file.getParentFile().mkdirs(); try { // copy to avoid persisting from same file File tmp = File.createTempFile( "config", ".xml" ); FileUtils.copyInputStreamToFile( location.getAsStream(), tmp ); tmp.renameTo( file ); return new DefaultResourceLocation<T>( file, location.getIdentifier() ); } catch ( Exception e ) { throw new ResourceException( "Could not persist resource location: " + e.getLocalizedMessage(), e ); } }