Logo Search packages:      
Sourcecode: inkscape version File versions

void Inkscape::URIReference::attach ( const URI uri  )  throw (BadURIException)

Attaches to a URI, relative to the specified document.

Throws a BadURIException if the URI is unsupported, or the fragment identifier is xpointer and malformed.

Parameters:
rel_document document for relative URIs
uri the URI to watch

Definition at line 38 of file uri-references.cpp.

{
      SPDocument *document = SP_OBJECT_DOCUMENT(_owner);
      gchar const *fragment = uri.getFragment();
      if ( !uri.isRelative() || uri.getQuery() || !fragment ) {
            throw UnsupportedURIException();
      }

      /* FIXME !!! real xpointer support should be delegated to document */
      /* for now this handles the minimal xpointer form that SVG 1.0
       * requires of us
       */
      gchar *id;
      if (!strncmp(fragment, "xpointer(", 9)) {
            /* FIXME !!! this is wasteful */
            /* FIXME: It looks as though this is including "))" in the id.  I suggest moving
               the strlen calculation and validity testing to before strdup, and copying just
               the id without the "))".  -- pjrm */
            if (!strncmp(fragment, "xpointer(id(", 12)) {
                  id = g_strdup(fragment+12);
                  size_t const len = strlen(id);
                  if ( len < 3 || strcmp(id+len-2, "))") ) {
                        g_free(id);
                        throw MalformedURIException();
                  }
            } else {
                  throw UnsupportedURIException();
            }
      } else {
            id = g_strdup(fragment);
      }

      /* FIXME !!! validate id as an NCName somewhere */

      if (_uri) {
            delete _uri;
      }
      _uri = new URI(uri);

      _connection.disconnect();
      _setObject(document->getObjectById(id));
      _connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject));

      g_free(id);
}


Generated by  Doxygen 1.6.0   Back to index