ruper2/src/java/eclipse/org/krysalis/ruper2/eclipse/api EclipseFileAPI.java,NONE,1.1

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

Added Files:
	EclipseFileAPI.java 
Log Message:
Changed the ResourceUpdater to ResourceUpdaterEngine and the ResourceAPI 
ResourceUpdater

--- NEW FILE: EclipseFileAPI.java ---
/*
 * Created on Oct 6, 2003
 */

package org.krysalis.ruper2.eclipse.api;

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

import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IResource;
import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.eclipse.util.RuperEclipseHelper;
import org.krysalis.ruper2.files.DefaultResourceFilenameAnalyzer;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.Resource;

/**
 * @author anou_mana
 */
public class EclipseFileAPI {

	private RuperEclipseHelper m_ruperEclipseHelper;

	/**
	 * 
	 */
	public EclipseFileAPI() throws RuperException {
		super();
		File file;
	}

	public void updateFiles(List files) {
	}

	public void updateFile(File file) {
	}

	public List findFile(File file) {
		List list = null;

		return list;
	}

	public void downloadFiles(List files) {

	}

	public void downloadFile(File file) {

	}

	private List getResourceList(File file) throws RuperException {
		List resourceList = null;
		if(file != null){
			try {
	
				switch (file.getType()) {
					case IResource.FILE :
						{
							// get the resource from the file
							Resource resource = getResource(file.getRawLocation().toFile());
							if (resource != null) {
								resourceList.add(resource);
							}
						}
						break;
					case IResource.FOLDER :
						{
							// get the files from the folder
							java.io.File folder = file.getRawLocation().toFile();
							if (folder.isDirectory()) {
								java.io.File[] stdFiles = folder.listFiles();
								// convert the files to resources
								for (int i = 0; i < stdFiles.length; i++) {
									Resource resource =
										getResource(
											folder.getCanonicalPath(),
											stdFiles[i]);
									resourceList.add(resource);
	
								}
							}
						}
						break;
					case IResource.PROJECT :
						{
							// get buildtime libraries for java project
							ArrayList buildLibs =
								m_ruperEclipseHelper.getBuildTimeLibraries(
									file.getProject());
							
							// convert to resources
							if(buildLibs != null){
								
								for (Iterator iterator=buildLibs.iterator(); iterator.hasNext();){
									String fileName = (String)iterator.next();
									Resource resource = getResource(new java.io.File(fileName));
									if (resource != null) {
										resourceList.add(resource);
									}
									
								}
							}								
						}
						break;
				}
			}
			catch (Exception exp) {
				throw new RuperException(exp);
			}
		}
		else{
			//TODO error message - file null
		}
		
		return resourceList;
	}

	private Resource getResource(java.io.File file) throws RuperException {
		Resource resource = null;
		try {
			if(file != null){
				
				// get the absolute file path
				String path = file.getCanonicalPath();
				
				if (path != null) {
					int baseIndex = path.lastIndexOf("/");
					String base = path.substring(0, baseIndex);
			
					String fileName =
						path.substring(baseIndex, path.length());
					resource = getResource(base, fileName);
				}
			}
		}
		catch (Exception exp) {
			// TODO message error
			//exp.printStackTrace();
			throw new RuperException(exp);
		}
		return resource;		
	}
	
	private Resource getResource(String base, Object file)
		throws RuperException {
		Resource resource = null;

		DefaultResourceFilenameAnalyzer fileNameAnalyzer =
			new DefaultResourceFilenameAnalyzer(
				new VirtualResourceLocator(new java.io.File(base)));

		resource = fileNameAnalyzer.determineResource(file);

		return resource;
	}

	public static void main(String[] args) {
	}
}




-------------------------------------------------------
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.