// $Revision: 1.6 $ #ifndef TaligentSamples_TURL #include "URL.h" #endif #ifndef TaligentSamples_LIBWWWINTERFACE #include "LibWWWInterface.h" #endif #ifndef TaligentSamples_MIMEDATASTREAM #include "MIMEDataStream.h" #endif #ifndef TaligentSamples_GRAPHICDOCUMENTVIEW #include #endif #ifndef Taligent_STANDARDTEXT #include #endif #ifndef Taligent_MEMORY #include #endif #ifndef Taligent_SCRAPITEMON #include #endif const TURL TURL::gTaligentHomePage(TStandardText("http://www.taligent.com")); VersionDefinitionsMacro(TURL, kOriginalVersion); TURL::TURL() : fURLText(gTaligentHomePage.fURLText) { } TURL::TURL(const TStandardText& urlText) : fURLText(urlText) { } TURL::TURL(const TURL& source) : fURLText(source.fURLText) { } TURL::~TURL() { } TURL& TURL::operator=(const TURL& source) { if (&source != this) { fURLText = source.fURLText; } return *this; } TStream& TURL::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); fURLText >>= toStream; return toStream; } TStream& TURL::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); fURLText <<= fromStream; return fromStream; } bool TURL::operator==(const TURL& other) const { return (fURLText == other.fURLText); } bool TURL::operator!=(const TURL& other) const { return !(operator==(other)); } TStandardText TURL::GetURLText() const { return fURLText; } TScrapItem* TURL::Follow(const TCollectionOf& acceptableScrapTypes) const { TScrapItem* resultScrapItem = 0; TTextCount bufSize = fURLText.GetLength()+1; char* charBuffer = new char [(long)bufSize]; fURLText.Extract(TTextRange::GetMaximumRange(), charBuffer, bufSize); HTRequest* request = HTRequest_new(); AddTaligentConversions(request->conversions); TDeleterFor htextScrapItem = new THypertextScrapItem; TDeleterFor stream = new TGrowingChunkyStream; TMIMEForeignDataType mimeType("text/html"); request->output_stream = new _HTStream(stream, htextScrapItem, &mimeType); request->output_format = WWW_PRESENT; HTLoadAbsolute(charBuffer, request); delete charBuffer; HTRequest_delete(request); if (mimeType == TMIMEForeignDataType("text/html")) { const TTypeDescription htextScrapDescription = TType(*THypertextScrapItem::gTypeInfo); if (acceptableScrapTypes.Member(htextScrapDescription) != NIL) { resultScrapItem = htextScrapItem.OrphanObject(); } } else { stream->Seek(0); resultScrapItem = TranslateNonTextStream(stream.OrphanObject(), mimeType, acceptableScrapTypes); } return resultScrapItem; } TScrapItem* TURL::TranslateNonTextStream(TChunkyStream* adoptStream, const TMIMEForeignDataType& mimeType, const TCollectionOf& acceptableTypes) const { TScrapItem* resultScrapItem = NIL; TForeignData* data = new TMIMEDataStream(adoptStream, mimeType); TImportForeignDataQuery query(data); TDequeOf queryTypeDeque( new TOperatorComparator, NIL); try { query.CopyAvailableTypes(queryTypeDeque); } catch (const TForeignDataException& exception) {} TIteratorOver* iterator = acceptableTypes.CreateIterator(); for (TTypeDescription* type = iterator->First(); type != NIL && resultScrapItem == NIL; type = iterator->Next()) { if (queryTypeDeque.Member(*type)) { resultScrapItem = query.CreateScrapItem(*type); break; } } queryTypeDeque.DeleteAll(); return resultScrapItem; }