Class Object<T extends Object<T>>


public class Object<T extends Object<T>> extends StyledElement<T>
Represents an HTML <object> element that embeds external resources in a document.

The <object> element is a generic container for external resources such as images, nested HTML pages, plugins, PDFs, Flash content, or other multimedia. It provides a flexible way to embed various types of content with fallback support.

Features:

  • Embeds various types of external resources (images, PDFs, videos, etc.)
  • Supports fallback content for unsupported resources
  • Configurable width and height dimensions
  • Can be associated with a form element
  • Supports image maps via usemap attribute
  • Named object references for scripting
  • Parameter passing via nested <param> elements

Usage:


 // Embed a PDF document
 Object pdf = new Object();
 pdf.setData("/documents/sample.pdf");
 pdf.setType("application/pdf");
 pdf.setIntrinsicWidth(600);
 pdf.setIntrinsicHeight(800);
 pdf.addElement(new Paragraph("Your browser doesn't support PDF viewing."));

 // Embed an image with fallback
 Object image = new Object();
 image.setData("/images/photo.jpg");
 image.setType("image/jpeg");
 image.setIntrinsicWidth(400);
 image.setIntrinsicHeight(300);
 image.addElement(new Img("/images/photo.jpg", "Photo"));

 // Embed with parameters
 Object flash = new Object();
 flash.setData("/media/animation.swf");
 flash.setType("application/x-shockwave-flash");
 Param quality = new Param();
 quality.setName("quality");
 quality.setValue("high");
 flash.addElement(quality);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Object

      public Object()
      Constructs a new Object element.

      Creates an HTML <object> element ready to embed external resources.

  • Method Details

    • setData

      public T setData(String url)
      Sets the URL of the resource to embed.

      The data attribute specifies the address of the resource. This can be an absolute or relative URL pointing to the content to be embedded.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      url - the URL of the resource to embed
      Returns:
      this element for method chaining
    • setForm

      public T setForm(String formId)
      Associates this object with a form element.
      Parameters:
      formId - the ID of the form element to associate with
      Returns:
      This element for method chaining.
    • setName

      public final T setName(String name)
      Sets the name of the object for scripting and form submission.

      The name attribute provides a way to reference this object from scripts or when submitting form data. This is particularly useful when the object represents a form control or needs to be accessed programmatically.

      Parameters:
      name - the name identifier for this object
    • setType

      public T setType(String mediaType)
      Sets the MIME type of the embedded resource.

      The type attribute specifies the media type (MIME type) of the data specified in the data attribute. Common values include "application/pdf", "image/jpeg", "text/html", etc.

      Parameters:
      mediaType - the MIME type of the resource (e.g., "application/pdf")
    • setUseMap

      public T setUseMap(String mapname)
      Sets the usemap attribute associating this object with a client-side image map.

      The value must be a hash reference to a <map> element (e.g., "#mymap").

      Parameters:
      mapname - The hash reference to a map element.
      Returns:
      This element for method chaining.
    • setIntrinsicWidth

      public T setIntrinsicWidth(int pixels)
      Sets the HTML width attribute to specify intrinsic width in pixels.

      This sets the HTML attribute (e.g., <img width="300">), not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(int) method.

      Parameters:
      pixels - The width in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicWidth

      public T setIntrinsicWidth(String width)
      Sets the HTML width attribute to specify intrinsic width.

      This sets the HTML attribute, not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(String) method.

      Parameters:
      width - The width value.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(int pixels)
      Sets the HTML height attribute to specify intrinsic height in pixels.

      This sets the HTML attribute (e.g., <img height="200">), not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(int) method.

      Parameters:
      pixels - The height in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(String height)
      Sets the HTML height attribute to specify intrinsic height.

      This sets the HTML attribute, not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(String) method.

      Parameters:
      height - The height value.
      Returns:
      This element for method chaining.
    • getIntrinsicWidth

      public String getIntrinsicWidth()
      Returns the HTML width attribute value.

      Returns the intrinsic width set via the HTML attribute, not the CSS width.

      Returns:
      The width value, or null if not set.
    • getIntrinsicHeight

      public String getIntrinsicHeight()
      Returns the HTML height attribute value.

      Returns the intrinsic height set via the HTML attribute, not the CSS height.

      Returns:
      The height value, or null if not set.