//---------------------------------------------------------------
    void StreamWriter::appendURIAttribute ( const String &name, const COLLADABU::URI &uri )
    {
        COLLADABU_ASSERT ( !mOpenTags.back().mHasContents );

		appendChar ( ' ' );
		appendNCNameString ( name );
		appendChar ( '=' );
		appendChar ( '\"' );
		appendString ( COLLADABU::StringUtils::translateToXML(uri.getURIString()) );
		appendChar ( '\"' );
    }
    bool SplineLoader::loadInTangents()
    {
        const InputUnshared * input = mVerticesInputs.getInputBySemantic( InputSemantic::IN_TANGENT );

        if( input )
        {
            // Get the source element with the uri of the input element.
            COLLADABU::URI inputUrl = input->getSource ();
            String sourceId = inputUrl.getFragment ();
            SourceBase* sourceBase = getSourceById ( sourceId );
            if ( sourceBase == 0 ) return false;

            // Get the source input array
            const SourceBase::DataType& dataType = sourceBase->getDataType ();
            switch ( dataType )
            {
            case SourceBase::DATA_TYPE_FLOAT:
                {
                    // Get the values array from the source
                    FloatSource* source = ( FloatSource* ) sourceBase;
                    FloatArrayElement& arrayElement = source->getArrayElement ();
                    COLLADAFW::ArrayPrimitiveType<float>& valuesArray = arrayElement.getValues ();

                    // TODO
                    unsigned long long stride = source->getStride ();

                    // Check if there are already some values in the positions list.
                    // If so, we have to store the last index to increment the following indexes.
                    COLLADAFW::MeshVertexData& positions = mSpline->getInTangents ();
                    const size_t initialIndex = positions.getValuesCount ();
                    sourceBase->setInitialIndex ( initialIndex );

                    // Push the new positions into the list of positions.
                    positions.setType ( COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT );
                    if ( initialIndex != 0 ) 
                    {
                        positions.appendValues ( valuesArray );
                    }
                    else
                    {
                        positions.setData ( valuesArray.getData (), valuesArray.getCount () );
                        valuesArray.yieldOwnerShip();
                    }

                    // Set the source base as loaded element.
                    sourceBase->addLoadedInputElement ( InputSemantic::POSITION  );

                    break;
                }
            case SourceBase::DATA_TYPE_DOUBLE:
                {
                    // Get the values array from the source
                    DoubleSource* source = ( DoubleSource* ) sourceBase;
                    DoubleArrayElement& arrayElement = source->getArrayElement ();
                    COLLADAFW::ArrayPrimitiveType<double>& valuesArray = arrayElement.getValues ();

                    // Check if there are already some values in the positions list.
                    // If so, we have to store the last index to increment the following indexes.
                    COLLADAFW::MeshVertexData& positions = mSpline->getInTangents ();
                    const size_t initialIndex = positions.getValuesCount ();
                    sourceBase->setInitialIndex ( initialIndex );

                    // Push the new positions into the list of positions.
                    positions.setType ( COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE );
                    if ( initialIndex != 0 ) 
                    {
                        positions.appendValues ( valuesArray );
                    }
                    else 
                    {
                        positions.setData ( valuesArray.getData (), valuesArray.getCount () );
                        valuesArray.yieldOwnerShip();
                    }

                    // Set the source base as loaded element.
                    sourceBase->addLoadedInputElement ( InputSemantic::IN_TANGENT  );

                    break;
                }
            default:
                std::cerr << "Position source has an other datatype as float or double! " << dataType << std::endl;
                return false;
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    //---------------------------------------------------------------
    void StreamWriter::appendURIElement ( const String& elementName, const COLLADABU::URI& uri )
    {
        openElement ( elementName );
		appendText ( COLLADABU::StringUtils::translateToXML(uri.getURIString()) );
        closeElement();
    }
    // ------------------------------
    MStatus FileTranslator::importFromFile ( const String& importFileName )
    {
        MStatus status = MS::kSuccess;

        // Get the time 
        clock_t startClock, endClock;
        startClock = clock();

        // TODO Ask the user where to save the maya file.
//         MString command = "fileBrowserDialog -m 0 -fc \"importFromFile\" -ft \"mayaAscii\" -fl \"*.ma\" -an \"Save_import_as\" -om \"SaveAs\"";
//         MString mayaAsciiFileNameM = MGlobal::executeCommandStringResult ( command );
//         String mayaAsciiFileName ( mayaAsciiFileNameM.asChar () );
//         MGlobal::displayInfo ( mayaAsciiFileName.c_str() );

        // Set the imported file name and path.
//        COLLADABU::URI mayaAsciiFileURI ( mayaAsciiFileName );
        COLLADABU::URI mayaAsciiFileURI ( importFileName );
#ifdef NDEBUG
        mayaAsciiFileURI.setPathExtension ( ASCII_PATH_EXTENSION );
#else
        mayaAsciiFileURI.setPathExtension ( ASCII_PATH_EXTENSION_DEBUG );
#endif
        String mayaAsciiFileName = mayaAsciiFileURI.getURIString ();
		const char* cpMayaAsciiFileName = mayaAsciiFileName.c_str();

        // Get the current maya version
        String mayaVersion ( MGlobal::mayaVersion ().asChar () );

        // We have to change the name on 64 bit machines. 
        // For example from "2008 x64" to "2008" or from "2008 Extension 2" to "2008".
        std::vector<String> words;
        String separator (" ");
        COLLADABU::Utils::split ( mayaVersion, separator, words );
        if ( words.size () > 1 ) 
        {
            mayaVersion = words[0];
        }

        // Actually import the document
		{
			DAE2MA::DocumentImporter documentImporter ( importFileName, mayaAsciiFileURI.getURIString (), mayaVersion.c_str () );
			documentImporter.importCurrentScene ();
		}

        // Display some closing information.
        endClock = clock();

        std::ostringstream stream; 
        stream << "Time to import into file \"" << mayaAsciiFileName << "\": " << endClock - startClock << std::endl;
        String message( stream.str() );
        std::cerr << message << std::endl;

        // TODO Open the maya ascii file in the maya instance
		MFileIO::importFile ( cpMayaAsciiFileName );
		//MFileIO::open ( mayaAsciiFileName.c_str (), "mayaAscii", true ); 

		//         mayaAsciiFileURI.setPathExtension ( ".opencollada.mb" );
		//         mayaFileName = mayaAsciiFileURI.getURIString ();
		//         MFileIO::saveAs ( mayaFileName.c_str () );
		//         MGlobal::displayInfo ( "File saved as maya binary: " );
		//         MGlobal::displayInfo ( mayaFileName.c_str () 
        
        return status;
    }