ruper2/src/java/core/org/krysalis/ruper2/api FileAPI.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/api
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/api

Added Files:
	FileAPI.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: FileAPI.java ---
/*
 * Created on Aug 27, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.api;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.files.DefaultResourceFilenameAnalyzer;
import org.krysalis.ruper2.files.ResourceFilenameAnalyzer;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.Resource;
import org.krysalis.ruper2.resource.ResourceSpecifier;
import org.krysalis.ruper2.util.io.ResolvedFile;
import org.krysalis.version.util.SystemUtils;

/**
 * @author arb_jack
 */
public class FileAPI /* implements Referenceable */ {
	private File m_baseFile = null;
	private ResourceFilenameAnalyzer m_analyzer = null;

	/**
	 * 
	 */
	public FileAPI() {
		this(SystemUtils.getCWD());
	}

	/**
	 * 
	 */
	public FileAPI(File baseFile) {
		m_analyzer =
			new DefaultResourceFilenameAnalyzer(
				new VirtualResourceLocator(baseFile));

		m_baseFile = baseFile;
	}

	/**
	 * 
	 * Resolve a file (i.e. get absolute path) within the "context" 
	 * of this API's baseFile (i.e. CWD or whatever)
	 * 
	 * @param file
	 * @return
	 */
	public File resolveFile(Object file) {
		return ResolvedFile.resolve(m_baseFile, file);
	}

	public List getResourceSpecifiersForFiles(List files)
		throws RuperException {
		List specifiers = new ArrayList();

		for (Iterator i = files.iterator(); i.hasNext();) {
			specifiers.add(getResourceSpecifierForFile(((File) i.next())));
		}

		return specifiers;
	}

	public ResourceSpecifier getResourceSpecifierForFile(File file)
		throws RuperException {
		Resource resource = m_analyzer.determineResource(file);
		return resource.getSpecifier();
	}

	public static void main(String args[]) throws Exception {
		String file = "test.jar";
		if (args.length > 0)
			file = args[0];

		FileAPI fa = new FileAPI(SystemUtils.getCWD());

		fa.getResourceSpecifierForFile(new File(file));
	}
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
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.