This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 199742
Collapse All | Expand All

(-)a/ant.grammar/nbproject/project.xml (-1 / +1 lines)
Lines 100-106 Link Here
100
                    <compile-dependency/>
100
                    <compile-dependency/>
101
                    <run-dependency>
101
                    <run-dependency>
102
                        <release-version>2</release-version>
102
                        <release-version>2</release-version>
103
                        <specification-version>1.9.0</specification-version>
103
                        <specification-version>1.28.0</specification-version>
104
                    </run-dependency>
104
                    </run-dependency>
105
                </dependency>
105
                </dependency>
106
                <dependency>
106
                <dependency>
(-)a/ant.grammar/src/org/netbeans/modules/ant/grammar/AntGrammar.java (-14 / +28 lines)
Lines 45-50 Link Here
45
package org.netbeans.modules.ant.grammar;
45
package org.netbeans.modules.ant.grammar;
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.net.URI;
48
import java.net.URL;
49
import java.net.URL;
49
import java.text.Collator;
50
import java.text.Collator;
50
import java.util.ArrayList;
51
import java.util.ArrayList;
Lines 66-71 Link Here
66
import org.netbeans.modules.xml.api.model.GrammarResult;
67
import org.netbeans.modules.xml.api.model.GrammarResult;
67
import org.netbeans.modules.xml.api.model.HintContext;
68
import org.netbeans.modules.xml.api.model.HintContext;
68
import org.netbeans.modules.xml.spi.dom.AbstractNode;
69
import org.netbeans.modules.xml.spi.dom.AbstractNode;
70
import org.netbeans.modules.xml.api.model.DescriptionSource;
69
import org.openide.filesystems.FileObject;
71
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.URLMapper;
72
import org.openide.filesystems.URLMapper;
71
import org.openide.util.Enumerations;
73
import org.openide.util.Enumerations;
Lines 395-418 Link Here
395
                case PROJECT:
397
                case PROJECT:
396
                case TARGET:
398
                case TARGET:
397
                    list.add(new MyElement(element) {
399
                    list.add(new MyElement(element) {
398
                        @Override public String getDescription() {
400
                        private URL manpage;
401
402
                        {
399
                            ClassLoader cl = Lookup.getDefault().lookup(ClassLoader.class);
403
                            ClassLoader cl = Lookup.getDefault().lookup(ClassLoader.class);
400
                            URL manpage = cl.getResource("org/apache/tools/ant/module/docs/ant-docs/Tasks/" + element + ".html");
404
                            manpage = cl.getResource("org/apache/tools/ant/module/docs/ant-docs/Tasks/" + element + ".html");
401
                            if (manpage == null) {
405
                            if (manpage == null) {
402
                                manpage = cl.getResource("org/apache/tools/ant/module/docs/ant-docs/Types/" + element + ".html");
406
                                manpage = cl.getResource("org/apache/tools/ant/module/docs/ant-docs/Types/" + element + ".html");
403
                            }
407
                            }
404
                            if (manpage != null) {
405
                                FileObject f = URLMapper.findFileObject(manpage);
406
                                if (f != null) {
407
                                    try {
408
                                        return new String(f.asBytes(), FileEncodingQuery.getEncoding(f));
409
                                    } catch (IOException x) {
410
                                        LOG.log(Level.INFO, "Could not load " + manpage, x);
411
                                    }
412
                                }
413
                            }
414
                            return null;
415
                        }
408
                        }
409
410
                        @Override
411
                        public URL getContentURL() {
412
                            return manpage;
413
                        }
414
                        
415
                        
416
                    });
416
                    });
417
                    break;
417
                    break;
418
                default:
418
                default:
Lines 827-833 Link Here
827
827
828
    }
828
    }
829
829
830
    private static class MyElement extends AbstractResultNode implements Element {
830
    private static class MyElement extends AbstractResultNode implements Element, DescriptionSource {
831
831
832
        private String name;
832
        private String name;
833
833
Lines 850-856 Link Here
850
        public @Override String toString() {
850
        public @Override String toString() {
851
            return name;
851
            return name;
852
        }
852
        }
853
        
854
        @Override
855
        public DescriptionSource resolveLink(String link) {
856
            return null;
857
        }
858
        
859
        @Override
860
        public boolean isExternal() {
861
            return false;
862
        }
853
863
864
        @Override
865
        public URL getContentURL() {
866
            return null;
867
        }
854
    }
868
    }
