[Kernow] Instanciate Source from either file system path or URI
Brought to you by:
ajwelch
From: Florent G. <dar...@ya...> - 2007-08-08 10:49:11
|
Hi Adnrew I thought about the creation of Source and Result objects from String representing either URIs or file system paths. I think that we first have to check if the string looks like a URI or not. If it does we instanciate a StreamSource with the string. If not we use in addition a File. To check if the string looks like a URI, maybe we could only check if it starts with between 2 and 6 lower case letter from A to Z, followed by a ':'. This is only a heuristic, please comment if you have a better idea. Why I don't try to build a URI object that will strictly check the string, then decide that is a URI if there is no error, is because I think we should accept string that are not real URIs as well. For example with a space not escaped: http://.../uri with spaces/doc.xml. If the user copy 'n paste it into Kernow, I think it will expect that will work (and not get "file not found" instead). So I propose a new class net.sf.kernow.util.JAXPUtil, with at least the following: private Pattern uriRegex = Pattern.compile("^[a-z]{2,6}:"); private boolean looksLikeURI(String s) { return uriRegex.matcher(s).matches(); } public Source makeSourceFromPathOrURI(String location) { if ( looksLikeURI(location) ) { return new StreamSource(location); } else { return new StreamSource(new File(location)); } } But we then should define how new StreamSource(location) would react if location is not a strict URI. What do you think? Regards, --drkm _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail |