Class ResourceType

  • java.lang.Object
    • com.aspose.words.ResourceType
public class ResourceType 
extends java.lang.Object

Utility class containing constants. Type of loaded resource.


Shows how to process inserted resources differently.
public void resourceLoadingCallback() throws Exception {
    Document doc = new Document();

    // Enable our custom image loading
    doc.setResourceLoadingCallback(new ImageNameHandler());

    DocumentBuilder builder = new DocumentBuilder(doc);

    // We usually insert images as a uri or byte array, but there are many other possibilities with ResourceLoadingCallback
    // In this case we are referencing images with simple names and keep the image fetching logic somewhere else
    builder.insertImage("Google Logo");
    builder.insertImage("Aspose Logo");
    builder.insertImage("My Watermark");

    // Images belong to Shape objects, which are placed and scaled in the document
    Assert.assertEquals(3, doc.getChildNodes(NodeType.SHAPE, true).getCount()); + "DocumentBase.ResourceLoadingCallback.docx");

private static class ImageNameHandler implements IResourceLoadingCallback {
    public int resourceLoading(final ResourceLoadingArgs args) throws URISyntaxException, IOException {
        if (args.getResourceType() == ResourceType.IMAGE) {
            // builder.InsertImage expects a uri so inputs like "Google Logo" would normally trigger a FileNotFoundException
            // We can still process those inputs and find an image any way we like, as long as an image byte array is passed to args.SetData()
            if ("Google Logo".equals(args.getOriginalUri())) {
                args.setData(DocumentHelper.getBytesFromStream(new URI("").toURL().openStream()));
                // We need this return statement any time a resource is loaded in a custom manner
                return ResourceLoadingAction.USER_PROVIDED;

            if ("Aspose Logo".equals(args.getOriginalUri())) {

                return ResourceLoadingAction.USER_PROVIDED;

            // We can find and add an image any way we like, as long as args.SetData() is called with some image byte array as a parameter
            if ("My Watermark".equals(args.getOriginalUri())) {
                InputStream imageStream = new FileInputStream(getImageDir() + "Transparent background logo.png");

                return ResourceLoadingAction.USER_PROVIDED;

        // All other resources such as documents, CSS stylesheets and images passed as uris are handled as they were normally
        return ResourceLoadingAction.DEFAULT;

Field Summary
static final intIMAGE = 0
static final intCSS_STYLE_SHEET = 1
Css style sheet.
static final intDOCUMENT = 2

    • Field Detail

      • IMAGE = 0

        public static final int IMAGE
      • CSS_STYLE_SHEET = 1

        public static final int CSS_STYLE_SHEET
        Css style sheet.
      • DOCUMENT = 2

        public static final int DOCUMENT