ruper2/src/java/core/org/krysalis/ruper2/protocols/impl HttpClientProtocolOperationsProvider.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/protocols/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv16855/src/java/core/org/krysalis/ruper2/protocols/impl

Added Files:
	HttpClientProtocolOperationsProvider.java 
Log Message:
1) Monitoring (so we can sniff out failures in testing, to improve)
2) First step in removing VFS...

--- NEW FILE: HttpClientProtocolOperationsProvider.java ---
/*
 * Created on Aug 27, 2003
 */
package org.krysalis.ruper2.protocols.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import org.krysalis.ruper2.impl.ResourceUpdaterContext;
import org.krysalis.ruper2.protocols.Protocol;
import org.krysalis.ruper2.util.io.HtmlUtils;
import org.krysalis.ruper2.util.net.VirtualResourceLocator;
import org.krysalis.ruper2.util.net.http.HttpClientUserAgent;
import org.krysalis.ruper2.util.select.ISelector;

/**
 * @author ajack
 */
public class HttpClientProtocolOperationsProvider
	extends AbstractProtocolOperationsProvider {

	private HttpClientUserAgent m_agent = null;

	public void init(ResourceUpdaterContext context) throws Exception {
		super.init(context);

		addSourceProtocol(Protocol.HTTP_PROTOCOL);
		addSourceProtocol(Protocol.FILE_PROTOCOL);

		addDestinationProtocol(Protocol.HTTP_PROTOCOL);
		addDestinationProtocol(Protocol.FILE_PROTOCOL);

		m_agent = new HttpClientUserAgent();
	}

	public boolean exists(VirtualResourceLocator container) throws Exception {
		return m_agent.exists(container.toExternalForm());
	}

	public List list(VirtualResourceLocator container, ISelector selector)
		throws Exception {
		return HtmlUtils.getChildren(
			container,
			m_agent.getContents(container.toExternalForm()));
	}

	public void copy(
		VirtualResourceLocator from,
		VirtualResourceLocator to,
		ISelector selector)
		throws Exception {
		File toFile = new File(to.toString());

		// Build Folders to this Folder
		toFile.getParentFile().mkdirs();

		// Copy data...
		FileOutputStream stream = null;

		try {
			stream = new FileOutputStream(toFile);

			m_agent.transferContents(from.toExternalForm(), stream);

		}
		catch (Exception e) {
			// Attempt at cleanup
			try {
				toFile.delete();
			}
			catch (Exception ee) {
			}
		}
		finally {
			// Close
			try {
				if (null != stream)
					stream.close();
			}
			catch (Exception ee) {
			}
		}
	}

}




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.