search/mag_sel search/close
Aspose::Words::Loading::ResourceLoadingArgs Class Reference

Provides data for the ResourceLoading() method.

Examples

Shows how to customize the process of loading external resources into a document.

void ResourceLoadingCallback()
{
auto doc = MakeObject<Document>();
doc->set_ResourceLoadingCallback(MakeObject<ExDocumentBase::ImageNameHandler>());
auto builder = MakeObject<DocumentBuilder>(doc);
// Images usually are inserted using a URI, or a byte array.
// Every instance of a resource load will call our callback's ResourceLoading method.
builder->InsertImage(u"Google logo");
builder->InsertImage(u"Aspose logo");
builder->InsertImage(u"Watermark");
ASSERT_EQ(3, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
doc->Save(ArtifactsDir + u"DocumentBase.ResourceLoadingCallback.docx");
}
class ImageNameHandler : public IResourceLoadingCallback
{
public:
ResourceLoadingAction ResourceLoading(SharedPtr<ResourceLoadingArgs> args) override
{
// If this callback encounters one of the image shorthands while loading an image,
// it will apply unique logic for each defined shorthand instead of treating it as a URI.
if (args->get_ResourceType() == ResourceType::Image)
{
String imageUri = args->get_OriginalUri();
if (imageUri == u"Google logo")
{
{
auto webClient = MakeObject<System::Net::WebClient>();
args->SetData(webClient->DownloadData(u"http://www.google.com/images/logos/ps_logo2.png"));
}
}
else if (imageUri == u"Aspose logo")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Logo.jpg"));
}
else if (imageUri == u"Watermark")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Transparent background logo.png"));
}
}
}
};

#include <Aspose.Words.Cpp/Loading/ResourceLoadingArgs.h>

+ Inheritance diagram for Aspose::Words::Loading::ResourceLoadingArgs:

Public Member Functions

String get_OriginalUri () const
 Original URI of the resource as specified in imported document. More...
 
ResourceType get_ResourceType () const
 Type of resource. More...
 
String get_Uri () const
 URI of the resource which is used for downloading if ResourceLoading() returns Default. Initially it's set to absolute URI of the resource, but user can redefine it to any value. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Uri (String value)
 Setter for get_Uri. More...
 
void SetData (ArrayPtr< uint8_t > data)
 Sets user provided data of the resource which is used if ResourceLoading() returns UserProvided. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_OriginalUri()

System::String Aspose::Words::Loading::ResourceLoadingArgs::get_OriginalUri ( ) const

Original URI of the resource as specified in imported document.

Examples

Shows how to customize the process of loading external resources into a document.

void ResourceLoadingCallback()
{
auto doc = MakeObject<Document>();
doc->set_ResourceLoadingCallback(MakeObject<ExDocumentBase::ImageNameHandler>());
auto builder = MakeObject<DocumentBuilder>(doc);
// Images usually are inserted using a URI, or a byte array.
// Every instance of a resource load will call our callback's ResourceLoading method.
builder->InsertImage(u"Google logo");
builder->InsertImage(u"Aspose logo");
builder->InsertImage(u"Watermark");
ASSERT_EQ(3, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
doc->Save(ArtifactsDir + u"DocumentBase.ResourceLoadingCallback.docx");
}
class ImageNameHandler : public IResourceLoadingCallback
{
public:
ResourceLoadingAction ResourceLoading(SharedPtr<ResourceLoadingArgs> args) override
{
// If this callback encounters one of the image shorthands while loading an image,
// it will apply unique logic for each defined shorthand instead of treating it as a URI.
if (args->get_ResourceType() == ResourceType::Image)
{
String imageUri = args->get_OriginalUri();
if (imageUri == u"Google logo")
{
{
auto webClient = MakeObject<System::Net::WebClient>();
args->SetData(webClient->DownloadData(u"http://www.google.com/images/logos/ps_logo2.png"));
}
}
else if (imageUri == u"Aspose logo")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Logo.jpg"));
}
else if (imageUri == u"Watermark")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Transparent background logo.png"));
}
}
}
};

◆ get_ResourceType()

