001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.deployment;
006:
007: import java.io.File;
008: import java.util.Vector;
009: import java.util.Properties;
010: import java.util.logging.Level;
011: import java.util.logging.Logger;
012:
013: import org.w3c.dom.Document;
014: import org.w3c.dom.Element;
015:
016: import com.sun.portal.desktop.dp.DPRoot;
017: import com.sun.portal.desktop.dp.DPChannel;
018: import com.sun.portal.desktop.dp.DPNode;
019: import com.sun.portal.desktop.dp.DPContainerChannel;
020: import com.sun.portal.desktop.dp.DPProvider;
021:
022: import com.sun.portal.desktop.dp.xml.XMLDPChannel;
023: import com.sun.portal.desktop.dp.xml.XMLDPProvider;
024:
025: public class DPBasedPPCtx extends DPBasedContext implements
026: ProviderPackageContext {
027:
028: public DPBasedPPCtx(DPRootSpecifier dpr, String ss)
029: throws ParFileException {
030: if (dpr != null) {
031: m_DPRoot = dpr.getRoot();
032: }
033: if (ss != null) {
034: setStaticSub(ss);
035: }
036: }
037:
038: public void setObject(String objname, int types)
039: throws ParFileException {
040: setPropertyHolder(m_DPRoot, objname, types);
041: }
042:
043: public String getContainerName(String channel)
044: throws ParFileException {
045: DPChannel ch = getChannel();
046:
047: if (ch == null) {
048: return null;
049: }
050:
051: try {
052: DPNode pn = ch.getParentNode();
053: if (pn instanceof DPContainerChannel) {
054: return pn.getName();
055: }
056: } catch (Exception ex) {
057: throw new ParFileException("errorContainerName", ex);
058: }
059:
060: return null;
061: }
062:
063: public Document getParEntry(String entryname, String desc)
064: throws ParFileException {
065:
066: // Note - we will ALWAYS try to package a provider, even in cases where we may not
067: // ultimately make use of it. It serves as an error check, if nothing else
068:
069: DPChannel ch = getChannel();
070: DPProvider pr = getProvider();
071:
072: // FIXME - we shouldn't be coercing to implementation class.
073:
074: Element chelt = ch == null ? null : ((XMLDPChannel) ch)
075: .getElement();
076: Element pelt = (pr == null) ? null : ((XMLDPProvider) pr)
077: .getElement();
078:
079: return Par.makeParEntry(entryname, desc, pelt, chelt);
080: }
081:
082: public ProviderPackageFile getStaticFile(String path, int types)
083: throws ParFileException {
084: return new StaticPPF(getStaticDirectory(), path, types);
085: }
086:
087: public ProviderPackageFile getWarFile(String path, int types)
088: throws ParFileException {
089: return new WarPPF(getPortalWarDirectory(), path, types);
090: }
091:
092: public ProviderPackageFile getConfigFile(String path, int types)
093: throws ParFileException {
094: return new ConfPPF(getPSDataDirectory(), path, types);
095: }
096:
097: public ProviderPackageFile getPropLocFile(String rootproperty,
098: String path, int types) throws ParFileException {
099: String rdir = getPBFProperty(rootproperty, false);
100: return new PropLocPPF(rootproperty, rdir, path, types);
101: }
102:
103: public ProviderPackageFile getClassFile(String classname, int types)
104: throws ParFileException {
105: Vector v = getClassPath();
106:
107: // Try the user class area first
108:
109: for (int i = 0; i < v.size(); ++i) {
110: String croot = (String) v.elementAt(i);
111: ClassPPF cpp = null;
112:
113: if (isJar(croot)) {
114: cpp = new ClassJarPPF(classname, croot, types);
115: } else {
116: cpp = new ClassFilePPF(classname, croot, types);
117: }
118:
119: if (cpp.classExists()) {
120: return cpp;
121: }
122: }
123:
124: // If it's not in the user class area, try just loading it as a
125: // a resource from our own classloader.
126:
127: ClassPPF cpp = new ClassLoaderPPF(classname, types);
128: if (cpp.classExists()) {
129: return cpp;
130: }
131:
132: Object tok[] = { classname };
133: throw new ParFileException("errorNoClass", tok);
134: }
135:
136: public void addBasicFiles(Vector v) throws ParFileException {
137:
138: String hlp = getPBFProperty("DeploymentFileHelper", true);
139:
140: if (hlp == null) {
141: return;
142: }
143:
144: BasicFileHelper bh = null;
145: try {
146: bh = (BasicFileHelper) Class.forName(hlp).newInstance();
147: } catch (Exception ex) {
148: throw new ParFileException("errorClassCreate", ex);
149: }
150: bh.addBasicFiles(this , getTypes(), v);
151: }
152:
153: public String getPropertyString(String prop)
154: throws ParFileException {
155: return getPBFProperty(prop, true);
156: }
157:
158: public void addDirectory(String prop, String subdir,
159: boolean recurse, boolean addFiles, String dfilter,
160: int types, String excludedDir, Vector v)
161: throws ParFileException {
162: String rdir = null;
163:
164: if (prop != null) {
165: if (prop.equals(ProviderPackageContext.PSWARDIR)) {
166: rdir = getPortalWarDirectory();
167: } else if (prop.equals(ProviderPackageContext.PSDATADIR)) {
168: rdir = getPSDataDirectory();
169: } else {
170: rdir = getPBFProperty(prop, false);
171: }
172: } else {
173: rdir = getStaticDirectory();
174: }
175:
176: if (rdir.endsWith(FS)) {
177: int len = rdir.length();
178: rdir = rdir.substring(0, len - 1);
179: }
180:
181: Vector dlist = new Vector();
182: if (recurse) {
183: if (dfilter != null && subdir != null) {
184: dlist.add(subdir);
185: }
186: addSubDirs(dlist, rdir, subdir, dfilter, excludedDir);
187: } else {
188: if (subdir != null) {
189: dlist.add(subdir);
190: }
191: }
192:
193: if (addFiles == true) {
194: if (subdir != null) {
195: dlist.add(subdir);
196: } else {
197: dlist.add("");
198: }
199: }
200:
201: for (int i = 0; i < dlist.size(); ++i) {
202: String dir = (String) dlist.elementAt(i);
203: if (dir.equals(excludedDir)) {
204: continue;
205: }
206:
207: File f = new File(rdir + FS + dir);
208:
209: File children[] = f.listFiles();
210: if (children == null) {
211: continue;
212: }
213: for (int j = 0; j < children.length; ++j) {
214: File child = children[j];
215:
216: if (child.isDirectory()) {
217: continue;
218: }
219:
220: String rp = (dir.equals("")) ? child.getName() : dir
221: + FS + child.getName();
222:
223: if (prop != null) {
224: if (prop.equals(ProviderPackageContext.PSWARDIR)) {
225: String psWarFile = System
226: .getProperty(ProviderPackageContext.PSWARFILE);
227: if (child.getName().lastIndexOf(psWarFile) == -1) {
228: v.add(getWarFile(rp, types));
229: }
230: } else if (prop
231: .equals(ProviderPackageContext.PSDATADIR)) {
232: v.add(getConfigFile(rp, types));
233: } else {
234: v.add(getPropLocFile(prop, rp, types));
235: }
236: } else {
237: v.add(getStaticFile(rp, types));
238: }
239: }
240: }
241: }
242:
243: public void setDTProps(Properties prop) {
244: m_DTProps = prop;
245: }
246:
247: private void addSubDirs(Vector dlist, String rdir, String subdir,
248: String dfilter, String excludedDir) {
249: File d = new File(subdir == null ? rdir : (rdir + FS + subdir));
250: File children[] = d.listFiles();
251: if (children == null) {
252: return;
253: }
254:
255: for (int i = 0; i < children.length; ++i) {
256: File child = children[i];
257: String nm = child.getName();
258:
259: if (child.isDirectory()) {
260: if (nm.equals(excludedDir)) {
261: continue;
262: }
263:
264: String nmplus = subdir == null ? nm
265: : (subdir + FS + nm);
266: if (dfilter == null || dfilter.equals(nm)) {
267: dlist.add(nmplus);
268: addSubDirs(dlist, rdir, nmplus, null, excludedDir);
269: continue;
270: }
271: addSubDirs(dlist, rdir, nmplus, dfilter, null);
272: }
273: }
274: }
275:
276: private DPRoot m_DPRoot;
277: }
|