Package ro.sync.contentcompletion.xml
Class Context
java.lang.Object
ro.sync.contentcompletion.xml.Context
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ro.sync.contentcompletion.xml.WhatContextInParent
,WhatElementsCanGoHereContext
The context for a node contains:
- elementStack - the stack with
ContextElement
up to the root. These represent the ancestors of the element for which theContext
was built. - previousSiblingElements - the list with the
ContextElement
representing the siblings of the element for which theContext
was built. - proxyNamespaceMapping - The mapping between namespace prefixes and URI's to the point
where the
Context
was built.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stack<ContextElement>
The stack with theContextElement
objects, ancestors of the element for which theContext
was built.protected List<ro.sync.xml.parser.IDValue>
The ID values list.protected ro.sync.contentcompletion.xml.AdditionalContextInformationProvider
Creates a full SAX source over the document and other useful methods.protected List<ContextElement>
The list ofContextElement
objects representing the next siblings (in document order) of the element for which theContext
was built.protected ProxyNamespaceMapping
The mapping between namespace prefixes and URI's determined to the point where theContext
was built.protected List<ContextElement>
The list ofContextElement
objects representing the previous siblings (in document order) of the element for which theContext
was built.protected XMLReader
TheXMLReader
used to create sources for executing XPath expressions in theContext
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Takes the position in the document where the content completion was invoked and converts it to an XPath expression that contains the path of elements.boolean
executeXPath
(String expression, String[] prefixNamespaceMappings) Executes an XPath 2.0 expression over a simplified version of the entire document, containing no text nodes for faster processing.executeXPath
(String expression, String[] prefixNamespaceMappings, boolean useFullDocumentContent) Executes an XPath 2.0 expression over the current document.getDefaultAttributeValue
(ContextElement elementContext, String attributeName) Returns the default value for the specified attribute and context element.Gets the stack ofContextElement
representing the ancestors of the element for which theContext
was built.List<ro.sync.xml.parser.IDValue>
Get the list of next sibling elements of the element theContext
was built for.
WARNING: The list must be treated as immutable, do not use the getter to modify it.Gets the mapping between namespace prefixes and URI's to the point theContext
was built.Get the list of previous sibling elements of the element theContext
was built for.
WARNING: The list must be treated as immutable, do not use the getter to modify it.static String[]
getProxyNamespaceMapping
(Context context) Create the proxy-namespace mapping based on the current context.Get the list with the attributes of the root element.Get the system ID of the current document for which the context has been built..void
pushContextElement
(ContextElement element, List<ContextElement> previousSiblingElements) Updates the context by adding the given element in the context.void
setAdditionalContextInformationProvider
(ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider) Set theAdditionalContextInformationProvider
used for creating a SAX source and other useful stuff.void
setElementStack
(Stack<ContextElement> elementStack) Sets the stack consisting ofContextElement
representing the ancestor elements of the element for which theContext
was built.void
setIdValuesList
(List<ro.sync.xml.parser.IDValue> idValuesList) void
setNextSiblingElements
(List<ContextElement> nextSiblingElements) Sets the list ofContextElement
representing the next siblings (in document order) of the element theContext
was built for.void
setPrefixNamespaceMapping
(ProxyNamespaceMapping prefixNamespaceMapping) Sets the mapping between the namespace prefixes and URI's to the point where theContext
was built.void
setPreviousSiblingElements
(List<ContextElement> previousSiblingElements) Sets the list ofContextElement
representing the previous siblings (in document order) of the element theContext
was built for.void
setXMLReader
(XMLReader xmlReader) Set theXMLReader
used for creating a SAX source.toString()
-
Field Details
-
elementStack
The stack with theContextElement
objects, ancestors of the element for which theContext
was built. -
prefixNamespaceMapping
The mapping between namespace prefixes and URI's determined to the point where theContext
was built. -
previousSiblingElements
The list ofContextElement
objects representing the previous siblings (in document order) of the element for which theContext
was built. -
nextSiblingElements
The list ofContextElement
objects representing the next siblings (in document order) of the element for which theContext
was built. -
xmlReader
TheXMLReader
used to create sources for executing XPath expressions in theContext
. -
infoProvider
protected ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProviderCreates a full SAX source over the document and other useful methods. -
idValuesList
The ID values list.
-
-
Constructor Details
-
Context
public Context()
-
-
Method Details
-
setElementStack
Sets the stack consisting ofContextElement
representing the ancestor elements of the element for which theContext
was built. The root is always added the first on the stack.- Parameters:
elementStack
- The stack of ancestorContextElement
.
-
getElementStack
Gets the stack ofContextElement
representing the ancestors of the element for which theContext
was built. The root is always added the first on the stack.- Returns:
- The stack with the ancestor
ContextElement
.
-
setPrefixNamespaceMapping
Sets the mapping between the namespace prefixes and URI's to the point where theContext
was built.- Parameters:
prefixNamespaceMapping
- The new mapping to be set.
-
getPrefixNamespaceMapping
Gets the mapping between namespace prefixes and URI's to the point theContext
was built.- Returns:
- The mapping between namespace prefixes and URI's.
-
getRootAttributes
Get the list with the attributes of the root element.- Returns:
- A list of
Attribute
objects representing the attributes of the root element.
-
setPreviousSiblingElements
Sets the list ofContextElement
representing the previous siblings (in document order) of the element theContext
was built for.- Parameters:
previousSiblingElements
- The list of previous siblingContextElement
.
-
getPreviousSiblingElements
Get the list of previous sibling elements of the element theContext
was built for.
WARNING: The list must be treated as immutable, do not use the getter to modify it.- Returns:
- The list of previous sibling
ContextElement
,null
orempty list
if no previous siblings exist for the current element.
-
setNextSiblingElements
Sets the list ofContextElement
representing the next siblings (in document order) of the element theContext
was built for.- Parameters:
nextSiblingElements
- The list of next siblingContextElement
.
-
getNextSiblingElements
Get the list of next sibling elements of the element theContext
was built for.
WARNING: The list must be treated as immutable, do not use the getter to modify it.- Returns:
- The list of next sibling
ContextElement
,null
orempty list
if no next siblings exist for the current element.
-
executeXPath
Executes an XPath 2.0 expression over a simplified version of the entire document, containing no text nodes for faster processing. The XML Reader over which the XPath is run does not contain any text nodes so this method is useful only for gathering attribute values which adhere to certain conditions (like //@id).- Parameters:
expression
- The XPath expression to be executed.prefixNamespaceMappings
- An array of prefixes followed by namespace URI's representing the namespace mappings to the point of theContext
.
Example:
{"xsl", "http://www.w3.org/1999/XSL/Transform", "xsd", "http://www.w3.org/2001/XMLSchema"}- Returns:
- A list of strings representing the text values of the matched XPath nodes, never
null
.
-
executeXPath
public List executeXPath(String expression, String[] prefixNamespaceMappings, boolean useFullDocumentContent) Executes an XPath 2.0 expression over the current document.- Parameters:
expression
- The XPath expression to be executed.prefixNamespaceMappings
- An array of prefixes followed by namespace URI's representing the namespace mappings to the point of theContext
.
Example:
{"xsl", "http://www.w3.org/1999/XSL/Transform", "xsd", "http://www.w3.org/2001/XMLSchema"}useFullDocumentContent
- Iffalse
the XML Reader over which the XPath is run does not contain any text nodes so this method is useful only for gathering attribute values which adhere to certain conditions (like //@id). iftrue
the reader will contain the entire XML document's information making it possible to also gather element values for example.- Returns:
- A list of DOM nodes or atomic values representing the XPath results, never
null
. - Since:
- 14
-
setXMLReader
Set theXMLReader
used for creating a SAX source. The content completion proposals for XSD and XSL documents are obtained by running XPath queries on this SAX source.- Parameters:
xmlReader
- The newXMLReader
.
-
setAdditionalContextInformationProvider
public void setAdditionalContextInformationProvider(ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider) Set theAdditionalContextInformationProvider
used for creating a SAX source and other useful stuff.- Parameters:
infoProvider
- The newAdditionalContextInformationProvider
.
-
pushContextElement
public void pushContextElement(ContextElement element, List<ContextElement> previousSiblingElements) Updates the context by adding the given element in the context. The new context can be used to get what elements can be added in the given element after the given previous children.- Parameters:
element
- Context element to be added.previousSiblingElements
- Previous siblings for the new insert position. They are children of the given element and the insertion position is after them.
-
clone
-
setIdValuesList
- Parameters:
idValuesList
- The list of string values representing all ID's collected from the XML document.
-
getIdValuesList
- Returns:
- Returns a list of string values representing all ID's collected from the XML document.
-
getSystemID
Get the system ID of the current document for which the context has been built..- Returns:
- The system ID of the current document
- Since:
- 14.1
-
computeContextXPathExpression
Takes the position in the document where the content completion was invoked and converts it to an XPath expression that contains the path of elements. /TEI[1]/body[1]/p[2]- Returns:
- An XPath expression that when executed on the document it will return the element in which the content completion was invoked.
-
getDefaultAttributeValue
Returns the default value for the specified attribute and context element.- Parameters:
elementContext
- The context element.attributeName
- The name of the attribute.- Returns:
- The default value of the attribute. Can be
null
-
getProxyNamespaceMapping
Create the proxy-namespace mapping based on the current context.- Parameters:
context
- The context where the handler is invoked.- Returns:
- An array containing the prefixes on even positions and the corresponding namespace URI on the following odd position.
-
equals
-
toString
-