org.netbeans.modules.xml.api.model |
XML Code Completion
XML Model SPIs
The SPI defines an interface of GrammarQuery provider.
Once registered (the registration methods depends on particular
client) it can reply to queries that can be resolved with a
grammar knowledge. It reuses DOM interfaces for context definition
however their semantics can be slightly changed. Most notably the DOM
is read-only and may throw DOMException.UNSUPPORTED_OPERATION from
more methods than defined by DOM IDLs.
How to Register a Provider
Default GrammarQuery registration mechanism uses
Lookup. Modules providing an implementation can register
{@link org.netbeans.modules.xml.api.model.GrammarQueryManager} at default filesystem. Such
registration can be than located by clients using
{@link org.netbeans.modules.xml.api.model.GrammarQueryManager#getDefault} which returns
an implementation proxing to registered ones.
XML Code Completion ("XCC") SPI Requirements
XML Phenomens to be Completed
- pairing end tag (must be solved by a client)
- element name and content
- attribute name and value (enumerated, ...)
- namespace prefix (namespaces declared)
- general reference name
- parameter reference name
- prolog content (must be solved by a client)
XCC Context
All bellow can be described by read-only DOM Node context.
- Current namespace (possibly derived from parents)
- Parents
- Siblings
- Attributes (what about default ones)
Document content that is not described by DOM Node that must be extra handled
by a client:
- Entity Prolog
- extra handling is easy no grammar required
- DTD Stuff
- what about it? exclude this support in GrammarQuery
Document DTD if any (note it is a responsibility of a binder)
XCC Interface
XCC behaviour should be pluggable, XML module should provide
a default implementation for:
- well formed document
- document history based completion (at least pairing tags)
- DTD grammar based completion
- content is forced by a DTD grammar
- Schema grammar based completion
- must be namespace aware
Particular XCC plugins can add some well-known global attributes at element content or
can provide information that is not provided by grammar (Ant task names and content)
or can handle new type of grammar.
Integration with Text Editor
Text editor must provide its context as virtual read-only Node representing
just edited phenomenon (therefore itself invalid).
Narrowing Context
Node context can be narrowed by knowledge of characters precending caret.
- whitespace in content
- complete element name, the first option is pairing end tag
- <ns:prefix
- complete element name starting with the prefix defined in given ns (detect that document use : for ordinary naming)
- </prefix
- complete pairing end tag starting with prefix
- <prefix
- complete element name or namespace starting with the prefix
- [prefix after] whitespace in element start tag markup
- complete namespace prefix of attribute name (global)
- &prefix
- list all declared general entities starting with prefix
- pseudo attribute name in prolog
- complete one of: version, standalone, encoding
- pseudo attribute value in prolog
- complete from list of known values (encodings)
Integration with Tree Editor
Narrowing Context
All particular text field values may be used as prefix, but in this mode
all other values can be hidden.
http://xml.netbeans.org/issues/show_bug.cgi?id=14296
|
Java Source File Name | Type | Comment |
DTDUtil.java | Class | |
ExtendedGrammarQuery.java | Interface | This class instance is returned by DTDGrammarQueryProvider.getGrammar(GrammarEnvironment env) method.
It is used in xml/text-edit module by GrammarManager class to obtain a list of external entities
resolved during the DTD parsing. |
GrammarEnvironment.java | Class | Grammar environment provides grammar factory with a context.
All returned object must be treated as read-only. |
GrammarQuery.java | Interface | A query interface returning possible fenomens as given by document grammar.
It provides at specified HintContext following information:
- allowed element names and namespaces
- allowed entity names
- allowed notation names
- allowed attribute names
- allowed values of attribute values or element content
This information are returned as Enumeration . |
GrammarQueryManager.java | Class | GrammarQuery service provider definition. |
GrammarQueryManagerTest.java | Class | The test always fails because you cannot register
test class in lookup using layer. |
GrammarResult.java | Interface | It represents additonal properties of a result option.
It enriches DOM Node with information useful for presenting
query result option to a user. |
HintContext.java | Interface | Completion context description that holds additional context information. |
SampleGrammarQueryManager.java | Class | |