* @param pathId (colon separated path for the repository file)
* @param newName (New name of the file)
* @return
*/
public boolean doRename( String pathId, String newName ) throws Exception {
IUnifiedRepository repository = getRepository();
RepositoryFile fileToBeRenamed = repository.getFile( FileUtils.idToPath( pathId ) );
StringBuilder buf = new StringBuilder( fileToBeRenamed.getPath().length() );
buf.append( getParentPath( fileToBeRenamed.getPath() ) );
buf.append( RepositoryFile.SEPARATOR );
buf.append( newName );
if ( !fileToBeRenamed.isFolder() ) {
String extension = getExtension( fileToBeRenamed.getName() );
if ( extension != null ) {
buf.append( extension );
}
}
repository.moveFile( fileToBeRenamed.getId(), buf.toString(), "Renaming the file" );
RepositoryFile movedFile = repository.getFileById( fileToBeRenamed.getId() );
if ( movedFile != null ) {
if ( !movedFile.isFolder() ) {
Map<String, Properties> localePropertiesMap = movedFile.getLocalePropertiesMap();
if ( localePropertiesMap == null ) {
localePropertiesMap = new HashMap<String, Properties>();
Properties properties = new Properties();
properties.setProperty( "file.title", newName );
properties.setProperty( "title", newName );
localePropertiesMap.put( "default", properties );
} else {
for ( Map.Entry<String, Properties> entry : localePropertiesMap.entrySet() ) {
Properties properties = entry.getValue();
if ( properties.containsKey( "file.title" ) ) {
properties.setProperty( "file.title", newName );
}
if ( properties.containsKey( "title" ) ) {
properties.setProperty( "title", newName );
}
}
}
RepositoryFile updatedFile =
new RepositoryFile.Builder( movedFile ).localePropertiesMap( localePropertiesMap ).name( newName ).title(
newName ).build();
repository.updateFile( updatedFile, getData( movedFile ), "Updating the file" );
}
return true;
} else {
return false;
//return Response.ok( "File to be renamed does not exist" ).build();