001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.portlet.admin.mbeans.tasks;
006:
007: import java.io.IOException;
008: import java.io.File;
009: import java.io.InputStream;
010: import java.io.FileInputStream;
011: import java.io.FileOutputStream;
012: import java.io.FileNotFoundException;
013:
014: import java.util.List;
015: import java.util.Properties;
016:
017: import java.util.jar.JarFile;
018: import java.util.jar.JarEntry;
019:
020: import java.util.zip.ZipEntry;
021:
022: import com.sun.portal.desktop.context.AdminDPContext;
023:
024: import java.util.logging.Level;
025: import java.util.logging.Logger;
026:
027: /**
028: * PDUNDeploy is responsible for removing the provider entries
029: * corresponding to the portlet entries in portlet.xml and updating
030: * the display profile.
031: */
032: public class PDUNDeploy {
033:
034: //private static final String CONFIG_LOCATION_PROPERTY = "deployer.propertiesFile";
035: private static final String DD_LOCATION = "DDFileLocation";
036: private static final String DD_SUFFIX = "_portlet.xml";
037:
038: private Properties configProps = null;
039:
040: public PDUNDeploy(Properties pdconfigProp)
041: throws PortletDeployerException {
042: this .configProps = pdconfigProp;
043: }
044:
045: public void process(AdminDPContext dadc, String dn, boolean global,
046: String warName, boolean verbose, Logger logger)
047: throws PortletDeployerException {
048:
049: if (verbose) {
050: logger.info("PSPL_CSPPAMT0003");
051: }
052:
053: // get the portlet.xml as InputStream
054: String ddLocation = configProps.getProperty(DD_LOCATION);
055:
056: //validate the portal webapp name
057: if (!(new File(ddLocation, warName + ".war").exists())) {
058: Object[] tokens = { warName };
059: throw new PortletDeployerException(
060: "errorInvalidWebAppName", tokens);
061: }
062:
063: String ddName = warName + DD_SUFFIX;
064: InputStream in = null;
065: File portletFile = null;
066: try {
067: portletFile = new File(ddLocation, ddName);
068: in = new FileInputStream(portletFile);
069: } catch (IOException ioe) {
070: Object[] tokens = { ddLocation + File.separator + ddName,
071: warName + ".war" };
072: throw new PortletDeployerException(
073: "errorStreamReadWhileUndeploy", ioe, tokens);
074: }
075:
076: if (verbose) {
077: logger.info("PSPL_CSPPAMT0008");
078: }
079: // Call deployment descriptor parser with portlet.xml and create provider elements.
080:
081: PDProviderEntryGenerator providerGen = new PDProviderEntryGenerator(
082: in, null, configProps, warName);
083: List providerNames = providerGen.getProviderNames();
084:
085: //System.out.println("PDDeploy: done getting provider names=" + providerNames);
086: try {
087: in.close();
088: } catch (IOException ioe) {
089: throw new PortletDeployerException("errorStreamClose", ioe);
090: }
091:
092: if (verbose) {
093: logger.info("PSPL_CSPPAMT0036");
094: }
095: // remove provider definition using DPAPI.
096:
097: PDDPUpdater dpUpdater = new PDDPUpdater(dadc, dn, global,
098: verbose, logger);
099: dpUpdater.removeProviders(providerNames);
100:
101: // remove the portletApp DD file.
102: if (portletFile != null) {
103: portletFile.delete();
104: }
105:
106: //System.out.println("PDDeploy: done removing providers");
107: return;
108:
109: }
110:
111: }
|