1 19 20 package org.netbeans.modules.javahelp; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import javax.swing.BoundedRangeModel ; 25 import javax.swing.DefaultBoundedRangeModel ; 26 import javax.swing.SwingUtilities ; 27 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 import org.xml.sax.SAXException ; 31 32 import javax.help.HelpSet; 33 import javax.help.HelpSetException; 34 35 import org.openide.cookies.InstanceCookie; 36 import org.openide.loaders.XMLDataObject; 37 import org.openide.util.Lookup; 38 39 43 public final class HelpSetProcessor implements XMLDataObject.Processor, InstanceCookie.Of { 44 45 47 public static final String HELPSET_MERGE_CONTEXT = "OpenIDE"; 49 53 public static final String HELPSET_MERGE_ATTR = "mergeIntoMaster"; 55 public static final BoundedRangeModel parseModel = new DefaultBoundedRangeModel (0, 0, 0, 0); 56 57 59 private XMLDataObject xml; 60 61 63 private HelpSet hs; 64 65 68 public void attachTo(XMLDataObject xml) { 69 if (this.xml == xml) return; 70 hs = null; 71 this.xml = xml; 73 Installer.log.fine("processing help set ref: " + xml.getPrimaryFile()); 74 BPMChanger.invoke(BPMChanger.INC_MAXIMUM); 75 } 76 77 78 protected void finalize() { 79 BPMChanger.invoke(BPMChanger.DEC_VALUE_AND_MAXIMUM); 80 } 81 82 87 public Class instanceClass() throws IOException , ClassNotFoundException { 88 return HelpSet.class; 89 } 90 91 94 public String instanceName() { 95 return "javax.help.HelpSet"; } 97 98 102 public boolean instanceOf(Class type) { 103 return type == HelpSet.class; 104 } 105 106 113 public synchronized Object instanceCreate() throws IOException , ClassNotFoundException { 114 if (hs == null) { 115 Installer.log.fine("creating help set from ref: " + xml.getPrimaryFile()); 116 try { 117 Document doc = xml.getDocument(); 118 Element el = doc.getDocumentElement(); 119 if (! el.getNodeName().equals("helpsetref")) throw new IOException (); String url = el.getAttribute("url"); if (url == null || url.equals("")) throw new IOException ("no url attr on <helpsetref>! doc.class=" + doc.getClass().getName() + " doc.documentElement=" + el); String mergeS = el.getAttribute("merge"); boolean merge = (mergeS == null) || mergeS.equals("") || Boolean.valueOf(mergeS).booleanValue(); 125 Object ignore = NbDocsStreamHandler.class; hs = new HelpSet(((ClassLoader )Lookup.getDefault().lookup(ClassLoader .class)), new URL (url)); 128 hs.setKeyData(HELPSET_MERGE_CONTEXT, HELPSET_MERGE_ATTR, merge ? Boolean.TRUE : Boolean.FALSE); 129 BPMChanger.invoke(BPMChanger.INC_VALUE); 130 } catch (SAXException saxe) { 131 throw (IOException ) new IOException (saxe.toString()).initCause(saxe); 132 } catch (HelpSetException hse) { 133 throw (IOException ) new IOException (hse.toString()).initCause(hse); 134 } 135 } 136 return hs; 137 } 138 139 private static final class BPMChanger implements Runnable { 140 public static final int INC_MAXIMUM = 0; 141 public static final int DEC_VALUE_AND_MAXIMUM = 1; 142 public static final int INC_VALUE = 2; 143 public static void invoke(int action) { 144 SwingUtilities.invokeLater(new BPMChanger(action)); 145 } 146 private final int action; 147 private BPMChanger(int action) { 148 this.action = action; 149 } 150 public void run() { 151 switch (action) { 152 case INC_MAXIMUM: 153 parseModel.setMaximum(parseModel.getMaximum() + 1); 154 break; 155 case DEC_VALUE_AND_MAXIMUM: 156 parseModel.setValue(parseModel.getValue() - 1); 157 parseModel.setMaximum(parseModel.getMaximum() - 1); 158 break; 159 case INC_VALUE: 160 parseModel.setValue(parseModel.getValue() + 1); 161 break; 162 default: 163 throw new IllegalStateException (); 164 } 165 } 166 } 167 168 } 169 170 | Popular Tags |