mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-07 14:37:32 +01:00
improvement of URIStreamOpener::open() implementation
This commit is contained in:
@@ -178,4 +178,5 @@ POCO_IMPLEMENT_EXCEPTION(URISyntaxException, SyntaxException, "Bad URI syntax")
|
|||||||
POCO_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception")
|
POCO_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception")
|
||||||
POCO_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception")
|
POCO_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception")
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -65,23 +65,16 @@ std::istream* URIStreamOpener::open(const std::string& pathOrURI) const
|
|||||||
{
|
{
|
||||||
return openURI(scheme, uri);
|
return openURI(scheme, uri);
|
||||||
}
|
}
|
||||||
else
|
else if (scheme.length() <= 1) // could be Windows path
|
||||||
{
|
{
|
||||||
Path path;
|
Path path;
|
||||||
if (path.tryParse(pathOrURI, Path::PATH_GUESS))
|
if (path.tryParse(pathOrURI, Path::PATH_GUESS))
|
||||||
|
{
|
||||||
return openFile(path);
|
return openFile(path);
|
||||||
else
|
}
|
||||||
|
}
|
||||||
throw UnknownURISchemeException(pathOrURI);
|
throw UnknownURISchemeException(pathOrURI);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (UnknownURISchemeException&)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (TooManyURIRedirectsException&)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (URISyntaxException&)
|
catch (URISyntaxException&)
|
||||||
{
|
{
|
||||||
Path path;
|
Path path;
|
||||||
@@ -105,25 +98,33 @@ std::istream* URIStreamOpener::open(const std::string& basePathOrURI, const std:
|
|||||||
if (it != _map.end())
|
if (it != _map.end())
|
||||||
{
|
{
|
||||||
uri.resolve(pathOrURI);
|
uri.resolve(pathOrURI);
|
||||||
|
scheme = uri.getScheme();
|
||||||
return openURI(scheme, uri);
|
return openURI(scheme, uri);
|
||||||
}
|
}
|
||||||
}
|
else if (scheme.length() <= 1) // could be Windows path
|
||||||
catch (UnknownURISchemeException&)
|
|
||||||
{
|
{
|
||||||
throw;
|
Path base;
|
||||||
}
|
Path path;
|
||||||
catch (TooManyURIRedirectsException&)
|
if (base.tryParse(basePathOrURI, Path::PATH_GUESS) && path.tryParse(pathOrURI, Path::PATH_GUESS))
|
||||||
{
|
{
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (Exception&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
Path base(basePathOrURI, Path::PATH_GUESS);
|
|
||||||
Path path(pathOrURI, Path::PATH_GUESS);
|
|
||||||
base.resolve(path);
|
base.resolve(path);
|
||||||
return openFile(base);
|
return openFile(base);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
throw UnknownURISchemeException(basePathOrURI);
|
||||||
|
}
|
||||||
|
catch (URISyntaxException&)
|
||||||
|
{
|
||||||
|
Path base;
|
||||||
|
Path path;
|
||||||
|
if (base.tryParse(basePathOrURI, Path::PATH_GUESS) && path.tryParse(pathOrURI, Path::PATH_GUESS))
|
||||||
|
{
|
||||||
|
base.resolve(path);
|
||||||
|
return openFile(base);
|
||||||
|
}
|
||||||
|
else throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void URIStreamOpener::registerStreamFactory(const std::string& scheme, URIStreamFactory* pFactory)
|
void URIStreamOpener::registerStreamFactory(const std::string& scheme, URIStreamFactory* pFactory)
|
||||||
|
|||||||
Reference in New Issue
Block a user