RepositoryUtils { public RepositoryFile getFile( final String path, final IRepositoryFileData data, final boolean createIfNotExist, final boolean createParents, final String versionMessage ) { RepositoryFile file = repository.getFile( path ); if ( null == file && createIfNotExist ) { final String parentFolderName = RepositoryFilenameUtils.getFullPathNoEndSeparator( path ); final RepositoryFile parentFolder = getFolder( parentFolderName, createParents, createParents, versionMessage ); if ( null != parentFolder ) { final String fileName = RepositoryFilenameUtils.getName( path ); file = new RepositoryFile.Builder( fileName ).folder( false ).build(); file = repository.createFile( parentFolder.getId(), file, data, versionMessage ); } } return file; } RepositoryUtils( final IUnifiedRepository repository ); IUnifiedRepository getRepository(); RepositoryFile getFolder( final String path, final boolean createIfNotExist, final boolean createParents,
      final String versionMessage ); RepositoryFile getFolder( final String path, final RepositoryFileAcl acl, final boolean createIfNotExist,
      final boolean createParents, final String versionMessage ); RepositoryFile getFile( final String path, final IRepositoryFileData data, final boolean createIfNotExist,
      final boolean createParents, final String versionMessage ); RepositoryFile saveFile( final String filePath, final IRepositoryFileData data, final boolean create,
      final boolean overwrite, final boolean createParentDirs, final boolean versioned, final String versionMessage );  }
@Test public void testGetFile() throws Exception { final MockUnifiedRepository repository = new MockUnifiedRepository( new SpringSecurityCurrentUserProvider() ); final RepositoryUtils repositoryUtils = new RepositoryUtils( repository ); final SimpleRepositoryFileData data = new SimpleRepositoryFileData( new ByteArrayInputStream( "Test".getBytes() ), "UTF-8", "text/plain" ); RepositoryFile test = repositoryUtils.getFile( "/public/one/two/three.prpt", data, true, true, null ); assertNotNull( test ); assertEquals( "The filename is invalid", "three.prpt", test.getName() ); assertEquals( "The path is invalid", "/public/one/two/three.prpt", test.getPath() ); assertFalse( "The file should not be defined as a folder", test.isFolder() ); RepositoryFile one = repositoryUtils.getFolder( "/public/one", false, false, null ); assertNotNull( one ); RepositoryFile two = repositoryUtils.getFolder( "/public/one/two", false, false, null ); assertNotNull( two ); }