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
FieldsModifier and TypeFieldDescriptionMap containing URL conversion rules (regex patterns to replacement strings)protected DataSerializerData serializer for converting objects to binary formatprotected org.codelibs.fess.mylasta.direction.FessConfigFess configuration instanceMap storing field pruning rulesbooleanFlag indicating whether content should be prunedCache for storing parsed pruned tags by configuration IDprotected booleanFlag indicating whether to process Google on/off commentsFields inherited from class org.codelibs.fess.crawler.transformer.impl.XpathTransformer
charsetName, dataClass, fieldRuleMap, trimSpaceEnabledFields inherited from class org.codelibs.fess.crawler.transformer.impl.HtmlTransformer
childUrlRuleMap, crawlerContainer, defaultEncoding, featureMap, invalidUrlPattern, LOCATION_HEADER, preloadSizeForCharset, propertyMapFields inherited from class org.codelibs.fess.crawler.transformer.impl.AbstractTransformer
nameFields inherited from interface org.codelibs.fess.crawler.transformer.FessTransformer
parentEncodingMap -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds child URL from tag attribute value.voidaddConvertUrl(String regex, String replacement) Adds a URL conversion rule.voidaddFieldRule(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.getAnchorList(Document document, org.codelibs.fess.crawler.entity.ResponseData responseData) Extracts anchor URLs from the HTML document.protected IntegergetAttributeAsInteger(NamedNodeMap attributes, String name) Gets an attribute value as an integer.protected URLgetBaseUrl(String currentUrl, String baseHref) Gets the base URL for resolving relative URLs.protected StringgetCanonicalUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document) Extracts the canonical URL from the HTML document.getChildUrlRules(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData) Gets child URL extraction rules from configuration.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 StringgetContentXpath(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.CrawlingConfiggetCrawlingConfig(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 StringgetDigestXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String, String> xpathConfigMap) Gets the XPath expression for extracting digest information.org.codelibs.fess.mylasta.direction.FessConfigReturns the Fess configuration instance.protected StringgetLangXpath(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, Map<String, String> xpathConfigMap) Gets the XPath expression for extracting language information.org.apache.logging.log4j.LoggerReturns the logger instance for this class.protected StringgetMultipleNodeValue(Document document, String xpath) Extracts text content from multiple nodes using XPath expression.protected PathMappingHelperGets the path mapping helper for URL transformations.protected StringgetSingleNodeValue(Document document, String xpath, UnaryOperator<Node> pruneFunc) Extracts text content from a single node using XPath expression.protected StringgetThumbnailSrc(String url, NamedNodeMap attributes) Extracts thumbnail source URL from image tag attributes.protected StringgetThumbnailUrl(org.codelibs.fess.crawler.entity.ResponseData responseData, Document document) Extracts thumbnail URL from the HTML document.protected URLCreates a URL object from the current URL and a relative or absolute URL string.voidinit()Initializes the transformer after dependency injection.protected booleanisPrunedTag(Node node, PrunedTag[] prunedTags) Checks if a node matches any of the pruned tag configurations.protected booleanisValidCanonicalUrl(String url, String canonicalUrl) Validates if the canonical URL is valid relative to the original URL.protected booleanisValidUrl(String urlStr) Validates if the given URL string is a valid URL.protected StringnormalizeCanonicalUrl(String baseUrl, String canonicalUrl) Normalizes the canonical URL relative to the base URL.protected voidnormalizeData(org.codelibs.fess.crawler.entity.ResponseData responseData, Map<String, Object> dataMap) Normalizes the extracted data, particularly handling title normalization.protected voidparseTextContent(Node node, StringBuilder buf) Recursively parses text content from a node and its children.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 NodeprocessGoogleOffOn(Node node, org.codelibs.core.misc.ValueHolder<Boolean> flag) Processes Google on/off comment directives in the node.protected voidprocessMetaRobots(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 voidprocessXRobotsTag(org.codelibs.fess.crawler.entity.ResponseData responseData, org.codelibs.fess.crawler.entity.ResultData resultData) Processes X-Robots-Tag HTTP headers.protected NodePrunes unwanted tags from the node based on configuration.protected NodepruneNodeByTags(Node node, PrunedTag[] prunedTags) Prunes nodes based on the specified pruned tags.protected voidputResultDataContent(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 StringremoveCommentTag(String content) Removes HTML comment tags from the content.protected StringReplaces duplicate hosts in the URL using the duplicate host helper.voidsetConvertUrlMap(Map<String, String> convertUrlMap) Sets the URL conversion map for transforming URLs.voidsetUseGoogleOffOn(boolean useGoogleOffOn) Sets whether to process Google on/off comment directives.protected voidstoreData(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, trimSpaceMethods 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, updateCharsetMethods inherited from class org.codelibs.fess.crawler.transformer.impl.AbstractTransformer
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codelibs.fess.crawler.transformer.FessTransformer
abbreviateSite, decodeUrlAsName, evaluateValue, getFileName, getHost, getMaxSiteLength, getParentEncoding, getSite, processFieldConfigs, putResultDataBody, putResultDataWithTemplate
-
Field Details
-
prunedContent
public boolean prunedContentFlag indicating whether content should be pruned -
convertUrlMap
Map containing URL conversion rules (regex patterns to replacement strings) -
fessConfig
protected org.codelibs.fess.mylasta.direction.FessConfig fessConfigFess configuration instance -
dataSerializer
Data serializer for converting objects to binary format -
useGoogleOffOn
protected boolean useGoogleOffOnFlag indicating whether to process Google on/off comments -
fieldPrunedRuleMap
Map storing field pruning rules -
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:
getFessConfigin interfaceFessTransformer- Returns:
- the Fess configuration
-
getLogger
public org.apache.logging.log4j.Logger getLogger()Returns the logger instance for this class.- Specified by:
getLoggerin interfaceFessTransformer- 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:
storeDatain classorg.codelibs.fess.crawler.transformer.impl.XpathTransformer- Parameters:
responseData- the response data from crawlingresultData- 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 crawlingdataMap- 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 crawlingresultData- the result data to store processed informationdocument- 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 crawlingresultData- 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 crawlingconfig- the configuration name to retrieve- Returns:
- map of configuration parameters
-
isValidUrl
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
Validates if the canonical URL is valid relative to the original URL. Specifically checks for HTTPS to HTTP downgrades.- Parameters:
url- the original URLcanonicalUrl- 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 populateresponseData- the response data from crawlingdocument- 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 populateresponseData- the response data from crawlingfessConfig- the Fess configurationcrawlingConfig- the crawling configurationdocumentHelper- the document helper for content processingbody- the extracted body contentfileName- 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 configurationxpathConfigMap- 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 configurationxpathConfigMap- 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 configurationxpathConfigMap- 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 crawlingdocument- the parsed HTML document- Returns:
- the canonical URL if found, null otherwise
-
normalizeCanonicalUrl
Normalizes the canonical URL relative to the base URL.- Parameters:
baseUrl- the base URLcanonicalUrl- the canonical URL to normalize- Returns:
- the normalized canonical URL
-
removeCommentTag
Removes HTML comment tags from the content.- Parameters:
content- the content to process- Returns:
- the content with comment tags removed
-
getSingleNodeValue
Extracts text content from a single node using XPath expression.- Parameters:
document- the parsed HTML documentxpath- the XPath expression to evaluatepruneFunc- the function to apply for node pruning- Returns:
- the extracted text content
-
parseTextContent
Recursively parses text content from a node and its children.- Parameters:
node- the node to parsebuf- the StringBuilder to append content to
-
processGoogleOffOn
Processes Google on/off comment directives in the node.- Parameters:
node- the node to processflag- 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 prunecrawlingConfig- the crawling configuration containing pruning rules- Returns:
- the pruned node
-
pruneNodeByTags
Prunes nodes based on the specified pruned tags.- Parameters:
node- the node to pruneprunedTags- the array of pruned tag configurations- Returns:
- the pruned node
-
isPrunedTag
Checks if a node matches any of the pruned tag configurations.- Parameters:
node- the node to checkprunedTags- the array of pruned tag configurations- Returns:
- true if the node should be pruned, false otherwise
-
getMultipleNodeValue
Extracts text content from multiple nodes using XPath expression.- Parameters:
document- the parsed HTML documentxpath- the XPath expression to evaluate- Returns:
- the concatenated text content from all matching nodes
-
replaceDuplicateHost
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 documentresponseData- the response data from crawling- Returns:
- list of anchor URLs found in the document
-
getBaseUrl
Gets the base URL for resolving relative URLs.- Parameters:
currentUrl- the current URLbaseHref- 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:
getChildUrlRulesin classorg.codelibs.fess.crawler.transformer.impl.HtmlTransformer- Parameters:
responseData- the response data from crawlingresultData- 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:
convertChildUrlListin classorg.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
Gets the path mapping helper for URL transformations.- Returns:
- the path mapping helper instance
-
getData
Deserializes data from access result data.- Specified by:
getDatain interfaceorg.codelibs.fess.crawler.transformer.Transformer- Overrides:
getDatain classorg.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:
addChildUrlFromTagAttributein classorg.codelibs.fess.crawler.transformer.impl.HtmlTransformer- Parameters:
urlList- the list to add URLs tourl- the base URL for resolving relative URLsattrValue- the attribute value containing the URLencoding- 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 crawlingdocument- the parsed HTML document- Returns:
- the thumbnail URL if found, null otherwise
-
getThumbnailSrc
Extracts thumbnail source URL from image tag attributes.- Parameters:
url- the base URL for resolving relative URLsattributes- the named node map of image tag attributes- Returns:
- the thumbnail source URL if found, null otherwise
-
getAttributeAsInteger
Gets an attribute value as an integer.- Parameters:
attributes- the named node map of attributesname- the attribute name- Returns:
- the attribute value as Integer, null if not found or not parseable
-
getURL
Creates a URL object from the current URL and a relative or absolute URL string.- Parameters:
currentUrl- the current URL as baseurl- the URL string to process- Returns:
- the URL object
- Throws:
MalformedURLException- if the URL is malformed
-
addFieldRule
Adds a field extraction rule with pruning option.- Parameters:
name- the field namexpath- the XPath expression for extractionisPruned- whether the extracted content should be pruned
-
setConvertUrlMap
Sets the URL conversion map for transforming URLs.- Parameters:
convertUrlMap- the map of regex patterns to replacement strings
-
addConvertUrl
Adds a URL conversion rule.- Parameters:
regex- the regular expression pattern to matchreplacement- the replacement string
-