// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   UrlEditor.java

package lt.ktu.gmj.propertySheet;

import java.io.IOException;
import java.io.PrintStream;
import java.net.*;

// Referenced classes of package lt.ktu.gmj.propertySheet:
//			StringablePropertyEditor, InvalidPropertyException, PropertyStringer, PropertyProvider

public class UrlEditor extends StringablePropertyEditor
	implements PropertyStringer
{

	private PropertyProvider provider;

	public UrlEditor(PropertyProvider _provider)
	{
		provider = _provider;
		provider.addObserver(this);
		setStringer(this);
	}

	public String getAsString()
	{
		return provider.get().toString();
	}

	public void setAsString(String text)
		throws InvalidPropertyException
	{
		try
		{
			URL myurl = new URL(text);
			System.out.println("Will read data from: " + myurl.getHost() + myurl.getFile());
			URLConnection mycon = myurl.openConnection();
			System.out.println("Data type will be: " + mycon.getContentType() + " and size: " + mycon.getContentLength());
			if(mycon.getContentLength() > 0)
				provider.set(text);
			else
				throw new InvalidPropertyException("!!!-Bad data file...");
		}
		catch(MalformedURLException e)
		{
			System.out.println("!!!-Bad URL: " + e);
		}
		catch(IOException e)
		{
			System.out.println("!!!-Bad Connection: " + e);
		}
	}
}
