private Pattern parsePattern ( Node node , Map < String , Scope > scopes ) { List < PatternElement > elements = new ArrayList < PatternElement > ( ) ; NodeList patternList = node . getChildNodes ( ) ; int patternLength = patternList . getLength ( ) ; if ( patternLength <= 0 ) { throw new TextProcessorFactoryException ( "Invalid pattern. Pattern is empty." ) ; } // Ignore case for all constants boolean ignoreCase = nodeAttribute ( node , "ignoreCase" , false ) ; for ( int k = 0 ; k < patternLength ; k ++ ) { Node el = patternList . item ( k ) ; short nodeType = el . getNodeType ( ) ; if ( nodeType == Node . TEXT_NODE ) { elements . add ( new Constant ( el . getNodeValue ( ) , ignoreCase ) ) ; } else if ( nodeType == Node . ELEMENT_NODE ) { String tagName = el . getLocalName ( ) ; if ( tagName . equals ( TAG_CONSTANT ) ) { elements . add ( parseConstant ( el , ignoreCase ) ) ; } else if ( tagName . equals ( TAG_VAR ) ) { elements . add ( parseNamedElement ( el , scopes ) ) ; } else if ( tagName . equals ( TAG_JUNK ) ) { elements . add ( new Junk ( ) ) ; } else if ( tagName . equals ( TAG_EOL ) ) { elements . add ( parseEol ( el ) ) ; } else if ( tagName . equals ( TAG_BOL ) ) { elements . add ( new Bol ( ) ) ; } else if ( tagName . equals ( TAG_BLANKLINE ) ) { elements . add ( new BlankLine ( nodeAttribute ( el , TAG_ATTR_GHOST , PatternElement . DEFAULT_GHOST_VALUE ) ) ) ; } else if ( tagName . equals ( TAG_URL ) ) { elements . add ( parseUrl ( el ) ) ; } else if ( tagName . equals ( TAG_EMAIL ) ) { elements . add ( parseEmail ( el ) ) ; } else { throw new TextProcessorFactoryException ( MessageFormat . format ( "Invalid pattern. Unknown XML element [{0}]." , tagName ) ) ; } } else { throw new TextProcessorFactoryException ( "Invalid pattern. Unsupported XML node type." ) ; } } return new Pattern ( elements ) ; }
Parse code pattern for parse text .