001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.php.rt.providers.impl.local;
042:
043: import java.io.File;
044: import java.util.logging.Logger;
045: import org.netbeans.modules.php.rt.providers.impl.HostImpl;
046: import org.openide.util.NbBundle;
047:
048: /**
049: * TODO: web and php config files are temporarily stored into LocalHostImpl.
050: * Move into ancestor.
051: *
052: * @author ads
053: *
054: */
055: public class LocalHostImpl extends HostImpl {
056:
057: public static final String DOCUMENT_PATH = "document-path"; // NOI18N
058: public static final String WEB_CONFIG_FILE = "web-config-file"; // NOI18N
059: public static final String PHP_CONFIG_FILE = "php-config-file"; // NOI18N
060:
061: private static final String MSG_NOT_CONFIGURED_FILE = "MSG_NotConfiguredFile"; // NOI18N
062:
063: private static Logger LOGGER = Logger.getLogger(LocalHostImpl.class
064: .getName());
065:
066: public LocalHostImpl(String name, LocalServerProvider provider) {
067: super (name, provider);
068: }
069:
070: public LocalHostImpl(String name, String domain, String port,
071: String baseDir, LocalServerProvider provider) {
072: super (name, domain, port, baseDir, provider);
073: }
074:
075: /* (non-Javadoc)
076: * @see org.netbeans.modules.php.rt.spi.providers.Host#getProperty(java.lang.String)
077: */
078: @Override
079: public Object getProperty(String key) {
080: Object obj = super .getProperty(key);
081: if (obj != null) {
082: return obj;
083: } else if (DOCUMENT_PATH.equals(key)) {
084: return myDocumentPath;
085: } else if (WEB_CONFIG_FILE.equals(key)) {
086: return myWebServerConfig;
087: } else if (PHP_CONFIG_FILE.equals(key)) {
088: return myPhpConfig;
089: }
090: return null;
091: }
092:
093: /* (non-Javadoc)
094: * @see org.netbeans.modules.php.rt.spi.providers.Host#putProperty(java.lang.String, java.lang.Object)
095: */
096: @Override
097: public void setProperty(String key, Object value) {
098: super .setProperty(key, value);
099: if (DOCUMENT_PATH.equals(key)) {
100: myDocumentPath = toStringValue(value);
101: } else if (WEB_CONFIG_FILE.equals(key)) {
102: myWebServerConfig = toStringValue(value);
103: } else if (PHP_CONFIG_FILE.equals(key)) {
104: myPhpConfig = toStringValue(value);
105: }
106: }
107:
108: /* (non-Javadoc)
109: * @see org.netbeans.modules.php.rt.providers.impl.HostImpl#getName()
110: */
111: @Override
112: protected String getName() {
113: return super .getName();
114: }
115:
116: /* (non-Javadoc)
117: * @see org.netbeans.modules.php.rt.providers.impl.HostImpl#getDomain()
118: */
119: @Override
120: protected String getDomain() {
121: return super .getDomain();
122: }
123:
124: /* (non-Javadoc)
125: * @see org.netbeans.modules.php.rt.providers.impl.HostImpl#getPort()
126: */
127: @Override
128: protected String getPort() {
129: return super .getPort();
130: }
131:
132: @Override
133: protected String getBaseDirectory() {
134: return super .getBaseDirectory();
135: }
136:
137: protected String getDocumentPath() {
138: return myDocumentPath;
139: }
140:
141: private String myDocumentPath;
142:
143: private String myWebServerConfig;
144:
145: private String myPhpConfig;
146:
147: /**
148: * contains FtpHost helper methods
149: */
150: public static class Helper extends HostImpl.Helper {
151:
152: public final static String FILE = "file";
153:
154: public static String noFileMessage() {
155: return NbBundle.getMessage(LocalHostImpl.class,
156: MSG_NOT_CONFIGURED_FILE);
157: //return FILE+":/";
158: }
159:
160: public static boolean isWebConfigSet(LocalHostImpl host) {
161: String conf = (String) host
162: .getProperty(LocalHostImpl.WEB_CONFIG_FILE);
163: return isStringValueSet(conf);
164: }
165:
166: public static boolean isPhpConfigSet(LocalHostImpl host) {
167: String conf = (String) host
168: .getProperty(LocalHostImpl.PHP_CONFIG_FILE);
169: return isStringValueSet(conf);
170: }
171:
172: public static boolean isFileReady(LocalHostImpl host) {
173: String path = (String) host
174: .getProperty(LocalHostImpl.DOCUMENT_PATH);
175: return isStringValueSet(path);
176: }
177:
178: public static String getFileUrl(LocalHostImpl host) {
179: if (!isFileReady(host)) {
180: return null;
181: }
182:
183: String path = (String) host
184: .getProperty(LocalHostImpl.DOCUMENT_PATH);
185:
186: if (path != null) {
187: path = path.replace('/', File.separatorChar);
188: if (path.endsWith(File.separator)) {
189: path = path.substring(0, path.length() - 1);
190: }
191: }
192:
193: return path;
194: }
195:
196: public static String addSubdirectoryToPath(String parent,
197: String child) {
198: File parentFile = new File(parent);
199: File childFile = new File(parentFile, child);
200: return childFile.getPath();
201: }
202:
203: private static boolean isStringValueSet(String value) {
204: if (value == null || value.trim().length() == 0) {
205: return false;
206: }
207: return true;
208: }
209:
210: }
211:
212: }
|