01: /*
02: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.ffj.wizards;
07:
08: import java.io.File;
09:
10: import org.openide.TopManager;
11:
12: import org.openide.nodes.Node;
13:
14: import org.openide.loaders.TemplateWizard;
15: import org.openide.loaders.DataFolder;
16: import org.openide.loaders.DataObject;
17:
18: import org.openide.filesystems.FileObject;
19: import org.openide.filesystems.FileUtil;
20: import org.openide.filesystems.FileSystem;
21:
22: class PortletAppWizardData {
23:
24: PortletAppWizardData(TemplateWizard tw) {
25:
26: m_Dir = null;
27: Node[] selectedNodes = org.openide.windows.TopComponent
28: .getRegistry().getActivatedNodes();
29: if ((selectedNodes != null) && selectedNodes.length > 0) {
30: for (int i = 0; m_Dir == null && i < selectedNodes.length; i++) {
31: Node target = selectedNodes[i];
32: DataObject obj = (DataObject) target
33: .getCookie(DataObject.class);
34: try {
35: FileSystem fs = obj.getPrimaryFile()
36: .getFileSystem();
37: if (canBeWebApplication(fs)) {
38: File f = FileUtil.toFile(fs.getRoot());
39: m_Dir = f.getPath();
40: }
41:
42: } catch (Exception fsiex) {
43: // keep looking.
44: }
45: }
46: }
47:
48: if (m_Dir == null) {
49: m_Dir = System.getProperty("netbeans.user");
50: if (m_Dir == null) {
51: m_Dir = System.getProperty("user.dir", "/");
52: }
53: }
54: }
55:
56: String getDirectory() {
57: return m_Dir;
58: }
59:
60: void setDirectory(String dir) {
61: m_Dir = dir;
62: }
63:
64: private boolean canBeWebApplication(FileSystem documentBase) {
65: if (documentBase == TopManager.getDefault().getRepository()
66: .getDefaultFileSystem()) {
67: return false;
68: }
69: if (documentBase.isReadOnly()) {
70: return false;
71: }
72: if (documentBase.isHidden()) {
73: return false;
74: }
75: if (documentBase instanceof org.openide.filesystems.JarFileSystem) {
76: return false;
77: }
78: if (documentBase instanceof com.sun.portal.ffj.filesystems.PSFileSystem) {
79: return false;
80: }
81: File f = FileUtil.toFile(documentBase.getRoot());
82: if (f.getPath().endsWith("classes")) {
83: return false;
84: }
85: return true;
86: }
87:
88: private String m_Dir;
89: }
|