public static boolean deploy()

in blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/deployment/Deployer.java [51:191]


    public static boolean deploy(InputStream inputStream,
                                 String  outputName,
                                 boolean stripLoggers,
                                 Log     logger,
                                 ServiceManager manager)
    throws DeploymentException, IOException, SAXException, ProcessingException {
        // first test, if the portlet is already deployed
        final File outputFile = new File(outputName);
        if ( outputFile.exists() ) {
            // TODO - check if the file to deploy is newer
            return false;
        }
        File tempFile = null;
        JarInputStream jin = null;
        JarOutputStream jout = null;
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;

        try {
            String portletApplicationName = getPortletApplicationName(outputName);
            tempFile = File.createTempFile(portletApplicationName, "");
            tempFile.deleteOnExit();

            jin = new JarInputStream(inputStream);
            jout = new JarOutputStream(new FileOutputStream(tempFile));

            // copy over all of the files in the input war to the output
            // war except for web.xml, portlet.xml, and context.xml which
            // we parse for use later
            Document webXml = null;
            Document portletXml = null;
            Document contextXml = null;
            ZipEntry src;
            while ( (src = jin.getNextJarEntry()) != null) {
                String target = src.getName();
                if ("WEB-INF/web.xml".equals(target)) {
                    logger.debug("Found web.xml");
                    webXml = parseXml(jin);
                } else if ("WEB-INF/portlet.xml".equals(target)) {
                    logger.debug("Found WEB-INF/portlet.xml");
                    portletXml = parseXml(jin);
                } else if ("META-INF/context.xml".equals(target)) {
                    logger.debug("Found META-INF/context.xml");
                    contextXml = parseXml(jin);
                } else {
                    if ( stripLoggers && target.endsWith(".jar") &&
                         (target.startsWith("WEB-INF/lib/commons-logging") || target.startsWith("WEB-INF/lib/log4j"))) {
                        logger.info("Stripping logger: "+target);
                        continue;
                    }
                    addFile(target, jin, jout);
                }
            }

            if (webXml == null) {
                throw new DeploymentException("WEB-INF/web.xml is missing.");
            }
            if (portletXml == null) {
                throw new DeploymentException("WEB-INF/portlet.xml is missing.");
            }

            WebApplicationRewriter webRewriter = new WebApplicationRewriter(webXml);
            webRewriter.processWebXML();
            ContextRewriter contextRewriter = new ContextRewriter(contextXml, portletApplicationName);
            contextRewriter.processContextXML();
            PortletRewriter.process(portletXml);

            // write the web.xml, portlet.xml, and context.xml files
            addFile("WEB-INF/web.xml", webXml, jout);
            addFile("WEB-INF/portlet.xml", portletXml, jout);
            addFile("META-INF/context.xml", contextXml, jout);

            if (webRewriter.isPortletTaglibAdded()) {
                logger.info("Attempting to add portlet.tld to war...");
                InputStream is = Deployer.class.getResourceAsStream("portlet.tld");
                if (is == null) {
                    logger.warn("Failed to find portlet.tld in classpath");
                } else {
                    logger.info("Adding portlet.tld to war...");
                    try {
                        addFile("WEB-INF/tld/portlet.tld", is, jout);
                    } finally {
                        is.close();
                    }
                }
            }

            jout.close();
            jin.close();
            jin = null;
            jout = null;

            logger.info("Creating war " + outputName + " ...");
            // Now copy the new war to its destination
            srcChannel = new FileInputStream(tempFile).getChannel();
            dstChannel = new FileOutputStream(outputName).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            srcChannel = null;
            dstChannel.close();
            dstChannel = null;
            tempFile.delete();
            tempFile = null;
            logger.info("War " + outputName + " created");
        } finally {
            if (srcChannel != null && srcChannel.isOpen()) {
                try {
                    srcChannel.close();
                } catch (IOException e1) {
                    // ignore
                }
            }
            if (dstChannel != null && dstChannel.isOpen()) {
                try {
                    dstChannel.close();
                } catch (IOException e1) {
                    // ignore
                }
            }
            if (jin != null) {
                try {
                    jin.close();
                    jin = null;
                } catch (IOException e1) {
                    // ignore
                }
            }
            if (jout != null) {
                try {
                    jout.close();
                    jout = null;
                } catch (IOException e1) {
                    // ignore
                }
            }
            if (tempFile != null && tempFile.exists()) {
                tempFile.delete();
            }
        }
        return true;
    }