KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > javahelp > NewJavaHelpIterator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.javahelp;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
29 import org.netbeans.modules.apisupport.project.CreatedModifiedFilesFactory;
30 import org.netbeans.modules.apisupport.project.CreatedModifiedFilesFactory.ModifyManifest;
31 import org.netbeans.modules.apisupport.project.EditableManifest;
32 import org.netbeans.modules.apisupport.project.ManifestManager;
33 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
34 import org.openide.WizardDescriptor;
35
36 /**
37  * Wizard for creating JavaHelp
38  *
39  * @author Radek Matous, Jesse Glick
40  */

41 public class NewJavaHelpIterator extends BasicWizardIterator {
42     
43     private NewJavaHelpIterator.DataModel data;
44     
45     public static NewJavaHelpIterator createIterator() {
46         return new NewJavaHelpIterator();
47     }
48     
49     public Set JavaDoc instantiate() throws IOException JavaDoc {
50         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
51         cmf.run();
52         return getCreatedFiles(cmf, data.getProject());
53     }
54     
55     protected BasicWizardIterator.Panel[] createPanels(WizardDescriptor wiz) {
56         data = new NewJavaHelpIterator.DataModel(wiz);
57         return new BasicWizardIterator.Panel[] {
58             new JavaHelpPanel(wiz, data)
59         };
60     }
61     
62     public void uninitialize(WizardDescriptor wiz) {
63         super.uninitialize(wiz);
64         data = null;
65     }
66     
67     static final class DataModel extends BasicWizardIterator.BasicDataModel {
68         
69         private static final String JavaDoc TEMPLATE_SUFFIX_HS = "-hs.xml"; // NOI18N
70
private static final String JavaDoc[] TEMPLATE_SUFFIXES = {
71             TEMPLATE_SUFFIX_HS,
72             "-idx.xml", // NOI18N
73
"-map.xml", // NOI18N
74
"-toc.xml", // NOI18N
75
"-about.html", // NOI18N
76
};
77         private static final String JavaDoc[] TEMPLATE_RESOURCES = {
78             // Historical names in CVS, do not match actual extensions when created:
79
"template_myplugin.hs", // NOI18N
80
"template_myplugin-idx.xml", // NOI18N
81
"template_myplugin-map.jhm", // NOI18N
82
"template_myplugin-toc.xml", // NOI18N
83
"template_myplugin-about.html", // NOI18N
84
};
85         
86         private CreatedModifiedFiles files;
87         
88         DataModel(WizardDescriptor wiz) {
89             super(wiz);
90         }
91         
92         public CreatedModifiedFiles getCreatedModifiedFiles() {
93             if (files == null) {
94                 // org.netbeans.modules.foo
95
String JavaDoc codeNameBase = getModuleInfo().getCodeNameBase();
96                 // foo
97
String JavaDoc basename = codeNameBase.substring(codeNameBase.lastIndexOf('.') + 1);
98                 // org/netbeans/modules/foo/docs/
99
String JavaDoc path = codeNameBase.replace('.','/') + "/docs/"; // NOI18N
100

101                 files = new CreatedModifiedFiles(getProject());
102                 Map JavaDoc tokens = new HashMap JavaDoc();
103                 tokens.put("@@CODE_NAME@@", basename); // NOI18N
104
tokens.put("@@FULL_CODE_NAME@@", codeNameBase); // NOI18N
105
tokens.put("@@DISPLAY_NAME@@", ProjectUtils.getInformation(getProject()).getDisplayName()); // NOI18N
106
tokens.put("@@HELPSET_PATH@@", path + basename + TEMPLATE_SUFFIX_HS); // NOI18N
107

108                 //layer registration
109
files.add(files.createLayerEntry("Services/JavaHelp/" + basename + "-helpset.xml", // NOI18N
110
NewJavaHelpIterator.class.getResource("template_myplugin-helpset.xml"), // NOI18N
111
tokens,
112                         null,
113                         null));
114                 
115                 //copying templates
116
for (int i = 0; i < TEMPLATE_SUFFIXES.length; i++) {
117                     URL JavaDoc template = NewJavaHelpIterator.class.getResource(TEMPLATE_RESOURCES[i]);
118                     String JavaDoc filePath = "javahelp/" + path + basename + TEMPLATE_SUFFIXES[i]; // NOI18N
119
files.add(files.createFileWithSubstitutions(filePath, template, tokens));
120                 }
121                 
122                 // edit some properties
123
Map JavaDoc props = new HashMap JavaDoc();
124                 // Default for javahelp.base (org/netbeans/modules/foo/docs) is correct.
125
// For <checkhelpset> (currently nb.org modules only, but may be bundled in harness some day):
126
props.put("javahelp.hs", basename + TEMPLATE_SUFFIX_HS); // NOI18N
127
// XXX 71527: props.put("jhall.jar", "${harness.dir}/lib/jhall.jar"); // NOI18N
128
files.add(files.propertiesModification("nbproject/project.properties", props)); // NOI18N
129

130                 //put OpenIDE-Module-Requires into manifest
131
ModifyManifest attribs = new CreatedModifiedFilesFactory.ModifyManifest(getProject()) {
132                     protected void performModification(final EditableManifest em,final String JavaDoc name,final String JavaDoc value,
133                             final String JavaDoc section) throws IllegalArgumentException JavaDoc {
134                         String JavaDoc originalValue = em.getAttribute(name, section);
135                         if (originalValue != null) {
136                             em.setAttribute(name, originalValue+","+value, section);
137                         } else {
138                             super.performModification(em, name, value, section);
139                         }
140                     }
141                     
142                 };
143                 attribs.setAttribute("OpenIDE-Module-Requires", "org.netbeans.api.javahelp.Help", null); // NOI18N
144
files.add(attribs);
145             }
146             return files;
147         }
148         
149     }
150     
151 }
152
Popular Tags