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.cli;
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.DSAMEAdminDPContext;
023:
024: /**
025: * PDUNDeploy is responsible for removing the provider entries
026: * corresponding to the portlet entries in portlet.xml and updating
027: * the display profile.
028: */
029: class PDUNDeploy {
030:
031: private static final String CONFIG_LOCATION_PROPERTY = "deployer.propertiesFile";
032: private static final String DD_LOCATION = "DDFileLocation";
033: private static final String DD_SUFFIX = "_portlet.xml";
034:
035: private Properties configProps = new Properties();
036:
037: public PDUNDeploy() throws PortletDeployerException {
038: String configName = System
039: .getProperty(CONFIG_LOCATION_PROPERTY);
040: if (configName == null) {
041: throw new PortletDeployerException("errorConfigFile");
042: }
043: try {
044: configProps.load(new FileInputStream(configName));
045: } catch (FileNotFoundException fnfe) {
046: Object[] tokens = { fnfe.toString() };
047: throw new PortletDeployerException("errorConfigFile",
048: tokens);
049: } catch (IOException ioe) {
050: Object[] tokens = { ioe.toString() };
051: throw new PortletDeployerException("errorConfigFile",
052: tokens);
053: }
054:
055: }
056:
057: public String process(DSAMEAdminDPContext dadc, String dn,
058: boolean global, String warName, boolean verbose)
059: throws PortletDeployerException {
060:
061: if (verbose) {
062: PortletDeployerLocalizer.debug("dbgGettingPortletDD");
063: }
064:
065: // get the portlet.xml as InputStream
066: String ddLocation = configProps.getProperty(DD_LOCATION);
067: String ddName = warName + DD_SUFFIX;
068: InputStream in = null;
069: File portletFile = null;
070: try {
071: portletFile = new File(ddLocation, ddName);
072: in = new FileInputStream(portletFile);
073: } catch (IOException ioe) {
074: Object[] tokens = { ioe.toString() };
075: throw new PortletDeployerException("errorStreamRead",
076: tokens);
077: }
078: //System.out.println("PDDeploy: done getting in from portlet file");
079:
080: if (verbose) {
081: PortletDeployerLocalizer.debug("dbgCreatingProviderNames");
082: }
083: // Call deployment descriptor parser with portlet.xml and create provider elements.
084:
085: PDProviderEntryGenerator providerGen = new PDProviderEntryGenerator(
086: in, null, configProps, warName);
087: List providerNames = providerGen.getProviderNames();
088:
089: //System.out.println("PDDeploy: done getting provider names=" + providerNames);
090: try {
091: in.close();
092: } catch (IOException ioe) {
093: Object[] tokens = { ioe.toString() };
094: throw new PortletDeployerException("errorStreamClose",
095: tokens);
096: }
097:
098: if (verbose) {
099: PortletDeployerLocalizer.debug("dbgRemovingProviders");
100: }
101: // remove provider definition using DPAPI.
102:
103: PDDPUpdater dpUpdater = new PDDPUpdater(dadc, dn, global,
104: verbose);
105: dpUpdater.removeProviders(providerNames);
106:
107: // remove the portletApp DD file.
108: if (portletFile != null) {
109: portletFile.delete();
110: }
111:
112: //System.out.println("PDDeploy: done removing providers");
113: return PortletDeployerLocalizer
114: .getLocalizedString("msgSuccess");
115:
116: }
117:
118: }
|