[Htmlparser-cvs] htmlparser/src/org/htmlparser/parserapplications SiteCapturer.java,1.7,1.8
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2005-04-05 01:02:29
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28518/htmlparser/src/org/htmlparser/parserapplications Modified Files: SiteCapturer.java Log Message: Update javadocs. Enable SiteCapturer to handle resource names containing spaces. Index: SiteCapturer.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/SiteCapturer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SiteCapturer.java 14 Feb 2005 23:49:24 -0000 1.7 --- SiteCapturer.java 5 Apr 2005 00:48:12 -0000 1.8 *************** *** 345,348 **** --- 345,395 ---- /** + * Unescape a URL to form a file name. + * Very crude. + * @param raw The escaped URI. + * @return The native URI. + */ + protected String decode (String raw) + { + int length; + int start; + int index; + int value; + StringBuffer ret; + + ret = new StringBuffer (raw.length ()); + + length = raw.length (); + start = 0; + while (-1 != (index = raw.indexOf ('%', start))) + { // append the part up to the % sign + ret.append (raw.substring (start, index)); + // there must be two hex digits after the percent sign + if (index + 2 < length) + { + try + { + value = Integer.parseInt (raw.substring (index + 1, index + 3), 16); + ret.append ((char)value); + start = index + 3; + } + catch (NumberFormatException nfe) + { + ret.append ('%'); + start = index + 1; + } + } + else + { // this case is actually illegal in a URI, but... + ret.append ('%'); + start = index + 1; + } + } + ret.append (raw.substring (start)); + + return (ret.toString ()); + } + + /** * Copy a resource (image) locally. * Removes one element from the 'to be copied' list and saves the *************** *** 352,355 **** --- 399,404 ---- { String link; + String raw; + String name; File file; File dir; *************** *** 365,369 **** if (getCaptureResources ()) { ! file = new File (getTarget (), makeLocalLink (link, "")); System.out.println ("copying " + link + " to " + file.getAbsolutePath ()); // ensure directory exists --- 414,420 ---- if (getCaptureResources ()) { ! raw = makeLocalLink (link, ""); ! name = decode (raw); ! file = new File (getTarget (), name); System.out.println ("copying " + link + " to " + file.getAbsolutePath ()); // ensure directory exists |