# HG changeset patch # Parent 9a52cf462a461279177ba2bb0044f4afc0bc3e64 Issue #41443: support HTTP URLs for Javadoc. diff --git a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/Bundle.properties b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/Bundle.properties --- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/Bundle.properties +++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/Bundle.properties @@ -105,3 +105,4 @@ AD_DownContent=N/A TXT_BrokenFile=The specified file does not exist. +J2SEVolumeCustomizer.addURLButton.text=Add UR&L... diff --git a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.form b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.form --- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.form +++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.form @@ -1,17 +1,18 @@ - + -
+ - + - + + @@ -70,7 +71,22 @@ - + + + + + + + + + + + + + + + + diff --git a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.java b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.java --- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.java +++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SEVolumeCustomizer.java @@ -57,7 +57,6 @@ import java.util.Collections; import javax.swing.AbstractAction; import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JList; @@ -77,6 +76,7 @@ import org.netbeans.spi.project.libraries.LibraryImplementation; import org.netbeans.spi.project.libraries.LibraryStorageArea; import org.netbeans.spi.project.libraries.support.LibrariesSupport; +import org.openide.DialogDescriptor; /** * @@ -90,7 +90,6 @@ private VolumeContentModel model; private Boolean allowRelativePaths = null; - /** Creates new form J2SEVolumeCustomizer */ J2SEVolumeCustomizer (String volumeType) { this.volumeType = volumeType; initComponents(); @@ -107,9 +106,7 @@ public void setEnabled(boolean enabled) { super.setEnabled(enabled); this.addButton.setEnabled(enabled); - if (this.addURLButton != null) { - this.addURLButton.setEnabled(enabled); - } + addURLButton.setEnabled(volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_JAVADOC)); int[] indices = content.getSelectedIndices(); this.removeButton.setEnabled(enabled && indices.length > 0); this.downButton.setEnabled(enabled && indices.length > 0 && indices[indices.length-1]//GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; @@ -196,15 +193,15 @@ jScrollPane1 = new javax.swing.JScrollPane(); content = new javax.swing.JList(); addButton = new javax.swing.JButton(); + addURLButton = new javax.swing.JButton(); removeButton = new javax.swing.JButton(); upButton = new javax.swing.JButton(); downButton = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); - getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_J2SEVolumeCustomizer")); message.setLabelFor(content); - org.openide.awt.Mnemonics.setLocalizedText(message, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_ContentMessage")); + org.openide.awt.Mnemonics.setLocalizedText(message, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_ContentMessage")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; @@ -225,30 +222,40 @@ gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6); add(jScrollPane1, gridBagConstraints); - org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_AddContent")); + org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_AddContent")); // NOI18N addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addResource(evt); } }); - gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6); + gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6); add(addButton, gridBagConstraints); - addButton.getAccessibleContext().setAccessibleDescription(null); + addButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_addButton")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_RemoveContent")); + org.openide.awt.Mnemonics.setLocalizedText(addURLButton, NbBundle.getMessage(J2SEVolumeCustomizer.class, "J2SEVolumeCustomizer.addURLButton.text")); // NOI18N + addURLButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addURLButtonActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6); + add(addURLButton, gridBagConstraints); + + org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_RemoveContent")); // NOI18N removeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeResource(evt); } }); - gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; @@ -257,15 +264,14 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6); add(removeButton, gridBagConstraints); - removeButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_RemoveContent")); + removeButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_RemoveContent")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(upButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_UpContent")); + org.openide.awt.Mnemonics.setLocalizedText(upButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_UpContent")); // NOI18N upButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { upResource(evt); } }); - gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; @@ -274,15 +280,14 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 6); add(upButton, gridBagConstraints); - upButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_UpContent")); + upButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_UpContent")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(downButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_DownContent")); + org.openide.awt.Mnemonics.setLocalizedText(downButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_DownContent")); // NOI18N downButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { downResource(evt); } }); - gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; @@ -291,10 +296,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6); add(downButton, gridBagConstraints); - downButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_DownContent")); + downButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_DownContent")); // NOI18N - } - // //GEN-END:initComponents + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_J2SEVolumeCustomizer")); // NOI18N + }// //GEN-END:initComponents private void downResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downResource int[] indices = this.content.getSelectedIndices(); @@ -396,27 +401,23 @@ } }//GEN-LAST:event_addResource - -// private void addURLResource () { -// DialogDescriptor.InputLine input = new DialogDescriptor.InputLine ( -// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLMessage"), -// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLTitle")); -// if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) { -// try { -// String value = input.getInputText(); -// URL url = new URL (value); -// this.model.addResource(url); -// this.content.setSelectedIndex(this.model.getSize()-1); -// } catch (MalformedURLException mue) { -// DialogDescriptor.Message message = new DialogDescriptor.Message ( -// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_InvalidURLFormat"), -// DialogDescriptor.ERROR_MESSAGE -// ); -// DialogDisplayer.getDefault().notify(message); -// } -// } -// } - + private void addURLButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addURLButtonActionPerformed + DialogDescriptor.InputLine input = new DialogDescriptor.InputLine( + NbBundle.getMessage(J2SEVolumeCustomizer.class, "CTL_AddJavadocURLMessage"), + NbBundle.getMessage(J2SEVolumeCustomizer.class, "CTL_AddJavadocURLTitle")); + if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) { + try { + String value = input.getInputText(); + URL url = new URL(value); + model.addResource(url); + content.setSelectedIndex(model.getSize() - 1); + } catch (MalformedURLException mue) { + DialogDisplayer.getDefault().notify(new DialogDescriptor.Message( + NbBundle.getMessage(J2SEVolumeCustomizer.class, "CTL_InvalidURLFormat"), + DialogDescriptor.ERROR_MESSAGE)); + } + } + }//GEN-LAST:event_addURLButtonActionPerformed private void addFiles (String[] fileNames, URL libraryLocation, String volume) throws MalformedURLException, URISyntaxException { int firstIndex = this.model.getSize(); @@ -579,6 +580,7 @@ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addButton; + private javax.swing.JButton addURLButton; private javax.swing.JList content; private javax.swing.JButton downButton; private javax.swing.JScrollPane jScrollPane1; @@ -586,7 +588,6 @@ private javax.swing.JButton removeButton; private javax.swing.JButton upButton; // End of variables declaration//GEN-END:variables - private JButton addURLButton; private static class ContentRenderer extends DefaultListCellRenderer { @@ -605,7 +606,9 @@ Exceptions.printStackTrace(ex); } } - if (uri != null) { + if (uri != null && uri.toString().startsWith("http")) { + displayName = uri.toString(); + } else if (uri != null) { if (uri.toString().contains("!/")) { //NOI18N uri = LibrariesSupport.getArchiveFile(uri); } diff --git a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/J2SEPlatformCustomizer.java b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/J2SEPlatformCustomizer.java --- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/J2SEPlatformCustomizer.java +++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/J2SEPlatformCustomizer.java @@ -40,8 +40,9 @@ */ package org.netbeans.modules.java.j2seplatform.platformdefinition; - -import java.awt.*; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.File; @@ -51,7 +52,16 @@ import java.net.URL; import java.net.URI; import java.net.MalformedURLException; -import javax.swing.*; +import javax.swing.AbstractListModel; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; import javax.swing.filechooser.FileFilter; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; @@ -61,10 +71,10 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.spi.java.classpath.PathResourceImplementation; import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; import org.openide.util.Exceptions; - - public class J2SEPlatformCustomizer extends JTabbedPane { private static final int CLASSPATH = 0; @@ -97,7 +107,7 @@ private JList resources; private JButton addButton; -// private JButton addURLButton; + private JButton addURLButton; private JButton removeButton; private JButton moveUpButton; private JButton moveDownButton; @@ -197,24 +207,24 @@ c.insets = new Insets (0,6,0,6); ((GridBagLayout)this.getLayout()).setConstraints(addButton,c); this.add (addButton); -// if (this.type == JAVADOC) { -// addURLButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddURL")); -// addURLButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_AddURL").charAt(0)); -// addURLButton.addActionListener(new ActionListener () { -// public void actionPerformed(ActionEvent e) { -// addURLElement (); -// } -// }); -// c = new GridBagConstraints(); -// c.gridx = 1; -// c.gridy = 2; -// c.gridwidth = GridBagConstraints.REMAINDER; -// c.fill = GridBagConstraints.HORIZONTAL; -// c.anchor = GridBagConstraints.NORTHWEST; -// c.insets = new Insets (0,6,6,12); -// ((GridBagLayout)this.getLayout()).setConstraints(addURLButton,c); -// this.add (addURLButton); -// } + if (this.type == JAVADOC) { + addURLButton = new JButton(NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddURL")); + addURLButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_AddURL").charAt(0)); + addURLButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + addURLElement(); + } + }); + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 2; + c.gridwidth = GridBagConstraints.REMAINDER; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.NORTHWEST; + c.insets = new Insets(0, 6, 6, 12); + ((GridBagLayout) this.getLayout()).setConstraints(addURLButton, c); + this.add(addURLButton); + } removeButton = new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Remove")); removeButton.setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Remove").charAt(0)); removeButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SEPlatformCustomizer.class,"AD_Remove")); @@ -272,55 +282,55 @@ } } -// private void addURLElement() { -// JPanel p = new JPanel (); -// GridBagLayout lm = new GridBagLayout(); -// p.setLayout (lm); -// GridBagConstraints c = new GridBagConstraints (); -// c.gridx = c.gridy = GridBagConstraints.RELATIVE; -// c.insets = new Insets (12,12,12,6); -// c.anchor = GridBagConstraints.NORTHWEST; -// JLabel label = new JLabel (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLMessage")); -// label.setDisplayedMnemonic ('U'); -// lm.setConstraints(label,c); -// p.add (label); -// c = new GridBagConstraints (); -// c.gridx = c.gridy = GridBagConstraints.RELATIVE; -// c.gridwidth = GridBagConstraints.REMAINDER; -// c.insets = new Insets (12,0,12,6); -// c.fill = GridBagConstraints.HORIZONTAL; -// c.anchor = GridBagConstraints.NORTHWEST; -// JTextField text = new JTextField (); -// text.setColumns(30); -// text.setText (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_DefaultProtocol")); -// text.selectAll(); -// label.setLabelFor(text); -// lm.setConstraints(text,c); -// p.add (text); -// JButton[] options = new JButton[] { -// new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLTitle")), -// new JButton (NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_Cancel")) -// }; -// options[0].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class,"MNE_Add").charAt(0)); -// options[1].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class,"MNE_Cancel").charAt(0)); -// DialogDescriptor input = new DialogDescriptor ( -// p, -// NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_AddJavadocURLTitle"), -// true, options, options[0], DialogDescriptor.DEFAULT_ALIGN, null, null); -// if (DialogDisplayer.getDefault().notify(input) == options[0]) { -// try { -// String value = text.getText(); -// URL url = new URL (value); -// ((PathModel)this.resources.getModel()).addPath(url); -// this.resources.setSelectedIndex (this.resources.getModel().getSize()-1); -// } catch (MalformedURLException mue) { -// DialogDescriptor.Message message = new DialogDescriptor.Message ( -// NbBundle.getMessage(J2SEPlatformCustomizer.class,"CTL_InvalidURLFormat"), -// DialogDescriptor.ERROR_MESSAGE); -// DialogDisplayer.getDefault().notify(message); -// } -// } -// } + private void addURLElement() { + JPanel p = new JPanel(); + GridBagLayout lm = new GridBagLayout(); + p.setLayout(lm); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = c.gridy = GridBagConstraints.RELATIVE; + c.insets = new Insets(12, 12, 12, 6); + c.anchor = GridBagConstraints.NORTHWEST; + JLabel label = new JLabel(NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddJavadocURLMessage")); + label.setDisplayedMnemonic('U'); + lm.setConstraints(label, c); + p.add(label); + c = new GridBagConstraints(); + c.gridx = c.gridy = GridBagConstraints.RELATIVE; + c.gridwidth = GridBagConstraints.REMAINDER; + c.insets = new Insets(12, 0, 12, 6); + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.NORTHWEST; + JTextField text = new JTextField(); + text.setColumns(30); + text.setText(NbBundle.getMessage(J2SEPlatformCustomizer.class, "TXT_DefaultProtocol")); + text.selectAll(); + label.setLabelFor(text); + lm.setConstraints(text, c); + p.add(text); + JButton[] options = new JButton[] { + new JButton(NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddJavadocURLTitle")), + new JButton(NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_Cancel")) + }; + options[0].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Add").charAt(0)); + options[1].setMnemonic(NbBundle.getMessage(J2SEPlatformCustomizer.class, "MNE_Cancel").charAt(0)); + DialogDescriptor input = new DialogDescriptor( + p, + NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_AddJavadocURLTitle"), + true, options, options[0], DialogDescriptor.DEFAULT_ALIGN, null, null); + if (DialogDisplayer.getDefault().notify(input) == options[0]) { + try { + String value = text.getText(); + URL url = new URL(value); + ((PathModel) this.resources.getModel()).addPath(url); + this.resources.setSelectedIndex(this.resources.getModel().getSize() - 1); + } catch (MalformedURLException mue) { + DialogDescriptor.Message message = new DialogDescriptor.Message( + NbBundle.getMessage(J2SEPlatformCustomizer.class, "CTL_InvalidURLFormat"), + DialogDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notify(message); + } + } + } private void addPathElement () { JFileChooser chooser = new JFileChooser (); diff --git a/java.source/src/org/netbeans/api/java/source/SourceUtils.java b/java.source/src/org/netbeans/api/java/source/SourceUtils.java --- a/java.source/src/org/netbeans/api/java/source/SourceUtils.java +++ b/java.source/src/org/netbeans/api/java/source/SourceUtils.java @@ -648,45 +648,39 @@ } } } + CharSequence fragment = buildFragment ? getFragment(element) : null; for (URL binary : binaries) { Result javadocResult = JavadocForBinaryQuery.findJavadoc(binary); URL[] result = javadocResult.getRoots(); - for (int cntr = 0; cntr < result.length; cntr++) { - if (!result[cntr].toExternalForm().endsWith("/")) { // NOI18N - Logger.getLogger(SourceUtils.class.getName()).log(Level.WARNING, "JavadocForBinaryQuery.Result: {0} returned non-folder URL: {1}, ignoring", new Object[] {javadocResult.getClass(), result[cntr].toExternalForm()}); - result[cntr] = null; + for (URL root : result) { + if (!root.toExternalForm().endsWith("/")) { // NOI18N + Logger.getLogger(SourceUtils.class.getName()).log(Level.WARNING, "JavadocForBinaryQuery.Result: {0} returned non-folder URL: {1}, ignoring", new Object[] {javadocResult.getClass(), root.toExternalForm()}); + continue; } - } - ClassPath cp = ClassPathSupport.createClassPath(result); - FileObject fo = cp.findResource(pkgName); - if (fo != null) { - for (FileObject child : fo.getChildren()) { - if (pageName.equals(child.getName()) && FileObjects.HTML.equalsIgnoreCase(child.getExt())) { - URL url = child.getURL(); - CharSequence fragment = null; - if (url != null && buildFragment) { - fragment = getFragment(element); - } - if (fragment != null && fragment.length() > 0) { - try { - // Javadoc fragments may contain chars that must be escaped to comply with RFC 2396. - // Unfortunately URLEncoder escapes almost everything but - // spaces replaces with '+' char which is wrong so it is - // replaced with "%20"escape sequence here. - String encodedfragment = URLEncoder.encode(fragment.toString(), "UTF-8"); // NOI18N - encodedfragment = encodedfragment.replace("+", "%20"); // NOI18N - return new URI(url.toExternalForm() + '#' + encodedfragment).toURL(); - } catch (URISyntaxException ex) { - Exceptions.printStackTrace(ex); - } catch (UnsupportedEncodingException ex) { - Exceptions.printStackTrace(ex); - } catch (MalformedURLException ex) { - Exceptions.printStackTrace(ex); - } - } - return url; + URL url = new URL(root, pkgName + "/" + pageName + ".html"); + try { + url.openStream().close(); + } catch (IOException x) { + continue; + } + if (fragment != null && fragment.length() > 0) { + try { + // Javadoc fragments may contain chars that must be escaped to comply with RFC 2396. + // Unfortunately URLEncoder escapes almost everything but + // spaces replaces with '+' char which is wrong so it is + // replaced with "%20"escape sequence here. + String encodedfragment = URLEncoder.encode(fragment.toString(), "UTF-8"); // NOI18N + encodedfragment = encodedfragment.replace("+", "%20"); // NOI18N + return new URI(url.toExternalForm() + '#' + encodedfragment).toURL(); + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); } } + return url; } } diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/IndexBuilder.java b/javadoc/src/org/netbeans/modules/javadoc/search/IndexBuilder.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/IndexBuilder.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/IndexBuilder.java @@ -48,6 +48,7 @@ import java.io.InputStreamReader; import java.lang.ref.Reference; import java.lang.ref.WeakReference; +import java.net.URL; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; @@ -58,13 +59,11 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; /** - * Builds index of Javadoc filesystems. + * Builds index of Javadoc sets. * @author Svata Dedic, Jesse Glick */ public class IndexBuilder implements Runnable, ChangeListener { @@ -87,9 +86,9 @@ private JavadocRegistry jdocRegs; /** - * information extracted from filesystems. + * information extracted from Javadoc. */ - Map filesystemInfo = Collections.emptyMap(); + Map filesystemInfo = Collections.emptyMap(); private static class Info { /** @@ -137,8 +136,8 @@ public static final class Index implements Comparable { private static final Collator c = Collator.getInstance(); public final String display; - public final FileObject fo; - private Index(String display, FileObject fo) { + public final URL fo; + private Index(String display, URL fo) { this.display = display; this.fo = fo; } @@ -147,10 +146,10 @@ return false; } final Index other = (Index) obj; - return display.equals(other.display) && fo == other.fo; + return display.equals(other.display) && fo.toString().equals(other.fo.toString()); } public @Override int hashCode() { - return display.hashCode() ^ fo.hashCode(); + return display.hashCode() ^ fo.toString().hashCode(); } public @Override int compareTo(Index o) { return c.compare(display, o.display); @@ -179,9 +178,9 @@ } err.log("getIndices"); List data = new ArrayList(); - for (Map.Entry entry : filesystemInfo.entrySet()) { + for (Map.Entry entry : filesystemInfo.entrySet()) { Info info = entry.getValue(); - FileObject fo = entry.getKey().getFileObject(info.indexFileName); + URL fo = URLUtils.findOpenable(entry.getKey(), info.indexFileName); if (fo == null) { continue; } @@ -196,18 +195,17 @@ if (err.isLoggable(ErrorManager.INFORMATIONAL)) { err.log("refreshIndex"); } - Map oldMap; + Map oldMap; synchronized (this) { oldMap = this.filesystemInfo; } - //Enumeration e = FileSystemCapability.DOC.fileSystems(); - FileObject docRoots[] = jdocRegs.getDocRoots(); + URL[] docRoots = jdocRegs.getDocRoots(); // XXX needs to be able to listen to result; when it changes, call scheduleTask() - Map m = new WeakHashMap(); + Map m = new WeakHashMap(); // long startTime = System.nanoTime(); for ( int ifCount = 0; ifCount < docRoots.length; ifCount++ ) { - FileObject fo = docRoots[ifCount]; + URL fo = docRoots[ifCount]; Info oldInfo = oldMap.get(fo); if (oldInfo != null) { // No need to reparse. @@ -215,30 +213,24 @@ continue; } - FileObject index = null; - for (int i = 0; i < INDEX_FILE_NAMES.length; i++) { - if ((index = fo.getFileObject(INDEX_FILE_NAMES[i])) != null) { - break; - } - } - if (index == null || index.getName().equals("index")) { // NOI18N + URL index = URLUtils.findOpenable(fo, INDEX_FILE_NAMES); + if (index == null || index.toString().endsWith("index.html")) { // NOI18N // For single-package doc sets, overview-summary.html is not present, // and index.html is less suitable (it is framed). Look for a package // summary. // [PENDING] Display name is not ideal, e.g. "org.openide.windows (NetBeans Input/Output API)" // where simply "NetBeans Input/Output API" is preferable... but standard title filter // regexps are not so powerful (to avoid matching e.g. "Servlets (Main Documentation)"). - FileObject packageList = fo.getFileObject("package-list"); // NOI18N - if (packageList != null) { + InputStream is = URLUtils.open(fo, "package-list"); // NOI18N + if (is != null) { try { - InputStream is = packageList.getInputStream(); try { BufferedReader r = new BufferedReader(new InputStreamReader(is)); String line = r.readLine(); if (line != null && r.readLine() == null) { // Good, exactly one line as expected. A package name. String resName = line.replace('.', '/') + "/package-summary.html"; // NOI18N - FileObject pindex = fo.getFileObject(resName); + URL pindex = URLUtils.findOpenable(fo, resName); if (pindex != null) { index = pindex; } @@ -264,7 +256,7 @@ title = st.getOverviewTitleBase(title); } if (title == null || "".equals(title)) { // NOI18N - String filename = FileUtil.getFileDisplayName(index); + String filename = URLUtils.getDisplayName(index); if (filename.length() > 54) { // trim to display 54 chars filename = filename.substring(0, 10) + "[...]" // NOI18N @@ -274,8 +266,8 @@ "FMT_NoOverviewTitle", new Object[] { filename }); // NOI18N } Info info = new Info(); - info.title = title == null ? fo.getName() : title; - info.indexFileName = FileUtil.getRelativePath(fo, index); + info.title = title; + info.indexFileName = index.toString().substring(fo.toString().length()); m.put(fo, info); } synchronized (this) { @@ -291,7 +283,7 @@ * Attempt to find the title of an HTML file object. * May return null if there is no title tag, or "" if it is empty. */ - private String parseTitle(FileObject html) { + private String parseTitle(URL html) { String title = null; try { // #71979: html parser used again to fix encoding issues. @@ -299,7 +291,7 @@ // is used (#32551). // In case the parser is stopped as soon as it finds the title it is // even faster than the previous fix. - InputStream is = new BufferedInputStream(html.getInputStream(), 1024); + InputStream is = new BufferedInputStream(html.openStream(), 1024); SimpleTitleParser tp = new SimpleTitleParser(is); try { tp.parse(); diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/IndexOverviewAction.java b/javadoc/src/org/netbeans/modules/javadoc/search/IndexOverviewAction.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/IndexOverviewAction.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/IndexOverviewAction.java @@ -53,11 +53,9 @@ import org.openide.ErrorManager; import org.openide.awt.HtmlBrowser; import org.openide.awt.Mnemonics; -import org.openide.filesystems.FileObject; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.awt.DynamicMenuContent; -import org.openide.filesystems.URLMapper; import org.openide.util.actions.SystemAction; import org.openide.util.actions.Presenter; @@ -183,30 +181,19 @@ */ private final class IndexMenuItem extends JMenuItem implements ActionListener, HelpCtx.Provider { - /** cached url */ - private URL u; - /** a reference to org.openide.filesystems.FileSystem */ - private final FileObject fsRef; + private final URL loc; @SuppressWarnings("LeakingThisInConstructor") - public IndexMenuItem(String display, FileObject index) { + public IndexMenuItem(String display, URL index) { super(display); - fsRef = index; + loc = index; addActionListener(this); } public @Override void actionPerformed(ActionEvent ev) { - URL loc = getURL(); HtmlBrowser.URLDisplayer.getDefault().showURL(loc); } - private URL getURL() { - if (u == null) { - u = URLMapper.findURL(fsRef, URLMapper.EXTERNAL); - } - return u; - } - public @Override HelpCtx getHelpCtx() { return IndexOverviewAction.this.getHelpCtx(); } @@ -222,11 +209,7 @@ } public @Override void actionPerformed(ActionEvent e) { - FileObject fsRef = ReferencesPanel.showInWindow(); - URL u = null; - if (fsRef != null) { - u = URLMapper.findURL(fsRef, URLMapper.EXTERNAL); - } + URL u = ReferencesPanel.showInWindow(); if (u != null) { HtmlBrowser.URLDisplayer.getDefault().showURL(u); } diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/IndexSearchThread.java b/javadoc/src/org/netbeans/modules/javadoc/search/IndexSearchThread.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/IndexSearchThread.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/IndexSearchThread.java @@ -41,10 +41,10 @@ package org.netbeans.modules.javadoc.search; +import java.net.URL; import java.util.StringTokenizer; import org.openide.util.RequestProcessor; -import org.openide.filesystems.FileObject; /** Abstract class for thread which searches for documentation * @@ -59,7 +59,7 @@ //protected String toFind; // documentation index file (or foldee for splitted index) - protected FileObject indexRoot; + protected URL indexRoot; private DocIndexItemConsumer ddiConsumer; private final RequestProcessor.Task rpTask; private boolean isFinished = false; @@ -77,7 +77,7 @@ abstract void stopSearch(); @SuppressWarnings("LeakingThisInConstructor") - public IndexSearchThread( String toFind, FileObject fo, DocIndexItemConsumer ddiConsumer, boolean caseSensitive ) { + public IndexSearchThread(String toFind, URL fo, DocIndexItemConsumer ddiConsumer, boolean caseSensitive) { this.ddiConsumer = ddiConsumer; this.indexRoot = fo; this.caseSensitive = caseSensitive; diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocRegistry.java b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocRegistry.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocRegistry.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocRegistry.java @@ -58,6 +58,8 @@ import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -69,7 +71,6 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import org.openide.filesystems.FileObject; import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.classpath.GlobalPathRegistryEvent; @@ -77,7 +78,6 @@ import org.netbeans.api.java.classpath.GlobalPathRegistryListener; import org.netbeans.api.java.queries.JavadocForBinaryQuery; -import org.openide.ErrorManager; import org.openide.util.ChangeSupport; import org.openide.util.Lookup; @@ -89,7 +89,7 @@ public class JavadocRegistry implements GlobalPathRegistryListener, ChangeListener, PropertyChangeListener { private static JavadocRegistry INSTANCE; - + private static final Logger LOG = Logger.getLogger(JavadocRegistry.class.getName()); private GlobalPathRegistry regs; private final ChangeSupport cs = new ChangeSupport(this); @@ -112,10 +112,10 @@ /** Returns Array of the Javadoc Index roots */ - public FileObject[] getDocRoots() { + public URL[] getDocRoots() { synchronized (this) { if (this.docRoots != null) { - return this.docRoots.getRoots(); + return docRoots(); } } //XXX must be called out of synchronized block to prevent @@ -131,12 +131,20 @@ this.results = _results; registerListeners(this, _classpaths, _results, this.docRoots); } - return this.docRoots.getRoots(); + return docRoots(); } } + private URL[] docRoots() { + List entries = docRoots.entries(); + URL[] roots = new URL[entries.size()]; + for (int i = 0; i < roots.length; i++) { + roots[i] = entries.get(i).getURL(); + } + return roots; + } - public JavadocSearchType findSearchType( FileObject apidocRoot ) { + public JavadocSearchType findSearchType(URL apidocRoot) { String encoding = getDocEncoding (apidocRoot); for (JavadocSearchType jdst : Lookup.getDefault().lookupAll(JavadocSearchType.class)) { if (jdst.accepts(apidocRoot, encoding)) { @@ -246,41 +254,27 @@ } - private String getDocEncoding (FileObject root) { - assert root != null && root.isFolder(); - FileObject fo = root.getFileObject("index-all.html"); //NOI18N - if (fo == null) { - fo = root.getFileObject("index-files"); //NOI18N - if (fo == null) { - return null; + private String getDocEncoding(URL root) { + assert root != null && root.toString().endsWith("/") : root; + InputStream is = URLUtils.open(root, "index-all.html", "index-files/index-1.html"); + if (is != null) { + try { + try { + ParserDelegator pd = new ParserDelegator(); + BufferedReader in = new BufferedReader(new InputStreamReader(is)); + EncodingCallback ecb = new EncodingCallback(in); + pd.parse(in, ecb, true); + return ecb.getEncoding(); + } finally { + is.close(); + } + } catch (IOException x) { + LOG.log(Level.FINE, "Getting encoding from " + root, x); } - fo = fo.getFileObject("index-1.html"); //NOI18N - if (fo == null) { - return null; - } - } - ParserDelegator pd = new ParserDelegator(); - try { - InputStream is = fo.getInputStream(); - try { - BufferedReader in = new BufferedReader(new InputStreamReader(is)); - EncodingCallback ecb = new EncodingCallback(in); - pd.parse(in, ecb, true); - return ecb.getEncoding(); - } catch (IOException ioe) { - //Do nothing - } finally { - is.close(); - } - } catch (IOException ioe) { - ErrorManager.getDefault().annotate(ioe, fo.toString()); - ErrorManager.getDefault().notify (ioe); } return null; } - - private static class EncodingCallback extends HTMLEditorKit.ParserCallback { diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchEngineImpl.java b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchEngineImpl.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchEngineImpl.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchEngineImpl.java @@ -41,12 +41,12 @@ package org.netbeans.modules.javadoc.search; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; /** * @author Petr Suchomel @@ -80,7 +80,7 @@ } }; - FileObject[] docRoots = JavadocRegistry.getDefault().getDocRoots(); + URL[] docRoots = JavadocRegistry.getDefault().getDocRoots(); synchronized(this) { if (isStopped) { return; @@ -100,7 +100,7 @@ ErrorManager.getDefault().log ("NO Search type for " + docRoots[i]); continue; } - FileObject indexFo = st.getDocFileObject( docRoots[i] ); + URL indexFo = st.getDocFileObject( docRoots[i] ); if (indexFo == null) { ErrorManager.getDefault().log ("NO Index files fot " + docRoots[i] ); continue; diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchType.java b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchType.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchType.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/JavadocSearchType.java @@ -41,13 +41,13 @@ package org.netbeans.modules.javadoc.search; +import java.net.URL; import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import org.openide.filesystems.FileObject; import org.openide.util.NbBundle; import org.openide.ErrorManager; @@ -64,7 +64,7 @@ * @return File object containing index-files e.g index-files directory * or index-all.html. */ - public abstract FileObject getDocFileObject( FileObject apidocRoot ); + public abstract URL getDocFileObject(URL apidocRoot); private Pattern[] overviewLabelFilters; @@ -114,7 +114,7 @@ * @param diiConsumer consumer for parse events * @return IndexSearchThread */ - public abstract IndexSearchThread getSearchThread( String toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer ); + public abstract IndexSearchThread getSearchThread(String toFind, URL fo, IndexSearchThread.DocIndexItemConsumer diiConsumer); /** @@ -122,6 +122,6 @@ * @param apidocRoot root of the javadoc * @param encoding of the javadoc, may be null if the javadoc has no encoding */ - public abstract boolean accepts (FileObject apidocRoot, String encoding); + public abstract boolean accepts(URL apidocRoot, String encoding); } diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType.java b/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType.java @@ -41,7 +41,9 @@ package org.netbeans.modules.javadoc.search; -import org.openide.filesystems.FileObject; +import java.net.MalformedURLException; +import java.net.URL; +import org.openide.util.Exceptions; import org.openide.util.lookup.ServiceProvider; /* Base class providing search for JDK1.2/1.3 documentation @@ -72,19 +74,14 @@ // this.firePropertyChange("caseSensitive", oldVal ? Boolean.TRUE : Boolean.FALSE, caseSensitive ? Boolean.TRUE : Boolean.FALSE); //NOI18N } - public @Override FileObject getDocFileObject(FileObject apidocRoot) { - - FileObject fo = apidocRoot.getFileObject( "index-files" ); // NOI18N - if ( fo != null ) { - return fo; + public @Override URL getDocFileObject(URL apidocRoot) { + URL u = URLUtils.findOpenable(apidocRoot, "index-files/index-1.html"); // NOI18N + try { + return u != null ? new URL(apidocRoot, "index-files/") : URLUtils.findOpenable(apidocRoot, "index-all.html"); // NOI18N + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + return null; } - - fo = apidocRoot.getFileObject( "index-all.html" ); // NOI18N - if ( fo != null ) { - return fo; - } - - return null; } /** Returns Java doc search thread for doument @@ -94,12 +91,12 @@ * @return IndexSearchThread * @see IndexSearchThread */ - public @Override IndexSearchThread getSearchThread(String toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer) { + public @Override IndexSearchThread getSearchThread(String toFind, URL fo, IndexSearchThread.DocIndexItemConsumer diiConsumer) { return new SearchThreadJdk12 ( toFind, fo, diiConsumer, isCaseSensitive() ); } - public @Override boolean accepts(FileObject apidocRoot, String encoding) { + public @Override boolean accepts(URL apidocRoot, String encoding) { //XXX returns always true, must be the last JavadocType return true; } diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType_japan.java b/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType_japan.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType_japan.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/Jdk12SearchType_japan.java @@ -46,8 +46,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import org.openide.util.Exceptions; -import org.openide.filesystems.FileObject; import org.openide.util.lookup.ServiceProvider; /* Base class providing search for JDK1.2/1.3 documentation @@ -89,13 +89,13 @@ * @see IndexSearchThread */ @Override - public IndexSearchThread getSearchThread( String toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer ){ + public IndexSearchThread getSearchThread(String toFind, URL fo, IndexSearchThread.DocIndexItemConsumer diiConsumer) { //here you can send one more parameter .. getJapanEncoding return new SearchThreadJdk12_japan ( toFind, fo, diiConsumer, isCaseSensitive(), getJapanEncoding() ); } @Override - public boolean accepts(org.openide.filesystems.FileObject root, String encoding) { + public boolean accepts(URL root, String encoding) { if (encoding == null) { return false; } @@ -112,11 +112,10 @@ if ("utf-8".equals(encoding)) { // NOI18N try { - FileObject fo = root.getFileObject("allclasses-frame.html"); // NOI18N - if (fo == null) { + InputStream is = URLUtils.open(root, "allclasses-frame.html"); // NOI18N + if (is == null) { return false; } - InputStream is = fo.getInputStream(); boolean jazip = false; try { BufferedReader r = new BufferedReader(new InputStreamReader(is, encoding)); diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/ReferencesPanel.java b/javadoc/src/org/netbeans/modules/javadoc/search/ReferencesPanel.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/ReferencesPanel.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/ReferencesPanel.java @@ -41,6 +41,7 @@ import java.awt.Dialog; import java.awt.EventQueue; +import java.net.URL; import java.util.List; import javax.swing.AbstractButton; import javax.swing.JButton; @@ -51,8 +52,6 @@ import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.awt.Mnemonics; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; @@ -86,7 +85,7 @@ this.openBtn = openBtn; } - public static FileObject showInWindow() { + public static URL showInWindow() { JButton openBtn = new JButton(); Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(ReferencesPanel.class, "ReferencesPanel.ok.text")); openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText()); @@ -163,15 +162,15 @@ } public @Override void valueChanged(ListSelectionEvent e) { - FileObject item = getSelectedItem(); + URL item = getSelectedItem(); String s = item == null ? EMPTY_LOCATION - : FileUtil.getFileDisplayName(item); + : URLUtils.getDisplayName(item); locationField.setText(s); openBtn.setEnabled(item != null); } - FileObject getSelectedItem() { + URL getSelectedItem() { int index = refList.getSelectedIndex(); synchronized (LOCK) { return index < 0 || items == null || items.length == 0 @@ -254,16 +253,16 @@ private static ItemDesc NO_ITEM; String name; String locationName; - FileObject location; + URL location; - public ItemDesc(String name, FileObject location) { + public ItemDesc(String name, URL location) { this.name = name; this.location = location; } String getLocationName() { if (locationName == null) { - locationName = FileUtil.getFileDisplayName(location); + locationName = URLUtils.getDisplayName(location); } return locationName; } diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12.java b/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12.java @@ -55,7 +55,6 @@ import org.openide.ErrorManager; import org.openide.util.NbBundle; -import org.openide.filesystems.FileObject; /** This class implements the index search through documenation * generated by Jdk 1.2 standard doclet @@ -70,17 +69,17 @@ private boolean splitedIndex = false; private int currentIndexNumber; - private FileObject folder = null; + private URL folder = null; private final Object LOCK = new Object(); public SearchThreadJdk12 ( String toFind, - FileObject fo, + URL fo, IndexSearchThread.DocIndexItemConsumer diiConsumer, boolean caseSensitive ) { super( toFind, fo, diiConsumer, caseSensitive); //this.caseSensitive = caseSensitive; - if ( fo.isFolder() ) { + if (fo.toString().endsWith("/")) { // Documentation uses splited index - resolve the right file // This is just a try in most cases the fileNumber should be @@ -106,14 +105,7 @@ splitedIndex = true; } else { - try { - contextURL = this.indexRoot.getURL(); - //contextURL = this.fo.getParent().getURL(); - } - catch ( org.openide.filesystems.FileStateInvalidException e ) { - throw new InternalError( "Can't create documentation folder URL - file state invalid" ); // NOI18N - } - + contextURL = indexRoot; splitedIndex = false; } } @@ -167,7 +159,7 @@ if (stopSearch) { break; } - in = new BufferedReader( new InputStreamReader( indexRoot.getInputStream () )); + in = new BufferedReader(new InputStreamReader(indexRoot.openStream())); } pd.parse( in, sc = new SearchCallbackJdk12( splitedIndex, caseSensitive ), true ); } @@ -213,22 +205,15 @@ return; } - String fileName = "index-" + currentIndexNumber; // NOI18N - if ( folder == null ) { indexRoot = null; return; } - indexRoot = folder.getFileObject( fileName, "html" ); // NOI18N + indexRoot = URLUtils.findOpenable(folder, "index-" + currentIndexNumber + ".html"); // NOI18N if ( indexRoot != null ) { - try { - contextURL = this.indexRoot.getURL(); - } - catch ( org.openide.filesystems.FileStateInvalidException e ) { - throw new InternalError( "Can't create documentation folder URL - file state invalid" ); // NOI18N - } + contextURL = indexRoot; } else { diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12_japan.java b/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12_japan.java --- a/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12_japan.java +++ b/javadoc/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12_japan.java @@ -56,7 +56,6 @@ import org.openide.ErrorManager; import org.openide.util.NbBundle; -import org.openide.filesystems.FileObject; /** This class implements the index search through documenation * generated by Jdk 1.2 standard doclet @@ -71,16 +70,16 @@ private boolean splitedIndex = false; private int currentIndexNumber; - private FileObject folder = null; + private URL folder = null; private String JapanEncoding; private final Object LOCK = new Object(); - public SearchThreadJdk12_japan(String toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer, boolean caseSensitive, String JapanEncoding) { + public SearchThreadJdk12_japan(String toFind, URL fo, IndexSearchThread.DocIndexItemConsumer diiConsumer, boolean caseSensitive, String JapanEncoding) { super( toFind, fo, diiConsumer, caseSensitive ); this.JapanEncoding = JapanEncoding; - if ( fo.isFolder() ) { + if (fo.toString().endsWith("/")) { // Documentation uses splited index - resolve the right file @@ -107,14 +106,7 @@ splitedIndex = true; } else { - try { - contextURL = this.indexRoot.getURL(); - //contextURL = this.fo.getParent().getURL(); - } - catch ( org.openide.filesystems.FileStateInvalidException e ) { - throw new InternalError( "Can't create documentation folder URL - file state invalid" ); // NOI18N - } - + contextURL = this.indexRoot; splitedIndex = false; } } @@ -168,7 +160,7 @@ if (stopSearch) { break; } - in = new BufferedReader( new InputStreamReader( indexRoot.getInputStream (), JapanEncoding )); + in = new BufferedReader(new InputStreamReader(indexRoot.openStream(), JapanEncoding)); } // System.out.println("Encoding: " + JapanEncoding); pd.parse( in, sc = new SearchCallbackJdk12_japan( splitedIndex, caseSensitive ), true ); @@ -213,22 +205,15 @@ return; } - String fileName = "index-" + currentIndexNumber; // NOI18N - if ( folder == null ) { indexRoot = null; return; } - indexRoot = folder.getFileObject( fileName, "html" ); // NOI18N + indexRoot = URLUtils.findOpenable(folder, "index-" + currentIndexNumber + ".html"); // NOI18N if ( indexRoot != null ) { - try { - contextURL = this.indexRoot.getURL(); - } - catch ( org.openide.filesystems.FileStateInvalidException e ) { - throw new InternalError( "Can't create documentation folder URL - file state invalid" ); // NOI18N - } + contextURL = indexRoot; } else { diff --git a/javadoc/src/org/netbeans/modules/javadoc/search/URLUtils.java b/javadoc/src/org/netbeans/modules/javadoc/search/URLUtils.java new file mode 100644 --- /dev/null +++ b/javadoc/src/org/netbeans/modules/javadoc/search/URLUtils.java @@ -0,0 +1,122 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.javadoc.search; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.URLMapper; + +/** + * Convenience methods for looking up available URLs such as Javadoc HTML pages. + */ +class URLUtils { + + private URLUtils() {} + + private static final Logger LOG = Logger.getLogger(URLUtils.class.getName()); + + /** + * Attempts to {@linkplain URL#openStream open} some URLs in turn. + * If opening a URL fails, it is skipped. + * It is the caller's responsibility to close any non-null result. + * @param base a base URL + * @param specs relative paths + * @return a stream from one of the constructed URLs, or null if none could be opened + */ + public static InputStream open(URL base, String... specs) { + for (String spec : specs) { + try { + URL url = new URL(base, spec); + try { + return url.openStream(); + } catch (IOException x) { + LOG.log(Level.FINE, "Could not open " + url, x); + } + } catch (MalformedURLException x) { + LOG.log(Level.INFO, "Could not construct " + base + spec, x); + } + } + return null; + } + + /** + * Like {@link #open} but just returns the URL that worked. + * Any opened stream is closed again. + * @param base a base URL + * @param specs relative paths + * @return the constructed URL, or null if none cannot be opened + */ + public static URL findOpenable(URL base, String... specs) { + for (String spec : specs) { + try { + URL url = new URL(base, spec); + try { + url.openStream().close(); + return url; + } catch (IOException x) { + LOG.log(Level.FINE, "Could not open " + url, x); + } catch (Exception x) { + LOG.log(Level.INFO, "Could not open " + url, x); + } + } catch (MalformedURLException x) { + LOG.log(Level.INFO, "Could not construct " + base + spec, x); + } + } + return null; + } + + /** + * Produces a display name appropriate to a URL. + * @param url a URL + * @return some display name, e.g. file path + * @see FileUtil#getFileDisplayName + */ + public static String getDisplayName(URL url) { + FileObject fo = URLMapper.findFileObject(url); + return fo != null ? FileUtil.getFileDisplayName(fo) : url.toString(); + } + +} diff --git a/javadoc/test/unit/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12Test.java b/javadoc/test/unit/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12Test.java --- a/javadoc/test/unit/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12Test.java +++ b/javadoc/test/unit/src/org/netbeans/modules/javadoc/search/SearchThreadJdk12Test.java @@ -42,11 +42,11 @@ package org.netbeans.modules.javadoc.search; import java.io.File; +import java.net.URL; import java.util.List; import java.util.LinkedList; import org.netbeans.junit.NbTestCase; import org.openide.filesystems.LocalFileSystem; -import org.openide.filesystems.FileObject; /** * @@ -70,8 +70,7 @@ } public void testSearchInJDK14_Class() throws Exception { - FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK14_INDEX_PATH).getURL(); String toFind = "DataFlavor"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -97,8 +96,7 @@ } public void testSearchInJDK14_Interface() throws Exception { - FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK14_INDEX_PATH).getURL(); String toFind = "DatabaseMetaData"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -117,8 +115,7 @@ } public void testSearchInJDK14_Exception() throws Exception { - FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK14_INDEX_PATH).getURL(); String toFind = "DataFormatException"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -145,8 +142,7 @@ } public void testSearchInJDK14_Method() throws Exception { - FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK14_INDEX_PATH).getURL(); String toFind = "damageLineRange"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -165,8 +161,7 @@ } public void testSearchInJDK14_Variables() throws Exception { - FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK14_INDEX_PATH).getURL(); String toFind = "darkShadow"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -193,8 +188,7 @@ } public void testSearchInJDK15_Class() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "DataFlavor"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -221,8 +215,7 @@ public void testSearchInJDK15_GenericClass_54244() throws Exception { // see issue #54244 - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "DemoHashMap"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -248,8 +241,7 @@ } public void testSearchInJDK15_Method() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "damageLineRange"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -268,8 +260,7 @@ } public void testSearchInJDK15_Variables() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "darkShadow"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -296,8 +287,7 @@ } public void testSearchInJDK15_Exception() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "DataFormatException"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -324,8 +314,7 @@ } public void testSearchInJDK15_Interface() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "DatabaseMetaData"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -344,8 +333,7 @@ } public void testSearchInJDK15_Enum() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "DemoMemoryType"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); @@ -364,8 +352,7 @@ } public void testSearchInJDK15_AnnotationType() throws Exception { - FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); - assertNotNull(idxFolder); + URL idxFolder = fs.findResource(JDK15_INDEX_PATH).getURL(); String toFind = "Deprecated"; MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();