Class ModelAwareXMLValuesExtractor

java.lang.Object
org.ametys.plugins.repository.data.extractor.xml.ModelAwareXMLValuesExtractor
All Implemented Interfaces:
ModelAwareValuesExtractor, ValuesExtractor
Direct Known Subclasses:
ImportCDMFrValuesExtractor

This class provides methods to extract values from an XML document, using a model
  • Field Details

  • Constructor Details

  • Method Details

    • extractValues

      Description copied from interface: ModelAwareValuesExtractor
      Extracts the values of all items This method will create a View with the items present in the data source
      Specified by:
      extractValues in interface ModelAwareValuesExtractor
      Returns:
      the values of all items
      Throws:
      Exception - if an error occurs
    • _fillViewItemContainerFromXML

      protected void _fillViewItemContainerFromXML(Element element, ViewItemContainer viewItemContainer, ModelItemContainer modelItemContainer) throws Exception
      Fill the given view item container with the data found in the given element.
      Parameters:
      element - The DOM element containing the values
      viewItemContainer - The view item container to fill
      modelItemContainer - The model item containing the items that could be in the element
      Throws:
      Exception - if an error occurs
    • _fillViewItemContainerFromXML

      protected void _fillViewItemContainerFromXML(Element element, ViewItemContainer viewItemContainer, Collection<? extends ModelItemContainer> modelItemContainers) throws Exception
      Fill the given view item container with the data found in the given element.
      Parameters:
      element - The DOM element containing the values
      viewItemContainer - The view item container to fill
      modelItemContainers - The model items containing the items that could be in the element
      Throws:
      Exception - if an error occurs
    • _getModelItemFromNodeName

      protected Optional<ModelItem> _getModelItemFromNodeName(Element parent, String nodeName, Collection<? extends ModelItemContainer> modelItemContainers)
      Retrieves the model item corresponding to the given node name
      Parameters:
      parent - the DOM parent element
      nodeName - the node name
      modelItemContainers - the model item containers where to search for the model item
      Returns:
      the model item corresponding to the given node name
    • extractValues

      public Map<String,Object> extractValues(View view) throws Exception
      Description copied from interface: ModelAwareValuesExtractor
      Extracts the values of all items in the given view
      Specified by:
      extractValues in interface ModelAwareValuesExtractor
      Parameters:
      view - the view
      Returns:
      the values of all items in the given view
      Throws:
      Exception - if an error occurs
    • _extractValues

      protected Map<String,Object> _extractValues(Element currentElement, ViewItemContainer viewItemContainer, String prefix) throws Exception
      Extracts the values of all items in the given view item container
      Parameters:
      currentElement - the DOM element containing the values of the items in the container
      viewItemContainer - the view item container
      prefix - the path of the item represented by the view item container (prefix of all contained items)
      Returns:
      the values of all items in the given view item containers
      Throws:
      Exception - if an error occurs
    • _hasChildForAttribute

      protected boolean _hasChildForAttribute(Element element, String attributeName)
      Checks if the given element contains a child for the given attribute name
      Parameters:
      element - the element to check
      attributeName - the name of the attribute to search
      Returns:
      true if the element contains a child corresponding to the given attribute name, false otherwise
    • extractValue

      public <T> T extractValue(String dataPath) throws Exception
      Description copied from interface: ValuesExtractor
      Extracts the value at the given path
      Specified by:
      extractValue in interface ValuesExtractor
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      dataPath - the data path
      Returns:
      the value at the given path
      Throws:
      Exception - if an error occurs
    • _extractValue

      protected <T> T _extractValue(ModelItemContainer modelItemContainer, Element currentElement, String relativeDataPath, String prefix) throws Exception
      Extracts the value at the given path
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      modelItemContainer - The model item containing the item of the value to extract
      currentElement - the DOM element containing the model item container's values
      relativeDataPath - The data path relative to the model item container
      prefix - the path of the item represented by the model item container (prefix of all contained items)
      Returns:
      the value
      Throws:
      Exception - if an error occurs
    • _extractValue

      protected <T> T _extractValue(Collection<? extends ModelItemContainer> modelItemContainers, Element currentElement, String relativeDataPath, String prefix) throws Exception
      Extracts the value at the given path
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      modelItemContainers - The model items containing the item of the value to extract
      currentElement - the DOM element containing the model item containers' values
      relativeDataPath - The data path relative to the model item containers
      prefix - the path of the item represented by the model item containers (prefix of all contained items)
      Returns:
      the value
      Throws:
      Exception - if an error occurs
    • _extractElementValue

      protected <T> T _extractElementValue(Element parent, ElementDefinition definition, String prefix) throws Exception
      Extracts the value of the given element
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      parent - the DOM element of the element definition's parent
      definition - the element's definition
      prefix - the path of the element's parent
      Returns:
      the value
      Throws:
      Exception - if an error occurs
    • _extractElementValue

      protected <T> Object _extractElementValue(Element parent, ElementDefinition<T> definition, Optional<Object> additionalData) throws Exception
      Extracts the value of the given element
      Type Parameters:
      T - type of the element definition
      Parameters:
      parent - the DOM element of the element definition's parent
      definition - the element's definition
      additionalData - the additional data needed to extract the value
      Returns:
      the value
      Throws:
      Exception - if an error occurs
    • _extractGroupValues

      protected <T> T _extractGroupValues(Element parent, ModelViewItemGroup modelViewItemGroup, String dataName, String prefix) throws Exception
      Extracts the values of the given group
      Type Parameters:
      T - type of the values to retrieve (example: Map for a composite, List for a repeater
      Parameters:
      parent - the DOM element of the group's parent
      modelViewItemGroup - view item corresponding to the group
      dataName - the name of the data to extract
      prefix - the path of the group's parent
      Returns:
      the value
      Throws:
      Exception - if an error occurs