Class ModelAwareXMLValuesExtractor
- java.lang.Object
-
- org.ametys.plugins.repository.data.extractor.xml.ModelAwareXMLValuesExtractor
-
- All Implemented Interfaces:
ModelAwareValuesExtractor
,ValuesExtractor
public class ModelAwareXMLValuesExtractor extends Object implements ModelAwareValuesExtractor
This class provides methods to extract values from an XML document, using a model
-
-
Field Summary
Fields Modifier and Type Field Description protected XMLValuesExtractorAdditionalDataGetter
_additionalDataGetter
The getter that retrieves needed additional data by typesprotected Element
_element
The DOM element containing the XML valuesprotected Collection<? extends ModelItemContainer>
_modelItemContainers
The model of the extracted values
-
Constructor Summary
Constructors Constructor Description ModelAwareXMLValuesExtractor(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <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 pathprotected Map<String,Object>
_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.<T> T
extractValue(String dataPath)
Extracts the value at the given pathMap<String,Object>
extractValues()
Extracts the values of all items This method will create aView
with the items present in the data sourceMap<String,Object>
extractValues(View view)
Extracts the values of all items in the given view
-
-
-
Field Detail
-
_additionalDataGetter
protected XMLValuesExtractorAdditionalDataGetter _additionalDataGetter
The getter that retrieves needed additional data by types
-
_modelItemContainers
protected Collection<? extends ModelItemContainer> _modelItemContainers
The model of the extracted values
-
-
Constructor Detail
-
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 Detail
-
extractValues
public Map<String,Object> extractValues() throws Exception
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
-
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 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
-
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 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
-
_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
-
-