Class AbstractTargetedUrlStrategy

java.lang.Object
org.craftercms.engine.targeting.impl.AbstractTargetedUrlStrategy
All Implemented Interfaces:
TargetedUrlStrategy
Direct Known Subclasses:
TargetedUrlByFileStrategy, TargetedUrlByFolderStrategy

public abstract class AbstractTargetedUrlStrategy extends Object implements TargetedUrlStrategy
TargetedUrlStrategy base class, that provides basic implementations of parseTargetedUrl(String) and buildTargetedUrl(String, String, String).
Author:
avasquez
  • Field Details

  • Constructor Details

    • AbstractTargetedUrlStrategy

      public AbstractTargetedUrlStrategy()
  • Method Details

    • setTargetIdManager

      public void setTargetIdManager(TargetIdManager targetIdManager)
    • toTargetedUrl

      public String toTargetedUrl(String url, boolean forceCurrentTargetId)
      Description copied from interface: TargetedUrlStrategy
      Returns the specified URL as a targeted URL (if it's not already a targeted URL) using the current target ID. For example, if the specified URL is /products/index.xml, the current target ID is "en_US", and the strategy handles targeted URLs by file name, then the resulting targeted URL is /products/index_en_US.xml.

      WARNING: The URLs strategies should receive should be relative, without the root folder, since most targeted URLs are handled using a regex.

      Specified by:
      toTargetedUrl in interface TargetedUrlStrategy
      Parameters:
      url - the URL to transform to a targeted URL
      forceCurrentTargetId - true if the URL should be forced to contain the current target ID (e.g the URL is /products/index_fr.xml but the current target ID is en, then the URL will be transformed to /products/index_en.xml)
      Returns:
      the targeted URL version of the URL.
    • parseTargetedUrl

      public TargetedUrlComponents parseTargetedUrl(String targetedUrl)
      Description copied from interface: TargetedUrlStrategy
      Parses the specified targeted URL, extracting it's components. For example, if the specified URL is /products/index_en_US.xml, and the strategy handles targeted URLs by file name, then the URL will be split into the following:
      • Prefix: /products/index
      • Target ID: en_US
      • Suffix: .xml
      Specified by:
      parseTargetedUrl in interface TargetedUrlStrategy
      Parameters:
      targetedUrl - the targeted URL to parse
      Returns:
      the URL components
    • buildTargetedUrl

      public String buildTargetedUrl(String prefix, String targetId, String suffix)
      Description copied from interface: TargetedUrlStrategy
      Builds the targeted URL with the specified prefix, target ID and suffix. For example, if the prefix is /products/index, the target ID en_US, the suffix .xml, and the strategy handles targeted URLs by file name, then the resulting URL will be /products/index_en_US.xml.
      Specified by:
      buildTargetedUrl in interface TargetedUrlStrategy
      Parameters:
      prefix - the URL prefix
      targetId - the target ID
      suffix - the URL suffix
      Returns:
      the built targeted URL
    • matchUrl

      protected Matcher matchUrl(String url)
    • getTargetedUrlComponents

      protected TargetedUrlComponents getTargetedUrlComponents(Matcher matcher)
    • getPrefix

      protected abstract String getPrefix(Matcher matcher)
    • getTargetId

      protected abstract String getTargetId(Matcher matcher)
    • getSuffix

      protected abstract String getSuffix(Matcher matcher)
    • getTargetedUrlPattern

      protected abstract Pattern getTargetedUrlPattern()
    • doToTargetedUrl

      protected abstract String doToTargetedUrl(String url, String currentTargetId)