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.

Bug 169254

Summary: XML Schema code completion not working in editor
Product: xml Reporter: kitfox <kitfox>
Component: Schema ToolsAssignee: Svata Dedic <sdedic>
Status: RESOLVED WONTFIX    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description kitfox 2009-07-27 18:41:58 UTC
I've created a MultiView component based on an XML file which provides a 
pane with an editor for the XML.  The editor currently lets me edit the 
content as a well-formed XML document.  Since I have a Schema which 
describes the content, it would be nice to use NB's code completion 
features when editing the document in the editor pane.

I followed the tutorial here, but it's not working:
http://blogs.sun.com/vivek/entry/schema_based_code_completion_tutorial

Below is the code I'm using to create my catalog.  The XSD itself is 
stored in a jar that's been wrapped by a NB module wrapper.  When I am 
in the editor pane and press <CTRL-Space>, the 
XMLCatalogEntry.resolveEntity() method is called, and it correctly loads 
and returns the input source.  However, the editor still does not 
provide code completion.  (<CTRL-Space> pops up "No Suggestions").

Any idea how I can get things working?

I've added this to my layer.xml file:
[code]
   <folder name="Plugins">
        <folder name="XML">
            <folder name="UserCatalogs">
                <file 
name="com-kitfox-nb-itemTable-ItemTableSchemaResolver.instance">
                    <attr name="instanceCreate" 
newvalue="com.kitfox.nb.itemTable.ItemTableSchemaResolver"/>
                    <attr name="instanceOf" 
stringvalue="org.netbeans.modules.xml.catalog.spi.CatalogReader"/>
                </file>
            </folder>
        </folder>
    </folder>
[/code]


This is the xml file itself:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<itemTable xmlns="http://xml.kitfox.com/schema/itemTable"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="nbres:/com/kitfox/item/asset/itemTable.xsd 
itemTable.xsd">
<item name="foo">
</item>
</itemTable>
[/code]


This is the class referenced by the layer:
[code]
public class ItemTableSchemaResolver extends XMLCatalogEntry
{
    public ItemTableSchemaResolver()
    {
        super("itemTable.xsd",
                "http://xml.kitfox.com/schema/itemTable",
                ItemTableAsset.class.getResource("itemTable.xsd"));
    }
}
[/code]


And this is a generic root class (stored in a different module):
[code]
public class XMLCatalogEntry implements CatalogReader, 
CatalogDescriptor, EntityResolver
{
    static final String ICON_PATH = "com/kitfox/game/asset/nb/api/book.png";

    final String shortName;
    final String namespace;
    final URL schemaUrl;
    final String id;

    /** Creates a new instance of XMLCatalogEntry */
    public XMLCatalogEntry(String shortName, String namespace, URL 
schemaUrl)
    {
        this.shortName = shortName;
        this.namespace = namespace;
        this.schemaUrl = schemaUrl;
        this.id = "SCHEMA:" + namespace;
    }

    @Override
    public Iterator getPublicIDs() {
        List<String> list = new ArrayList<String>();
        list.add(id);

        return list.listIterator();
    }

    @Override
    public void refresh() {
    }

    @Override
    public String getSystemID(String publicId) {
        if(publicId.equals(id)) {
            return schemaUrl.toString();
        } else {
            return null;
        }
    }

    @Override
    public String resolveURI(String string) {
        return null;
    }

    @Override
    public String resolvePublic(String string) {
        return null;
    }

    @Override
    public void addCatalogListener(CatalogListener catalogListener) {
    }

    @Override
    public void removeCatalogListener(CatalogListener catalogListener) {
    }

    @Override
    public Image getIcon(int i)
    {
        return ImageUtilities.loadImage(ICON_PATH, true);
    }

    @Override
    public String getDisplayName() {
        return "Generic XML Schema Catalog";
    }

    @Override
    public String getShortDescription() {
        return "XML Catalog for Generic Schema";
    }

    @Override
    public void addPropertyChangeListener(PropertyChangeListener 
propertyChangeListener) {
    }

    @Override
    public void removePropertyChangeListener(PropertyChangeListener 
propertyChangeListener) {
    }

    @Override
    public InputSource resolveEntity(String publicId, String systemId) 
throws SAXException, IOException {
        if (systemId != null)
        {
            if (namespace.equals(systemId) || systemId.endsWith(shortName))
            {
                InputSource source = new 
InputSource(schemaUrl.openStream());
                source.setSystemId(systemId);
                return source;
            }
        }

        return null;
    }
}
[/code]
Comment 1 kitfox 2009-07-27 18:43:27 UTC
One more thing:

I get the following exception when I run NB with my catalog is installed
and a file which uses is open in the editor.  newItemTemplate.xml is the
name of a file which implements the schema I am trying to expose.


Caused: java.io.FileNotFoundException:
C:\Users\kitfox\AppData\Local\Temp\vcs-1248470790563\newItemTemplate.xml
(The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at
org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObj$2.<init>(FileObj.java:144)
        at
org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObj.getInputStream(FileObj.java:143)
Caused: java.io.FileNotFoundException:
C:\Users\kitfox\AppData\Local\Temp\vcs-1248470790563\newItemTemplate.xml
(The system cannot find the path specified)
        at
org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObj.getInputStream(FileObj.java:156)
        at
org.openide.text.DataEditorSupport$Env.inputStream(DataEditorSupport.java:686)
        at
org.openide.text.CloneableEditorSupport.loadDocument(CloneableEditorSupport.java:1972)
        at
org.openide.text.CloneableEditorSupport.access$2500(CloneableEditorSupport.java:120)
        at
org.openide.text.CloneableEditorSupport$Listener.run(CloneableEditorSupport.java:2742)
        at
org.openide.text.CloneableEditorSupport$2.doRun(CloneableEditorSupport.java:636)
        at
org.openide.text.CloneableEditorSupport$2.run(CloneableEditorSupport.java:607)
        at
org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:324)
        at org.openide.text.NbDocument.runAtomic(NbDocument.java:384)
        at
org.openide.text.CloneableEditorSupport$2.doRun(CloneableEditorSupport.java:617)
        at
org.openide.text.CloneableEditorSupport$2.run(CloneableEditorSupport.java:607)
        at
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
[catch] at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
ALL [null]:
C:\Users\kitfox\AppData\Local\Temp\vcs-1248470790563\newItemTemplate.xml
(The system cannot find the path specified)
ALL [null]: The document  could not be loaded.
Comment 2 kitfox 2009-09-02 07:22:32 UTC
Have you had a chance to look at this?  Please let me know if there is a way to enable XML code completion.
Comment 3 _ alexpetrov 2009-09-02 16:49:20 UTC
Unfortunately I didn't look at this bug yet, I'm afraid that fixes for bugs related to XML code completion based on XML
schema won't be produced very quickly.
Comment 4 Martin Balin 2016-07-07 09:56:50 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss