Class Q<T extends Q<T>>

Direct Known Subclasses:
Quotation

public class Q<T extends Q<T>> extends PhrasingContentElement<T>
Represents an HTML <q> (inline quotation) element that marks short inline quotations.

The <q> element is used for short inline quotations that don't require paragraph breaks. Browsers typically render the content in quotation marks. For longer, block-level quotations, use the <blockquote> element instead.

Features:

  • Semantic representation of inline quotations
  • Browsers automatically add quotation marks
  • Can reference the source URL via cite attribute
  • Proper quotation mark nesting for nested quotes
  • Supports text content and nested HTML elements
  • Inline element (doesn't break text flow)

Usage:


 // Simple inline quote
 Paragraph p = new Paragraph();
 p.addText("As Shakespeare wrote, ");
 Q quote = new Q("To be or not to be");
 p.addElement(quote);
 p.addText(", that is the question.");

 // Quote with source citation
 Q cited = new Q("The only way to do great work is to love what you do.");
 cited.setCite("https://example.com/steve-jobs-quotes");

 // Empty quote for dynamic content
 Q dynamic = new Q();
 dynamic.addText("Dynamically added quote text");
 dynamic.setCite("https://example.com/source");

 // Nested quotes
 Q outer = new Q();
 outer.addText("He said, ");
 Q inner = new Q("Hello");
 outer.addElement(inner);
 outer.addText(" to me.");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Q

      public Q()
      Constructs a new empty Q element.

      Creates an HTML <q> element with no initial content. Text can be added later using the inherited text methods.

    • Q

      public Q(String text)
      Constructs a new Q element with the specified quoted text.

      Creates an HTML <q> element containing the specified text. Browsers will automatically add appropriate quotation marks around the text.

      Parameters:
      text - the text to be quoted
  • Method Details

    • setCite

      public final T setCite(String url)
      Sets the URL of the source of the quotation.

      The cite attribute specifies a URL that points to the source document or message for the quotation. This is primarily for documentation purposes and is not typically displayed to users by browsers. It's useful for providing attribution and reference information.

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

      Parameters:
      url - the URL of the quotation source