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 General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.product.components;
038:
039: import java.io.File;
040: import java.io.InputStream;
041: import java.util.List;
042: import java.util.Map;
043: import org.netbeans.installer.utils.FileUtils;
044: import org.netbeans.installer.utils.ResourceUtils;
045: import org.netbeans.installer.utils.StringUtils;
046: import org.netbeans.installer.utils.SystemUtils;
047: import org.netbeans.installer.utils.exceptions.InstallationException;
048: import org.netbeans.installer.utils.exceptions.UninstallationException;
049: import org.netbeans.installer.utils.helper.RemovalMode;
050: import org.netbeans.installer.utils.helper.Status;
051: import org.netbeans.installer.utils.helper.Text;
052: import org.netbeans.installer.utils.helper.Text.ContentType;
053: import org.netbeans.installer.utils.progress.Progress;
054: import org.netbeans.installer.wizard.components.WizardComponent;
055:
056: public abstract class ProductConfigurationLogic {
057: private Product product;
058:
059: // abstract /////////////////////////////////////////////////////////////////////
060: public abstract void install(final Progress progress)
061: throws InstallationException;
062:
063: public abstract void uninstall(final Progress progress)
064: throws UninstallationException;
065:
066: public abstract List<WizardComponent> getWizardComponents();
067:
068: // product getter/setter ////////////////////////////////////////////////////////
069: protected final Product getProduct() {
070: return product;
071: }
072:
073: final void setProduct(final Product product) {
074: this .product = product;
075: }
076:
077: // validation ///////////////////////////////////////////////////////////////////
078: public String validateInstallation() {
079: if (getProduct().getStatus() == Status.INSTALLED) {
080: final File installLocation = getProduct()
081: .getInstallationLocation();
082: if (installLocation == null) {
083: return ResourceUtils.getString(
084: ProductConfigurationLogic.class,
085: "PCL.validation.directory.null");
086: }
087: if (!installLocation.exists()) {
088: return ResourceUtils.getString(
089: ProductConfigurationLogic.class,
090: "PCL.validation.directory.missing",
091: installLocation);
092: }
093: if (!installLocation.isDirectory()) {
094: return ResourceUtils.getString(
095: ProductConfigurationLogic.class,
096: "PCL.validation.directory.file",
097: installLocation);
098: }
099: if (FileUtils.isEmpty(installLocation)) {
100: return ResourceUtils.getString(
101: ProductConfigurationLogic.class,
102: "PCL.validation.directory.empty",
103: installLocation);
104: }
105: }
106:
107: return null;
108: }
109:
110: // product properties ///////////////////////////////////////////////////////////
111: protected final String getProperty(String name) {
112: return getProperty(name, true);
113: }
114:
115: protected final String getProperty(String name, boolean parse) {
116: final String value = product.getProperty(name);
117:
118: if (parse) {
119: return value != null ? parseString(value) : null;
120: } else {
121: return value;
122: }
123: }
124:
125: protected final void setProperty(final String name,
126: final String value) {
127: product.setProperty(name, value);
128: }
129:
130: // various documentation/legal getters //////////////////////////////////////////
131: public Text getLicense() {
132: final String text = parseString("$R{"
133: + StringUtils.asPath(getClass()) + "/license.txt}");
134:
135: return new Text(text, ContentType.PLAIN_TEXT);
136: }
137:
138: public Map<String, Text> getThirdPartyLicenses() {
139: return null;
140: }
141:
142: public Text getThirdPartyLicense() {
143: return null;
144: }
145:
146: public Text getReleaseNotes() {
147: return null;
148: }
149:
150: public Text getReadme() {
151: return null;
152: }
153:
154: public Text getDistributionReadme() {
155: return null;
156: }
157:
158: public Text getInstallationInstructions() {
159: return null;
160: }
161:
162: // various informational probes /////////////////////////////////////////////////
163: public boolean registerInSystem() {
164: return true;
165: }
166:
167: public String getSystemDisplayName() {
168: return product.getDisplayName();
169: }
170:
171: public boolean allowModifyMode() {
172: return true;
173: }
174:
175: /**
176: * Specifies whether some special handling should be applied to the product's
177: * files when placing them on disk. If this method returns <code>true</code>,
178: * then the files of the product will be "wrapped" in the standard MacOS
179: * application directories structure. Also the {@link #getExecutable()} and
180: * {@link #getIcon()} methods will be called and will be expected to return
181: * proper values for the product's executable and icon so that they are
182: * symlinked from appropriate locations.
183: *
184: * @return Whether the product's files should be wrapped with the standard
185: * Mac OS application directories structure.
186: */
187: public boolean wrapForMacOs() {
188: return false;
189: }
190:
191: /**
192: * Specifies whether the the installation directory for the product should end
193: * with Mac OS's specific extension - <code>.app</code>.
194: *
195: * @return <code>true</code> - if the installation directory must end with
196: * <code>.app</code>, <code>false</code> - otherwise.
197: */
198: public boolean requireDotAppForMacOs() {
199: return false;
200: }
201:
202: /**
203: * @deprecated Use <code>getProhibitedInstallationPathParts</code> instead.
204: */
205: @Deprecated
206: public boolean prohibitExclamation() {
207: return true;
208: }
209:
210: /**
211: * Get the array of strings with each element deprecating the specific paths.<br><br>
212: * One char length elements are treated as the single deprecated char.<br> String.contains() is used for the check.<br><br>
213: * Two and more chars length elements are treated as the regexp patterns.<br> String.matches() is used for the check<br><br>
214: * @return Array of prohibited path parts.
215: */
216: public String[] getProhibitedInstallationPathParts() {
217: return new String[] { "!", File.pathSeparator };
218: }
219:
220: public String getExecutable() {
221: return null;
222: }
223:
224: public String getIcon() {
225: return null;
226: }
227:
228: public int getLogicPercentage() {
229: return 10;
230: }
231:
232: // installation behavior ////////////////////////////////////////////////////////
233: public RemovalMode getRemovalMode() {
234: return RemovalMode.ALL;
235: }
236:
237: // helper methods for system utils and resource utils ///////////////////////////
238: protected final String parseString(String string) {
239: return SystemUtils.resolveString(string, product
240: .getClassLoader());
241: }
242:
243: protected final File parsePath(String path) {
244: return SystemUtils.resolvePath(path, product.getClassLoader());
245: }
246:
247: protected final String getString(String key) {
248: return ResourceUtils.getString(getClass(), key);
249: }
250:
251: protected final String getString(String key, Object... arguments) {
252: return ResourceUtils.getString(getClass(), key, arguments);
253: }
254:
255: protected final InputStream getResource(String path) {
256: return ResourceUtils
257: .getResource(path, product.getClassLoader());
258: }
259: }
|