01: /**
02: * $Id: DPUNRegister.java,v 1.3 2006/08/08 10:55:39 nk137934 Exp $
03: * Copyright 2004 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.portlet.admin.mbeans.tasks;
14:
15: import java.util.*;
16: import java.io.*;
17: import com.sun.portal.desktop.context.AdminDPContext;
18: import java.util.logging.Level;
19: import java.util.logging.Logger;
20: import com.sun.portal.portlet.admin.mbeans.tasks.*;
21:
22: public class DPUNRegister {
23:
24: private static final String WEB_XML = "web.xml";
25: private static final String PORTLET_XML = "portlet.xml";
26: private static final String EXT_XML = "sun-portlet.xml";
27: private static final String WEB_INF_PREFIX = "WEB-INF" + "/";
28: private static final String DD_LOCATION = "DDFileLocation";
29: private static final String DD_SUFFIX = "_portlet.xml";
30: private static final String WAR_SUFFIX = ".war";
31:
32: private Properties configProps = null;
33:
34: public DPUNRegister(Properties pdconfigProp)
35: throws PortletDeployerException {
36:
37: this .configProps = pdconfigProp;
38: }
39:
40: public void process(AdminDPContext dadc, String dn, boolean global,
41: String earAppName, boolean verbose, Logger logger)
42: throws PortletDeployerException {
43:
44: if (verbose) {
45: logger.log(Level.INFO, "PSPL_CSPPAMT0027",
46: new Object[] { earAppName });
47: }
48:
49: try {
50:
51: DeploymentDescriptorFinder finder = new DeploymentDescriptorFinder(
52: earAppName, configProps, verbose, logger);
53: List list = finder.findPortletDescriptors();
54: if (verbose) {
55: logger.log(Level.INFO, "PSPL_CSPPAMT0028",
56: new Object[] { new Integer(list.size()) });
57: }
58: if (verbose && list.size() == 0) {
59: logger.log(Level.INFO, "PSPL_CSPPAMT0029");
60: }
61: for (int i = 0; i < list.size(); i++) {
62: File descriptorFile = (File) list.get(i);
63: FileInputStream portletXMLStream = new FileInputStream(
64: descriptorFile);
65: String webAppName = getWebAppNameFromFileName(descriptorFile
66: .getName());
67: if (verbose) {
68: logger.log(Level.INFO, "PSPL_CSPPAMT0030",
69: new Object[] { webAppName });
70: }
71: PDProviderEntryGenerator providerGen = new PDProviderEntryGenerator(
72: portletXMLStream, null, configProps, webAppName);
73: List providerNames = providerGen.getProviderNames();
74: PDDPUpdater dpUpdater = new PDDPUpdater(dadc, dn,
75: global, verbose, logger);
76: if (verbose) {
77: logger.log(Level.INFO, "PSPL_CSPPAMT0031");
78: }
79: dpUpdater.removeProviders(providerNames);
80:
81: //remove the portlet.xml
82: descriptorFile.delete();
83: }
84:
85: } catch (IOException excp) {
86: logger.log(Level.SEVERE, "PSPL_CSPPAMT0032", excp);
87: }
88: }
89:
90: public String getWebAppNameFromFileName(String descriptorFileName) {
91: StringTokenizer tokenizer = new StringTokenizer(
92: descriptorFileName, "_");
93: tokenizer.nextToken(); // Ear name -ignore
94: return tokenizer.nextToken();
95:
96: }
97:
98: }
|