Iwant to know if an extern resource (e.g. stylesheets) could not be loaded

Hello,
if a HTML contains a linked resource that refers to an extern file
which is not available or could not be loaded,
(e.g. a Stylsheet) then i must notified about it.
Is it possible to get a warning about linked resoures that couldn´t be loaded
while executing the methode “insertingHTML”.
If not, is there a other posibility for checking occurred errors after the method was executing.

Example:

Hi Cailun,

Thanks for your inquiry. A class implementing IResourceLoadingCallback interface can be used to control how resources such as images or CSS are handled when they need to be downloaded from an external source i.e a network or internet. Please see the following example which bans all CSS style sheet resources from loading:

HtmlLoadOptions loadOptions = new HtmlLoadOptions();
loadOptions.LoadFormat = LoadFormat.Html;
loadOptions.ResourceLoadingCallback = new HandleResourceLoading();
Document document = new Document(MyDir + @"in.html", loadOptions);
document.Save(MyDir + @"16.11.0.docx");
public class HandleResourceLoading : IResourceLoadingCallback
{
    public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
    {
        if (args.ResourceType == ResourceType.CssStyleSheet)
            return ResourceLoadingAction.Skip;
    }
}

Hope, this helps.

Best regards,

Thanks for the quick reply, but I have already implemented it the same way.
My problem is a different.
Of course I could try to check within this callback function
whether the URL (resourceLoadingArgs.getUri) of the resource is valid and available.
But actually, I would like to leave it to Aspose to check the URL while inserting the Resource.
It would be fine, if an exception would have be thrown when the linked Resource doesn´t exist or it would also be ok, if it could be catched and logged via IWarningCallback.

Currently, we have implemented it ourselves, because we are not receiving a message if a resource could be loaded or not.

IResourceLoadingCallback _iResourceLoadingCallback = resourceLoadingArgs-> { 
    URL url = new URL(resourceLoadingArgs.getUri());
    try
    {
        data = ReaderUtils.readBytesFromURL(url);
        resourceLoadingArgs.setData(data);
        resourceLoadingAction = ResourceLoadingAction.USER_PROVIDED;
    }
    catch (IOException e)
    {
        throw new ResourceLoadingRuntimeException("Can't get byte[] from URL: " +
        resourceLoadingArgs.getUri(), e);
    }
    return resourceLoadingAction; 
}

Aspose does not check if a resource is realy available. So if the generated document is displayed later, then it does not look like as we expected and the reason is the missing stylesheet because it could not be loaded and applied correctly.

Hi Cailun,

Thanks for the additional information. Did you manage to fix the issue on your side or are you still in need of assistance?

Best regards,

Hello,

Yes, we are still in need of assistance,
because we do not want to program it ourselves.
We want to remove our own solution soon as possible,
it should be a general solution.
Aspose should load the resource, but tell us,
when loading the resource did not work.

Best regards

Hi Cailun,

Thanks for your inquiry. We have logged your requirement as WORDSNET-14515 in our issue tracking system. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for any inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-14515) have been fixed in this Aspose.Words for .NET 17.6 update and this Aspose.Words for Java 17.6 update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.