Aspose::Words::Loading::ResourceType Aspose::Words::Loading::ResourceLoadingArgs::get_ResourceType ( ) const

Type of resource.

Examples

Shows how to customize the process of loading external resources into a document.

void ResourceLoadingCallback()
{
auto doc = MakeObject<Document>();
doc->set_ResourceLoadingCallback(MakeObject<ExDocumentBase::ImageNameHandler>());
auto builder = MakeObject<DocumentBuilder>(doc);
// Images usually are inserted using a URI, or a byte array.
// Every instance of a resource load will call our callback's ResourceLoading method.
builder->InsertImage(u"Google logo");
builder->InsertImage(u"Aspose logo");
builder->InsertImage(u"Watermark");
ASSERT_EQ(3, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
doc->Save(ArtifactsDir + u"DocumentBase.ResourceLoadingCallback.docx");
}
class ImageNameHandler : public IResourceLoadingCallback
{
public:
ResourceLoadingAction ResourceLoading(SharedPtr<ResourceLoadingArgs> args) override
{
// If this callback encounters one of the image shorthands while loading an image,
// it will apply unique logic for each defined shorthand instead of treating it as a URI.
if (args->get_ResourceType() == ResourceType::Image)
{
String imageUri = args->get_OriginalUri();
if (imageUri == u"Google logo")
{
{
auto webClient = MakeObject<System::Net::WebClient>();
args->SetData(webClient->DownloadData(u"http://www.google.com/images/logos/ps_logo2.png"));
}
}
else if (imageUri == u"Aspose logo")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Logo.jpg"));
}
else if (imageUri == u"Watermark")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Transparent background logo.png"));
}
}
}
};

◆ get_Uri()

System::String Aspose::Words::Loading::ResourceLoadingArgs::get_Uri ( ) const

URI of the resource which is used for downloading if ResourceLoading() returns Default. Initially it's set to absolute URI of the resource, but user can redefine it to any value.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Loading::ResourceLoadingArgs::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Loading::ResourceLoadingArgs::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_Uri()

void Aspose::Words::Loading::ResourceLoadingArgs::set_Uri ( System::String  value)

◆ SetData()

void Aspose::Words::Loading::ResourceLoadingArgs::SetData ( System::ArrayPtr< uint8_t >  data)

Sets user provided data of the resource which is used if ResourceLoading() returns UserProvided.

Examples

Shows how to customize the process of loading external resources into a document.

void ResourceLoadingCallback()
{
auto doc = MakeObject<Document>();
doc->set_ResourceLoadingCallback(MakeObject<ExDocumentBase::ImageNameHandler>());
auto builder = MakeObject<DocumentBuilder>(doc);
// Images usually are inserted using a URI, or a byte array.
// Every instance of a resource load will call our callback's ResourceLoading method.
builder->InsertImage(u"Google logo");
builder->InsertImage(u"Aspose logo");
builder->InsertImage(u"Watermark");
ASSERT_EQ(3, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
doc->Save(ArtifactsDir + u"DocumentBase.ResourceLoadingCallback.docx");
}
class ImageNameHandler : public IResourceLoadingCallback
{
public:
ResourceLoadingAction ResourceLoading(SharedPtr<ResourceLoadingArgs> args) override
{
// If this callback encounters one of the image shorthands while loading an image,
// it will apply unique logic for each defined shorthand instead of treating it as a URI.
if (args->get_ResourceType() == ResourceType::Image)
{
String imageUri = args->get_OriginalUri();
if (imageUri == u"Google logo")
{
{
auto webClient = MakeObject<System::Net::WebClient>();
args->SetData(webClient->DownloadData(u"http://www.google.com/images/logos/ps_logo2.png"));
}
}
else if (imageUri == u"Aspose logo")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Logo.jpg"));
}
else if (imageUri == u"Watermark")
{
args->SetData(System::IO::File::ReadAllBytes(ImageDir + u"Transparent background logo.png"));
}
}
}
};

◆ Type()

static const System::TypeInfo& Aspose::Words::Loading::ResourceLoadingArgs::Type ( )
static