Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::URI Class Reference

Represents an URI as per RFC 2396. More...

#include <uri.h>

Public Member Functions

 URI ()
 
 URI (char const *preformed, char const *baseuri=nullptr)
 Constructor from a C-style ASCII string.
 
 URI (char const *preformed, URI const &baseuri)
 
bool isOpaque () const
 Determines if the URI represented is an 'opaque' URI.
 
bool isRelative () const
 Determines if the URI represented is 'relative' as per RFC 2396.
 
bool isNetPath () const
 Determines if the relative URI represented is a 'net-path' as per RFC 2396.
 
bool isRelativePath () const
 Determines if the relative URI represented is a 'relative-path' as per RFC 2396.
 
bool isAbsolutePath () const
 Determines if the relative URI represented is a 'absolute-path' as per RFC 2396.
 
const char * getScheme () const
 Return the scheme, e.g. "http", or NULL if this is not an absolute URI.
 
const char * getPath () const
 Return the path.
 
const char * getQuery () const
 Return the query, which is the part between "?" and the optional fragment hash ("#")
 
const char * getFragment () const
 Return the fragment, which is everything after "#".
 
const char * getOpaque () const
 For an opaque URI, return everything between the scheme colon (":") and the optional fragment hash ("#").
 
std::string toNativeFilename () const
 Convert this URI to a native filename.
 
std::string str (char const *baseuri=nullptr) const
 Return the string representation of this URI.
 
std::string getMimeType () const
 Get the MIME type (e.g. "image/png")
 
std::string getContents () const
 Return the contents of the file.
 
std::string cssStr (char const *baseuri=nullptr) const
 Return a CSS formatted url value.
 
bool hasScheme (const char *scheme) const
 True if the scheme equals the given string (not case sensitive)
 

Static Public Member Functions

static URI from_native_filename (char const *path)
 Construct a "file" URI from an absolute filename.
 
static URI from_dirname (char const *path)
 URI of a local directory.
 
static URI from_href_and_basedir (char const *href, char const *basedir)
 Convenience function for the common use case given a xlink:href attribute and a local directory as the document base.
 

Private Member Functions

void init (xmlURI *ptr)
 
xmlURI * _xmlURIPtr () const
 

Private Attributes

std::shared_ptr< xmlURI > m_shared
 

Detailed Description

Represents an URI as per RFC 2396.

Typical use-cases of this class:

  • converting between relative and absolute URIs
  • converting URIs to/from filenames (alternative: Glib functions, but those only handle absolute paths)
  • generic handling of data/file/http URIs (e.g. URI::getContents and URI::getMimeType)

Wraps libxml2's URI functions. Direct usage of libxml2's C-API is discouraged if favor of Inkscape::URI. (At the time of writing this, no de-factor standard C++ URI library exists, so wrapping libxml2 seems like a good solution)

Implementation detail: Immutable type, copies share a ref-counted data pointer.

Definition at line 36 of file uri.h.

Constructor & Destructor Documentation

◆ URI() [1/3]

Inkscape::URI::URI ( )

Definition at line 45 of file uri.cpp.

References init().

Referenced by from_dirname(), and from_href_and_basedir().

◆ URI() [2/3]

Inkscape::URI::URI ( char const *  preformed,
char const *  baseuri = nullptr 
)
explicit

Constructor from a C-style ASCII string.

Parameters
preformedProperly quoted C-style string to be represented.
baseuriIf preformed is a relative URI, use baseuri to make it absolute
Exceptions
MalformedURIException

◆ URI() [3/3]

Inkscape::URI::URI ( char const *  preformed,
URI const &  baseuri 
)
explicit

Definition at line 97 of file uri.cpp.

Member Function Documentation

◆ _xmlURIPtr()

xmlURI * Inkscape::URI::_xmlURIPtr ( ) const
inlineprivate

◆ cssStr()

std::string Inkscape::URI::cssStr ( char const *  baseuri = nullptr) const
inline

Return a CSS formatted url value.

Parameters
baseuriReturn a relative path if this URI shares protocol and host with baseuri

Definition at line 176 of file uri.h.

References str().

Referenced by SPIFilter::get_value(), and SPItem::write().

◆ from_dirname()

URI Inkscape::URI::from_dirname ( char const *  path)
static

URI of a local directory.

The URI path will end with a slash.

Definition at line 197 of file uri.cpp.

References URI().

Referenced by from_href_and_basedir(), and Inkscape::Extension::Internal::OdfOutput::save().

◆ from_href_and_basedir()

URI Inkscape::URI::from_href_and_basedir ( char const *  href,
char const *  basedir 
)
static

Convenience function for the common use case given a xlink:href attribute and a local directory as the document base.

Returns an empty URI on failure.

Definition at line 214 of file uri.cpp.

References from_dirname(), and URI().

Referenced by Inkscape::URIReference::attach(), SPImage::getURI(), and SPImage::readImage().

◆ from_native_filename()

URI Inkscape::URI::from_native_filename ( char const *  path)
static

Construct a "file" URI from an absolute filename.

Definition at line 190 of file uri.cpp.

References result.

Referenced by Inkscape::ColorProfile::createFromProfile().

◆ getContents()

std::string Inkscape::URI::getContents ( ) const

Return the contents of the file.

Exceptions
Glib::ErrorIf the URL can't be read

