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 Summary
Modifier and TypeFieldDescriptionprotected XMLValuesExtractorAdditionalDataGetter
The getter that retrieves needed additional data by typesprotected Element
The DOM element containing the XML valuesprotected Collection<? extends ModelItemContainer>
The model of the extracted values -
Constructor Summary
ConstructorDescriptionModelAwareXMLValuesExtractor
(Element element, XMLValuesExtractorAdditionalDataGetter additionalDataGetter, Collection<? extends ModelItemContainer> modelItemContainers) Creates a model aware XML values extractorModelAwareXMLValuesExtractor
(Element element, XMLValuesExtractorAdditionalDataGetter additionalDataGetter, Model... models) Creates a model aware XML values extractor -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> Object
_extractElementValue
(Element parent, ElementDefinition<T> definition, Optional<Object> additionalData) Extracts the value of the given elementprotected <T> T
_extractElementValue
(Element parent, ElementDefinition definition, String prefix) Extracts the value of the given elementprotected <T> T
_extractGroupValues
(Element parent, ModelViewItemGroup modelViewItemGroup, String dataName, String prefix) Extracts the values of the given groupprotected <T> T
_extractValue
(Collection<? extends ModelItemContainer> modelItemContainers, Element currentElement, String relativeDataPath, String prefix) Extracts the value at the given pathprotected <T> T
_extractValue
(ModelItemContainer modelItemContainer, Element currentElement, String relativeDataPath, String prefix) Extracts the value at the given path_extractValues
(Element currentElement, ViewItemContainer viewItemContainer, String prefix) Extracts the values of all items in the given view item containerprotected void
_fillViewItemContainerFromXML
(Element element, ViewItemContainer viewItemContainer, Collection<? extends ModelItemContainer> modelItemContainers) Fill the given view item container with the data found in the given element.protected void
_fillViewItemContainerFromXML
(Element element, ViewItemContainer viewItemContainer, ModelItemContainer modelItemContainer) Fill the given view item container with the data found in the given element._getModelItemFromNodeName
(Element parent, String nodeName, Collection<? extends ModelItemContainer> modelItemContainers) Retrieves the model item corresponding to the given node nameprotected boolean
_hasChildForAttribute
(Element element, String attributeName) Checks if the given element contains a child for the given attribute name<T> T
extractValue
(String dataPath) Extracts the value at the given pathExtracts the values of all items This method will create aView
with the items present in the data sourceextractValues
(View view) Extracts the values of all items in the given view
-
Field Details
-
_element
The DOM element containing the XML values -
_additionalDataGetter
The getter that retrieves needed additional data by types -
_modelItemContainers
The model of the extracted values
-
-
Constructor Details
-
ModelAwareXMLValuesExtractor
public ModelAwareXMLValuesExtractor(Element element, XMLValuesExtractorAdditionalDataGetter additionalDataGetter, Model... models) Creates a model aware XML values extractor- Parameters:
element
- the DOM element containing the XML valuesadditionalDataGetter
- the getter that retrieves needed additional data by typesmodels
- the model of the extracted values
-
ModelAwareXMLValuesExtractor
public ModelAwareXMLValuesExtractor(Element element, XMLValuesExtractorAdditionalDataGetter additionalDataGetter, Collection<? extends ModelItemContainer> modelItemContainers) Creates a model aware XML values extractor- Parameters:
element
- the DOM element containing the XML valuesadditionalDataGetter
- the getter that retrieves needed additional data by typesmodelItemContainers
- the model of the extracted values
-
-
Method Details
-
extractValues
Description copied from interface:ModelAwareValuesExtractor
Extracts the values of all items This method will create aView
with the items present in the data source- Specified by:
extractValues
in interfaceModelAwareValuesExtractor
- 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 valuesviewItemContainer
- The view item container to fillmodelItemContainer
- 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 valuesviewItemContainer
- The view item container to fillmodelItemContainers
- 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 elementnodeName
- the node namemodelItemContainers
- the model item containers where to search for the model item- Returns:
- the model item corresponding to the given node name
-
extractValues
Description copied from interface:ModelAwareValuesExtractor
Extracts the values of all items in the given view- Specified by:
extractValues
in interfaceModelAwareValuesExtractor
- 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 containerviewItemContainer
- the view item containerprefix
- 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
Checks if the given element contains a child for the given attribute name- Parameters:
element
- the element to checkattributeName
- the name of the attribute to search- Returns:
true
if the element contains a child corresponding to the given attribute name,false
otherwise
-
extractValue
Description copied from interface:ValuesExtractor
Extracts the value at the given path- Specified by:
extractValue
in interfaceValuesExtractor
- 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 extractcurrentElement
- the DOM element containing the model item container's valuesrelativeDataPath
- The data path relative to the model item containerprefix
- 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 extractcurrentElement
- the DOM element containing the model item containers' valuesrelativeDataPath
- The data path relative to the model item containersprefix
- 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 parentdefinition
- the element's definitionprefix
- 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 parentdefinition
- the element's definitionadditionalData
- 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 parentmodelViewItemGroup
- view item corresponding to the groupdataName
- the name of the data to extractprefix
- the path of the group's parent- Returns:
- the value
- Throws:
Exception
- if an error occurs
-