1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.javahelp; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import java.util.Set ; 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 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 instantiate() throws IOException { 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 TEMPLATE_SUFFIX_HS = "-hs.xml"; private static final String [] TEMPLATE_SUFFIXES = { 71 TEMPLATE_SUFFIX_HS, 72 "-idx.xml", "-map.xml", "-toc.xml", "-about.html", }; 77 private static final String [] TEMPLATE_RESOURCES = { 78 "template_myplugin.hs", "template_myplugin-idx.xml", "template_myplugin-map.jhm", "template_myplugin-toc.xml", "template_myplugin-about.html", }; 85 86 private CreatedModifiedFiles files; 87 88 DataModel(WizardDescriptor wiz) { 89 super(wiz); 90 } 91 92 public CreatedModifiedFiles getCreatedModifiedFiles() { 93 if (files == null) { 94 String codeNameBase = getModuleInfo().getCodeNameBase(); 96 String basename = codeNameBase.substring(codeNameBase.lastIndexOf('.') + 1); 98 String path = codeNameBase.replace('.','/') + "/docs/"; 101 files = new CreatedModifiedFiles(getProject()); 102 Map tokens = new HashMap (); 103 tokens.put("@@CODE_NAME@@", basename); tokens.put("@@FULL_CODE_NAME@@", codeNameBase); tokens.put("@@DISPLAY_NAME@@", ProjectUtils.getInformation(getProject()).getDisplayName()); tokens.put("@@HELPSET_PATH@@", path + basename + TEMPLATE_SUFFIX_HS); 108 files.add(files.createLayerEntry("Services/JavaHelp/" + basename + "-helpset.xml", NewJavaHelpIterator.class.getResource("template_myplugin-helpset.xml"), tokens, 112 null, 113 null)); 114 115 for (int i = 0; i < TEMPLATE_SUFFIXES.length; i++) { 117 URL template = NewJavaHelpIterator.class.getResource(TEMPLATE_RESOURCES[i]); 118 String filePath = "javahelp/" + path + basename + TEMPLATE_SUFFIXES[i]; files.add(files.createFileWithSubstitutions(filePath, template, tokens)); 120 } 121 122 Map props = new HashMap (); 124 props.put("javahelp.hs", basename + TEMPLATE_SUFFIX_HS); files.add(files.propertiesModification("nbproject/project.properties", props)); 130 ModifyManifest attribs = new CreatedModifiedFilesFactory.ModifyManifest(getProject()) { 132 protected void performModification(final EditableManifest em,final String name,final String value, 133 final String section) throws IllegalArgumentException { 134 String 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); files.add(attribs); 145 } 146 return files; 147 } 148 149 } 150 151 } 152 | Popular Tags |