private void printMergedCopy(String output) throws IOException, ParserConfigurationException, TransformerConfigurationException, TransformerException {
        tc = "printMergedCopy - ";
        if (debug)
            Tr.info(traceComponent, tc + "Output File: " + output);
        cleanPlugins();
        FileOutputStream fos = new FileOutputStream(output);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = dbf.newDocumentBuilder();
        Document mergeDoc = parser.newDocument();
        final Comment comment = mergeDoc.createComment(" This config file was generated by plugin's merge tool v1.0.0.2 on " +
                                                       new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z").format(new Date()) + " ");
        mergeDoc.appendChild(comment);

        mergeDoc.appendChild(mergeDoc.importNode(mergeConfigNode, true));
        mergeConfigNode = mergeDoc.getDocumentElement();
        removeComments(parser, mergeDoc);

        mergeConfigNode.appendChild(mergeDoc.importNode(mergeDoc.createComment(" Server Clusters "), true));

        Node[] sc = null;
        sharedPlugins.trimToSize();
        Iterator<PluginInfo> itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            if (failOver)
                sc = (itrSharedPlugins.next()).getFailOverServerClusters();
            else
                sc = (itrSharedPlugins.next()).getSharedServerClusters();

            for (int i = 0; i < sc.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(sc[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            if (!plugins[i].getUniquePluginRep().isEmpty()) {
                sc = plugins[i].getUnsharedServerClusters();
                for (int j = 0; j < sc.length; j++)
                    mergeConfigNode.appendChild(mergeDoc.importNode(sc[j], true));
            }
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" Virtual Host Groups "));

        Node[] vhgs = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            vhgs = (itrSharedPlugins.next()).getSharedVHostGrps();
            for (int i = 0; i < vhgs.length; i++) {
                mergeConfigNode.appendChild(mergeDoc.importNode(vhgs[i], true));
            }
        }

        vhgs = null;
        for (int i = 0; i < plugins.length - paramCnt; i++) {
            vhgs = plugins[i].getUnsharedVHostGrp();
            for (int j = 0; j < vhgs.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(vhgs[j], true));
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" URI Groups "));

        Node[] uriGrps = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            uriGrps = (itrSharedPlugins.next()).getUriGrps();
            for (int i = 0; i < uriGrps.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            uriGrps = plugins[i].getUriGrps();
            for (int j = 0; j < uriGrps.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[j], true));

            //output unqiueUriGrps needed due to vhost def
            uriGrps = plugins[i].getUniqueUriGrps();
            for (int j = 0; j < uriGrps.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[j], true));
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" Routes "));

        Node[] routes = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            routes = (itrSharedPlugins.next()).getRoutes();
            for (int i = 0; i < routes.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(routes[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            routes = plugins[i].getRoutes();
            for (int j = 0; j < routes.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(routes[j], true));
        }

        TransformerFactory transfac = TransformerFactory.newInstance();

        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        trans.setOutputProperty(OutputKeys.METHOD, "xml");
        trans.setOutputProperty(OutputKeys.ENCODING, encoding);
        trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        //create string from xml tree
        StreamResult result = new StreamResult(fos);
        DOMSource source = new DOMSource(mergeDoc);
        trans.transform(source, result);

        fos.flush();
        fos.close();

        Tr.info(traceComponent, "Merged plugin config file written to " + output);
    }
private void printMergedCopy ( String output ) throws IOException , ParserConfigurationException , TransformerConfigurationException , TransformerException { tc = "printMergedCopy - " ; if ( debug ) Tr . info ( traceComponent , tc + "Output File: " + output ) ; cleanPlugins ( ) ; FileOutputStream fos = new FileOutputStream ( output ) ; DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder parser = dbf . newDocumentBuilder ( ) ; Document mergeDoc = parser . newDocument ( ) ; final Comment comment = mergeDoc . createComment ( " This config file was generated by plugin's merge tool v1.0.0.2 on " + new SimpleDateFormat ( "yyyy.MM.dd 'at' HH:mm:ss z" ) . format ( new Date ( ) ) + " " ) ; mergeDoc . appendChild ( comment ) ; mergeDoc . appendChild ( mergeDoc . importNode ( mergeConfigNode , true ) ) ; mergeConfigNode = mergeDoc . getDocumentElement ( ) ; removeComments ( parser , mergeDoc ) ; mergeConfigNode . appendChild ( mergeDoc . importNode ( mergeDoc . createComment ( " Server Clusters " ) , true ) ) ; Node [ ] sc = null ; sharedPlugins . trimToSize ( ) ; Iterator < PluginInfo > itrSharedPlugins = sharedPlugins . iterator ( ) ; while ( itrSharedPlugins . hasNext ( ) ) { if ( failOver ) sc = ( itrSharedPlugins . next ( ) ) . getFailOverServerClusters ( ) ; else sc = ( itrSharedPlugins . next ( ) ) . getSharedServerClusters ( ) ; for ( int i = 0 ; i < sc . length ; i ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( sc [ i ] , true ) ) ; } for ( int i = 0 ; i < plugins . length - paramCnt ; i ++ ) { if ( ! plugins [ i ] . getUniquePluginRep ( ) . isEmpty ( ) ) { sc = plugins [ i ] . getUnsharedServerClusters ( ) ; for ( int j = 0 ; j < sc . length ; j ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( sc [ j ] , true ) ) ; } } mergeConfigNode . appendChild ( mergeDoc . createComment ( " Virtual Host Groups " ) ) ; Node [ ] vhgs = null ; itrSharedPlugins = sharedPlugins . iterator ( ) ; while ( itrSharedPlugins . hasNext ( ) ) { vhgs = ( itrSharedPlugins . next ( ) ) . getSharedVHostGrps ( ) ; for ( int i = 0 ; i < vhgs . length ; i ++ ) { mergeConfigNode . appendChild ( mergeDoc . importNode ( vhgs [ i ] , true ) ) ; } } vhgs = null ; for ( int i = 0 ; i < plugins . length - paramCnt ; i ++ ) { vhgs = plugins [ i ] . getUnsharedVHostGrp ( ) ; for ( int j = 0 ; j < vhgs . length ; j ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( vhgs [ j ] , true ) ) ; } mergeConfigNode . appendChild ( mergeDoc . createComment ( " URI Groups " ) ) ; Node [ ] uriGrps = null ; itrSharedPlugins = sharedPlugins . iterator ( ) ; while ( itrSharedPlugins . hasNext ( ) ) { uriGrps = ( itrSharedPlugins . next ( ) ) . getUriGrps ( ) ; for ( int i = 0 ; i < uriGrps . length ; i ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( uriGrps [ i ] , true ) ) ; } for ( int i = 0 ; i < plugins . length - paramCnt ; i ++ ) { uriGrps = plugins [ i ] . getUriGrps ( ) ; for ( int j = 0 ; j < uriGrps . length ; j ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( uriGrps [ j ] , true ) ) ; uriGrps = plugins [ i ] . getUniqueUriGrps ( ) ; for ( int j = 0 ; j < uriGrps . length ; j ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( uriGrps [ j ] , true ) ) ; } mergeConfigNode . appendChild ( mergeDoc . createComment ( " Routes " ) ) ; Node [ ] routes = null ; itrSharedPlugins = sharedPlugins . iterator ( ) ; while ( itrSharedPlugins . hasNext ( ) ) { routes = ( itrSharedPlugins . next ( ) ) . getRoutes ( ) ; for ( int i = 0 ; i < routes . length ; i ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( routes [ i ] , true ) ) ; } for ( int i = 0 ; i < plugins . length - paramCnt ; i ++ ) { routes = plugins [ i ] . getRoutes ( ) ; for ( int j = 0 ; j < routes . length ; j ++ ) mergeConfigNode . appendChild ( mergeDoc . importNode ( routes [ j ] , true ) ) ; } TransformerFactory transfac = TransformerFactory . newInstance ( ) ; Transformer trans = transfac . newTransformer ( ) ; trans . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; trans . setOutputProperty ( OutputKeys . METHOD , "xml" ) ; trans . setOutputProperty ( OutputKeys . ENCODING , encoding ) ; trans . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , "4" ) ; StreamResult result = new StreamResult ( fos ) ; DOMSource source = new DOMSource ( mergeDoc ) ; trans . transform ( source , result ) ; fos . flush ( ) ; fos . close ( ) ; Tr . info ( traceComponent , "Merged plugin config file written to " + output ) ; }
Output the finalized merged plugin-cfg.xml

@param output - filename for output
@throws IOException
@throws IOException
@throws ParserConfigurationException
@throws ParserConfigurationException