try { location = new URI(f.toURL().toString()).toASCIIString(); } catch (Exception e1) { }
location = f.toURI().toASCIIString();
	public void importModule(String namespaceURI, String prefix, String location)		throws XPathException {		Module module = getModule(namespaceURI);		if(module != null) {			LOG.debug("Module " + namespaceURI + " already present.");		} else {			if(location == null)				location = namespaceURI;			// is it a Java module?			if(location.startsWith("java:")) {				location = location.substring("java:".length());				module = loadBuiltInModule(namespaceURI, location);			} else {				if(location.indexOf(':') < 0) {					File f = new File(moduleLoadPath + File.separatorChar + location);					if(!f.canRead()) {						f = new File(location);						if(!f.canRead())							throw new XPathException("cannot read module source from file at " + f.getAbsolutePath());					}					try {						location = new URI(f.toURL().toString()).toASCIIString();					} catch (Exception e1) {					}				}				LOG.debug("Loading module from " + location);				InputStreamReader reader;				try {					URL url = new URL(location);					reader = new InputStreamReader(url.openStream(), "UTF-8");				} catch (MalformedURLException e) {					throw new XPathException("source location for module " + namespaceURI + " should be a valid URL");				} catch (UnsupportedEncodingException e) {					throw new XPathException("unsupported source encoding");				} catch (IOException e) {					throw new XPathException("IO exception while loading module " + namespaceURI, e);				}				XQueryContext context = new ModuleContext(this);				XQueryLexer lexer = new XQueryLexer(context, reader);				XQueryParser parser = new XQueryParser(lexer);				XQueryTreeParser astParser = new XQueryTreeParser(context);				try {					parser.xpath();					if (parser.foundErrors()) {						LOG.debug(parser.getErrorMessage());						throw new XPathException(							"error found while loading module from " + location + ": "								+ parser.getErrorMessage());					}					AST ast = parser.getAST();							PathExpr path = new PathExpr(context);					astParser.xpath(ast, path);					if (astParser.foundErrors()) {						throw new XPathException(							"error found while loading module from " + location + ": "								+ astParser.getErrorMessage(),							astParser.getLastException());					}										module = astParser.getModule();					if(module == null)						throw new XPathException("source at " + location + " is not a valid module");					if(!module.getNamespaceURI().equals(namespaceURI))						throw new XPathException("namespace URI declared by module (" + module.getNamespaceURI() + 							") does not match namespace URI in import statement, which was: " + namespaceURI);					modules.put(module.getNamespaceURI(), module);				} catch (RecognitionException e) {					throw new XPathException(						"error found while loading module from " + location + ": " + e.getMessage(),						e);				} catch (TokenStreamException e) {					throw new XPathException(						"error found while loading module from " + location + ": " + e.getMessage(),						e);				}			}		}		if(prefix == null)			prefix = module.getDefaultPrefix();		declareNamespace(prefix, namespaceURI);	}