View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.maintenance.backup.vfs;
17  
18  import java.text.DateFormat;
19  import java.text.SimpleDateFormat;
20  import java.util.Date;
21  
22  import org.apache.commons.vfs2.FileSystemManager;
23  
24  /** Simple implementation of a backup context */
25  public class SimpleBackupContext implements BackupContext {
26  	private DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmm");
27  	private final Date timestamp;
28  	private final String name;
29  
30  	private final FileSystemManager fileSystemManager;
31  
32  	public SimpleBackupContext(FileSystemManager fileSystemManager,
33  			String backupsBase, String name) {
34  		this.name = name;
35  		this.timestamp = new Date();
36  		this.fileSystemManager = fileSystemManager;
37  	}
38  
39  	public Date getTimestamp() {
40  		return timestamp;
41  	}
42  
43  	public String getTimestampAsString() {
44  		return dateFormat.format(timestamp);
45  	}
46  
47  	public String getSystemName() {
48  		return name;
49  	}
50  
51  	public String getRelativeFolder() {
52  		return name + '/' + getTimestampAsString();
53  	}
54  
55  	public DateFormat getDateFormat() {
56  		return dateFormat;
57  	}
58  
59  	public FileSystemManager getFileSystemManager() {
60  		return fileSystemManager;
61  	}
62  
63  }