Definition at line 318 of file uri.cpp.

References getPath(), hasScheme(), and str().

◆ getFragment()

const gchar * Inkscape::URI::getFragment ( ) const

Return the fragment, which is everything after "#".

Definition at line 163 of file uri.cpp.

References _xmlURIPtr().

Referenced by Inkscape::URIReference::attach(), and toNativeFilename().

◆ getMimeType()

std::string Inkscape::URI::getMimeType ( ) const

Get the MIME type (e.g. "image/png")

Definition at line 297 of file uri.cpp.

References getPath(), and hasScheme().

◆ getOpaque()

const gchar * Inkscape::URI::getOpaque ( ) const

For an opaque URI, return everything between the scheme colon (":") and the optional fragment hash ("#").

For non-opaque URIs, return NULL.

Definition at line 167 of file uri.cpp.

References _xmlURIPtr(), getPath(), and isRelative().

Referenced by isOpaque().

◆ getPath()

const gchar * Inkscape::URI::getPath ( ) const

Return the path.

Example: "http://host/foo/bar?query#frag" -> "/foo/bar"

For an opaque URI, this is identical to getOpaque()

Definition at line 155 of file uri.cpp.

References _xmlURIPtr().

Referenced by Inkscape::URIReference::attach(), getContents(), getMimeType(), getOpaque(), isAbsolutePath(), and isRelativePath().

◆ getQuery()

const gchar * Inkscape::URI::getQuery ( ) const

Return the query, which is the part between "?" and the optional fragment hash ("#")

Definition at line 159 of file uri.cpp.

References _xmlURIPtr().

Referenced by Inkscape::URIReference::attach().

◆ getScheme()

const gchar * Inkscape::URI::getScheme ( ) const

Return the scheme, e.g. "http", or NULL if this is not an absolute URI.

Definition at line 151 of file uri.cpp.

References _xmlURIPtr().

Referenced by hasScheme().

◆ hasScheme()

bool Inkscape::URI::hasScheme ( const char *  scheme) const

True if the scheme equals the given string (not case sensitive)

Definition at line 362 of file uri.cpp.

References getScheme().

Referenced by getContents(), and getMimeType().

◆ init()

void Inkscape::URI::init ( xmlURI *  ptr)
inlineprivate

Definition at line 188 of file uri.h.

References m_shared.

Referenced by URI().

◆ isAbsolutePath()

bool Inkscape::URI::isAbsolutePath ( ) const

Determines if the relative URI represented is a 'absolute-path' as per RFC 2396.

An absolute-path is one that starts with a single "/".

Returns
true if the URI is relative and an absolute-path, false otherwise.

Definition at line 143 of file uri.cpp.

References _xmlURIPtr(), getPath(), and isRelative().

◆ isNetPath()

bool Inkscape::URI::isNetPath ( ) const

Determines if the relative URI represented is a 'net-path' as per RFC 2396.

A net-path is one that starts with "//".

Returns
true if the URI is relative and a net-path, false otherwise.

Definition at line 131 of file uri.cpp.

References _xmlURIPtr(), and isRelative().

◆ isOpaque()

bool Inkscape::URI::isOpaque ( ) const

Determines if the URI represented is an 'opaque' URI.

Returns
true if the URI is opaque, false if hierarchial.

Definition at line 123 of file uri.cpp.

References getOpaque().

◆ isRelative()

bool Inkscape::URI::isRelative ( ) const

Determines if the URI represented is 'relative' as per RFC 2396.

Relative URI references are distinguished by not beginning with a scheme name.

Returns
true if the URI is relative, false if it is absolute.

Definition at line 127 of file uri.cpp.

References _xmlURIPtr().

Referenced by getOpaque(), isAbsolutePath(), isNetPath(), and isRelativePath().

◆ isRelativePath()

bool Inkscape::URI::isRelativePath ( ) const

Determines if the relative URI represented is a 'relative-path' as per RFC 2396.

A relative-path is one that starts with no slashes.

Returns
true if the URI is relative and a relative-path, false otherwise.

Definition at line 135 of file uri.cpp.

References _xmlURIPtr(), getPath(), and isRelative().

◆ str()

std::string Inkscape::URI::str ( char const *  baseuri = nullptr) const

Return the string representation of this URI.

Parameters
baseuriReturn a relative path if this URI shares protocol and host with baseuri

Definition at line 281 of file uri.cpp.

References _xmlURIPtr(), and Inkscape::build_relative_uri().

Referenced by Inkscape::URIReference::attach(), cssStr(), getContents(), Inkscape::XML::rebase_hrefs(), Inkscape::Extension::Internal::OdfOutput::save(), toNativeFilename(), SPTRef::write(), SPBox3D::write(), SPGradient::write(), SPUse::write(), and SPConnEndPair::writeRepr().

◆ toNativeFilename()

std::string Inkscape::URI::toNativeFilename ( ) const

Convert this URI to a native filename.

Discards the fragment identifier.

Exceptions
Glib::ConvertErrorIf this is not a "file" URI

Definition at line 177 of file uri.cpp.

References getFragment(), and str().

Member Data Documentation

◆ m_shared

std::shared_ptr<xmlURI> Inkscape::URI::m_shared
private

Definition at line 186 of file uri.h.

Referenced by _xmlURIPtr(), and init().


The documentation for this class was generated from the following files: