private final void parseDocument(Node currentNode) {
	    	try {
	    		mutex.acquire();
	        String nodeName = currentNode.getNodeName();
	
	        if ((currentNode.getNodeType() == Node.ELEMENT_NODE)
	                && (nodeName.equals("type"))
	        ) {
	            String typeName = ((Element) currentNode).getAttribute("name");
	            mapFilter.put(
	                typeName + ".filter",
	                new ArrayList()
	            );
	            mapFilter.put(
	                typeName + ".tag",
	                new ArrayList()
	            );
	            mapFilter.put(
	                typeName + ".merge",
	                new ArrayList()
	            );
	        }
	
	        if ((currentNode.getNodeType() == Node.ELEMENT_NODE)
	                && (currentNode.getParentNode() != null)
	        ) {
	            if (nodeName.equals("filter")) {
	                String typeName =
	                    ((Element) currentNode.getParentNode()
	                                          .getParentNode()).getAttribute(
	                        "name"
	                    );
	                ArrayList vMapFilter =
	                    (ArrayList) mapFilter.get(typeName + ".filter");
	                ArrayList vFilter = new ArrayList();
	                int iOrder =
	                    ((Element) currentNode).getAttribute("order")
	                     .equals("")
	                    ? vMapFilter.size()
	                    : Integer.parseInt(
	                        ((Element) currentNode).getAttribute("order")
	                    );
	                String replacement = "";
	                NodeList nl = currentNode.getChildNodes();
	
	                for (int i = 0; i < nl.getLength(); i++) {
	                    Node childNode = nl.item(i);
	
	                    if (childNode.getNodeName()
	                                     .equals("replacement")) {
	                        NodeList nl2 = childNode.getChildNodes();
	
	                        for (int j = 0; j < nl2.getLength(); j++) {
	                            Node child = nl2.item(j);
	
	                            if (child.getNodeType() == Node.TEXT_NODE) {
	                                replacement =
	                                    replacement + child.getNodeValue();
	                            }
	                        }
	                    } else if (childNode.getNodeName()
	                                            .equals("match")) {
	                        String match = "";
	                        NodeList nl2 = childNode.getChildNodes();
	
	                        for (int j = 0; j < nl2.getLength(); j++) {
	                            Node child = nl2.item(j);
	
	                            if (child.getNodeType() == Node.TEXT_NODE) {
	                                match = match + child.getNodeValue();
	                            }
	                        }
	
	                        Pattern p = null;
	
	                        try {
	                            p = Pattern.compile(
	                                    match,
	                                    Pattern.MULTILINE | Pattern.DOTALL
	                                );
	                            vFilter.add(p);
	                        } catch (Exception ignore) {
	                        }
	                    }
	                }
	
	                vMapFilter.add(
	                    iOrder,
	                    new Object[] {
	                        replacement,
	                        vFilter
	                    }
	                );
	            } else if ((nodeName.equals("tag"))
	                    && (
	                        currentNode.getParentNode().getNodeName().equals(
	                            "tags"
	                        )
	                    )
	            ) {
	                String typeName =
	                    ((Element) currentNode.getParentNode()
	                                          .getParentNode()
	                                          .getParentNode()).getAttribute(
	                        "name"
	                    );
	                String tagName = ((Element) currentNode).getAttribute("name");
	                ArrayList vMapTags =
	                    (ArrayList) mapFilter.get(typeName + ".tag");
	                ArrayList vAttributes = new ArrayList();
	                NodeList nl = currentNode.getChildNodes();
	
	                for (int i = 0; i < nl.getLength(); i++) {
	                    Node childNode = nl.item(i);
	
	                    if (childNode.getNodeName()
	                                     .equals("attribute")) {
	                        vAttributes.add(
	                            (String) ((Element) childNode).getAttribute("name")
	                        );
	                    }
	                }
	
	                vMapTags.add(new Object[] {
	                        tagName,
	                        vAttributes
	                    }
	                );
	            } else if (nodeName.equals("source_attribute")) {
	                String typeName =
	                    ((Element) currentNode.getParentNode()
	                                          .getParentNode()
	                                          .getParentNode()
	                                          .getParentNode()).getAttribute(
	                        "name"
	                    );
	                String tagName =
	                    ((Element) currentNode.getParentNode()).getAttribute(
	                        "name"
	                    );
	                String attribName =
	                    ((Element) currentNode).getAttribute("name");
	                String srcAttribNameInDest =
	                    ((Element) currentNode).getAttribute("name_in_destination");
	                ArrayList vMapMerge =
	                    (ArrayList) mapFilter.get(typeName + ".merge");
	                String separator = null;
	                String destAttribName = null;
	                ArrayList match = new ArrayList();
	                ArrayList value = new ArrayList();
	                NodeList nl = currentNode.getChildNodes();
	
	                for (int i = 0; i < nl.getLength(); i++) {
	                    Node childNode = nl.item(i);
	
	                    if (childNode.getNodeName()
	                                     .equals("destination_attribute")) {
	                        destAttribName =
	                            ((Element) childNode).getAttribute("name");
	                    } else if (childNode.getNodeName()
	                                            .equals("separator")) {
	                        separator = ((Element) childNode).getAttribute("value");
	                    } else if (childNode.getNodeName()
	                                            .equals("replace")) {
	                        match.add(((Element) childNode).getAttribute("match"));
	                        value.add(((Element) childNode).getAttribute("value"));
	                    }
	                }
	
	                vMapMerge.add(
	                    new Object[] {
	                        tagName,
	                        attribName,
	                        srcAttribNameInDest,
	                        destAttribName,
	                        separator,
	                        match,
	                        value
	                    }
	                );
	            }
	        }
	
	        NodeList nl = currentNode.getChildNodes();
	
	        for (int i = 0; i < nl.getLength(); i++) {
	            parseDocument(nl.item(i));
	        }
	    	}
	    	finally {
	    		try{mutex.release();}catch(Throwable ignore){}
	    	}
    }
