Package org.codelibs.fess.util
Class GsaConfigParser
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.codelibs.fess.util.GsaConfigParser
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
Parser for Google Search Appliance (GSA) configuration files.
This SAX-based parser reads GSA XML configuration files and converts them into
Fess configuration objects including web crawling configurations, file crawling
configurations, and label types for access control.
The parser handles the following GSA configuration elements:
- Collections with good/bad URL patterns
- Global parameters including start URLs and filtering rules
- User agent settings
- URL pattern matching with regular expressions and contains filters
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringXML element name for bad (excluded) URLs configuration.protected static final StringXML element name for individual collection.protected static final StringXML element name for collections container.static final StringPrefix for contains-based string matching patterns.protected org.codelibs.fess.opensearch.config.exentity.FileConfigGenerated file crawling configuration from parsed GSA config.protected String[]Array of supported file protocols for URL classification.Map to store global configuration parameters.protected static final StringXML element name for global parameters container.protected static final StringXML element name for good (included) URLs configuration.protected List<org.codelibs.fess.opensearch.config.exentity.LabelType> List to store parsed label types for access control.protected org.codelibs.fess.opensearch.config.exentity.LabelTypeCurrent label type being processed during parsing.static final StringPrefix for regular expression patterns.static final StringPrefix for case-sensitive regular expression patterns.static final StringPrefix for case-insensitive regular expression patterns.protected static final StringXML element name for start URLs configuration.protected LinkedList<String> Queue to track the current XML element hierarchy during parsing.protected StringBuilderBuffer to accumulate character data between XML tags.protected StringUser agent string to be used for web crawling.protected org.codelibs.fess.opensearch.config.exentity.WebConfigGenerated web crawling configuration from parsed GSA config.protected String[]Array of supported web protocols for URL classification. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringappendFileterPath(StringBuilder buf, String v) Appends a filter path pattern to a string buffer with appropriate wildcards.voidcharacters(char[] ch, int start, int length) SAX event handler called to process character data between XML elements.voidSAX event handler called at the end of document parsing.voidendElement(String uri, String localName, String qName) SAX event handler called when an XML end element is encountered.protected StringEscapes special regex characters in a string to create a literal pattern.org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.config.exentity.FileConfig> Gets the file crawling configuration generated from the parsed GSA config.protected StringConverts a GSA URL pattern into a regular expression pattern suitable for Fess.org.codelibs.fess.opensearch.config.exentity.LabelType[]Gets all label types (collections) parsed from the GSA configuration.org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.config.exentity.WebConfig> Gets the web crawling configuration generated from the parsed GSA config.voidparse(InputSource is) Parses a GSA configuration XML file from the given input source.protected StringparseFilterPaths(String text, boolean web, boolean file) Parses and filters URL patterns from text based on protocol types.voidsetFileProtocols(String[] fileProtocols) Sets the array of file protocols to recognize for URL classification.voidsetWebProtocols(String[] webProtocols) Sets the array of web protocols to recognize for URL classification.voidSAX event handler called at the beginning of document parsing.voidstartElement(String uri, String localName, String qName, Attributes attributes) SAX event handler called when an XML start element is encountered.toString()Returns a string representation of this parser's current state.protected StringUnescapes double backslashes in regex patterns.Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
REGEXP
Prefix for regular expression patterns.- See Also:
-
REGEXP_CASE
Prefix for case-sensitive regular expression patterns.- See Also:
-
REGEXP_IGNORE_CASE
Prefix for case-insensitive regular expression patterns.- See Also:
-
CONTAINS
Prefix for contains-based string matching patterns.- See Also:
-
COLLECTIONS
XML element name for collections container.- See Also:
-
COLLECTION
XML element name for individual collection.- See Also:
-
GLOBALPARAMS
XML element name for global parameters container.- See Also:
-
START_URLS
XML element name for start URLs configuration.- See Also:
-
GOOD_URLS
XML element name for good (included) URLs configuration.- See Also:
-
BAD_URLS
XML element name for bad (excluded) URLs configuration.- See Also:
-
webProtocols
Array of supported web protocols for URL classification. -
fileProtocols
Array of supported file protocols for URL classification. -
tagQueue
Queue to track the current XML element hierarchy during parsing. -
labelList
List to store parsed label types for access control. -
labelType
protected org.codelibs.fess.opensearch.config.exentity.LabelType labelTypeCurrent label type being processed during parsing. -
globalParams
Map to store global configuration parameters. -
webConfig
protected org.codelibs.fess.opensearch.config.exentity.WebConfig webConfigGenerated web crawling configuration from parsed GSA config. -
fileConfig
protected org.codelibs.fess.opensearch.config.exentity.FileConfig fileConfigGenerated file crawling configuration from parsed GSA config. -
textBuf
Buffer to accumulate character data between XML tags. -
userAgent
User agent string to be used for web crawling.
-
-
Constructor Details
-
GsaConfigParser
public GsaConfigParser()Default constructor for GsaConfigParser.
-
-
Method Details
-
parse
Parses a GSA configuration XML file from the given input source. This method configures a secure SAX parser and processes the XML content to extract configuration information for web and file crawling.- Parameters:
is- the input source containing the GSA configuration XML- Throws:
GsaConfigException- if parsing fails due to XML format issues or other errors
-
startDocument
SAX event handler called at the beginning of document parsing. Initializes internal data structures for processing the GSA configuration.- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException- if a SAX error occurs during initialization
-
endDocument
SAX event handler called at the end of document parsing. Cleans up internal data structures used during parsing.- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException- if a SAX error occurs during cleanup
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException SAX event handler called when an XML start element is encountered. Processes collection definitions and tracks the element hierarchy.- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Parameters:
uri- the namespace URI, or empty string if nonelocalName- the local name without prefix, or empty string if namespace processing is not performedqName- the qualified name with prefix, or empty string if qualified names are not availableattributes- the attributes attached to the element- Throws:
SAXException- if a SAX error occurs or if the XML format is invalid
-
endElement
SAX event handler called when an XML end element is encountered. Processes the accumulated text content and creates appropriate configuration objects based on the element type (good_urls, bad_urls, start_urls, etc.).- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Parameters:
uri- the namespace URI, or empty string if nonelocalName- the local name without prefix, or empty string if namespace processing is not performedqName- the qualified name with prefix, or empty string if qualified names are not available- Throws:
SAXException- if a SAX error occurs during processing
-
characters
SAX event handler called to process character data between XML elements. Accumulates text content in a buffer for later processing when the element ends.- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Parameters:
ch- the characters from the XML documentstart- the start position in the character arraylength- the number of characters to use from the character array- Throws:
SAXException- if a SAX error occurs during character processing
-
parseFilterPaths
Parses and filters URL patterns from text based on protocol types. Processes each line of the input text, filtering URLs based on web and file protocol support.- Parameters:
text- the raw text containing URL patterns, one per lineweb- true if web protocol URLs should be includedfile- true if file protocol URLs should be included- Returns:
- a newline-separated string of filtered URL patterns
-
getFilterPath
Converts a GSA URL pattern into a regular expression pattern suitable for Fess. Handles various GSA pattern formats including regexp, contains, and URL-based patterns.- Parameters:
s- the input GSA pattern string- Returns:
- a regular expression pattern string, or empty string for comments/invalid patterns
-
escape
Escapes special regex characters in a string to create a literal pattern. Handles anchor characters (^ and $) specially to preserve their regex meaning.- Parameters:
s- the string to escape- Returns:
- an escaped regex pattern, or empty string for comments
-
unescape
Unescapes double backslashes in regex patterns. Converts escaped backslashes (\\) back to single backslashes (\).- Parameters:
s- the string to unescape- Returns:
- the unescaped string
-
appendFileterPath
Appends a filter path pattern to a string buffer with appropriate wildcards. Handles various pattern formats including anchored patterns and quoted patterns.- Parameters:
buf- the string buffer to append tov- the pattern value to append- Returns:
- the complete pattern string from the buffer
-
setWebProtocols
Sets the array of web protocols to recognize for URL classification.- Parameters:
webProtocols- array of protocol prefixes (e.g., "http:", "https:")
-
setFileProtocols
Sets the array of file protocols to recognize for URL classification.- Parameters:
fileProtocols- array of protocol prefixes (e.g., "file:", "smb:", "ftp:")
-
toString
Returns a string representation of this parser's current state. Includes information about parsed label types and configuration objects. -
getWebConfig
public org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.config.exentity.WebConfig> getWebConfig()Gets the web crawling configuration generated from the parsed GSA config.- Returns:
- an optional containing the web configuration, or empty if no web URLs were found
-
getFileConfig
public org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.config.exentity.FileConfig> getFileConfig()Gets the file crawling configuration generated from the parsed GSA config.- Returns:
- an optional containing the file configuration, or empty if no file URLs were found
-
getLabelTypes
public org.codelibs.fess.opensearch.config.exentity.LabelType[] getLabelTypes()Gets all label types (collections) parsed from the GSA configuration. Each label type represents a collection with its own URL filtering rules.- Returns:
- an array of label types representing the parsed collections
-