void daeDocument::addExternalReference( daeURI &uri ) {
    if ( uri.getContainer() == NULL || uri.getContainer()->getDocument() != this ) {
        return;
    }
    daeURI tempURI( *dae, uri.getURI(), true );  // Remove fragment
    referencedDocuments.appendUnique( tempURI.getURI() );
}
示例#2
0
daeBool
daeLIBXMLResolver::resolveElement(daeURI& uri, daeString typeNameHint)
{
	// Make sure the URI is validated
	if (uri.getState() == daeURI::uri_loaded)
	{
		uri.validate();
	}

	daeElement* resolved = NULL;
	int status;

	// Does the URI have a document reference?
	if ( (uri.getFile() != NULL) &&	(strlen(uri.getFile())>0)) 
	{
		// The URI contains a document reference, see if it is loaded and try to load it if it's not
		if (!_database->isDocumentLoaded(uri.getURI())) {
			if ( _loadExternalDocuments ) {
				_plugin->read(uri,NULL);
			}
			else {
				uri.setState( daeURI::uri_failed_external_document );
				return false;
			}
		}
		// Try to find the id by searching this document only
		status = _database->getElement(&resolved,0,uri.getID(),typeNameHint,uri.getURI());
	}
	else
	{
		// The URI was just a fragment, so try to find it in the document that contains it.
		// !!!GAC not sure if all these pointers will be set when we get here, so assert if any of them aren't
		daeElement *tempElement = uri.getContainer();
		//assert(tempElement);
		daeDocument *tempDocument;
		if ( tempElement == NULL || (tempDocument = tempElement->getDocument()) == NULL ) {
			uri.setState(daeURI::uri_failed_missing_container);
			char msg[256];
			sprintf(msg,
					"daeLIBXMLResolver::resolveElement() - failed to resolve %s\n",
					uri.getURI());
			daeErrorHandler::get()->handleError( msg );
			return false;
		}
		//assert(tempDocument);
		daeURI *tempURI = tempDocument->getDocumentURI();
		//assert(tempURI);
		status = _database->getElement(&resolved,0,uri.getID(),typeNameHint,tempURI->getURI());
	}

	uri.setElement(resolved);

	// Error if we didn't successfully resolve the uri

	if (status ||(resolved==NULL)) 
	{
		uri.setState(daeURI::uri_failed_id_not_found);
		char msg[256];
		sprintf(msg,
				"daeLIBXMLResolver::resolveElement() - failed to resolve %s\n",
				uri.getURI());
		daeErrorHandler::get()->handleError( msg );
		return false;
	}

	uri.setState(daeURI::uri_success);
	return true;
}