/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft Corporation. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/

package com.togethersoft.modules.qa.utils;

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import com.togethersoft.openapi.ide.*;
import com.togethersoft.openapi.ide.window.*;
import com.togethersoft.openapi.sci.*;
import com.togethersoft.openapi.sci.enum.*;
import com.togethersoft.modules.qa.*;
import com.togethersoft.modules.qa.api.*;


/**
 * Audit plugin implementation -
 * abstract class serving as ancestor for all audit plugins
 *
 * @version 3.1.0
 * @author TogetherSoft
 *
 **/
public abstract  class AuditPluginImpl extends PluginImpl implements AuditPlugin
{

	/**
	* Gets default severity for plugin (SEVERITY_LOW, SEVERITY_NORMAL or SEVERITY_HIGH).
	* Default implementation returns SEVERITY_NORMAL.
	*
	* @return default severity
	*
	* @see #SEVERITY_LOW
	* @see #SEVERITY_NORMAL
	* @see #SEVERITY_HIGH
	*
	* @deprecated Since Together 4.01 this method is never called.
	* Defaults are now provided by loading default value sets from files.
	*
	**/
	public String getDefaultSeverity () {
        return SEVERITY_NORMAL;
    }


   /**
    * Gets the of description file name of plugin
    * By default, description file name is the same as plugin class file name but with the extemsion of ".html".
    * @return description file name
    **/
	public String getDescriptionFileName() {
        String name = Utils.getClsName(this);
        String fileName = TgUtils.getAuditHomeDir() +
            File.separator + name +
            File.separator + name + ".html";
        return fileName;
    }


	/**
	 * plugin's property name prefix
	 */
	private String propertyPrefix = null;

	protected String getPropertyPrefix() {
		if( propertyPrefix == null ) {
			String s = getClass().getName();
			int pos = s.lastIndexOf('.');
			propertyPrefix = "Audit." + s.substring(pos + 1);
		}
		return propertyPrefix;
	}

	protected Properties getProperties() {
		return Audit.getProperties();
	}

	/**
	 * Severity of audit rule violation.
	 * May be equal to SEVERITY_LOW, SEVERITY_NORMAL or SEVERITY_HIGH
     *
     * @see #SEVERITY_LOW
     * @see #SEVERITY_NORMAL
	 * @see #SEVERITY_HIGH
	 */
	private String severity = SEVERITY_NORMAL;

	public String getSeverity() {
		return severity;
	}

	public void setSeverity(String severity) {
		this.severity = severity;
	}

	// used to restore options from  the properties file
	public void restoreOptions() {
		setSeverity(getProperty("Severity", SEVERITY_NORMAL));
		super.restoreOptions();
	}

	// used to store options from  the properties file.
	public boolean storeOptions() {
		putProperty("Severity", getSeverity());
		return super.storeOptions();
	}

}
