com.ibm.commerce.seo.url.helpers

Class SEOURLMapperImpl

  • java.lang.Object
    • com.ibm.commerce.seo.url.helpers.SEOURLMapperImpl
  • All Implemented Interfaces:
    SEOURLMapper


    public class SEOURLMapperImpl
    extends java.lang.Object
    implements SEOURLMapper
    This class is the default implementation for the SEOURLMapper interface.
    See Also:
    SEOURLMapper
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String CLASSNAME
      Class name field.
      static java.lang.String COPYRIGHT
      IBM copyright field.
    • Constructor Summary

      Constructors 
      Constructor and Description
      SEOURLMapperImpl()
      Default constructor for the class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.util.Map<java.lang.String,java.lang.String> buildTokenNameUrlKeywordMapForPattern(com.ibm.commerce.seo.url.configuration.SEOURLPatternType pattern, com.ibm.commerce.seo.url.configuration.SEOURLPatternConfiguration patternConfiguration, TypedProperty properties, java.lang.String device)
      This method builds the URL token name and keyword map for the specified pattern using the request properties provided.
      java.lang.String constructDynamicURLByPatternName(java.lang.String patternName, TypedProperty requestProperties, javax.servlet.jsp.PageContext pageContext)
      This method constructs the dynamic url using the patternName and set of request properties.
      java.lang.String constructSEOURLByPatternName(java.lang.String patternName, TypedProperty requestProperties, javax.servlet.jsp.PageContext pageContext, java.lang.String mappingName, java.util.Map params)
      This method constructs the SEO URL using the URL pattern name and request properties specified.
      java.util.List<java.lang.String> constructSEOUrlPrefixByUsageAndDevice(java.lang.String usage, java.lang.String device, TypedProperty urlProperties)
      This method constructs all the valid URL prefixes for the usage and device specified.The method looks up all the URL pattern configurations for the store specified based on the usage to find all the applicable URL patterns.
      javax.servlet.http.HttpServletRequest deconstructHttpRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Integer storeId)
      This method deconstructs the incoming SEO URL to its dynamic equivalent.
      java.lang.Integer getStoreIdFromSEOURL(java.lang.String seoURL)
      This method parses the input seoUrl and returns storeId.
      java.lang.String getStoreKeywordFromSEOURL(java.lang.String seoUrl)
      This method returns the store keyword present in the SEO URL
      boolean isSEOURLPatternFeatureEnabled(java.lang.Integer storeId)
      If SEO URL pattern based feature is enabled at instance level, then this method checks to see if SEO URL pattern based feature is enabled for the given store or not.
      java.util.List processRequestURL(javax.servlet.http.HttpServletRequest request)
      This method checks if the incoming URL in the request is actually an SEO URL or not.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM copyright field.
        See Also:
        Constant Field Values
      • CLASSNAME

        public static final java.lang.String CLASSNAME
        Class name field.
    • Constructor Detail

      • SEOURLMapperImpl

        public SEOURLMapperImpl()
        Default constructor for the class.
    • Method Detail

      • constructSEOUrlPrefixByUsageAndDevice

        public java.util.List<java.lang.String> constructSEOUrlPrefixByUsageAndDevice(java.lang.String usage,
                                                                                      java.lang.String device,
                                                                                      TypedProperty urlProperties)
                                                                               throws SEOApplicationException
        Description copied from interface: SEOURLMapper
        This method constructs all the valid URL prefixes for the usage and device specified.The method looks up all the URL pattern configurations for the store specified based on the usage to find all the applicable URL patterns. Using the identified patterns and the input parameters specified, it identifies the URL prefixes that can be constructed.

        The storeId and langId are expected to be passed in the request properties.

        The URL prefix would have the location of the primary token for the usage, tagged with a special marker. All the other tokens in the URL pattern would be fully resolved. The marker used to identify the primary token location in the URL is $SEO:PRIMARYTOKEN$.

                Assuming there is an URL pattern /StoreToken/LangToken/ProductToken for usage PRODUCT and device mobile,
         the method would construct the following URL prefix if the storeId, langId are specified in the properties.
         
         http://localhost/shop/Madisons/en/$SEO:PRIMARYTOKEN$
         
         Where, 
         localhost is the host name for the web server, 
         //shop is the context root simplification defined for the site
         Madisons/en/$SEO:PRIMARYTOKEN$ is the URL prefix.
         
         
        Specified by:
        constructSEOUrlPrefixByUsageAndDevice in interface SEOURLMapper
        Parameters:
        usage - The usage of the URL prefixes being constructed. For example, ITEM, PRODUCT etc.
        device - The device for which the URL is being constructed. Values supported are: SEOConstants#DEVICE_TYPE_MOBILE or SEOConstants#DEVICE_TYPE_STANDARD_BROWSER
        urlProperties - The input properties to construct the URL prefix.
        Returns:
        A list of valid URL prefixes if found. An empty list otherwise.
        Throws:
        SEOApplicationException
      • deconstructHttpRequest

        public javax.servlet.http.HttpServletRequest deconstructHttpRequest(javax.servlet.http.HttpServletRequest request,
                                                                            javax.servlet.http.HttpServletResponse response,
                                                                            java.lang.Integer storeId)
                                                                     throws SEOApplicationException
        Description copied from interface: SEOURLMapper
        This method deconstructs the incoming SEO URL to its dynamic equivalent. The method parses the incoming URL to match a specific URL pattern defined for a specific store. If a valid match is found, the method builds the dynamic properties and sets it as the request properties for the struts view defined in the pattern.
        Specified by:
        deconstructHttpRequest in interface SEOURLMapper
        Parameters:
        request - The incoming servlet request.
        response - The incoming servlet response object.
        storeId - - Store Id for which the url needs to be deconstructed
        Returns:
        The converted servlet request containing the struts view and the deconstructed request properties.
        Throws:
        SEOApplicationException
      • buildTokenNameUrlKeywordMapForPattern

        public java.util.Map<java.lang.String,java.lang.String> buildTokenNameUrlKeywordMapForPattern(com.ibm.commerce.seo.url.configuration.SEOURLPatternType pattern,
                                                                                                      com.ibm.commerce.seo.url.configuration.SEOURLPatternConfiguration patternConfiguration,
                                                                                                      TypedProperty properties,
                                                                                                      java.lang.String device)
                                                                                               throws SEOApplicationException
        This method builds the URL token name and keyword map for the specified pattern using the request properties provided. This map is then used to replace the appropriate tokens in the pattern to construct the SEO URL.
        Parameters:
        pattern - The SEOURLPatternType object that represents the URL for whom the map is being built.
        patternConfiguration - The SEOURLPatternConfiguration object that represents the pattern configuration for the store.
        properties - The request properties containing the values to be used to find the key words.
        device - The device type for which the pattern is being applied.
        Returns:
        A map containing the tokens in the URL pattern along with their respective keywords.
        Throws:
        SEOApplicationException - When an error occurs while building the map. Possible errors are:
        • The input properties does not have all the required values to find the keywords
        • A URL keyword has not been defined for the token in the pattern.
        • The value specified for a token in the request properties is invalid.
      • constructSEOURLByPatternName

        public java.lang.String constructSEOURLByPatternName(java.lang.String patternName,
                                                             TypedProperty requestProperties,
                                                             javax.servlet.jsp.PageContext pageContext,
                                                             java.lang.String mappingName,
                                                             java.util.Map params)
                                                      throws SEOApplicationException
        Description copied from interface: SEOURLMapper
        This method constructs the SEO URL using the URL pattern name and request properties specified. The storeId and langId are expected to be part of the request properties. If SEO URL based on pattern feature is needed, then patternName parameter is mandatory and should be non-null while mappingName will be ignored and null can be passed for mappingName If SEO URL based on mapper file feature is needed, then mappingName parameter is mandatory and should be non-null, while patternName will be ignored and null can be passed for patternName.
        Specified by:
        constructSEOURLByPatternName in interface SEOURLMapper
        Parameters:
        patternName - The URL pattern name to be used for constructing the SEO URL based on pattern feature.
        requestProperties - The input request properties for constructing the URL.
        pageContext - The page context of the page on which the URL is being constructed.
        mappingName - The mapping name used in old SEO implementation.
        params - Map of parameters passed to be used while constructing SEO URL based on mapping name. Will be ignored when construction is done based on patternName
        Returns:
        The SEO URL
        Throws:
        SEOApplicationException
      • isSEOURLPatternFeatureEnabled

        public boolean isSEOURLPatternFeatureEnabled(java.lang.Integer storeId)
        If SEO URL pattern based feature is enabled at instance level, then this method checks to see if SEO URL pattern based feature is enabled for the given store or not.
        Specified by:
        isSEOURLPatternFeatureEnabled in interface SEOURLMapper
        Parameters:
        storeId - - StoreId for which this check needs to be done
        Returns:
        true - if SEO based on URL pattern is enabled in instance XML and for the given storeId false, otherwise.
        See Also:
        SEOURLPatternConfigurationRegistry.isSEOURLPatternFeatureEnabled(Integer)
      • constructDynamicURLByPatternName

        public java.lang.String constructDynamicURLByPatternName(java.lang.String patternName,
                                                                 TypedProperty requestProperties,
                                                                 javax.servlet.jsp.PageContext pageContext)
                                                          throws SEOApplicationException
        Description copied from interface: SEOURLMapper
        This method constructs the dynamic url using the patternName and set of request properties. PageContext is used to retrieve the storeId and patternName is used to retrieve the viewName from the pattern. All the key/value pair in requestProperties are set as query parameters in the resulting URL.
        Specified by:
        constructDynamicURLByPatternName in interface SEOURLMapper
        Parameters:
        patternName - - Name of the pattern. ViewName will be retrieved based on this pattern name.
        requestProperties - - Request properties which goes in as query parameters in the resulting URL.
        pageContext - - JSP page context object.
        Returns:
        String - Dynamic URL
        Throws:
        SEOApplicationException
      • getStoreKeywordFromSEOURL

        public java.lang.String getStoreKeywordFromSEOURL(java.lang.String seoUrl)
        This method returns the store keyword present in the SEO URL
        Parameters:
        seoUrl - - SEO URL which will be parsed to find the store keyword
        Returns:
        String - Store keyword present in the SEO URL
      • getStoreIdFromSEOURL

        public java.lang.Integer getStoreIdFromSEOURL(java.lang.String seoURL)
        Description copied from interface: SEOURLMapper
        This method parses the input seoUrl and returns storeId. Input string is parsed and each token in the string is matched against the available tokens whose usageType is set to 'Store' SEOConfigurationRegistry#getAllStaticSEOTokenUsageTypesForStore(Integer). Token value of the matched token will be returned as storeId.
        Specified by:
        getStoreIdFromSEOURL in interface SEOURLMapper
        Parameters:
        seoURL - - Input string which will be tokenized and parsed.
        Returns:
        - storeId computed from input string
      • processRequestURL

        public java.util.List processRequestURL(javax.servlet.http.HttpServletRequest request)
        Description copied from interface: SEOURLMapper
        This method checks if the incoming URL in the request is actually an SEO URL or not. The string after the last / in the request path of the request object is used to do this check. The incoming URL is considered as SEO URL only if it satisfies all of the below conditions:
        • It doesn't match any entry in the old SEO URL mapper XML
        • It doesn't match any action entry defined in the struts XML for the stores web app
        • The path doesn't contain dot(.) Ex: index.jsp, furniture.jpeg are all non-SEO URL's
        • storeId is present in the request object or it can be deduced by parsing the incoming URL.
        • SEO Pattern feature is enabled for the current store.
        This method also modifies the request object in following scenario's:
        • If the request path is found to be dynamic, then it modifies the request path in the request object by replacing the request path with the computed relative path (subString after the last / in the request path)
        • If the storeId is not present in request object and if it can be computed by parsing the request path then the storeId will be added to the request object.
        Specified by:
        processRequestURL in interface SEOURLMapper
        Parameters:
        request - - HttpServletRequest object. Note that this object might be modified in certain scenario's.
        Returns:
        - List -- Returns an ArrayList with 3 elements
        • Element 0 -- Contains Boolean.TRUE if the incoming URL is SEO URL based on pattern feature. Otherwise, Boolean FALSE
        • Element 1 -- The modified HTTPServletRequest object
        • Element 3 -- An Integer object specifying the URL Type, with following convention: value 0 indicates unknown url type. value 1 indicates old SEO URL. value 2 indicates dynamic view/action. value 3 indicates new SEO URL based on pattern feature.