FileDocCategorySizeDatePackage
Status.javaAPI DocGlassfish v2 API8342Fri May 04 22:23:14 BST 2007com.sun.enterprise.config.backup

Status

public class Status extends Object
author
Byron Nevins

Fields Summary
private BackupRequest
request
private File
statusFile
private Properties
props
Constructors Summary
Methods Summary
private java.lang.StringbadStatusFileMessage(java.io.File file)

		String msg = StringHelper.get("backup-res.Props.backup.file", file);
		msg += "\n";
		msg += StringHelper.get("backup-res.CorruptBackupFile.NoStatusFile");
		return msg;
	
voiddelete()

		if(!statusFile.delete())
		{
			// TBD warning message
			statusFile.deleteOnExit();
		}
	
java.lang.StringgetDomainName()

		if(props == null)
			return null;
		
		return props.getProperty(Constants.PROPS_DOMAIN_NAME);
	
longgetInternalTimestamp(java.io.File f)
open the zip file, parse the status file and return the timestamp of when it was created.

		props = null;
		setPropsFromFile(f);

		try
		{
			String s = props.getProperty(Constants.PROPS_TIMESTAMP_MSEC);
			return Long.parseLong(s);
		}
		catch(Exception e)
		{
			LoggerHelper.warning(badStatusFileMessage(f));
			return 0;
		}
	
private java.lang.StringpropsToString(boolean terse)

		final String pre = "backup-res.Props.";
		StringBuffer sb = new StringBuffer();
		
		
		if(terse)
		{
			sb.append(props.getProperty(Constants.PROPS_BACKUP_FILE));
		}

		else
		{
			sb.append(StringHelper.get(pre + Constants.PROPS_DESCRIPTION, props.getProperty(Constants.PROPS_DESCRIPTION)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_BACKUP_FILE, props.getProperty(Constants.PROPS_BACKUP_FILE)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_TIMESTAMP_HUMAN, props.getProperty(Constants.PROPS_TIMESTAMP_HUMAN)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_DOMAINS_DIR, props.getProperty(Constants.PROPS_DOMAINS_DIR)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_DOMAIN_DIR, props.getProperty(Constants.PROPS_DOMAIN_DIR)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_DOMAIN_NAME, props.getProperty(Constants.PROPS_DOMAIN_NAME)));
			sb.append("\n");
			sb.append(StringHelper.get(pre + Constants.PROPS_USER_NAME, props.getProperty(Constants.PROPS_USER_NAME)));
		}

		return sb.toString();
	
java.lang.Stringread(java.io.File file)

param
file Either a zip file that contains backup.properties -- or backup.properties itself. terse is automatically set to true.
return
a String summary of the backup

		return read(file, true);
	
java.lang.Stringread(java.io.File file, boolean terse)

param
file Either a zip file that contains backup.properties -- or backup.properties itself.
param
terse if true, give a short summary
return
a String summary of the backup

		props = null;
		
		setPropsFromFile(file);
		if(props == null)
		{
			return badStatusFileMessage(file);
		}

		return propsToString(terse);
	
private voidreadPropertiesFile(java.io.File propsFile)

		try
		{
			BufferedInputStream in = new BufferedInputStream(new FileInputStream(propsFile));
			props = new Properties();
			props.load(in);
			in.close();
		}
		catch(IOException ioe)
		{
			props = null;
		}
	
private voidsetProps()

		props.setProperty(Constants.PROPS_USER_NAME, System.getProperty(Constants.PROPS_USER_NAME));
		props.setProperty(Constants.PROPS_TIMESTAMP_MSEC,	"" + request.timestamp);
		props.setProperty(Constants.PROPS_DOMAINS_DIR,	FileUtils.safeGetCanonicalPath(request.domainsDir));
		props.setProperty(Constants.PROPS_DOMAIN_DIR,	FileUtils.safeGetCanonicalPath(request.domainDir));
		props.setProperty(Constants.PROPS_BACKUP_FILE,	FileUtils.safeGetCanonicalPath(request.backupFile));
		props.setProperty(Constants.PROPS_DOMAIN_NAME,	request.domainName);
		props.setProperty(Constants.PROPS_DESCRIPTION,	request.description);
		props.setProperty(Constants.PROPS_TIMESTAMP_HUMAN,	new Date(request.timestamp).toString());
	
private voidsetPropsFromFile(java.io.File file)

param
file Either a zip file that contains backup.properties -- or backup.properties itself.
param
terse if true, give a short summary
return
a String summary of the backup

		props = null;
		ZipInputStream zis = null;


		if(file.getName().toLowerCase().endsWith(".properties"))
		{
			readPropertiesFile(file);
			// props is now set...
			return;
		}

		try
		{
			zis = new ZipInputStream(new FileInputStream(file));
			ZipEntry ze;

			while( (ze = zis.getNextEntry()) != null )
			{
				if(ze.getName().equals(Constants.PROPS_FILENAME))
				{
					props = new Properties();
					props.load(zis);
					break;
				}
			}
			// props may be null
		}
		catch(Exception e)
		{
			// overkill...
			props = null;
		}
		finally
		{
			if(zis != null)
			{
				try
				{
					zis.close();
				}
				catch(Exception e)
				{
				}
			}
		}
	
java.lang.Stringwrite(BackupRequest req)

		props = new Properties();
		request = req;
		statusFile = new File(request.domainDir, Constants.PROPS_FILENAME);

		try
		{
			setProps();
			FileOutputStream out = new FileOutputStream(statusFile);
			props.store(out, Constants.PROPS_HEADER);
			return propsToString(false);
		}
		catch(Exception e)
		{
			return StringHelper.get("backup-res.CantWriteStatus", statusFile);
		}