ListLinkHandlerFactory extends LinkHandlerFactory to support content filtering and sorting for list-based resources like channel tabs, kiosks, or categorized content pages.
Class Overview
ListLinkHandler instances that include:
- All base LinkHandler properties (URL, ID)
- Content filters (e.g., “videos”, “playlists”, “shorts”)
- Sort filters (e.g., “recent”, “popular”, “oldest”)
Abstract Methods (Must Override)
Construct a URL from an ID with content and sort filters applied.Parameters:
id(String) - The resource IDcontentFilter(List<String>) - List of content type filters to applysortFilter(String) - Sort order to apply
ParsingException- If the URL cannot be constructedUnsupportedOperationException- If URL construction is not supported
Optional Methods
Construct a URL with filters and a base URL. Override if your service requires base URL context.Parameters:
id(String) - The resource IDcontentFilter(List<String>) - Content type filterssortFilter(String) - Sort orderbaseUrl(String) - The base URL for the service
ParsingException- If the URL cannot be constructedUnsupportedOperationException- If URL construction is not supported
getUrl(id, contentFilter, sortFilter) and ignores baseUrlReturn the content filters that this extractor can handle.Returns: String[] - Array of available content filter namesDefault: Returns empty arrayExample implementation:These filters represent different types of content that can be displayed, such as:
- “videos” - Regular video content
- “playlists” - Playlist collections
- “channels” - Channel listings
- “music” - Music-specific content
Return the sort filters that this extractor can handle.Returns: String[] - Array of available sort filter namesDefault: Returns empty arrayExample implementation:These filters represent different sorting options, such as:
- “recent” / “newest” - Most recent content first
- “popular” - Most popular/viewed content
- “oldest” - Oldest content first
- “A-Z” - Alphabetical sorting
Public Methods
Build a ListLinkHandler from a URL.Parameters:
url(String) - The URL to parse. Must not be null or empty.
IllegalArgumentException- If URL is null or emptyParsingException- If URL cannot be parsed or is not accepted
- Follows Google redirects automatically
- Extracts base URL
- Delegates to
fromUrl(url, baseUrl) - Wraps result in ListLinkHandler with empty filters
Build a ListLinkHandler from a URL and base URL.Parameters:
url(String) - The URL without Google redirects. Must not be null.baseUrl(String) - The base URL
NullPointerException- If URL is nullParsingException- If URL is not accepted or cannot be parsed
- Calls parent
LinkHandlerFactory.fromUrl(url, baseUrl) - Wraps the LinkHandler in a new ListLinkHandler with empty filters
Build a ListLinkHandler from a resource ID.Parameters:
id(String) - The resource ID. Must not be null.
NullPointerException- If ID is nullParsingException- If URL cannot be constructed from ID
- Calls parent
LinkHandlerFactory.fromId(id) - Wraps result in ListLinkHandler with empty filters
Build a ListLinkHandler from a resource ID and base URL.Parameters:
id(String) - The resource ID. Must not be null.baseUrl(String) - The base URL
NullPointerException- If ID is nullParsingException- If URL cannot be constructed
- Calls parent
LinkHandlerFactory.fromId(id, baseUrl) - Wraps result in ListLinkHandler with empty filters
Build a ListLinkHandler from an ID with specific content and sort filters. This is the primary method for creating filtered list handlers.Parameters:
id(String) - The resource IDcontentFilters(List<String>) - Content type filters to applysortFilter(String) - Sort order to apply
ParsingException- If URL cannot be constructed with filters
- Constructs URL using
getUrl(id, contentFilters, sortFilter) - Creates ListLinkHandler with URL, ID, and filters
- Both originalUrl and url are set to the same constructed URL
fromQuery
ListLinkHandler fromQuery(String id, List<String> contentFilters, String sortFilter, String baseUrl)
Build a ListLinkHandler from an ID with filters and base URL.Parameters:
id(String) - The resource IDcontentFilters(List<String>) - Content type filterssortFilter(String) - Sort orderbaseUrl(String) - The base URL
ParsingException- If URL cannot be constructed
- Constructs URL using
getUrl(id, contentFilters, sortFilter, baseUrl) - Creates ListLinkHandler with URL, ID, and filters
Construct a URL from an ID without any filters. Inherited from LinkHandlerFactory.Parameters:
id(String) - The resource ID
ParsingException- If URL cannot be constructedUnsupportedOperationException- If not supported
- Calls
getUrl(id, new ArrayList<>(0), "")with empty filters - This maintains compatibility with the base LinkHandlerFactory
Construct a URL from an ID and base URL without filters. Inherited from LinkHandlerFactory.Parameters:
id(String) - The resource IDbaseUrl(String) - The base URL
ParsingException- If URL cannot be constructed
- Calls
getUrl(id, new ArrayList<>(0), "", baseUrl)with empty filters - Maintains compatibility with base class
ListLinkHandler Class
TheListLinkHandler class extends LinkHandler with filter support:
Immutable data class that holds URL, ID, and filter information.Constructors:Inherited Fields:
originalUrl(String) - The URL as originally providedurl(String) - The cleaned/normalized URLid(String) - The extracted resource ID
contentFilters(List<String>) - Immutable list of content type filterssortFilter(String) - The sort filter
- All methods from LinkHandler:
getOriginalUrl(),getUrl(),getId(),getBaseUrl() List<String> getContentFilters()- Returns unmodifiable list of content filtersString getSortFilter()- Returns the sort filter
contentFilters list is wrapped with Collections.unmodifiableList() to ensure it cannot be modified after creation.Implementation Example
Usage Example
Filter Design Guidelines
-
Content Filters: Should represent different types or categories of content
- Keep names lowercase and consistent
- Use plural forms (“videos”, “playlists”)
- Match the service’s terminology
-
Sort Filters: Should represent ordering mechanisms
- Use descriptive names (“recent”, “popular”, not “r”, “p”)
- Be consistent across your service implementations
- Document expected behavior
-
Multiple Filters: If supporting multiple content filters simultaneously
- Document the order of precedence
- Consider how filters interact
- Handle conflicts gracefully
-
Empty Filters: Always handle empty filter lists and strings
- Empty list means “no filter” or “default view”
- Empty string for sort means “default sort order”
Best Practices
- Filter Validation: Validate filters in
getUrl()before building the URL - Default Behavior: Define clear default behavior when no filters are provided
- Document Filters: Clearly document what each filter does in your implementation
- Compatibility: Ensure
fromUrl()works with URLs that have filters embedded - Immutability: Never modify the contentFilters list parameter
See Also
- Link Handler System Overview
- LinkHandlerFactory - Base factory class
- SearchQueryHandlerFactory - For search queries