package com.ibm.emb.junit;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * this class provides Helper functionality to prepare embedded media on the
 * test Server and abstract over naming for usage in testcases
 */
public class EmbeddedMediaLocationInfo {

    protected EMBTestConfiguration tstCfg = null;

    protected String extension = "";

    protected String mediaName = "";

    protected URL mediaURL = null;

    protected File mediaFile = null;

    /**
     * contructor
     */
    public EmbeddedMediaLocationInfo(String argMediaName) throws MalformedURLException, IOException {
        this.tstCfg = EMBTestConfiguration.instance();
        this.mediaName = argMediaName;
        prepareMedia();
    }

    /**
     *
     */
    protected void prepareMedia() throws MalformedURLException, IOException {

        // remove C:
        this.mediaFile = new File(tstCfg.getMediaDir() + File.separator + this.mediaName);
        this.mediaURL = new URL("file", tstCfg.getTestClientIPAddress(), tstCfg.getMediaDir() + "/"
                + this.mediaName);
        this.extension = this.mediaName.substring(this.mediaName.lastIndexOf("."));

    }

    /**
     * Gets the mediaFile
     * @return Returns a File
     */
    public File getMediaFile() {
        return mediaFile;
    }

    /**
     * Sets the mediaFile
     * @param mediaFile The mediaFile to set
     */
    public void setMediaFile(File mediaFile) {
        this.mediaFile = mediaFile;
    }

    /**
     * Gets the extension
     * @return Returns a String
     */
    public String getExtension() {
        return extension;
    }

    /**
     * Sets the extension
     * @param extension The extension to set
     */
    public void setExtension(String extension) {
        this.extension = extension;
    }

    /**
     * Gets the mediaName
     * @return Returns a String
     */
    public String getMediaName() {
        return mediaName;
    }

    /**
     * Sets the mediaName
     * @param mediaName The mediaName to set
     */
    public void setMediaName(String mediaName) {
        this.mediaName = mediaName;
    }

    /**
     * Gets the mediaURL
     * @return Returns a URL
     */
    public URL getMediaURL() {
        return mediaURL;
    }

    /**
     * Sets the mediaURL
     * @param mediaURL The mediaURL to set
     */
    public void setMediaURL(URL mediaURL) {
        this.mediaURL = mediaURL;
    }

}