krysalis-update/src/java/org/krysalis/depot/update/util/io ResolvedFile.java,1.1,1.2 VfsUtils.java,1.1,1.2 FileUtils.java,1.1,1.2 HtmlUtils.java,1.1,1.2

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:11:55 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/io
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26470/src/java/org/krysalis/depot/update/util/io

Modified Files:
	ResolvedFile.java VfsUtils.java FileUtils.java HtmlUtils.java 
Log Message:
format

Index: ResolvedFile.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/io/ResolvedFile.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ResolvedFile.java	8 Dec 2004 09:06:32 -0000	1.1
--- ResolvedFile.java	8 Dec 2004 09:11:53 -0000	1.2
***************
*** 21,32 ****
  
  /**
!  * The ResolvedFile adds some attributes to the File class. Basically the resolverContext (most cases
!  * a directory where the fly is) and the originalInput (most cases the file).
   * 
!  * @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
   */
  public class ResolvedFile extends File {
  
  	private Object m_originalInput = null;
  	private Object m_resolverContext = null;
  
--- 21,35 ----
  
  /**
!  * The ResolvedFile adds some attributes to the File class. Basically the
!  * resolverContext (most cases a directory where the fly is) and the
!  * originalInput (most cases the file).
   * 
!  * @author <a href="http://incubator.apache.org/depot">The Apache Incubator
!  *         Depot Project </a>
   */
  public class ResolvedFile extends File {
  
  	private Object m_originalInput = null;
+ 
  	private Object m_resolverContext = null;
  
***************
*** 50,54 ****
  		// Previously resolved within this context...
  		if ((file instanceof ResolvedFile)
! 				&& (((ResolvedFile) file).m_resolverContext.equals(resolverContext)))
  			return (ResolvedFile) file;
  
--- 53,58 ----
  		// Previously resolved within this context...
  		if ((file instanceof ResolvedFile)
! 				&& (((ResolvedFile) file).m_resolverContext
! 						.equals(resolverContext)))
  			return (ResolvedFile) file;
  
***************
*** 80,85 ****
  					fullyQualified = new File((String) resolverContext);
  				} else
! 					fullyQualified = new File(new File(
! 							(String) resolverContext), path);
  			else {
  				throw new IllegalArgumentException(
--- 84,89 ----
  					fullyQualified = new File((String) resolverContext);
  				} else
! 					fullyQualified = new File(
! 							new File((String) resolverContext), path);
  			else {
  				throw new IllegalArgumentException(

Index: FileUtils.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/io/FileUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FileUtils.java	8 Dec 2004 09:06:32 -0000	1.1
--- FileUtils.java	8 Dec 2004 09:11:53 -0000	1.2
***************
*** 26,30 ****
  import java.text.StringCharacterIterator;
  
- import org.krysalis.depot.common.util.io.IOUtils;
  import org.krysalis.depot.update.UpdateRuntimeException;
  import org.krysalis.depot.update.util.UpdateConstants;
--- 26,29 ----
***************
*** 34,38 ****
--- 33,39 ----
  	// for toURI
  	private static boolean[] isSpecial = new boolean[256];
+ 
  	private static char[] escapedChar1 = new char[256];
+ 
  	private static char[] escapedChar2 = new char[256];
  
***************
*** 47,52 ****
  		escapedChar1[0x7f] = '7';
  		escapedChar2[0x7f] = 'F';
! 		char[] escChs = {'<', '>', '#', '%', '"', '{', '}', '|', '\\', '^',
! 				'~', '[', ']', '`'};
  		int len = escChs.length;
  		char ch;
--- 48,53 ----
  		escapedChar1[0x7f] = '7';
  		escapedChar2[0x7f] = 'F';
! 		char[] escChs = { '<', '>', '#', '%', '"', '{', '}', '|', '\\', '^',
! 				'~', '[', ']', '`' };
  		int len = escChs.length;
  		char ch;
***************
*** 73,77 ****
  			url = new URL(str);
  		} catch (MalformedURLException e) {
! 			//:TODO: Ought never happen, so it is a bug on
  			// us ..
  			throw new UpdateRuntimeException("Bogus: " + file + " ? " + str, e);
--- 74,78 ----
  			url = new URL(str);
  		} catch (MalformedURLException e) {
! 			// :TODO: Ought never happen, so it is a bug on
  			// us ..
  			throw new UpdateRuntimeException("Bogus: " + file + " ? " + str, e);
***************
*** 107,111 ****
  		//
  		CharacterIterator iter = new StringCharacterIterator(pathString);
! 		for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
  			if (isSpecial[c]) {
  				sb.append('%');
--- 108,113 ----
  		//
  		CharacterIterator iter = new StringCharacterIterator(pathString);
! 		for (char c = iter.first(); c != CharacterIterator.DONE; c = iter
! 				.next()) {
  			if (isSpecial[c]) {
  				sb.append('%');

Index: VfsUtils.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/io/VfsUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VfsUtils.java	8 Dec 2004 09:06:32 -0000	1.1
--- VfsUtils.java	8 Dec 2004 09:11:53 -0000	1.2
***************
*** 42,46 ****
   */
  /**
!  *
   * @author $Author$
   * @version $Revision$
--- 42,46 ----
   */
  /**
!  * 
   * @author $Author$
   * @version $Revision$
***************
*** 49,52 ****
--- 49,53 ----
  public class VfsUtils {
  	private static FileSystemManager l_defaultFsm = null;
+ 
  	private static FileSelector l_defaultAllFileSelector = null;
  
***************
*** 56,60 ****
  
  	public static FileSystemManager createFSM(String name, String base)
! 		throws FileSystemException {
  
  		DefaultFileSystemManager fsm = new StandardFileSystemManager();
--- 57,61 ----
  
  	public static FileSystemManager createFSM(String name, String base)
! 			throws FileSystemException {
  
  		DefaultFileSystemManager fsm = new StandardFileSystemManager();
***************
*** 70,78 ****
  	/**
  	 * Create the Default FSM (if it does not exist)
  	 * @return
  	 * @throws FileSystemException
  	 */
  	private static FileSystemManager createDefaultFSM()
! 		throws FileSystemException {
  		if (null == l_defaultFsm) {
  			l_defaultFsm = createFSM("Depot::FileSystemManager", ".");
--- 71,80 ----
  	/**
  	 * Create the Default FSM (if it does not exist)
+ 	 * 
  	 * @return
  	 * @throws FileSystemException
  	 */
  	private static FileSystemManager createDefaultFSM()
! 			throws FileSystemException {
  		if (null == l_defaultFsm) {
  			l_defaultFsm = createFSM("Depot::FileSystemManager", ".");
***************
*** 83,91 ****
  	/**
  	 * Get (or create) the Default FSM
  	 * @return
  	 * @throws FileSystemException
  	 */
! 	public static FileSystemManager getDefaultFSM()
! 		throws FileSystemException {
  		if (l_defaultFsm == null) {
  			createDefaultFSM();
--- 85,93 ----
  	/**
  	 * Get (or create) the Default FSM
+ 	 * 
  	 * @return
  	 * @throws FileSystemException
  	 */
! 	public static FileSystemManager getDefaultFSM() throws FileSystemException {
  		if (l_defaultFsm == null) {
  			createDefaultFSM();
***************
*** 97,100 ****
--- 99,103 ----
  	 * 
  	 * Resolve a URL within the scope of this FSM
+ 	 * 
  	 * @param url
  	 * @return
***************
*** 107,111 ****
  	/**
  	 * 
! 	 *  Convert a File to a FileObject within the scope of this FSM
  	 * @param file
  	 * @return
--- 110,115 ----
  	/**
  	 * 
! 	 * Convert a File to a FileObject within the scope of this FSM
! 	 * 
  	 * @param file
  	 * @return
***************
*** 116,122 ****
  	}
  
! 	public static List getChildren(FileObject folder)
! 		throws IOException, MalformedURLException, FileSystemException {
! 		
  		List result = new ArrayList();
  
--- 120,126 ----
  	}
  
! 	public static List getChildren(FileObject folder) throws IOException,
! 			MalformedURLException, FileSystemException {
! 
  		List result = new ArrayList();
  
***************
*** 125,141 ****
  			if (folder.getType() == FileType.FILE) {
  				result.add(folder);
! 			}
! 			else {
  				FileObject array[] = folder.getChildren();
  				for (int i = 0; i < array.length; ++i)
  					result.add(array[i]);
  			}
! 		}
! 		else if ("http".equals(folder.getURL().getProtocol())) {
  			ArrayList list = new ArrayList();
  			InputStream urlStream = null;
  
! 			//Logger.getLogger().debug("Extract HTML Links from VFS");
! 			
  			// try opening the URL
  			urlStream = null;
--- 129,143 ----
  			if (folder.getType() == FileType.FILE) {
  				result.add(folder);
! 			} else {
  				FileObject array[] = folder.getChildren();
  				for (int i = 0; i < array.length; ++i)
  					result.add(array[i]);
  			}
! 		} else if ("http".equals(folder.getURL().getProtocol())) {
  			ArrayList list = new ArrayList();
  			InputStream urlStream = null;
  
! 			// Logger.getLogger().debug("Extract HTML Links from VFS");
! 
  			// try opening the URL
  			urlStream = null;
***************
*** 145,155 ****
  
  				if (null != urlStream) {
! 					String type =
! 						URLConnection.guessContentTypeFromStream(urlStream);
  
  					if ((type == null) || !type.startsWith("text/html")) {
  						result.add(folder);
! 					}
! 					else {
  						// search the input stream for links
  						// first, read in the entire URL
--- 147,156 ----
  
  				if (null != urlStream) {
! 					String type = URLConnection
! 							.guessContentTypeFromStream(urlStream);
  
  					if ((type == null) || !type.startsWith("text/html")) {
  						result.add(folder);
! 					} else {
  						// search the input stream for links
  						// first, read in the entire URL
***************
*** 167,192 ****
  						String lowerCaseContent = content.toLowerCase();
  						int index = 0;
! 						while ((index = lowerCaseContent.indexOf("<a", index))
! 							!= -1) {
! 							if ((index =
! 								lowerCaseContent.indexOf("href", index))
! 								== -1) {
  								break;
  							}
! 							if ((index = lowerCaseContent.indexOf("=", index))
! 								== -1) {
  								break;
  							}
  							index++;
  							String remaining = content.substring(index);
! 							StringTokenizer st =
! 								new StringTokenizer(remaining, "\t\n\r\">#");
  							String strLink = st.nextToken();
  
  							// Filter out dynamics... and mail
  							if ((strLink.length() > 0)
! 								&& (strLink.indexOf("?") == -1)
! 								&& (!strLink.startsWith("mailto:"))) {
! 								//boolean added = false;
  								FileObject f = folder.resolveFile(strLink);
  
--- 168,190 ----
  						String lowerCaseContent = content.toLowerCase();
  						int index = 0;
! 						while ((index = lowerCaseContent.indexOf("<a", index)) != -1) {
! 							if ((index = lowerCaseContent
! 									.indexOf("href", index)) == -1) {
  								break;
  							}
! 							if ((index = lowerCaseContent.indexOf("=", index)) == -1) {
  								break;
  							}
  							index++;
  							String remaining = content.substring(index);
! 							StringTokenizer st = new StringTokenizer(remaining,
! 									"\t\n\r\">#");
  							String strLink = st.nextToken();
  
  							// Filter out dynamics... and mail
  							if ((strLink.length() > 0)
! 									&& (strLink.indexOf("?") == -1)
! 									&& (!strLink.startsWith("mailto:"))) {
! 								// boolean added = false;
  								FileObject f = folder.resolveFile(strLink);
  
***************
*** 195,199 ****
  
  									//
! 									// Check that the parent of the child is this
  									//
  									if (f.getParent().equals(folder)) {
--- 193,198 ----
  
  									//
! 									// Check that the parent of the child is
! 									// this
  									//
  									if (f.getParent().equals(folder)) {
***************
*** 204,213 ****
  										if (!list.contains(f)) {
  											list.add(f);
! 											//added = true;
  										}
  
! 										//if (added)
! 										//	Logger.getLogger().debug(
! 										//		"Selected      : " + strLink);
  									}
  								}
--- 203,212 ----
  										if (!list.contains(f)) {
  											list.add(f);
! 											// added = true;
  										}
  
! 										// if (added)
! 										// Logger.getLogger().debug(
! 										// "Selected : " + strLink);
  									}
  								}
***************
*** 219,229 ****
  					}
  				}
! 			}
! 			finally {
  				if (null != urlStream) {
  					try {
  						urlStream.close();
! 					}
! 					catch (Exception ce){						
  					}
  				}
--- 218,226 ----
  					}
  				}
! 			} finally {
  				if (null != urlStream) {
  					try {
  						urlStream.close();
! 					} catch (Exception ce) {
  					}
  				}
***************
*** 243,263 ****
  	 */
  	public static FileObject unarchive(FileObject input)
! 		throws FileSystemException {
  		return unarchive(getDefaultFSM(), input);
  	}
  
  	/**
! 	* 
! 	* Unarchive a file (if we can, i.e. JAR or ZIP) using a specified FSM
! 	* 
! 	* NOTE: This only returns a referece to the contents, one has to copy
! 	* it to another location to get a real unarchive.
! 	* 
! 	* @param input
! 	* @return
! 	* @throws FileSystemException
! 	*/
  	public static FileObject unarchive(FileSystemManager fsm, FileObject input)
! 		throws FileSystemException {
  		FileObject temp = null;
  		FileObject output = null;
--- 240,260 ----
  	 */
  	public static FileObject unarchive(FileObject input)
! 			throws FileSystemException {
  		return unarchive(getDefaultFSM(), input);
  	}
  
  	/**
! 	 * 
! 	 * Unarchive a file (if we can, i.e. JAR or ZIP) using a specified FSM
! 	 * 
! 	 * NOTE: This only returns a referece to the contents, one has to copy it to
! 	 * another location to get a real unarchive.
! 	 * 
! 	 * @param input
! 	 * @return
! 	 * @throws FileSystemException
! 	 */
  	public static FileObject unarchive(FileSystemManager fsm, FileObject input)
! 			throws FileSystemException {
  		FileObject temp = null;
  		FileObject output = null;
***************
*** 270,275 ****
  				temp = fsm.createFileSystem("jar", input);
  				output = temp.resolveFile(basename);
! 			}
! 			else if (basename.endsWith(".zip")) {
  				basename = basename.substring(0, basename.length() - 4);
  				temp = fsm.createFileSystem("zip", input);
--- 267,271 ----
  				temp = fsm.createFileSystem("jar", input);
  				output = temp.resolveFile(basename);
! 			} else if (basename.endsWith(".zip")) {
  				basename = basename.substring(0, basename.length() - 4);
  				temp = fsm.createFileSystem("zip", input);
***************
*** 279,285 ****
  
  		/*
! 		* NOTE: This only returns a referece to the contents, one has to copy
! 		* it to another location to get a real unarchive.
! 		*/
  		if (null == output)
  			output = input;
--- 275,281 ----
  
  		/*
! 		 * NOTE: This only returns a referece to the contents, one has to copy
! 		 * it to another location to get a real unarchive.
! 		 */
  		if (null == output)
  			output = input;
***************
*** 298,302 ****
  
  	public static void copyFrom(FileObject destination, FileObject origin)
! 		throws FileSystemException {
  		VfsUtils.copyFrom(destination, origin, l_defaultAllFileSelector);
  	}
--- 294,298 ----
  
  	public static void copyFrom(FileObject destination, FileObject origin)
! 			throws FileSystemException {
  		VfsUtils.copyFrom(destination, origin, l_defaultAllFileSelector);
  	}
***************
*** 311,319 ****
  	 * @throws FileSystemException
  	 */
! 	public static void copyFrom(
! 		FileObject destination,
! 		FileObject origin,
! 		FileSelector selector)
! 		throws FileSystemException {
  		destination.copyFrom(origin, selector);
  	}
--- 307,312 ----
  	 * @throws FileSystemException
  	 */
! 	public static void copyFrom(FileObject destination, FileObject origin,
! 			FileSelector selector) throws FileSystemException {
  		destination.copyFrom(origin, selector);
  	}
***************
*** 324,331 ****
  
  	//
! 	// :TODO: not working -- gives some odd file names when a file comes from a jar
  	//
! 	public static File toFile(FileObject fileObject)
! 		throws FileSystemException {
  		File resultFile = null;
  
--- 317,324 ----
  
  	//
! 	// :TODO: not working -- gives some odd file names when a file comes from a
! 	// jar
  	//
! 	public static File toFile(FileObject fileObject) throws FileSystemException {
  		File resultFile = null;
  
***************
*** 333,340 ****
  			FileSystem fileSystem = fileObject.getFileSystem();
  
! 			resultFile =
! 				fileSystem.replicateFile(fileObject, l_defaultAllFileSelector);
  
! 			//DepotLogger.g_log.warn("toFile: " + resultFile);
  		}
  
--- 326,333 ----
  			FileSystem fileSystem = fileObject.getFileSystem();
  
! 			resultFile = fileSystem.replicateFile(fileObject,
! 					l_defaultAllFileSelector);
  
! 			// DepotLogger.g_log.warn("toFile: " + resultFile);
  		}
  
***************
*** 350,355 ****
  		FileObject folder = fsm.resolveFile(url);
  
! 		//if ( !folder.exists() )
! 		//	System.out.println("Bad Folder : " + folder);
  
  		List kids = VfsUtils.getChildren(folder);
--- 343,348 ----
  		FileObject folder = fsm.resolveFile(url);
  
! 		// if ( !folder.exists() )
! 		// System.out.println("Bad Folder : " + folder);
  
  		List kids = VfsUtils.getChildren(folder);

Index: HtmlUtils.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/io/HtmlUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HtmlUtils.java	8 Dec 2004 09:06:32 -0000	1.1
--- HtmlUtils.java	8 Dec 2004 09:11:53 -0000	1.2
***************
*** 42,49 ****
  	 * @throws IOException
  	 */
! 	public static List getChildren(
! 		VirtualResourceLocator parent,
! 		InputStream contentStream)
! 		throws IOException {
  
  		// search the input stream for links
--- 42,47 ----
  	 * @throws IOException
  	 */
! 	public static List getChildren(VirtualResourceLocator parent,
! 			InputStream contentStream) throws IOException {
  
  		// search the input stream for links
***************
*** 71,78 ****
  	 * @throws IOException
  	 */
! 	public static List getChildren(
! 		VirtualResourceLocator parent,
! 		String content)
! 		throws IOException {
  		return getLinks(parent, content, new ChildVrlSelector(parent));
  	}
--- 69,74 ----
  	 * @throws IOException
  	 */
! 	public static List getChildren(VirtualResourceLocator parent, String content)
! 			throws IOException {
  		return getLinks(parent, content, new ChildVrlSelector(parent));
  	}
***************
*** 87,98 ****
  	 * @throws IOException
  	 */
! 	public static List getMatching(
! 		VirtualResourceLocator parent,
! 		String content,
! 		String pattern)
! 		throws IOException {
  		return getLinks(parent, content, new MatchingVrlSelector(pattern));
  	}
! 	
  	/**
  	 * Get all links matching this selector.
--- 83,91 ----
  	 * @throws IOException
  	 */
! 	public static List getMatching(VirtualResourceLocator parent,
! 			String content, String pattern) throws IOException {
  		return getLinks(parent, content, new MatchingVrlSelector(pattern));
  	}
! 
  	/**
  	 * Get all links matching this selector.
***************
*** 104,118 ****
  	 * @throws IOException
  	 */
! 	public static List getLinks(
! 		VirtualResourceLocator parent,
! 		String content,
! 		ISelector selector)
! 		throws IOException {
  		List children = new ArrayList();
! 		Logger.getLogger().debug("Extract HTML Links Selector      : " + selector);
! 		
  		// Dro pthe case everywhere, to simplify
  		String lowerCaseContent = content.toLowerCase();
! 		
  		int index = 0;
  		while ((index = lowerCaseContent.indexOf("<a", index)) != -1) {
--- 97,109 ----
  	 * @throws IOException
  	 */
! 	public static List getLinks(VirtualResourceLocator parent, String content,
! 			ISelector selector) throws IOException {
  		List children = new ArrayList();
! 		Logger.getLogger().debug(
! 				"Extract HTML Links Selector      : " + selector);
! 
  		// Dro pthe case everywhere, to simplify
  		String lowerCaseContent = content.toLowerCase();
! 
  		int index = 0;
  		while ((index = lowerCaseContent.indexOf("<a", index)) != -1) {
***************
*** 128,140 ****
  			String strLink = st.nextToken();
  
! 			if ((strLink.length() > 0)
! 				&& (strLink.indexOf("?") == -1)
! 				&& (!"/".equals(strLink))) {
  				boolean added = false;
  
  				Logger.getLogger().debug("Link          : " + strLink);
  
! 				VirtualResourceLocator v =
! 					new VirtualResourceLocator(parent, strLink);
  
  				try {
--- 119,130 ----
  			String strLink = st.nextToken();
  
! 			if ((strLink.length() > 0) && (strLink.indexOf("?") == -1)
! 					&& (!"/".equals(strLink))) {
  				boolean added = false;
  
  				Logger.getLogger().debug("Link          : " + strLink);
  
! 				VirtualResourceLocator v = new VirtualResourceLocator(parent,
! 						strLink);
  
  				try {
***************
*** 151,158 ****
  						if (added)
  							Logger.getLogger().debug(
! 								"Selected      : " + strLink);
  					}
! 				}
! 				catch (Exception e) {
  					// :TODO: ...
  				}
--- 141,147 ----
  						if (added)
  							Logger.getLogger().debug(
! 									"Selected      : " + strLink);
  					}
! 				} catch (Exception e) {
  					// :TODO: ...
  				}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/