private final void parseDocument ( Node currentNode ) { try { mutex . acquire ( ) ; String nodeName = currentNode . getNodeName ( ) ; if ( ( currentNode . getNodeType ( ) == Node . ELEMENT_NODE ) && ( nodeName . equals ( "type" ) ) ) { String typeName = ( ( Element ) currentNode ) . getAttribute ( "name" ) ; mapFilter . put ( typeName + ".filter" , new ArrayList ( ) ) ; mapFilter . put ( typeName + ".tag" , new ArrayList ( ) ) ; mapFilter . put ( typeName + ".merge" , new ArrayList ( ) ) ; } if ( ( currentNode . getNodeType ( ) == Node . ELEMENT_NODE ) && ( currentNode . getParentNode ( ) != null ) ) { if ( nodeName . equals ( "filter" ) ) { String typeName = ( ( Element ) currentNode . getParentNode ( ) . getParentNode ( ) ) . getAttribute ( "name" ) ; ArrayList vMapFilter = ( ArrayList ) mapFilter . get ( typeName + ".filter" ) ; ArrayList vFilter = new ArrayList ( ) ; int iOrder = ( ( Element ) currentNode ) . getAttribute ( "order" ) . equals ( "" ) ? vMapFilter . size ( ) : Integer . parseInt ( ( ( Element ) currentNode ) . getAttribute ( "order" ) ) ; String replacement = "" ; NodeList nl = currentNode . getChildNodes ( ) ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { Node childNode = nl . item ( i ) ; if ( childNode . getNodeName ( ) . equals ( "replacement" ) ) { NodeList nl2 = childNode . getChildNodes ( ) ; for ( int j = 0 ; j < nl2 . getLength ( ) ; j ++ ) { Node child = nl2 . item ( j ) ; if ( child . getNodeType ( ) == Node . TEXT_NODE ) { replacement = replacement + child . getNodeValue ( ) ; } } } else if ( childNode . getNodeName ( ) . equals ( "match" ) ) { String match = "" ; NodeList nl2 = childNode . getChildNodes ( ) ; for ( int j = 0 ; j < nl2 . getLength ( ) ; j ++ ) { Node child = nl2 . item ( j ) ; if ( child . getNodeType ( ) == Node . TEXT_NODE ) { match = match + child . getNodeValue ( ) ; } } Pattern p = null ; try { p = Pattern . compile ( match , Pattern . MULTILINE | Pattern . DOTALL ) ; vFilter . add ( p ) ; } catch ( Exception ignore ) { } } } vMapFilter . add ( iOrder , new Object [ ] { replacement , vFilter } ) ; } else if ( ( nodeName . equals ( "tag" ) ) && ( currentNode . getParentNode ( ) . getNodeName ( ) . equals ( "tags" ) ) ) { String typeName = ( ( Element ) currentNode . getParentNode ( ) . getParentNode ( ) . getParentNode ( ) ) . getAttribute ( "name" ) ; String tagName = ( ( Element ) currentNode ) . getAttribute ( "name" ) ; ArrayList vMapTags = ( ArrayList ) mapFilter . get ( typeName + ".tag" ) ; ArrayList vAttributes = new ArrayList ( ) ; NodeList nl = currentNode . getChildNodes ( ) ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { Node childNode = nl . item ( i ) ; if ( childNode . getNodeName ( ) . equals ( "attribute" ) ) { vAttributes . add ( ( String ) ( ( Element ) childNode ) . getAttribute ( "name" ) ) ; } } vMapTags . add ( new Object [ ] { tagName , vAttributes } ) ; } else if ( nodeName . equals ( "source_attribute" ) ) { String typeName = ( ( Element ) currentNode . getParentNode ( ) . getParentNode ( ) . getParentNode ( ) . getParentNode ( ) ) . getAttribute ( "name" ) ; String tagName = ( ( Element ) currentNode . getParentNode ( ) ) . getAttribute ( "name" ) ; String attribName = ( ( Element ) currentNode ) . getAttribute ( "name" ) ; String srcAttribNameInDest = ( ( Element ) currentNode ) . getAttribute ( "name_in_destination" ) ; ArrayList vMapMerge = ( ArrayList ) mapFilter . get ( typeName + ".merge" ) ; String separator = null ; String destAttribName = null ; ArrayList match = new ArrayList ( ) ; ArrayList value = new ArrayList ( ) ; NodeList nl = currentNode . getChildNodes ( ) ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { Node childNode = nl . item ( i ) ; if ( childNode . getNodeName ( ) . equals ( "destination_attribute" ) ) { destAttribName = ( ( Element ) childNode ) . getAttribute ( "name" ) ; } else if ( childNode . getNodeName ( ) . equals ( "separator" ) ) { separator = ( ( Element ) childNode ) . getAttribute ( "value" ) ; } else if ( childNode . getNodeName ( ) . equals ( "replace" ) ) { match . add ( ( ( Element ) childNode ) . getAttribute ( "match" ) ) ; value . add ( ( ( Element ) childNode ) . getAttribute ( "value" ) ) ; } } vMapMerge . add ( new Object [ ] { tagName , attribName , srcAttribNameInDest , destAttribName , separator , match , value } ) ; } } NodeList nl = currentNode . getChildNodes ( ) ; for ( int i = 0 ; i < nl . getLength ( ) ; i ++ ) { parseDocument ( nl . item ( i ) ) ; } } finally { try { mutex . release ( ) ; } catch ( Throwable ignore ) { } } }
parse the configuration file

@param currentNode current analysed node