FileDocCategorySizeDatePackage
ProfileTransformer.javaAPI DocGlassfish v2 API6633Fri May 04 22:24:32 BST 2007com.sun.enterprise.admin.servermgmt.pe

ProfileTransformer

public final class ProfileTransformer extends Object

Fields Summary
private final File
baseXml
private final List
styleSheets
private final File
destDir
private final EntityResolver
er
private final Properties
op
private static final com.sun.enterprise.util.i18n.StringManager
sm
Constructors Summary
ProfileTransformer(File baseXml, List styleSheets, File destDir, EntityResolver er, Properties op)

    
            
              
        if (baseXml == null || styleSheets == null || destDir == null) {
            throw new IllegalArgumentException("null arguments");
        }
        this.baseXml     = baseXml;
        this.styleSheets = Collections.unmodifiableList(styleSheets);
        this.destDir     = destDir;
        this.er          = er;
        this.op          = new Properties(op);
    
Methods Summary
java.io.Filetransform()

        if (styleSheets.isEmpty()) {
            return ( baseXml );
        }
        BufferedOutputStream bos = null;
        try {
            final String fn = baseXml.getName();
            final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
            // it is OK to keep this as a non-validating parser.
            final DocumentBuilder builder   = bf.newDocumentBuilder();
            builder.setEntityResolver(er);
            final TransformerFactory tf     = TransformerFactory.newInstance();
            Document doc  = null;
            DOMSource src = null;
            int cnt       = 0;
            File   rfn    = null;
            for (final File ss : styleSheets) {
                //System.out.println("ss = " + ss.getAbsolutePath());
                if (cnt == 0)
                    doc = builder.parse(baseXml);
                src             = new DOMSource(doc);
                rfn             = new File(destDir, fn + "transformed" + cnt);
                bos             = new BufferedOutputStream(new FileOutputStream(rfn));
                final StreamResult result = new StreamResult(bos);
                final StreamSource sss    = new StreamSource(ss);
                final Transformer xf      = tf.newTransformer(sss);
                xf.setURIResolver(new TemplateUriResolver());
                xf.setOutputProperties(op);
                xf.transform(src, result);
                doc = builder.parse(rfn);
                cnt++;
                final String msg = sm.getString("xformPhaseComplete", ss.getAbsolutePath(), rfn.getAbsolutePath());
                System.out.println(msg);
            }
            return ( rfn );
        } catch (final Exception e) {
            throw new ProfileTransformationException(e);
        } finally {
            try {
                if (bos != null) bos.close();
            } catch (IOException eee) {
                //Have to squelch
            }
        }