Class FessXpathTransformer

java.lang.Object
org.codelibs.fess.crawler.transformer.impl.AbstractTransformer
org.codelibs.fess.crawler.transformer.impl.HtmlTransformer
org.codelibs.fess.crawler.transformer.impl.XpathTransformer
org.codelibs.fess.crawler.transformer.FessXpathTransformer
All Implemented Interfaces:
FessTransformer, org.codelibs.fess.crawler.transformer.Transformer

public class FessXpathTransformer extends org.codelibs.fess.crawler.transformer.impl.XpathTransformer implements FessTransformer
A transformer implementation for processing HTML documents using XPath expressions. This class extends XpathTransformer to provide Fess-specific document processing capabilities including content extraction, metadata processing, and robots tag handling.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Map<String,String>
    Map containing URL conversion rules (regex patterns to replacement strings)
    protected DataSerializer
    Data serializer for converting objects to binary format
    protected org.codelibs.fess.mylasta.direction.FessConfig
    Fess configuration instance
    protected Map<String,Boolean>
    Map storing field pruning rules
    boolean
    Flag indicating whether content should be pruned
    protected Map<String,PrunedTag[]>
    Cache for storing parsed pruned tags by configuration ID
    protected boolean
    Flag indicating whether to process Google on/off comments

    Fields inherited from class org.codelibs.fess.crawler.transformer.impl.XpathTransformer

    charsetName, dataClass, fieldRuleMap, trimSpaceEnabled

    Fields inherited from class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer

    childUrlRuleMap, crawlerContainer, defaultEncoding, featureMap, invalidUrlPattern, LOCATION_HEADER, preloadSizeForCharset, propertyMap

    Fields inherited from class org.codelibs.fess.crawler.transformer.impl.AbstractTransformer

    name

    Fields inherited from interface org.codelibs.fess.crawler.transformer.FessTransformer

    parentEncodingMap
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addChildUrlFromTagAttribute(List<String> urlList, URL url, String attrValue, String encoding)
    Adds child URL from tag attribute value.
    void
    addConvertUrl(String regex, String replacement)
    Adds a URL conversion rule.
    void
    addFieldRule(String name, String xpath, boolean isPruned)
    Adds a field extraction rule with pruning option.
    protected List<org.codelibs.fess.crawler.entity.RequestData>
    convertChildUrlList(List<org.codelibs.fess.crawler.entity.RequestData> urlList)
    Converts and processes child URLs using path mapping and URL conversion rules.
    protected List<String>
    getAnchorList(Document document, org.codelibs.fess.crawler.entity.ResponseData responseData)
    Extracts anchor URLs from the HTML document.
    protected Integer
    Gets an attribute value as an integer.
    protected URL
    getBaseUrl(String currentUrl, String baseHref)
    Gets the base URL for resolving relative URLs.
    protected String
    getCanonicalUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
    Extracts the canonical URL from the HTML document.
    protected Stream<org.codelibs.core.misc.Pair<String,String>>
    getChildUrlRules(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
    Gets child URL extraction rules from configuration.
    protected Map<String,String>
    getConfigPrameterMap(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig.ConfigName config)
    Retrieves configuration parameter map for the given configuration name.
    protected String
    getContentXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
    Gets the XPath expression for extracting content.
    protected org.codelibs.fess.opensearch.config.exentity.CrawlingConfig
    getCrawlingConfig(org.codelibs.fess.crawler.entity.ResponseData responseData)
    Retrieves the crawling configuration for the given response data.
    getData(org.codelibs.fess.crawler.entity.AccessResultData<?> accessResultData)
    Deserializes data from access result data.
    protected String
    getDigestXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
    Gets the XPath expression for extracting digest information.
    org.codelibs.fess.mylasta.direction.FessConfig
    Returns the Fess configuration instance.
    protected String
    getLangXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
    Gets the XPath expression for extracting language information.
    org.apache.logging.log4j.Logger
    Returns the logger instance for this class.
    protected String
    Extracts text content from multiple nodes using XPath expression.
    Gets the path mapping helper for URL transformations.
    protected String
    getSingleNodeValue(Document document, String xpath, UnaryOperator<Node> pruneFunc)
    Extracts text content from a single node using XPath expression.
    protected String
    Extracts thumbnail source URL from image tag attributes.
    protected String
    getThumbnailUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
    Extracts thumbnail URL from the HTML document.
    protected URL
    getURL(String currentUrl, String url)
    Creates a URL object from the current URL and a relative or absolute URL string.
    void
    Initializes the transformer after dependency injection.
    protected boolean
    isPrunedTag(Node node, PrunedTag[] prunedTags)
    Checks if a node matches any of the pruned tag configurations.
    protected boolean
    isValidCanonicalUrl(String url, String canonicalUrl)
    Validates if the canonical URL is valid relative to the original URL.
    protected boolean
    Validates if the given URL string is a valid URL.
    protected String
    normalizeCanonicalUrl(String baseUrl, String canonicalUrl)
    Normalizes the canonical URL relative to the base URL.
    protected void
    normalizeData(org.codelibs.fess.crawler.entity.ResponseData responseData, Map<String,Object> dataMap)
    Normalizes the extracted data, particularly handling title normalization.
    protected void
    Recursively parses text content from a node and its children.
    protected Map<String,Object>
    processAdditionalData(Map<String,Object> dataMap, org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
    Processes additional data including canonical URLs, content extraction, and metadata.
    protected Node
    processGoogleOffOn(Node node, org.codelibs.core.misc.ValueHolder<Boolean> flag)
    Processes Google on/off comment directives in the node.
    protected void
    processMetaRobots(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData, Document document)
    Processes robots meta tags in the HTML document.
    protected void
    processXRobotsTag(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
    Processes X-Robots-Tag HTTP headers.
    protected Node
    pruneNode(Node node, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig crawlingConfig)
    Prunes unwanted tags from the node based on configuration.
    protected Node
    pruneNodeByTags(Node node, PrunedTag[] prunedTags)
    Prunes nodes based on the specified pruned tags.
    protected void
    putResultDataContent(Map<String,Object> dataMap, org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.mylasta.direction.FessConfig fessConfig, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig crawlingConfig, DocumentHelper documentHelper, String body, String fileName)
    Puts content data into the result data map.
    protected String
    Removes HTML comment tags from the content.
    protected String
    Replaces duplicate hosts in the URL using the duplicate host helper.
    void
    Sets the URL conversion map for transforming URLs.
    void
    setUseGoogleOffOn(boolean useGoogleOffOn)
    Sets whether to process Google on/off comment directives.
    protected void
    storeData(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
    Stores parsed data from response into result data.

    Methods inherited from class org.codelibs.fess.crawler.transformer.impl.XpathTransformer

    addFieldRule, getAdditionalData, getCharsetName, getDataClass, getFieldRuleMap, getResultDataBody, getResultDataBody, getResultDataFooter, getResultDataHeader, isTrimSpace, setCharsetName, setDataClass, setFieldRuleMap, setTrimSpace, trimSpace

    Methods inherited from class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer

    addChildUrlRule, addFeature, addProperty, encodeUrl, getBaseHref, getChildUrlRuleMap, getDefaultEncoding, getDomParser, getDuplicateUrl, getFeatureMap, getInvalidUrlPattern, getPreloadSizeForCharset, getPropertyMap, getUrlFromTagAttribute, getXPathAPI, isHtml, isSupportedCharset, isValidPath, loadCharset, normalizeEncoding, normalizeUrl, parseCharset, setChildUrlRuleMap, setDefaultEncoding, setFeatureMap, setInvalidUrlPattern, setPreloadSizeForCharset, setPropertyMap, storeChildUrls, storeChildUrls, transform, updateCharset

    Methods inherited from class org.codelibs.fess.crawler.transformer.impl.AbstractTransformer

    getName, setName

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • prunedContent

      public boolean prunedContent
      Flag indicating whether content should be pruned
    • convertUrlMap

      protected Map<String,String> convertUrlMap
      Map containing URL conversion rules (regex patterns to replacement strings)
    • fessConfig

      protected org.codelibs.fess.mylasta.direction.FessConfig fessConfig
      Fess configuration instance
    • dataSerializer

      protected DataSerializer dataSerializer
      Data serializer for converting objects to binary format
    • useGoogleOffOn

      protected boolean useGoogleOffOn
      Flag indicating whether to process Google on/off comments
    • fieldPrunedRuleMap

      protected Map<String,Boolean> fieldPrunedRuleMap
      Map storing field pruning rules
    • prunedTagsCache

      protected Map<String,PrunedTag[]> prunedTagsCache
      Cache for storing parsed pruned tags by configuration ID
  • Constructor Details

    • FessXpathTransformer

      public FessXpathTransformer()
      Default constructor.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the transformer after dependency injection. Sets up the Fess configuration and data serializer components.
    • getFessConfig

      public org.codelibs.fess.mylasta.direction.FessConfig getFessConfig()
      Returns the Fess configuration instance.
      Specified by:
      getFessConfig in interface FessTransformer
      Returns:
      the Fess configuration
    • getLogger

      public org.apache.logging.log4j.Logger getLogger()
      Returns the logger instance for this class.
      Specified by:
      getLogger in interface FessTransformer
      Returns:
      the logger instance
    • storeData

      protected void storeData(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
      Stores parsed data from response into result data. Processes HTML content using XPath expressions and handles robots tags.
      Overrides:
      storeData in class org.codelibs.fess.crawler.transformer.impl.XpathTransformer
      Parameters:
      responseData - the response data from crawling
      resultData - the result data to store processed information
    • normalizeData

      protected void normalizeData(org.codelibs.fess.crawler.entity.ResponseData responseData, Map<String,Object> dataMap)
      Normalizes the extracted data, particularly handling title normalization.
      Parameters:
      responseData - the response data from crawling
      dataMap - the data map containing extracted field values
    • processMetaRobots

      protected void processMetaRobots(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData, Document document)
      Processes robots meta tags in the HTML document. Handles noindex, nofollow, and none directives.
      Parameters:
      responseData - the response data from crawling
      resultData - the result data to store processed information
      document - the parsed HTML document
    • processXRobotsTag

      protected void processXRobotsTag(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
      Processes X-Robots-Tag HTTP headers. Handles noindex, nofollow, and none directives from HTTP headers.
      Parameters:
      responseData - the response data from crawling
      resultData - the result data to store processed information
    • getConfigPrameterMap

      protected Map<String,String> getConfigPrameterMap(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig.ConfigName config)
      Retrieves configuration parameter map for the given configuration name.
      Parameters:
      responseData - the response data from crawling
      config - the configuration name to retrieve
      Returns:
      map of configuration parameters
    • isValidUrl

      protected boolean isValidUrl(String urlStr)
      Validates if the given URL string is a valid URL.
      Parameters:
      urlStr - the URL string to validate
      Returns:
      true if the URL is valid, false otherwise
    • isValidCanonicalUrl

      protected boolean isValidCanonicalUrl(String url, String canonicalUrl)
      Validates if the canonical URL is valid relative to the original URL. Specifically checks for HTTPS to HTTP downgrades.
      Parameters:
      url - the original URL
      canonicalUrl - the canonical URL to validate
      Returns:
      true if the canonical URL is valid, false otherwise
    • processAdditionalData

      protected Map<String,Object> processAdditionalData(Map<String,Object> dataMap, org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
      Processes additional data including canonical URLs, content extraction, and metadata.
      Parameters:
      dataMap - the data map to populate
      responseData - the response data from crawling
      document - the parsed HTML document
      Returns:
      the processed data map
    • putResultDataContent

      protected void putResultDataContent(Map<String,Object> dataMap, org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.mylasta.direction.FessConfig fessConfig, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig crawlingConfig, DocumentHelper documentHelper, String body, String fileName)
      Puts content data into the result data map.
      Parameters:
      dataMap - the data map to populate
      responseData - the response data from crawling
      fessConfig - the Fess configuration
      crawlingConfig - the crawling configuration
      documentHelper - the document helper for content processing
      body - the extracted body content
      fileName - the file name if applicable
    • getCrawlingConfig

      protected org.codelibs.fess.opensearch.config.exentity.CrawlingConfig getCrawlingConfig(org.codelibs.fess.crawler.entity.ResponseData responseData)
      Retrieves the crawling configuration for the given response data.
      Parameters:
      responseData - the response data from crawling
      Returns:
      the crawling configuration
    • getLangXpath

      protected String getLangXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
      Gets the XPath expression for extracting language information.
      Parameters:
      fessConfig - the Fess configuration
      xpathConfigMap - the XPath configuration map
      Returns:
      the XPath expression for language extraction
    • getContentXpath

      protected String getContentXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
      Gets the XPath expression for extracting content.
      Parameters:
      fessConfig - the Fess configuration
      xpathConfigMap - the XPath configuration map
      Returns:
      the XPath expression for content extraction
    • getDigestXpath

      protected String getDigestXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String,String> xpathConfigMap)
      Gets the XPath expression for extracting digest information.
      Parameters:
      fessConfig - the Fess configuration
      xpathConfigMap - the XPath configuration map
      Returns:
      the XPath expression for digest extraction
    • getCanonicalUrl

      protected String getCanonicalUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
      Extracts the canonical URL from the HTML document.
      Parameters:
      responseData - the response data from crawling
      document - the parsed HTML document
      Returns:
      the canonical URL if found, null otherwise
    • normalizeCanonicalUrl

      protected String normalizeCanonicalUrl(String baseUrl, String canonicalUrl)
      Normalizes the canonical URL relative to the base URL.
      Parameters:
      baseUrl - the base URL
      canonicalUrl - the canonical URL to normalize
      Returns:
      the normalized canonical URL
    • removeCommentTag

      protected String removeCommentTag(String content)
      Removes HTML comment tags from the content.
      Parameters:
      content - the content to process
      Returns:
      the content with comment tags removed
    • getSingleNodeValue

      protected String getSingleNodeValue(Document document, String xpath, UnaryOperator<Node> pruneFunc)
      Extracts text content from a single node using XPath expression.
      Parameters:
      document - the parsed HTML document
      xpath - the XPath expression to evaluate
      pruneFunc - the function to apply for node pruning
      Returns:
      the extracted text content
    • parseTextContent

      protected void parseTextContent(Node node, StringBuilder buf)
      Recursively parses text content from a node and its children.
      Parameters:
      node - the node to parse
      buf - the StringBuilder to append content to
    • processGoogleOffOn

      protected Node processGoogleOffOn(Node node, org.codelibs.core.misc.ValueHolder<Boolean> flag)
      Processes Google on/off comment directives in the node.
      Parameters:
      node - the node to process
      flag - the flag indicating whether content should be included
      Returns:
      the processed node
    • pruneNode

      protected Node pruneNode(Node node, org.codelibs.fess.opensearch.config.exentity.CrawlingConfig crawlingConfig)
      Prunes unwanted tags from the node based on configuration.
      Parameters:
      node - the node to prune
      crawlingConfig - the crawling configuration containing pruning rules
      Returns:
      the pruned node
    • pruneNodeByTags

      protected Node pruneNodeByTags(Node node, PrunedTag[] prunedTags)
      Prunes nodes based on the specified pruned tags.
      Parameters:
      node - the node to prune
      prunedTags - the array of pruned tag configurations
      Returns:
      the pruned node
    • isPrunedTag

      protected boolean isPrunedTag(Node node, PrunedTag[] prunedTags)
      Checks if a node matches any of the pruned tag configurations.
      Parameters:
      node - the node to check
      prunedTags - the array of pruned tag configurations
      Returns:
      true if the node should be pruned, false otherwise
    • getMultipleNodeValue

      protected String getMultipleNodeValue(Document document, String xpath)
      Extracts text content from multiple nodes using XPath expression.
      Parameters:
      document - the parsed HTML document
      xpath - the XPath expression to evaluate
      Returns:
      the concatenated text content from all matching nodes
    • replaceDuplicateHost

      protected String replaceDuplicateHost(String url)
      Replaces duplicate hosts in the URL using the duplicate host helper.
      Parameters:
      url - the URL to process
      Returns:
      the URL with duplicate hosts replaced
    • getAnchorList

      protected List<String> getAnchorList(Document document, org.codelibs.fess.crawler.entity.ResponseData responseData)
      Extracts anchor URLs from the HTML document.
      Parameters:
      document - the parsed HTML document
      responseData - the response data from crawling
      Returns:
      list of anchor URLs found in the document
    • getBaseUrl

      protected URL getBaseUrl(String currentUrl, String baseHref) throws MalformedURLException
      Gets the base URL for resolving relative URLs.
      Parameters:
      currentUrl - the current URL
      baseHref - the base href value from HTML
      Returns:
      the base URL
      Throws:
      MalformedURLException - if the URL is malformed
    • getChildUrlRules

      protected Stream<org.codelibs.core.misc.Pair<String,String>> getChildUrlRules(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData)
      Gets child URL extraction rules from configuration.
      Overrides:
      getChildUrlRules in class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer
      Parameters:
      responseData - the response data from crawling
      resultData - the result data
      Returns:
      stream of tag-attribute pairs for URL extraction
    • convertChildUrlList

      protected List<org.codelibs.fess.crawler.entity.RequestData> convertChildUrlList(List<org.codelibs.fess.crawler.entity.RequestData> urlList)
      Converts and processes child URLs using path mapping and URL conversion rules.
      Overrides:
      convertChildUrlList in class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer
      Parameters:
      urlList - the list of request data containing URLs to convert
      Returns:
      the converted list of request data
    • getPathMappingHelper

      protected PathMappingHelper getPathMappingHelper()
      Gets the path mapping helper for URL transformations.
      Returns:
      the path mapping helper instance
    • getData

      public Object getData(org.codelibs.fess.crawler.entity.AccessResultData<?> accessResultData)
      Deserializes data from access result data.
      Specified by:
      getData in interface org.codelibs.fess.crawler.transformer.Transformer
      Overrides:
      getData in class org.codelibs.fess.crawler.transformer.impl.XpathTransformer
      Parameters:
      accessResultData - the access result data containing serialized data
      Returns:
      the deserialized object
    • addChildUrlFromTagAttribute

      protected void addChildUrlFromTagAttribute(List<String> urlList, URL url, String attrValue, String encoding)
      Adds child URL from tag attribute value.
      Overrides:
      addChildUrlFromTagAttribute in class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer
      Parameters:
      urlList - the list to add URLs to
      url - the base URL for resolving relative URLs
      attrValue - the attribute value containing the URL
      encoding - the character encoding
    • setUseGoogleOffOn

      public void setUseGoogleOffOn(boolean useGoogleOffOn)
      Sets whether to process Google on/off comment directives.
      Parameters:
      useGoogleOffOn - true to enable Google on/off processing, false to disable
    • getThumbnailUrl

      protected String getThumbnailUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document)
      Extracts thumbnail URL from the HTML document. Looks for thumbnail meta tags, Open Graph images, and image tags.
      Parameters:
      responseData - the response data from crawling
      document - the parsed HTML document
      Returns:
      the thumbnail URL if found, null otherwise
    • getThumbnailSrc

      protected String getThumbnailSrc(String url, NamedNodeMap attributes)
      Extracts thumbnail source URL from image tag attributes.
      Parameters:
      url - the base URL for resolving relative URLs
      attributes - the named node map of image tag attributes
      Returns:
      the thumbnail source URL if found, null otherwise
    • getAttributeAsInteger

      protected Integer getAttributeAsInteger(NamedNodeMap attributes, String name)
      Gets an attribute value as an integer.
      Parameters:
      attributes - the named node map of attributes
      name - the attribute name
      Returns:
      the attribute value as Integer, null if not found or not parseable
    • getURL

      protected URL getURL(String currentUrl, String url) throws MalformedURLException
      Creates a URL object from the current URL and a relative or absolute URL string.
      Parameters:
      currentUrl - the current URL as base
      url - the URL string to process
      Returns:
      the URL object
      Throws:
      MalformedURLException - if the URL is malformed
    • addFieldRule

      public void addFieldRule(String name, String xpath, boolean isPruned)
      Adds a field extraction rule with pruning option.
      Parameters:
      name - the field name
      xpath - the XPath expression for extraction
      isPruned - whether the extracted content should be pruned
    • setConvertUrlMap

      public void setConvertUrlMap(Map<String,String> convertUrlMap)
      Sets the URL conversion map for transforming URLs.
      Parameters:
      convertUrlMap - the map of regex patterns to replacement strings
    • addConvertUrl

      public void addConvertUrl(String regex, String replacement)
      Adds a URL conversion rule.
      Parameters:
      regex - the regular expression pattern to match
      replacement - the replacement string