Class StaticAssetPathServiceImpl

java.lang.Object
org.broadleafcommerce.common.file.service.StaticAssetPathServiceImpl
All Implemented Interfaces:
StaticAssetPathService

@Service("blStaticAssetPathService") public class StaticAssetPathServiceImpl extends Object implements StaticAssetPathService
  • Field Details

    • staticAssetUrlPrefix

      @Value("${asset.server.url.prefix.internal}") protected String staticAssetUrlPrefix
    • staticAssetEnvironmentUrlPrefix

      @Value("${asset.server.url.prefix}") protected String staticAssetEnvironmentUrlPrefix
    • staticAssetEnvironmentSecureUrlPrefix

      @Value("${asset.server.url.prefix.secure}") protected String staticAssetEnvironmentSecureUrlPrefix
  • Constructor Details

    • StaticAssetPathServiceImpl

      public StaticAssetPathServiceImpl()
  • Method Details

    • convertAllAssetPathsInContent

      public String convertAllAssetPathsInContent(String content, boolean secureRequest)
      This method will take in a content string (e.g. StructuredContentDTO or PageDTO HTML/ASSET_LOOKUP/STRING field value) and replace any instances of "staticAssetUrlPrefix" in the string with the "staticAssetEnvironmentUrlPrefix" or the "staticAssetEnvironmentSecureUrlPrefix" depending on if the request was secure and if it was configured.

      Given asset.server.url.prefix.internal=cmsstatic Given asset.server.url.prefix=http://static.mydomain.com/cmsstatic Given asset.server.url.prefix.secure=https://static.mydomain.com/cmsstatic

      Example 1: Given content = "

      "

      The result should yield: "

      "

      Example 2: Given content = "

      "

      The result should yield: "

      "
      Specified by:
      convertAllAssetPathsInContent in interface StaticAssetPathService
      Parameters:
      content - - The content string to rewrite if it contains a cms managed asset
      secureRequest - - True if the request is being served over https
      Returns:
      See Also:
      • org.broadleafcommerce.common.file.service.StaticAssetService#getStaticAssetUrlPrefix()
      • org.broadleafcommerce.common.file.service.StaticAssetService#getStaticAssetEnvironmentUrlPrefix()
    • convertAssetPath

      public String convertAssetPath(String assetPath, String contextPath, boolean secureRequest)
      This method will take in an assetPath (think image url) and prepend the staticAssetUrlPrefix if one exists.

      Will append any contextPath onto the request. If the incoming assetPath contains the internalStaticAssetPrefix and the image is being prepended, the prepend will be removed.

      Example 1: Given asset.server.url.prefix.internal=cmsstatic Given asset.server.url.prefix=http://static.mydomain.com/cmsstatic Given asset.server.url.prefix.secure=https://static.mydomain.com/cmsstatic Given assetPath = "/cmsstatic/my_image.jpg"

      The result should yield: "http://static.mydomain.com/cmsstatic/my_image.jpg"

      Example 2: Given asset.server.url.prefix.internal=cmsstatic Given asset.server.url.prefix= Given asset.server.url.prefix.secure= Given assetPath = "/cmsstatic/my_image.jpg" Given contextPath = "myApp"

      The result should yield: "/myApp/cmsstatic/my_image.jpg"

      Also, since all paths are intended to be URLs, there should be no system-specific separator characters like '\' for Windows. All paths should be unix file paths as URLs.

      Specified by:
      convertAssetPath in interface StaticAssetPathService
      Parameters:
      assetPath - - The path to rewrite if it is a cms managed asset
      contextPath - - The context path of the web application (if applicable)
      secureRequest - - True if the request is being served over https
      Returns:
      See Also:
      • org.broadleafcommerce.common.file.service.StaticAssetService#getStaticAssetUrlPrefix()
      • org.broadleafcommerce.common.file.service.StaticAssetService#getStaticAssetEnvironmentUrlPrefix()
    • getStaticAssetUrlPrefix

      public String getStaticAssetUrlPrefix()
      Description copied from interface: StaticAssetPathService
      Returns the value configured to mark an item as a static URL.

      OOB BLC maintains this value in common.properties.

      Specified by:
      getStaticAssetUrlPrefix in interface StaticAssetPathService
    • setStaticAssetUrlPrefix

      public void setStaticAssetUrlPrefix(String staticAssetUrlPrefix)
      Description copied from interface: StaticAssetPathService
      Sets the static asset url prefix
      Specified by:
      setStaticAssetUrlPrefix in interface StaticAssetPathService
    • getStaticAssetEnvironmentUrlPrefix

      public String getStaticAssetEnvironmentUrlPrefix()
      Description copied from interface: StaticAssetPathService
      Returns the value configured for the current environment for the static asset url prefix. If this is different than the common value, then the URLs will get rewritten by the FieldMapWrapper when called from the DisplayContentTag or ProcessURLFilter.
      Specified by:
      getStaticAssetEnvironmentUrlPrefix in interface StaticAssetPathService
    • setStaticAssetEnvironmentUrlPrefix

      public void setStaticAssetEnvironmentUrlPrefix(String staticAssetEnvironmentUrlPrefix)
      Description copied from interface: StaticAssetPathService
      Sets the environment url prefix.
      Specified by:
      setStaticAssetEnvironmentUrlPrefix in interface StaticAssetPathService
    • getStaticAssetEnvironmentSecureUrlPrefix

      public String getStaticAssetEnvironmentSecureUrlPrefix()
      Description copied from interface: StaticAssetPathService
      Returns the secure value of the environment url prefix (e.g. prefixed with https if needed).
      Specified by:
      getStaticAssetEnvironmentSecureUrlPrefix in interface StaticAssetPathService
    • setStaticAssetEnvironmentSecureUrlPrefix

      public void setStaticAssetEnvironmentSecureUrlPrefix(String staticAssetEnvironmentSecureUrlPrefix)
    • addThemeContextIfNeeded

      protected String addThemeContextIfNeeded(String assetURL)