Class Context

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    ro.sync.contentcompletion.xml.WhatContextInParent, WhatElementsCanGoHereContext

    @API(type=EXTENDABLE,
         src=PRIVATE)
    public class Context
    extends java.lang.Object
    implements java.lang.Cloneable
    The context for a node contains:
    • elementStack - the stack with ContextElement up to the root. These represent the ancestors of the element for which the Context was built.
    • previousSiblingElements - the list with the ContextElement representing the siblings of the element for which the Context was built.
    • proxyNamespaceMapping - The mapping between namespace prefixes and URI's to the point where the Context was built.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Stack<ContextElement> elementStack
      The stack with the ContextElement objects, ancestors of the element for which the Context was built.
      protected java.util.List<ro.sync.xml.parser.IDValue> idValuesList
      The ID values list.
      protected ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider
      Creates a full SAX source over the document and other useful methods.
      protected java.util.List<ContextElement> nextSiblingElements
      The list of ContextElement objects representing the next siblings (in document order) of the element for which the Context was built.
      protected ProxyNamespaceMapping prefixNamespaceMapping
      The mapping between namespace prefixes and URI's determined to the point where the Context was built.
      protected java.util.List<ContextElement> previousSiblingElements
      The list of ContextElement objects representing the previous siblings (in document order) of the element for which the Context was built.
      protected org.xml.sax.XMLReader xmlReader
      The XMLReader used to create sources for executing XPath expressions in the Context.
    • Constructor Summary

      Constructors 
      Constructor Description
      Context()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      java.lang.String 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.
      boolean equals​(java.lang.Object obj)  
      java.util.List<java.lang.String> executeXPath​(java.lang.String expression, java.lang.String[] prefixNamespaceMappings)
      Executes an XPath 2.0 expression over a simplified version of the entire document, containing no text nodes for faster processing.
      java.util.List executeXPath​(java.lang.String expression, java.lang.String[] prefixNamespaceMappings, boolean useFullDocumentContent)
      Executes an XPath 2.0 expression over the current document.
      java.lang.String getDefaultAttributeValue​(ContextElement elementContext, java.lang.String attributeName)
      Returns the default value for the specified attribute and context element.
      java.util.Stack<ContextElement> getElementStack()
      Gets the stack of ContextElement representing the ancestors of the element for which the Context was built.
      java.util.List<ro.sync.xml.parser.IDValue> getIdValuesList()  
      java.util.List<ContextElement> getNextSiblingElements()
      Get the list of next sibling elements of the element the Context was built for.
      WARNING: The list must be treated as immutable, do not use the getter to modify it.
      ProxyNamespaceMapping getPrefixNamespaceMapping()
      Gets the mapping between namespace prefixes and URI's to the point the Context was built.
      java.util.List<ContextElement> getPreviousSiblingElements()
      Get the list of previous sibling elements of the element the Context was built for.
      WARNING: The list must be treated as immutable, do not use the getter to modify it.
      static java.lang.String[] getProxyNamespaceMapping​(Context context)
      Create the proxy-namespace mapping based on the current context.
      Attribute[] getRootAttributes()
      Get the list with the attributes of the root element.
      java.lang.String getSystemID()
      Get the system ID of the current document for which the context has been built..
      void pushContextElement​(ContextElement element, java.util.List<ContextElement> previousSiblingElements)
      Updates the context by adding the given element in the context.
      void setAdditionalContextInformationProvider​(ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider)
      Set the AdditionalContextInformationProvider used for creating a SAX source and other useful stuff.
      void setElementStack​(java.util.Stack<ContextElement> elementStack)
      Sets the stack consisting of ContextElement representing the ancestor elements of the element for which the Context was built.
      void setIdValuesList​(java.util.List<ro.sync.xml.parser.IDValue> idValuesList)  
      void setNextSiblingElements​(java.util.List<ContextElement> nextSiblingElements)
      Sets the list of ContextElement representing the next siblings (in document order) of the element the Context was built for.
      void setPrefixNamespaceMapping​(ProxyNamespaceMapping prefixNamespaceMapping)
      Sets the mapping between the namespace prefixes and URI's to the point where the Context was built.
      void setPreviousSiblingElements​(java.util.List<ContextElement> previousSiblingElements)
      Sets the list of ContextElement representing the previous siblings (in document order) of the element the Context was built for.
      void setXMLReader​(org.xml.sax.XMLReader xmlReader)
      Set the XMLReader used for creating a SAX source.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • elementStack

        protected java.util.Stack<ContextElement> elementStack
        The stack with the ContextElement objects, ancestors of the element for which the Context was built.
      • prefixNamespaceMapping

        protected ProxyNamespaceMapping prefixNamespaceMapping
        The mapping between namespace prefixes and URI's determined to the point where the Context was built.
      • previousSiblingElements

        protected java.util.List<ContextElement> previousSiblingElements
        The list of ContextElement objects representing the previous siblings (in document order) of the element for which the Context was built.
      • nextSiblingElements

        protected java.util.List<ContextElement> nextSiblingElements
        The list of ContextElement objects representing the next siblings (in document order) of the element for which the Context was built.
      • xmlReader

        protected org.xml.sax.XMLReader xmlReader
        The XMLReader used to create sources for executing XPath expressions in the Context.
      • infoProvider

        protected ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider
        Creates a full SAX source over the document and other useful methods.
      • idValuesList

        protected java.util.List<ro.sync.xml.parser.IDValue> idValuesList
        The ID values list.
    • Constructor Detail

      • Context

        public Context()
    • Method Detail

      • setElementStack

        public void setElementStack​(java.util.Stack<ContextElement> elementStack)
        Sets the stack consisting of ContextElement representing the ancestor elements of the element for which the Context was built. The root is always added the first on the stack.
        Parameters:
        elementStack - The stack of ancestor ContextElement.
      • getElementStack

        public java.util.Stack<ContextElement> getElementStack()
        Gets the stack of ContextElement representing the ancestors of the element for which the Context was built. The root is always added the first on the stack.
        Returns:
        The stack with the ancestor ContextElement.
      • setPrefixNamespaceMapping

        public void setPrefixNamespaceMapping​(ProxyNamespaceMapping prefixNamespaceMapping)
        Sets the mapping between the namespace prefixes and URI's to the point where the Context was built.
        Parameters:
        prefixNamespaceMapping - The new mapping to be set.
      • getPrefixNamespaceMapping

        public ProxyNamespaceMapping getPrefixNamespaceMapping()
        Gets the mapping between namespace prefixes and URI's to the point the Context was built.
        Returns:
        The mapping between namespace prefixes and URI's.
      • getRootAttributes

        public Attribute[] 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

        public void setPreviousSiblingElements​(java.util.List<ContextElement> previousSiblingElements)
        Sets the list of ContextElement representing the previous siblings (in document order) of the element the Context was built for.
        Parameters:
        previousSiblingElements - The list of previous sibling ContextElement.
      • getPreviousSiblingElements

        public java.util.List<ContextElement> getPreviousSiblingElements()
        Get the list of previous sibling elements of the element the Context 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 or empty list if no previous siblings exist for the current element.
      • setNextSiblingElements

        public void setNextSiblingElements​(java.util.List<ContextElement> nextSiblingElements)
        Sets the list of ContextElement representing the next siblings (in document order) of the element the Context was built for.
        Parameters:
        nextSiblingElements - The list of next sibling ContextElement.
      • getNextSiblingElements

        public java.util.List<ContextElement> getNextSiblingElements()
        Get the list of next sibling elements of the element the Context 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 or empty list if no next siblings exist for the current element.
      • executeXPath

        public java.util.List<java.lang.String> executeXPath​(java.lang.String expression,
                                                             java.lang.String[] prefixNamespaceMappings)
        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 the Context.
        Example:
        {"xsl", "http://www.w3.org/1999/XSL/Transform", "xsd", "http://www.w3.org/2001/XMLSchema"}
        Returns:
        A list of strings representing the XPath results, never null.
      • executeXPath

        public java.util.List executeXPath​(java.lang.String expression,
                                           java.lang.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 the Context.
        Example:
        {"xsl", "http://www.w3.org/1999/XSL/Transform", "xsd", "http://www.w3.org/2001/XMLSchema"}
        useFullDocumentContent - If false 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). if true 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

        public void setXMLReader​(org.xml.sax.XMLReader xmlReader)
        Set the XMLReader 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 new XMLReader.
      • setAdditionalContextInformationProvider

        public void setAdditionalContextInformationProvider​(ro.sync.contentcompletion.xml.AdditionalContextInformationProvider infoProvider)
        Set the AdditionalContextInformationProvider used for creating a SAX source and other useful stuff.
        Parameters:
        infoProvider - The new AdditionalContextInformationProvider.
      • pushContextElement

        public void pushContextElement​(ContextElement element,
                                       java.util.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

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
        See Also:
        Object.clone()
      • setIdValuesList

        public void setIdValuesList​(java.util.List<ro.sync.xml.parser.IDValue> idValuesList)
        Parameters:
        idValuesList - The list of string values representing all ID's collected from the XML document.
      • getIdValuesList

        public java.util.List<ro.sync.xml.parser.IDValue> getIdValuesList()
        Returns:
        Returns a list of string values representing all ID's collected from the XML document.
      • getSystemID

        public java.lang.String 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

        public java.lang.String 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

        public java.lang.String getDefaultAttributeValue​(ContextElement elementContext,
                                                         java.lang.String attributeName)
        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

        public static java.lang.String[] getProxyNamespaceMapping​(Context context)
        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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()