855
869
856
    private static class MyAttr extends AbstractResultNode implements Attr {
870
    private static class MyAttr extends AbstractResultNode implements Attr {
(-)a/xml.core/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint -Xlint:-serial
43
javac.compilerargs=-Xlint -Xlint:-serial
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=1.27.0
45
spec.version.base=1.28.0
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.packages=\
48
javadoc.packages=\
(-)a/xml.core/nbproject/project.xml (+9 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.modules.xml.core</code-name-base>
50
            <code-name-base>org.netbeans.modules.xml.core</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.11</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
53
                    <code-name-base>org.netbeans.api.xml</code-name-base>
62
                    <code-name-base>org.netbeans.api.xml</code-name-base>
54
                    <build-prerequisite/>
63
                    <build-prerequisite/>
55
                    <compile-dependency/>
64
                    <compile-dependency/>
(-)a/xml.core/src/org/netbeans/modules/xml/api/model/DescriptionSource.java (+106 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.xml.api.model;
43
44
import java.net.URI;
45
import java.net.URL;
46
import org.netbeans.api.annotations.common.CheckForNull;
47
48
/**
49
 * Optional mixin interface, which can be implemented together with the
50
 * {@link GrammarResult} interface on the returned completion item. 
51
 * It allows to resolve links and provide description contents.
52
 * <p/>
53
 * Implementation may return {@code null} from {@link #getDescription} to 
54
 * indicate that the system should load contents from the URL supplied by {@link #getContentURL()}.
55
 * <p/>
56
 * The implementation may choose to provide the content URL to open within the IDE
57
 * or in an external browser. Any links will be resolved relatively to that URL.
58
 * For special cases, the implementation may resolve a link to another instance
59
 * of DescriptionSource by implementing {@link #resolveLink}.
60
 * <p/>
61
 * If both {@link #getDescription} and {@link #getContentURL} return null, there's
62
 * no description at all for the {@link GrammarResult}.
63
 * 
64
 * @author sdedic
65
 * @since 1.28
66
 */
67
public interface DescriptionSource {
68
    /**
69
     * Provides text of the description. If the method returns null, the 
70
     * IDE will try to load contents of the {@link #getContentURL()} and use that
71
     * as a description.
72
     * 
73
     * @return Description contents or {@code null}, if contents should be loaded
74
     * from {@link #getContentURL}.
75
     */
76
    @CheckForNull
77
    public String  getDescription();
78
79
    /**
80
     * True, if the description can be opened by an external browser, following the
81
     * {@link #getContentURL}.
82
     * 
83
     * @return true, if the content URL can be used outside of the IDE
84
     */
85
    public boolean isExternal();
86
    
87
    /**
88
     * Returns URL for the content, so it can be retrieved. If this URL is provided,
89
     * any link not resolved by {@link #resolveLink(java.net.URI)} will be treated
90
     * as relative to this content URL.
91
     * 
92
     * @return URL of the description content
93
     */
94
    @CheckForNull
95
    public URL  getContentURL();
96
    
97
    /**
98
     * Resolves a link in the documentation to another DescriptionSource. Can
99
     * return null, if the link cannot be resolved.
100
     * 
101
     * @param link link found in the text
102
     * @return resolved description, or {@code null}
103
     */
104
    @CheckForNull
105
    public DescriptionSource  resolveLink(String link);
106
}
(-)a/xml.core/src/org/netbeans/modules/xml/api/model/GrammarResult.java (-1 / +7 lines)
Lines 46-51 Link Here
46
46
47
import org.w3c.dom.Node;
47
import org.w3c.dom.Node;
48
import javax.swing.Icon;
48
import javax.swing.Icon;
49
import org.netbeans.api.annotations.common.CheckForNull;
49
50
50
/**
51
/**
51
 * It represents additonal properties of a result option.
52
 * It represents additonal properties of a result option.
Lines 78-85 Link Here
78
79
79
    /**
80
    /**
80
     * @return provide additional information simplifing decision
81
     * @return provide additional information simplifing decision
81
     * (suitable for tooltip) or <code>null</code>
82
     * (suitable for tooltip) or {@code null}. If the description may contain
83
     * links, consider to implement {@link DescriptionSource} on the same class,
84
     * which allows to resolve those links to content and/or URLs.
85
     * 
86
     * @since 1.28 - DescriptionSource extension
82
     */
87
     */
88
    @CheckForNull
83
    String getDescription();
89
    String getDescription();
84
90
85
    /**
91
    /**
(-)a/xml.text/nbproject/project.xml (-1 / +10 lines)
Lines 166-177 Link Here
166
                    </run-dependency>
166
                    </run-dependency>
167
                </dependency>
167
                </dependency>
168
                <dependency>
168
                <dependency>
169
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
170
                    <build-prerequisite/>
171
                    <compile-dependency/>
172
                    <run-dependency>
173
                        <release-version>1</release-version>
174
                        <specification-version>1.25</specification-version>
175
                    </run-dependency>
176
                </dependency>
177
                <dependency>
169
                    <code-name-base>org.netbeans.modules.xml.core</code-name-base>
178
                    <code-name-base>org.netbeans.modules.xml.core</code-name-base>
170
                    <build-prerequisite/>
179
                    <build-prerequisite/>
171
                    <compile-dependency/>
180
                    <compile-dependency/>
172
                    <run-dependency>
181
                    <run-dependency>
173
                        <release-version>2</release-version>
182
                        <release-version>2</release-version>
174
                        <specification-version>1.14</specification-version>
183
                        <specification-version>1.28</specification-version>
175
                    </run-dependency>
184
                    </run-dependency>
176
                </dependency>
185
                </dependency>
177
                <dependency>
186
                <dependency>
(-)a/xml.text/src/org/netbeans/modules/xml/text/completion/XMLResultItem.java (-8 / +141 lines)
Lines 49-55 Link Here
49
import java.awt.Font;
49
import java.awt.Font;
50
import java.awt.Graphics;
50
import java.awt.Graphics;
51
import java.awt.event.KeyEvent;
51
import java.awt.event.KeyEvent;
52
import java.io.IOException;
53
import java.net.MalformedURLException;
52
import java.net.URL;
54
import java.net.URL;
55
import java.util.logging.Level;
56
import java.util.logging.Logger;
53
import javax.swing.Action;
57
import javax.swing.Action;
54
import javax.swing.text.*;
58
import javax.swing.text.*;
55
import javax.swing.Icon;
59
import javax.swing.Icon;
Lines 57-69 Link Here
57
import org.netbeans.editor.*;
61
import org.netbeans.editor.*;
58
import javax.swing.JLabel;
62
import javax.swing.JLabel;
59
import org.netbeans.api.editor.completion.Completion;
63
import org.netbeans.api.editor.completion.Completion;
64
import org.netbeans.api.queries.FileEncodingQuery;
60
import org.netbeans.modules.xml.api.model.GrammarResult;
65
import org.netbeans.modules.xml.api.model.GrammarResult;
66
import org.netbeans.modules.xml.api.model.DescriptionSource;
61
import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext;
67
import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext;
62
import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport;
68
import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport;
63
import org.netbeans.spi.editor.completion.CompletionDocumentation;
69
import org.netbeans.spi.editor.completion.CompletionDocumentation;
64
import org.netbeans.spi.editor.completion.CompletionItem;
70
import org.netbeans.spi.editor.completion.CompletionItem;
65
import org.netbeans.spi.editor.completion.CompletionResultSet;
71
import org.netbeans.spi.editor.completion.CompletionResultSet;
66
import org.netbeans.spi.editor.completion.CompletionTask;
72
import org.netbeans.spi.editor.completion.CompletionTask;
73
import org.openide.filesystems.FileObject;
74
import org.openide.filesystems.URLMapper;
75
import org.openide.util.Exceptions;
67
76
68
/**
77
/**
69
 * This class carries result information required by NetBeans Editor module.
78
 * This class carries result information required by NetBeans Editor module.
Lines 72-77 Link Here
72
 * @author  Sandeep Randhawa
81
 * @author  Sandeep Randhawa
73
 */
82
 */
74
class XMLResultItem implements CompletionItem {
83
class XMLResultItem implements CompletionItem {
84
    private static final Logger LOG = Logger.getLogger(XMLResultItem.class.getName());
75
    
85
    
76
    // text to be diplayed to user
86
    // text to be diplayed to user
77
    public final String displayText;
87
    public final String displayText;
Lines 304-328 Link Here
304
    protected CompletionTask doCreateDocumentationTask(final GrammarResult res) {
314
    protected CompletionTask doCreateDocumentationTask(final GrammarResult res) {
305
        return new CompletionTask() {
315
        return new CompletionTask() {
306
            public void query(CompletionResultSet resultSet) {
316
            public void query(CompletionResultSet resultSet) {
307
                if (res != null && res.getDescription() != null) {
317
                CompletionDocumentation cd = create();
308
                    resultSet.setDocumentation(new Docum(res.getDescription()));
318
                if (cd != null) {
309
    
319
                    resultSet.setDocumentation(cd);
310
                }
320
                }
311
                resultSet.finish();
321
                resultSet.finish();
312
            }
322
            }
313
            public void refresh(CompletionResultSet resultSet) {
323
            public void refresh(CompletionResultSet resultSet) {
314
                if (res != null && res.getDescription() != null) {
324
                query(resultSet);
315
                    resultSet.setDocumentation(new Docum(res.getDescription()));
316
                }
317
                resultSet.finish();
318
            }
325
            }
319
            public void cancel() {}
326
            public void cancel() {}
327
328
            
329
            private CompletionDocumentation create() {
330
                String doc;
331
                
332
                doc = res.getDescription();
333
                if (!(res instanceof DescriptionSource)) {
334
                    if (doc == null) {
335
                        return null;
336
                    }
337
                    return new Docum(doc);
338
                } else {
339
                    DescriptionSource ds = (DescriptionSource)res;
340
                    if (doc == null && ds.getContentURL() == null) {
341
                        return null;
342
                    }
343
                    return new ExtDocum(ds,  doc);
344
                }
345
            }
320
        };
346
        };
321
    }
347
    }
348
349
    /**
350
     * Extended documentation, based on the {@link DescriptionSource} SPI.
351
     */
352
    private static class ExtDocum extends URLDocum implements CompletionDocumentation {
353
        private DescriptionSource src;
354
        private String doc;
355
356
        ExtDocum(DescriptionSource src, String doc) {
357
            super(src.getContentURL(), src.isExternal());
358
            this.src = src;
359
            this.doc = doc;
360
        }
361
362
        @Override
363
        public String getText() {
364
            if (doc == null) {
365
                doc = src.getDescription();
366
                if (doc == null) {
367
                    doc = super.getText();
368
                }
369
            }
370
            return doc;
371
        }
372
373
        @Override
374
        public CompletionDocumentation resolveLink(String link) {
375
            try {
376
                DescriptionSource target = src.resolveLink(link);
377
                if (target != null) {
378
                    return new ExtDocum(target, null);
379
                }
380
                
381
                URL base = src.getContentURL();
382
                if (base == null) {
383
                    // sorry, cannot resolve.
384
                    return null;
385
                }
386
                
387
                URL targetURL = new URL(base, link);
388
                return new URLDocum(targetURL, src.isExternal());
389
            } catch (MalformedURLException ex) {
390
                Exceptions.printStackTrace(ex);
391
                return null;
392
            }
393
        }
394
395
        @Override
396
        public Action getGotoSourceAction() {
397
            return null;
398
        }
399
    }
400
    
401
    /**
402
     * Pure URL documentation item. Resolves links, if original URL was able
403
     * to open externally, the derived URLs do it as well.
404
     */
405
    private static class URLDocum implements CompletionDocumentation {
406
        URL content;
407
        boolean external;
408
        
409
        URLDocum(URL content, boolean external) {
410
            this.content = content;
411
            this.external = external;
412
        }
413
        
414
        URLDocum(boolean external) {
415
            this.external = external;
416
        }
417
418
        @Override
419
        public Action getGotoSourceAction() {
420
            return null;
421
        }
422
423
        @Override
424
        public String getText() {
425
            FileObject f = URLMapper.findFileObject(content);
426
            if (f != null) {
427
                try {
428
                    return new String(f.asBytes(), FileEncodingQuery.getEncoding(f));
429
                } catch (IOException x) {
430
                    LOG.log(Level.INFO, "Could not load " + content, x);
431
                }
432
            }
433
            return null;
434
        }
435
436
        @Override
437
        public URL getURL() {
438
            return external ? content : null;
439
        }
440
441
        @Override
442
        public CompletionDocumentation resolveLink(String link) {
443
            if (content == null) {
444
                return null;
445
            }
446
            try {
447
                return new URLDocum(new URL(content, link), external);
448
            } catch (MalformedURLException ex) {
449
                Exceptions.printStackTrace(ex);
450
                return null;
451
            }
452
        }
453
        
454
    }
322
    
455
    
323
    private static class Docum implements CompletionDocumentation {
456
    private static class Docum implements CompletionDocumentation {
324
        private String doc;
457
        private String doc;
325
458
        
326
        private Docum(String doc) {
459
        private Docum(String doc) {
327
            this.doc = doc;
460
            this.doc = doc;
328
        }
461
        }

Return to bug 199742