} else {
tmpMode = Mode.CUSTOM;
}
final Mode mode = tmpMode;
if ( fileName != null ) {
final JcrTemplate jcrTemplate = PentahoSystem.get( JcrTemplate.class, "jcrTemplate", pentahoSession ); //$NON-NLS-1$
TransactionTemplate txnTemplate =
PentahoSystem.get( TransactionTemplate.class, "jcrTransactionTemplate", pentahoSession ); //$NON-NLS-1$
String repositoryAdminUsername = PentahoSystem.get( String.class, "repositoryAdminUsername", pentahoSession ); //$NON-NLS-1$
final String ZIP_EXTENSION = ".zip"; //$NON-NLS-1$
// let the user know this is a zip
if ( !fileName.endsWith( ZIP_EXTENSION ) ) {
fileName = fileName + ZIP_EXTENSION;
}
logger.debug( String.format( "dumping repository to file \"%s\"", fileName ) ); //$NON-NLS-1$
ZipOutputStream tmpOut = null;
try {
tmpOut = new ZipOutputStream( new BufferedOutputStream( FileUtils.openOutputStream( new File( fileName ) ) ) );
} catch ( IOException e ) {
IOUtils.closeQuietly( tmpOut );
throw new RuntimeException( e );
}
final ZipOutputStream out = tmpOut;
// stash existing session
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
// run as repo super user
PentahoSessionHolder.setSession( createRepositoryAdminPentahoSession( repositoryAdminUsername ) );
try {
txnTemplate.execute( new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult( final TransactionStatus status ) {
jcrTemplate.execute( new JcrCallback() {
public Object doInJcr( final Session session ) throws RepositoryException, IOException {
switch ( mode ) {
case SYS: {
final boolean SKIP_BINARY = false;
final boolean NO_RECURSE = false;