/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { Locale } from "../../types/java/util/Locale"; import type { String } from "../../types/java/lang/String"; /** * FileIconRenderer is a stateful utility interface that can be used to render valid xhtml img elements based on the file icons of the website. * *

* An instance of the Sitevision class implementing this interface can be obtained via {@link senselogic.sitevision.api.Utils#getFileIconRenderer()}. * See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface. *

* *

* FileIconRenderer is very suitable when rendering more than one file icon (for instance when rendering a search result where different icons should * be displayed for different types of hits) or if you don't want to bother about how to get file icons from the icon repository of the site. *

* *

* FileIconRenderer has few attributes: *

* * *

* ---------------------------------------------------------------------------------------------------- *

* *

* Using the FileIconRenderer is pretty straightforward, if you remember that it is stateful and that previously loaded icons * will be cleared whenever you try to load new ones. * Conceptually you would typically use it like this: *

*
    *
  1. Get the FileIconRenderer
  2. *
  3. Possibly init the renderer with rendering settings (locale, useSmallIcons, description)
  4. *
  5. Possibly load the renderer with a default icon
  6. *
  7. Load a file icon
  8. *
  9. Do render
  10. *
*

* When you have rendered once, you can re-use the FileIconRenderer until you are done. Something like: *

*
    *
  1. Load a new icon.
  2. *
  3. Do render.
  4. *
* *

* Loading of an icon can be done using: *

* *

* Whenever you try to load the renderer with an icon, the (possibly) previously loaded icon will be cleared. * If loading fails, no result will be rendered by default (i.e. an empty string will be the output when calling the render method). * If a default icon has been loaded successfully, it will be the output if the renderer contains no icon. * (Note that the result of every icon loading is cached for best performance, hence no need for you to do the same in your code.) *

*

* Please note that all load methods return a boolean! To prevent the boolean to be part of the page output you might in * some cases need to do a workaround. The set statement for $ignore in below example demonstrates a simple workaround. *

* *

* Example of how this strategy could be implemented in Velocity:
* (You want to do a simple listing of all nodes in a collection/iterator "$items" and use FileIconRenderer to render the file icons of all items * that has a configured file icon *

*

 *    ## Get PropertyUtil to ease Node property fetching
 *    #set ($propertyUtil = $sitevisionUtils.propertyUtil)
 *
 *    ## Get FileIconRenderer
 *    #set ($iconRenderer = $sitevisionUtils.fileIconRenderer)
 *
 *    ## Iterate through items and render the names and file icons (if they exist)
 *    <ul style="list-style:none">
 *    #foreach ($item in $items)
 *       ## Try to load the renderer by the item's uri (e.g. "/aPath/aFile.pdf")
 *       #if (!$iconRenderer.loadIconByURI(${propertyUtil.getString($item, 'URI')}))
 *          ## If loading failed, try to load the renderer by the item's content type instead (e.g. "application/pdf")
 *          #set ($ignore = $iconRenderer.loadIconByContentType(${propertyUtil.getString($item, 'mimeType')}))
 *       #end
 *
 *       <li>
 *          ## Render the name of the node
 *          $propertyUtil.getString($item, 'displayName', '')
 *          ## Render the file icon of the node (if no icon was loaded, an empty string will be rendered)
 *          $iconRenderer.render()
 *       </li>
 *    #end
 *    </ul>
 *  
* *
* Tip! If you use Velocity and call a load method, you must suppress the boolean result so * it doesn't get a part of the rendered output. The above example contains an assignment workaround to suppress the load result:
*
   #set ($ignore = $iconRenderer.loadIconByContentType(${propertyUtil.getString($item, 'mimeType')}))
* This type of workaround can also be achieved via the swallow method of {@link senselogic.sitevision.api.script.ScriptUtil} as:
*
   $scriptUtil.swallow($iconRenderer.loadIconByContentType(${propertyUtil.getString($item, 'mimeType')}))
*
* *

* Since FileIconRenderer is stateful and likely will be used in Velocity frequently, there are some "shortcuts" that might be useful. * Due to the lack of proper boolean support in Velocity, the boolean attributes has corresponding force/clear methods to set the boolean * to true/false. For example: *

* * @author Magnus Lövgren * @since Sitevision 2.6.1_08 * @deprecated */ export interface FileIconRenderer { /** * The locale to use when extracting the decription of file icons. *

Default is the locale of the currently executing portlet.

*

* Note! Icons (icon and default icon) that has been loaded with a different locale will be removed whenever an invocation * of this method changes the locale. *

* @param aLocale the locale to use when extracting the icon description */ setLocale(aLocale: Locale): void; /** * Which type if file icons (small or large) that should be rendered. *

Default is true.

*

* Note! Icons (icon and default icon) that has been loaded with a different useSmallIcons state will be removed whenever * an invocation of this method changes the useSmallIcons state. *

* @param aUseSmallIcons whether or not to use small icons (true == "use small icons", false == "use large icons") */ setUseSmallIcons(aUseSmallIcons: boolean): void; /** * Utility method for executing setUseSmallIcons(false), i.e. "use large icons when rendering". * @see #setUseSmallIcons(boolean) */ clearUseSmallIcons(): void; /** * Utility method for executing setUseSmallIcons(true), i.e. "use small icons when rendering". * @see #setUseSmallIcons(boolean) */ forceUseSmallIcons(): void; /** * If file icon descriptions should be used or not. *

Default is true.

*

Note that file icon descriptions may be locale-dependent, see {@link #setLocale(java.util.Locale)}.

* @param aUseDescription whether or not a file icon description should be used when rendering */ setUseDescription(aUseDescription: boolean): void; /** * Utility method for executing setUseDescription(false), i.e. "don't use description when rendering". * @see #setUseDescription(boolean) */ clearUseDescription(): void; /** * Utility method for executing setUseDescription(true), i.e. "use description when rendering". * @see #setUseDescription(boolean) */ forceUseDescription(): void; /** * Uses a content type to load the fallback icon that should be used when rendering if no icon is loaded. * @param aContentType the content type (mime type) that decides what file icon to load * @return true if a default file icon was loaded, false if not */ loadDefaultIconByContentType(aContentType: String | string): boolean; /** * Uses a URI to load the fallback icon that should be used when rendering if no icon is loaded. *

* This method tries to extract a file extension from the URI and use that extension to load the default file icon. * If the URI doesn't end with a file extension, default icon loading will fail. *

* @param aURI the uri that decides what file icon to load * @return true if a default file icon was loaded, false if not */ loadDefaultIconByURI(aURI: String | string): boolean; /** * Uses a file extension to load the fallback icon that should be used when rendering if no icon is loaded. * @param aFileExtension the file extension that decides what file icon to load * @return true if a default file icon was loaded, false if not */ loadDefaultIconByFileExtension(aFileExtension: String | string): boolean; /** * Whether or not a default icon is loaded. * @return true if a default icon is loaded, false if not. */ isDefaultIconLoaded(): boolean; /** * Removes loaded default icon (does nothing if no default icon is loaded) */ clearDefaultIcon(): void; /** * Uses a content type to load the icon that should be rendered. * @param aContentType the content type (mime type) that decides what file icon to load * @return true if a file icon was loaded, false if not */ loadIconByContentType(aContentType: String | string): boolean; /** * Uses a URI to load the icon that should be rendered. *

* This method tries to extract a file extension from the URI and use that extension to load the icon. * If the URI doesn't end with a file extension, icon loading will fail. *

* @param aURI the URI that decides what file icon to load * @return true if a file icon was loaded, false if not */ loadIconByURI(aURI: String | string): boolean; /** * Uses a URI to load the icon that should be rendered. * @param aFileExtension the file extension that decides what file icon to load * @return true if a file icon was loaded, false if not */ loadIconByFileExtension(aFileExtension: String | string): boolean; /** * Whether or not an icon is loaded. * @return true if an icon is loaded, false if not. */ isIconLoaded(): boolean; /** * Removes loaded icon (does nothing if no icon is loaded) */ clearIcon(): void; /** * Sets the CSS class name(-s) to use when rendering. * @param aFontClass the CSS class name(-s) expression. An empty string is equivalent to null - no class attribute will be rendered * @since Sitevision 3.0 */ setFontClass(aFontClass: String | string): void; /** * Removes the CSS class name(-s). * No class attribute will be rendered until a fontClass is set again. * @since Sitevision 3.0 */ clearFontClass(): void; /** * Builds a html img element based on current state. * @return a html img element based on current state, or empty string if no icon and no default icon was loaded */ render(): string; } declare namespace FileIconRenderer {} declare var fileIconRenderer: FileIconRenderer; export default fileIconRenderer;