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:
042: package org.netbeans.modules.apisupport.project.ui.wizard.updatecenter;
043:
044: import java.net.URL;
045: import java.util.Collections;
046: import java.util.Map;
047: import java.util.jar.Manifest;
048: import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
049: import org.netbeans.modules.apisupport.project.ManifestManager;
050: import org.netbeans.modules.apisupport.project.NbModuleProject;
051: import org.netbeans.modules.apisupport.project.Util;
052: import org.netbeans.modules.apisupport.project.layers.LayerUtils;
053: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
054: import org.openide.WizardDescriptor;
055: import org.openide.filesystems.FileObject;
056: import org.openide.filesystems.FileSystem;
057:
058: /**
059: * Data model used across the <em>New Update Center Wizard</em>.
060: * @author Jiri Rechtacek
061: */
062: final class DataModel extends BasicWizardIterator.BasicDataModel {
063:
064: static private String AUTOUPDATE_TYPES = "Services/AutoupdateType"; //NOI18N
065: private String AUTOUPDATE_SERVICE_TYPE = "_update_center"; //NOI18N
066: static private String AUTOUPDATE_SETTINGS_TYPE_EXT = "settings"; //NOI18N
067: static private String AUTOUPDATE_INSTANCE_TYPE_EXT = "instance"; //NOI18N
068: static private String UC_LOCALIZING_BUNDLE = "SystemFileSystem.localizingBundle"; //NOI18N
069: static private String AUTOUPDATE_MODULE = "org.netbeans.modules.autoupdate"; // NOI18N
070: static private String AUTOUPDATE_MODULE_NEW = "org.netbeans.modules.autoupdate.services"; // NOI18N
071:
072: private CreatedModifiedFiles cmf;
073:
074: // third panel data (Name, and Location)
075: private String ucUrl;
076: private String ucDisplayName;
077:
078: DataModel(WizardDescriptor wiz) {
079: super (wiz);
080: }
081:
082: private CreatedModifiedFiles regenerate() {
083: if (cmf == null) {
084: cmf = new CreatedModifiedFiles(getProject());
085: }
086: boolean newAPI = ((NbModuleProject) getProject()).getPlatform(
087: true).getModule(AUTOUPDATE_MODULE_NEW) != null;
088: String extension = (newAPI) ? AUTOUPDATE_INSTANCE_TYPE_EXT
089: : AUTOUPDATE_SETTINGS_TYPE_EXT;
090: FileObject template = newAPI ? null : CreatedModifiedFiles
091: .getTemplate("update_center.xml"); // NOI18N
092: String serviceTypeName = getModuleInfo().getCodeNameBase()
093: .replace('.', '_')
094: + AUTOUPDATE_SERVICE_TYPE; // NOI18N
095: FileSystem layer = LayerUtils.layerForProject(getProject())
096: .layer(false);
097:
098: String pathToAutoUpdateType = AUTOUPDATE_TYPES + '/'
099: + serviceTypeName + '.' + extension;
100: int sequence = 0;
101: if (layer != null) {
102: FileObject f;
103: do {
104: f = layer.findResource(pathToAutoUpdateType);
105: if (f != null) {
106: pathToAutoUpdateType = AUTOUPDATE_TYPES + '/'
107: + serviceTypeName + '_' + ++sequence + '.'
108: + extension;
109: }
110: } while (f != null);
111: }
112: String codename = null;
113: Manifest mani = ((NbModuleProject) getProject()).getManifest();
114: if (mani != null) {
115: codename = mani.getMainAttributes().getValue(
116: "OpenIDE-Module"); // NOI18N
117: }
118: if (codename == null) {
119: codename = getModuleInfo().getCodeNameBase();
120: }
121: final Map<String, String> substitutionTokens = newAPI ? null
122: : Collections.singletonMap("MODULECODENAME", codename);
123: cmf.add(cmf.createLayerEntry(pathToAutoUpdateType, template,
124: substitutionTokens, null, null)); // NOI18N
125:
126: if (newAPI) {
127: cmf
128: .add(cmf
129: .createLayerAttribute(
130: pathToAutoUpdateType,
131: "instanceCreate",
132: "methodvalue:org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory.createUpdateProvider")); //NOI18N
133: cmf.add(cmf.createLayerAttribute(pathToAutoUpdateType,
134: "instanceOf",
135: "org.netbeans.spi.autoupdate.UpdateProvider")); //NOI18N
136: }
137: String url_key_base = getModuleInfo().getCodeNameBase()
138: .replace('.', '_')
139: + AUTOUPDATE_SERVICE_TYPE; //NOI18N
140: String url_key = sequence == 0 ? url_key_base : url_key_base
141: + '_' + sequence; // NOI18N
142: cmf.add(cmf.createLayerAttribute(pathToAutoUpdateType,
143: "url_key", url_key)); //NOI18N
144: cmf.add(cmf.createLayerAttribute(pathToAutoUpdateType,
145: "enabled", Boolean.TRUE)); //NOI18N
146:
147: // write into bundle
148: ManifestManager mm = ManifestManager.getInstance(Util
149: .getManifest(getModuleInfo().getManifestFile()), false);
150: String localizingBundle = mm.getLocalizingBundle();
151: localizingBundle = localizingBundle.substring(0,
152: localizingBundle.indexOf('.'));
153: localizingBundle = localizingBundle.replace('/', '.');
154: cmf.add(cmf.createLayerAttribute(pathToAutoUpdateType,
155: UC_LOCALIZING_BUNDLE, localizingBundle));
156:
157: cmf.add(cmf.bundleKeyDefaultBundle(pathToAutoUpdateType,
158: ucDisplayName));
159: cmf.add(cmf.bundleKeyDefaultBundle(url_key, ucUrl));
160:
161: // add dependency to autoupdate module
162: cmf.add(cmf.addModuleDependency(newAPI ? AUTOUPDATE_MODULE_NEW
163: : AUTOUPDATE_MODULE, null, null, false));
164:
165: return cmf;
166: }
167:
168: CreatedModifiedFiles refreshCreatedModifiedFiles() {
169: return regenerate();
170: }
171:
172: void setUpdateCenterURL(String url) {
173: this .ucUrl = url;
174: }
175:
176: String getUpdateCenterURL() {
177: return ucUrl != null ? ucUrl : ""; //NOI18N
178: }
179:
180: void setUpdateCenterDisplayName(String name) {
181: this .ucDisplayName = name;
182: }
183:
184: String getUpdateCenterDisplayName() {
185: return ucDisplayName != null ? ucDisplayName : ""; //NOI18N
186: }
187:
188: }
|